View Javadoc
1   /*
2    * Copyright (c) 2002-2025 Gargoyle Software Inc.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * https://www.apache.org/licenses/LICENSE-2.0
8    *
9    * Unless required by applicable law or agreed to in writing, software
10   * distributed under the License is distributed on an "AS IS" BASIS,
11   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12   * See the License for the specific language governing permissions and
13   * limitations under the License.
14   */
15  package org.htmlunit.javascript.host;
16  
17  import org.htmlunit.WebDriverTestCase;
18  import org.htmlunit.javascript.host.xml.XMLDocumentTest;
19  import org.htmlunit.junit.BrowserRunner;
20  import org.htmlunit.junit.annotation.Alerts;
21  import org.htmlunit.junit.annotation.HtmlUnitNYI;
22  import org.htmlunit.util.MimeType;
23  import org.junit.Test;
24  import org.junit.runner.RunWith;
25  
26  /**
27   * Tests for {@link Element}.
28   *
29   * @author Ahmed Ashour
30   * @author Marc Guillemot
31   * @author Ronald Brill
32   * @author Frank Danek
33   * @author Anton Demydenko
34   */
35  @RunWith(BrowserRunner.class)
36  public class ElementTest extends WebDriverTestCase {
37  
38      /**
39       * @throws Exception if the test fails
40       */
41      @Test
42      @Alerts({"1", "attrName attrValue", "attrValue", "null", "anotherValue",
43               "1", "4", "<span id='label'>changed</span>"})
44      public void attributes() throws Exception {
45          final String html = DOCTYPE_HTML
46              + "<html><head><script>\n"
47              + LOG_TITLE_FUNCTION
48              + "  function test() {\n"
49              + "    var doc = " + XMLDocumentTest.callLoadXMLDocumentFromFile("'foo.xml'") + ";\n"
50              + "    var attributes = doc.documentElement.attributes;\n"
51              + "    log(attributes.length);\n"
52              + "    log(attributes[0].name + ' ' + attributes[0].value);\n"
53              + "    var root = doc.documentElement;\n"
54              + "    log(root.getAttribute('attrName'));\n"
55              + "    log(root.getAttribute('notExisting'));\n"
56              + "    root.setAttribute('attrName', 'anotherValue');\n"
57              + "    log(root.getAttribute('attrName'));\n"
58              + "    log(root.getElementsByTagName('book').length);\n"
59              + "    var description = root.getElementsByTagName('description')[0];\n"
60              + "    log(description.firstChild.nodeType);\n"
61              + "    log(description.firstChild.nodeValue);\n"
62              + "  }\n"
63              + XMLDocumentTest.LOAD_XML_DOCUMENT_FROM_FILE_FUNCTION
64              + "</script></head><body onload='test()'>\n"
65              + "</body></html>";
66  
67          final String xml
68              = "<books attrName=\"attrValue\">\n"
69              + "  <book>\n"
70              + "    <title>Immortality</title>\n"
71              + "    <author>John Smith</author>\n"
72              + "    <description><![CDATA[<span id='label'>changed</span>]]></description>\n"
73              + "  </book>\n"
74              + "</books>";
75  
76          getMockWebConnection().setDefaultResponse(xml, MimeType.TEXT_XML);
77          loadPageVerifyTitle2(html);
78      }
79  
80      /**
81       * @throws Exception if the test fails
82       */
83      @Test
84      @Alerts("TypeError")
85      public void selectNodes() throws Exception {
86          final String html = DOCTYPE_HTML
87              + "<html><head><script>\n"
88              + LOG_TITLE_FUNCTION
89              + "  function test() {\n"
90              + "    var doc = " + XMLDocumentTest.callLoadXMLDocumentFromFile("'" + URL_SECOND + "'") + ";\n"
91              + "    try {\n"
92              + "      var nodes = doc.documentElement.selectNodes('//title');\n"
93              + "      log(nodes.length);\n"
94              + "      log(nodes[0].tagName);\n"
95              + "    } catch(e) { logEx(e); }\n"
96              + "  }\n"
97              + XMLDocumentTest.LOAD_XML_DOCUMENT_FROM_FILE_FUNCTION
98              + "</script></head><body onload='test()'>\n"
99              + "</body></html>";
100 
101         final String xml
102             = "<books>\n"
103             + "  <book>\n"
104             + "    <title>Immortality</title>\n"
105             + "    <author>John Smith</author>\n"
106             + "  </book>\n"
107             + "</books>";
108 
109         getMockWebConnection().setDefaultResponse(xml, MimeType.TEXT_XML);
110         loadPageVerifyTitle2(html);
111     }
112 
113     /**
114      * @throws Exception if the test fails
115      */
116     @Test
117     @Alerts({"2", "1"})
118     public void removeChild() throws Exception {
119         final String html = DOCTYPE_HTML
120             + "<html><head><script>\n"
121             + LOG_TITLE_FUNCTION
122             + "  function test() {\n"
123             + "    var doc = " + XMLDocumentTest.callLoadXMLDocumentFromFile("'" + URL_SECOND + "'") + ";\n"
124             + "    var parent = doc.documentElement.firstChild;\n"
125             + "    log(parent.childNodes.length);\n"
126             + "    parent.removeChild(parent.firstChild);\n"
127             + "    log(parent.childNodes.length);\n"
128             + "  }\n"
129             + XMLDocumentTest.LOAD_XML_DOCUMENT_FROM_FILE_FUNCTION
130             + "</script></head><body onload='test()'>\n"
131             + "</body></html>";
132 
133         final String xml = "<books><book><title>Immortality</title><author>John Smith</author></book></books>";
134 
135         getMockWebConnection().setDefaultResponse(xml, MimeType.TEXT_XML);
136         loadPageVerifyTitle2(html);
137     }
138 
139     /**
140      * @throws Exception if the test fails
141      */
142     @Test
143     @Alerts({"lbl_SettingName", "outerHTML", "undefined"})
144     public void getAttributeNode() throws Exception {
145         final String html = DOCTYPE_HTML
146             + "<html><head><script>\n"
147             + LOG_TITLE_FUNCTION
148             + "  function test() {\n"
149             + "    var doc = " + XMLDocumentTest.callLoadXMLDocumentFromFile("'" + URL_SECOND + "'") + ";\n"
150             + "    parseXML(doc);\n"
151             + "  }\n"
152             + "  function parseXML(xml) {\n"
153             + "    if (xml.documentElement.hasChildNodes()) {\n"
154             + "      for (var i = 0; i < xml.documentElement.childNodes.length; i++) {\n"
155             + "        var elem = xml.documentElement.childNodes.item(i);\n"
156             + "        if (elem.nodeName == 'control') {\n"
157             + "          var target = elem.getAttributeNode('id').value;\n"
158             + "          if(document.all(target) != null) {\n"
159             + "            for (var j = 0; j < elem.childNodes.length; j++) {\n"
160             + "              var node = elem.childNodes.item(j);\n"
161             + "              if (node.nodeName == 'tag') {\n"
162             + "                var type = node.getAttributeNode('type').value;\n"
163             + "                log(target);\n"
164             + "                log(type);\n"
165             + "                log(node.text);\n"
166             + "                eval('document.all(\"' + target + '\").' + type + '=\"' + node.text + '\"');\n"
167             + "              }\n"
168             + "            }\n"
169             + "          }\n"
170             + "        }\n"
171             + "      }\n"
172             + "    }\n"
173             + "  }\n"
174             + XMLDocumentTest.LOAD_XML_DOCUMENT_FROM_FILE_FUNCTION
175             + "</script></head><body onload='test()'>\n"
176             + "  <div id='lbl_SettingName'/>\n"
177             + "</body></html>";
178 
179         final String xml
180             = "<responsexml>\n"
181             + "  <control id='lbl_SettingName'>\n"
182             + "    <tag type='outerHTML'><span id='lbl_SettingName' class='lbl-white-001'>Item</span></tag>\n"
183             + "  </control>\n"
184             + "</responsexml>";
185 
186         getMockWebConnection().setDefaultResponse(xml, MimeType.TEXT_XML);
187         loadPageVerifyTitle2(html);
188     }
189 
190     /**
191      * @throws Exception if the test fails
192      */
193     @Test
194     @Alerts({"book", "TypeError"})
195     public void selectNode_root() throws Exception {
196         final String html = DOCTYPE_HTML
197             + "<html><head><script>\n"
198             + LOG_TITLE_FUNCTION
199             + "  function test() {\n"
200             + "    var doc = " + XMLDocumentTest.callLoadXMLDocumentFromFile("'" + URL_SECOND + "'") + ";\n"
201             + "    var child = doc.documentElement.firstChild;\n"
202             + "    log(child.tagName);\n"
203             + "    try {\n"
204             + "      log(child.selectNodes('/title').length);\n"
205             + "      log(child.selectNodes('title').length);\n"
206             + "    } catch(e) { logEx(e); }\n"
207             + "  }\n"
208             + XMLDocumentTest.LOAD_XML_DOCUMENT_FROM_FILE_FUNCTION
209             + "</script></head><body onload='test()'>\n"
210             + "</body></html>";
211 
212         final String xml = "<books><book><title>Immortality</title><author>John Smith</author></book></books>";
213 
214         getMockWebConnection().setDefaultResponse(xml, MimeType.TEXT_XML);
215         loadPageVerifyTitle2(html);
216     }
217 
218     /**
219      * @throws Exception if the test fails
220      */
221     @Test
222     @Alerts({"1", "1"})
223     public void getElementsByTagNameNS() throws Exception {
224         final String html = DOCTYPE_HTML
225             + "<html><head><script>\n"
226             + LOG_TITLE_FUNCTION
227             + "  function test() {\n"
228             + "    var text='<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\\n';\n"
229             + "    text += '<xsl:stylesheet version=\"1.0\" xmlns:xsl=\"http://myNS\">\\n';\n"
230             + "    text += '  <xsl:template match=\"/\">\\n';\n"
231             + "    text += '  <html>\\n';\n"
232             + "    text += '    <body>\\n';\n"
233             + "    text += '    </body>\\n';\n"
234             + "    text += '  </html>\\n';\n"
235             + "    text += '  </xsl:template>\\n';\n"
236             + "    text += '</xsl:stylesheet>';\n"
237             + "    var doc = " + XMLDocumentTest.callLoadXMLDocumentFromString("text") + ";\n"
238             + "    try {\n"
239             + "      log(doc.documentElement.getElementsByTagNameNS('http://myNS', 'template').length);\n"
240             + "      log(doc.documentElement.getElementsByTagNameNS(null, 'html').length);\n"
241             + "    } catch(e) { logEx(e); }\n"
242             + "  }\n"
243             + XMLDocumentTest.LOAD_XML_DOCUMENT_FROM_STRING_FUNCTION
244             + "</script></head><body onload='test()'>\n"
245             + "</body></html>";
246 
247         loadPageVerifyTitle2(html);
248     }
249 
250     /**
251      * @throws Exception if the test fails
252      */
253     @Test
254     @Alerts({"1", "2", "3"})
255     public void getElementsByTagNameNSAsterisk() throws Exception {
256         final String html = DOCTYPE_HTML
257             + "<html><head><script>\n"
258             + LOG_TITLE_FUNCTION
259             + "  function test() {\n"
260             + "    var text='<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\\n';\n"
261             + "    text += '<xsl:stylesheet version=\"1.0\" xmlns:xsl=\"http://myNS\">\\n';\n"
262             + "    text += '  <xsl:template match=\"/\">\\n';\n"
263             + "    text += '  <html>\\n';\n"
264             + "    text += '    <body>\\n';\n"
265             + "    text += '    </body>\\n';\n"
266             + "    text += '  </html>\\n';\n"
267             + "    text += '  </xsl:template>\\n';\n"
268             + "    text += '</xsl:stylesheet>';\n"
269             + "    var doc = " + XMLDocumentTest.callLoadXMLDocumentFromString("text") + ";\n"
270             + "    try {\n"
271             + "      log(doc.documentElement.getElementsByTagNameNS('http://myNS', '*').length);\n"
272             + "      log(doc.documentElement.getElementsByTagNameNS(null, '*').length);\n"
273             + "      log(doc.documentElement.getElementsByTagNameNS('*', '*').length);\n"
274             + "    } catch(e) { logEx(e); }\n"
275             + "  }\n"
276             + XMLDocumentTest.LOAD_XML_DOCUMENT_FROM_STRING_FUNCTION
277             + "</script></head><body onload='test()'>\n"
278             + "</body></html>";
279 
280         loadPageVerifyTitle2(html);
281     }
282 
283     /**
284      * @throws Exception if an error occurs
285      */
286     @Test
287     @Alerts({"2", "<nested>Three</nested>", "Four", "1", "Two", "0", "0"})
288     public void getElementsByTagNameXml() throws Exception {
289         final String html = DOCTYPE_HTML
290             + "<html><head>\n"
291             + "<meta http-equiv='X-UA-Compatible' content='IE=edge'>\n"
292             + "</head><body>\n"
293             + "<script>\n"
294             + LOG_TITLE_FUNCTION
295             + "  var xmlString = [\n"
296             + "                 '<ResultSet>',\n"
297             + "                 '<Result>One</Result>',\n"
298             + "                 '<RESULT>Two</RESULT>',\n"
299             + "                 '<result><nested>Three</nested></result>',\n"
300             + "                 '<result>Four</result>',\n"
301             + "                 '</ResultSet>'\n"
302             + "                ].join('');\n"
303             + "  var parser = new DOMParser();\n"
304             + "  xml = parser.parseFromString(xmlString, 'text/xml');\n"
305             + "  var xmlDoc = parser.parseFromString(xmlString, 'text/xml');\n"
306             + "  var de = xmlDoc.documentElement;\n"
307             + "  try {\n"
308 
309             + "    var res = de.getElementsByTagName('result');\n"
310             + "    log(res.length);\n"
311             + "    log(res[0].innerHTML);\n"
312             + "    log(res[1].innerHTML);\n"
313 
314             + "    res = de.getElementsByTagName('RESULT');\n"
315             + "    log(res.length);\n"
316             + "    log(res[0].innerHTML);\n"
317 
318             + "    res = de.getElementsByTagName('resulT');\n"
319             + "    log(res.length);\n"
320 
321             + "    res = de.getElementsByTagName('rEsulT');\n"
322             + "    log(res.length);\n"
323             + "  } catch(e) { logEx(e); }\n"
324             + "</script></body></html>";
325 
326         loadPageVerifyTitle2(html);
327     }
328 
329     /**
330      * @throws Exception if the test fails
331      */
332     @Test
333     @Alerts("false")
334     public void hasAttribute() throws Exception {
335         final String html = DOCTYPE_HTML
336             + "<html><head><script>\n"
337             + LOG_TITLE_FUNCTION
338             + "  function test() {\n"
339             + "    var doc = " + XMLDocumentTest.callLoadXMLDocumentFromFile("'foo.xml'") + ";\n"
340             + "    if (!doc.documentElement.hasAttribute) { log('hasAttribute not available'); return }\n"
341             + "    log(doc.documentElement.hasAttribute('something'));\n"
342             + "  }\n"
343             + XMLDocumentTest.LOAD_XML_DOCUMENT_FROM_FILE_FUNCTION
344             + "</script></head><body onload='test()'>\n"
345             + "</body></html>";
346 
347         final String xml
348             = "<books>\n"
349             + "  <book>\n"
350             + "    <title>Immortality</title>\n"
351             + "    <author>John Smith</author>\n"
352             + "  </book>\n"
353             + "</books>";
354 
355         getMockWebConnection().setDefaultResponse(xml, MimeType.TEXT_XML);
356         loadPageVerifyTitle2(html);
357     }
358 
359     /**
360      * @throws Exception if the test fails
361      */
362     @Test
363     @Alerts("true")
364     public void attributes2() throws Exception {
365         final String html = DOCTYPE_HTML
366             + "<html><head><script>\n"
367             + LOG_TITLE_FUNCTION
368             + "  function test() {\n"
369             + "    var doc = " + XMLDocumentTest.callLoadXMLDocumentFromFile("'foo.xml'") + ";\n"
370             + "    log(doc.documentElement.attributes.getNamedItem('library') != undefined);\n"
371             + "  }\n"
372             + XMLDocumentTest.LOAD_XML_DOCUMENT_FROM_FILE_FUNCTION
373             + "</script></head><body onload='test()'>\n"
374             + "</body></html>";
375 
376         final String xml
377             = "<books library=\"Hope\">\n"
378             + "  <book>\n"
379             + "    <title>Immortality</title>\n"
380             + "    <author>John Smith</author>\n"
381             + "  </book>\n"
382             + "</books>";
383 
384         getMockWebConnection().setDefaultResponse(xml, MimeType.TEXT_XML);
385         loadPageVerifyTitle2(html);
386     }
387 
388     /**
389      * @throws Exception if the test fails
390      */
391     @Test
392     @Alerts({"undefined", "undefined"})
393     public void xml() throws Exception {
394         final String html = DOCTYPE_HTML
395             + "<html><head><script>\n"
396             + LOG_TITLE_FUNCTION
397             + "function test() {\n"
398             + "  var text = '<a><b c=\"d\">e</b></a>';\n"
399             + "  var doc = " + XMLDocumentTest.callLoadXMLDocumentFromString("text") + ";\n"
400             + "  log(doc.xml);\n"
401             + "  log(doc.documentElement.xml);\n"
402             + "}\n"
403             + XMLDocumentTest.LOAD_XML_DOCUMENT_FROM_STRING_FUNCTION
404             + "</script></head><body onload='test()'>\n"
405             + "</body></html>";
406 
407         loadPageVerifyTitle2(html);
408     }
409 
410     /**
411      * @throws Exception if the test fails
412      */
413     @Test
414     @Alerts({"[object HTMLDivElement],DIV",
415                 "[object HTMLUnknownElement],APP:DIV",
416                 "[object Element],app:dIv",
417                 "[object HTMLDivElement],DIV",
418                 "[object HTMLUnknownElement],APP:DIV"})
419     public void html_nodeName() throws Exception {
420         html("nodeName");
421     }
422 
423     /**
424      * @throws Exception if the test fails
425      */
426     @Test
427     @Alerts({"[object HTMLDivElement],DIV",
428                 "[object HTMLUnknownElement],APP:DIV",
429                 "[object Element],app:dIv",
430                 "[object HTMLDivElement],DIV",
431                 "[object HTMLUnknownElement],APP:DIV"})
432     public void html_tagName() throws Exception {
433         html("tagName");
434     }
435 
436     /**
437      * @throws Exception if the test fails
438      */
439     @Test
440     @Alerts({"[object HTMLDivElement],null",
441                 "[object HTMLUnknownElement],null",
442                 "[object Element],app",
443                 "[object HTMLDivElement],null",
444                 "[object HTMLUnknownElement],null"})
445     public void html_prefix() throws Exception {
446         html("prefix");
447     }
448 
449     /**
450      * @throws Exception if the test fails
451      */
452     @Test
453     @Alerts({"[object HTMLDivElement],div",
454                 "[object HTMLUnknownElement],app:div",
455                 "[object Element],dIv",
456                 "[object HTMLDivElement],div",
457                 "[object HTMLUnknownElement],app:div"})
458     public void html_localName() throws Exception {
459         html("localName");
460     }
461 
462     /**
463      * @throws Exception if the test fails
464      */
465     @Test
466     @Alerts({"[object HTMLDivElement],undefined",
467                 "[object HTMLUnknownElement],undefined",
468                 "[object Element],undefined",
469                 "[object HTMLDivElement],undefined",
470                 "[object HTMLUnknownElement],undefined"})
471     public void html_baseName() throws Exception {
472         html("baseName");
473     }
474 
475     /**
476      * @throws Exception if the test fails
477      */
478     @Test
479     @Alerts({"[object HTMLDivElement],http://www.w3.org/1999/xhtml",
480                 "[object HTMLUnknownElement],http://www.w3.org/1999/xhtml",
481                 "[object Element],http://www.appcelerator.org",
482                 "[object HTMLDivElement],http://www.w3.org/1999/xhtml",
483                 "[object HTMLUnknownElement],http://www.w3.org/1999/xhtml"})
484     public void html_namespaceURI() throws Exception {
485         html("namespaceURI");
486     }
487 
488     private void html(final String methodName) throws Exception {
489         final String html = DOCTYPE_HTML
490             + "<html>\n"
491             + "<script>\n"
492             + LOG_TITLE_FUNCTION
493             + "  function test() {\n"
494             + "    debug(document.createElement('dIv'));\n"
495             + "    debug(document.createElement('app:dIv'));\n"
496             + "    debug(document.createElementNS('http://www.appcelerator.org', 'app:dIv'));\n"
497             + "    debug(document.getElementById('dIv1'));\n"
498             + "    debug(document.getElementById('dIv2'));\n"
499             + "  }\n"
500             + "  function debug(e) {\n"
501             + "    log(e + ',' + e." + methodName + ");\n"
502             + "  }\n"
503             + "</script>\n"
504             + "</head>\n"
505             + "<body onload='test()'>\n"
506             + "<dIv id='dIv1'></dIv>\n"
507             + "<app:dIv id='dIv2'>log(2)</app:dIv>\n"
508             + "</body></html>";
509 
510         loadPageVerifyTitle2(html);
511     }
512 
513     /**
514      * @throws Exception if the test fails
515      */
516     @Test
517     @Alerts({"[object HTMLDivElement],DIV",
518                 "[object HTMLUnknownElement],APP:DIV",
519                 "[object HTMLUnknownElement],ANOTHER:DIV",
520                 "[object Element],app:dIv",
521                 "[object HTMLDivElement],DIV",
522                 "[object HTMLUnknownElement],APP:DIV",
523                 "[object HTMLUnknownElement],ANOTHER:DIV"})
524     public void namespace_nodeName() throws Exception {
525         namespace("nodeName");
526     }
527 
528     /**
529      * @throws Exception if the test fails
530      */
531     @Test
532     @Alerts({"[object HTMLDivElement],DIV",
533                 "[object HTMLUnknownElement],APP:DIV",
534                 "[object HTMLUnknownElement],ANOTHER:DIV",
535                 "[object Element],app:dIv",
536                 "[object HTMLDivElement],DIV",
537                 "[object HTMLUnknownElement],APP:DIV",
538                 "[object HTMLUnknownElement],ANOTHER:DIV"})
539     public void namespace_tagName() throws Exception {
540         namespace("tagName");
541     }
542 
543     /**
544      * @throws Exception if the test fails
545      */
546     @Test
547     @Alerts({"[object HTMLDivElement],null",
548                 "[object HTMLUnknownElement],null",
549                 "[object HTMLUnknownElement],null",
550                 "[object Element],app",
551                 "[object HTMLDivElement],null",
552                 "[object HTMLUnknownElement],null",
553                 "[object HTMLUnknownElement],null"})
554     public void namespace_prefix() throws Exception {
555         namespace("prefix");
556     }
557 
558     /**
559      * @throws Exception if the test fails
560      */
561     @Test
562     @Alerts({"[object HTMLDivElement],div",
563                 "[object HTMLUnknownElement],app:div",
564                 "[object HTMLUnknownElement],another:div",
565                 "[object Element],dIv",
566                 "[object HTMLDivElement],div",
567                 "[object HTMLUnknownElement],app:div",
568                 "[object HTMLUnknownElement],another:div"})
569     public void namespace_localName() throws Exception {
570         namespace("localName");
571     }
572 
573     /**
574      * @throws Exception if the test fails
575      */
576     @Test
577     @Alerts({"[object HTMLDivElement],http://www.w3.org/1999/xhtml",
578                 "[object HTMLUnknownElement],http://www.w3.org/1999/xhtml",
579                 "[object HTMLUnknownElement],http://www.w3.org/1999/xhtml",
580                 "[object Element],http://www.appcelerator.org",
581                 "[object HTMLDivElement],http://www.w3.org/1999/xhtml",
582                 "[object HTMLUnknownElement],http://www.w3.org/1999/xhtml",
583                 "[object HTMLUnknownElement],http://www.w3.org/1999/xhtml"})
584     public void namespace_namespaceURI() throws Exception {
585         namespace("namespaceURI");
586     }
587 
588     private void namespace(final String methodName) throws Exception {
589         final String html
590             = "<html xmlns='http://www.w3.org/1999/xhtml' xmlns:app='http://www.appcelerator.org'>\n"
591             + "<script>\n"
592             + LOG_TITLE_FUNCTION
593             + "  function test() {\n"
594             + "    debug(document.createElement('dIv'));\n"
595             + "    debug(document.createElement('app:dIv'));\n"
596             + "    debug(document.createElement('another:dIv'));\n"
597             + "    debug(document.createElementNS('http://www.appcelerator.org', 'app:dIv'));\n"
598             + "    debug(document.getElementById('dIv1'));\n"
599             + "    debug(document.getElementById('dIv2'));\n"
600             + "    debug(document.getElementById('dIv3'));\n"
601             + "  }\n"
602             + "  function debug(e) {\n"
603             + "    log(e + ',' + e." + methodName + ");\n"
604             + "  }\n"
605             + "</script>\n"
606             + "</head>\n"
607             + "<body onload='test()'>\n"
608             + "<dIv id='dIv1'></dIv>\n"
609             + "<app:dIv id='dIv2'></app:dIv>\n"
610             + "<another:dIv id='dIv3'></another:dIv>\n"
611             + "</body></html>";
612 
613         loadPageVerifyTitle2(html);
614     }
615 
616     /**
617      * @throws Exception if the test fails
618      */
619     @Test
620     @Alerts({"[object Element]", "dIv",
621                 "[object HTMLHtmlElement]", "html",
622                 "[object HTMLDivElement]", "div",
623                 "[object HTMLUnknownElement]", "dIv"})
624     public void xml_nodeName() throws Exception {
625         xml("nodeName");
626     }
627 
628     /**
629      * @throws Exception if the test fails
630      */
631     @Test
632     @Alerts({"[object Element]", "dIv",
633                 "[object HTMLHtmlElement]", "html",
634                 "[object HTMLDivElement]", "div",
635                 "[object HTMLUnknownElement]", "dIv"})
636     public void xml_tagName() throws Exception {
637         xml("tagName");
638     }
639 
640     /**
641      * @throws Exception if the test fails
642      */
643     @Test
644     @Alerts({"[object Element]", "null",
645                 "[object HTMLHtmlElement]", "null",
646                 "[object HTMLDivElement]", "null",
647                 "[object HTMLUnknownElement]", "null"})
648     public void xml_prefix() throws Exception {
649         xml("prefix");
650     }
651 
652     /**
653      * @throws Exception if the test fails
654      */
655     @Test
656     @Alerts({"[object Element]", "dIv",
657                 "[object HTMLHtmlElement]", "html",
658                 "[object HTMLDivElement]", "div",
659                 "[object HTMLUnknownElement]", "dIv"})
660     public void xml_localName() throws Exception {
661         xml("localName");
662     }
663 
664     /**
665      * @throws Exception if the test fails
666      */
667     @Test
668     @Alerts({"[object Element]", "undefined",
669                 "[object HTMLHtmlElement]", "undefined",
670                 "[object HTMLDivElement]", "undefined",
671                 "[object HTMLUnknownElement]", "undefined"})
672     public void xml_baseName() throws Exception {
673         xml("baseName");
674     }
675 
676     /**
677      * @throws Exception if the test fails
678      */
679     @Test
680     @Alerts({"[object Element]", "null",
681                 "[object HTMLHtmlElement]", "http://www.w3.org/1999/xhtml",
682                 "[object HTMLDivElement]", "http://www.w3.org/1999/xhtml",
683                 "[object HTMLUnknownElement]", "http://www.w3.org/1999/xhtml"})
684     public void xml_namespaceURI() throws Exception {
685         xml("namespaceURI");
686     }
687 
688     private void xml(final String methodName) throws Exception {
689         final String html = DOCTYPE_HTML
690             + "<html>\n"
691             + "  <head>\n"
692             + "    <script>\n"
693             + LOG_TITLE_FUNCTION
694             + "      function test() {\n"
695             + "        var doc = " + XMLDocumentTest.callLoadXMLDocumentFromFile("'foo.xml'") + ";\n"
696             + "        debug(doc.documentElement.childNodes[0]);\n"
697             + "        debug(doc.documentElement.childNodes[1]);\n"
698             + "        debug(doc.documentElement.childNodes[1].childNodes[0]);\n"
699             + "        debug(doc.documentElement.childNodes[1].childNodes[1]);\n"
700             + "      }\n"
701             + "      function debug(e) {\n"
702             + "        try {\n"
703             + "          log(e);\n"
704             + "        } catch(ex) {log(ex)}\n"
705             + "        log(e." + methodName + ");\n"
706             + "      }\n"
707             + XMLDocumentTest.LOAD_XML_DOCUMENT_FROM_FILE_FUNCTION
708             + "    </script>\n"
709             + "  </head>\n"
710             + "  <body onload='test()'>\n"
711             + "  </body>\n"
712             + "</html>";
713 
714         final String xml =
715               "<xml>"
716             + "<dIv></dIv>"
717             + "<html xmlns='http://www.w3.org/1999/xhtml'>"
718             + "<div></div>"
719             + "<dIv></dIv>"
720             + "</html>"
721             + "</xml>";
722 
723         getMockWebConnection().setDefaultResponse(xml, MimeType.TEXT_XML);
724         loadPageVerifyTitle2(html);
725     }
726 
727     /**
728      * @throws Exception if the test fails
729      */
730     @Test
731     @Alerts({"prototype found", ""
732                     + "ELEMENT_NODE, ATTRIBUTE_NODE, TEXT_NODE, CDATA_SECTION_NODE, ENTITY_REFERENCE_NODE, "
733                     + "ENTITY_NODE, PROCESSING_INSTRUCTION_NODE, COMMENT_NODE, DOCUMENT_NODE, DOCUMENT_TYPE_NODE, "
734                     + "DOCUMENT_FRAGMENT_NODE, NOTATION_NODE, DOCUMENT_POSITION_DISCONNECTED, "
735                     + "DOCUMENT_POSITION_PRECEDING, "
736                     + "DOCUMENT_POSITION_FOLLOWING, DOCUMENT_POSITION_CONTAINS, DOCUMENT_POSITION_CONTAINED_BY, "
737                     + "DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC, "})
738     public void enumeratedProperties() throws Exception {
739         final String html = DOCTYPE_HTML
740             + "<html><head>\n"
741             + "<script>\n"
742             + LOG_TITLE_FUNCTION
743             + "  function test() {\n"
744             + "    var str = '';\n"
745             + "    try {\n"
746             + "      log(Element.prototype ? 'prototype found' : 'prototype not found');\n"
747             + "      var str = '';\n"
748             + "      for (var i in Element)\n"
749             + "        str += i + ', ';\n"
750             + "      log(str);\n"
751             + "    } catch(e) { log('exception occured')}\n"
752             + "  }\n"
753             + "</script>\n"
754             + "</head>\n"
755             + "<body onload='test()'>\n"
756             + "</body></html>";
757 
758         loadPageVerifyTitle2(html);
759     }
760 
761     /**
762      * @throws Exception if the test fails
763      */
764     @Test
765     @Alerts("finished")
766     public void removeAttribute() throws Exception {
767         final String html = DOCTYPE_HTML
768             + "<html>\n"
769             + "  <head>\n"
770             + "    <script>\n"
771             + LOG_TITLE_FUNCTION
772             + "      function test() {\n"
773             + "        var doc = " + XMLDocumentTest.callLoadXMLDocumentFromFile("'foo.xml'") + ";\n"
774             + "        var e = doc.getElementsByTagName('title');\n"
775             + "        e[0].removeAttribute('hello');\n"
776             + "        log('finished');\n"
777             + "      }\n"
778             + XMLDocumentTest.LOAD_XML_DOCUMENT_FROM_FILE_FUNCTION
779             + "    </script>\n"
780             + "  </head>\n"
781             + "  <body onload='test()'>\n"
782             + "  </body>\n"
783             + "</html>";
784 
785         final String xml
786             = "<books>\n"
787             + "  <book>\n"
788             + "    <title>Immortality</title>\n"
789             + "    <author>John Smith</author>\n"
790             + "  </book>\n"
791             + "</books>";
792 
793         getMockWebConnection().setDefaultResponse(xml, MimeType.TEXT_XML);
794         loadPageVerifyTitle2(html);
795     }
796 
797     /**
798      * @throws Exception if the test fails
799      */
800     @Test
801     @Alerts("function")
802     public void getBoundingClientRect() throws Exception {
803         final String html = DOCTYPE_HTML
804             + "<html><body><script>\n"
805             + LOG_TITLE_FUNCTION
806             + "try {\n"
807             + "  log(typeof Element.prototype.getBoundingClientRect);\n"
808             + "} catch(e) { logEx(e);}\n"
809             + "</script></body></html>";
810         loadPageVerifyTitle2(html);
811     }
812 
813     /**
814      * @throws Exception if the test fails
815      */
816     @Test
817     @Alerts("0")
818     public void commentIsElement() throws Exception {
819         final String html = DOCTYPE_HTML
820             + "<html><body>\n"
821             + "<div id='myId'><!-- --></div>\n"
822             + "<script>\n"
823             + LOG_TITLE_FUNCTION
824             + "  log(myId.getElementsByTagName('*').length);\n"
825             + "</script></body></html>";
826         loadPageVerifyTitle2(html);
827     }
828 
829     /**
830      * Node should not have 'innerText', however HTMLElement should have.
831      * The below case checks if Element (which is Node) doesn't define it.
832      *
833      * @throws Exception if the test fails
834      */
835     @Test
836     @Alerts("undefined")
837     public void nodeHasUndefinedInnerText() throws Exception {
838         final String html = DOCTYPE_HTML
839             + "<html><head>\n"
840             + "<script>\n"
841             + LOG_TITLE_FUNCTION
842             + "  function test() {\n"
843             + "    var data = \"<?xml version='1.0' encoding='UTF-8'?>\\\n"
844             + "        <dashboard> \\\n"
845             + "          <locations class='foo'> \\\n"
846             + "            <location for='bar' checked='different'> \\\n"
847             + "              <infowindowtab normal='ab' mixedCase='yes'> \\\n"
848             + "                <tab title='Location'><![CDATA[blabla]]></tab> \\\n"
849             + "                <tab title='Users'><![CDATA[blublu]]></tab> \\\n"
850             + "              </infowindowtab> \\\n"
851             + "            </location> \\\n"
852             + "          </locations> \\\n"
853             + "        </dashboard>\";\n"
854             + "    var xml, tmp;\n"
855             + "    try {\n"
856             + "      tmp = new DOMParser();\n"
857             + "      xml = tmp.parseFromString(data, 'text/xml');\n"
858             + "    } catch(e) {\n"
859             + "      xml = undefined;\n"
860             + "    }\n"
861             + "\n"
862             + "    log(xml.getElementsByTagName('tab')[0].innerText);\n"
863             + "  }\n"
864             + "</script>\n"
865             + "</head>\n"
866             + "<body onload='test()'/></html>";
867 
868         loadPageVerifyTitle2(html);
869     }
870 
871     /**
872      * @throws Exception if the test fails
873      */
874     @Test
875     @Alerts({"3", "first", "third", "second", "second"})
876     public void firstElementChild() throws Exception {
877         final String html = DOCTYPE_HTML
878             + "<html><head>\n"
879             + "<script>\n"
880             + LOG_TITLE_FUNCTION
881             + "  function test() {\n"
882             + "    var e = document.getElementById('myDiv');\n"
883             + "    if (e.firstElementChild) {\n"
884             + "      log(e.childElementCount);\n"
885             + "      log(e.firstElementChild.id);\n"
886             + "      log(e.lastElementChild.id);\n"
887             + "      log(e.firstElementChild.nextElementSibling.id);\n"
888             + "      log(e.lastElementChild.previousElementSibling.id);\n"
889             + "    }\n"
890             + "  }\n"
891             + "</script>\n"
892             + "</head>\n"
893             + "<body onload='test()'>\n"
894             + "  <div id='myDiv'>\n"
895             + "    <input id='first' type='button' value='someValue'>\n"
896             + "    <br id='second'/>\n"
897             + "    <input id='third' type=button' value='something'>\n"
898             + "  </div>\n"
899             + "</body></html>";
900 
901         loadPageVerifyTitle2(html);
902     }
903 
904     /**
905      * @throws Exception if the test fails
906      */
907     @Test
908     @Alerts({"0", "null", "null"})
909     public void firstElementChildTextNode() throws Exception {
910         final String html
911             = "<html><head>\n"
912             + "<script>\n"
913             + LOG_TITLE_FUNCTION
914             + "  function test() {\n"
915             + "    var e = document.getElementById('myDiv');\n"
916             + "    if (e.childElementCount !== undefined) {\n"
917             + "      log(e.childElementCount);\n"
918             + "      log(e.firstElementChild);\n"
919             + "      log(e.lastElementChild);\n"
920             + "    }\n"
921             + "  }\n"
922             + "</script>\n"
923             + "</head>\n"
924             + "<body onload='test()'>\n"
925             + "  <div id='myDiv'>HtmlUnit</div>\n"
926             + "</body></html>";
927 
928         loadPageVerifyTitle2(html);
929     }
930 
931     /**
932      * @throws Exception if the test fails
933      */
934     @Test
935     @Alerts({"§§URL§§", "§§URL§§"})
936     public void baseURI() throws Exception {
937         final String html = DOCTYPE_HTML
938             + "<html><head>\n"
939             + "<script>\n"
940             + LOG_TITLE_FUNCTION
941             + "function test() {\n"
942             + "  var text = '<hello><child></child></hello>';\n"
943             + "  var doc = " + XMLDocumentTest.callLoadXMLDocumentFromString("text") + ";\n"
944             + "  var e = doc.documentElement.firstChild;\n"
945             + "  log(e.baseURI);\n"
946             + "\n"
947             + "  e = document.getElementById('myId');\n"
948             + "  log(e.baseURI);\n"
949             + "}\n"
950             + XMLDocumentTest.LOAD_XML_DOCUMENT_FROM_STRING_FUNCTION
951             + "</script></head><body onload='test()'>\n"
952             + "  <div id='myId'>abcd</div>\n"
953             + "</body></html>";
954 
955         expandExpectedAlertsVariables(URL_FIRST);
956         loadPageVerifyTitle2(html);
957     }
958 
959     /**
960      * @throws Exception if the test fails
961      */
962     @Test
963     @Alerts({"[object HTMLCollection] 1", "[object HTMLCollection] 2", "[object HTMLCollection] 0"})
964     public void children() throws Exception {
965         final String html = DOCTYPE_HTML
966             + "<html><head><script>\n"
967             + LOG_TITLE_FUNCTION
968             + "function test() {\n"
969             + "  var text = '<hello><child></child></hello>';\n"
970             + "  var doc = " + XMLDocumentTest.callLoadXMLDocumentFromString("text") + ";\n"
971 
972             + "  try {\n"
973             + "    var children = doc.documentElement.children;\n"
974             + "    log(children + ' ' + children.length);\n"
975             + "  } catch(e) { logEx(e); }\n"
976 
977             + "  try {\n"
978             + "    children = document.documentElement.children;\n"
979             + "    log(children + ' ' + children.length);\n"
980             + "  } catch(e) { logEx(e); }\n"
981 
982             + "  try {\n"
983             + "    children = document.getElementById('myId').children;\n"
984             + "    log(children + ' ' + children.length);\n"
985             + "  } catch(e) { logEx(e); }\n"
986             + "}\n"
987             + XMLDocumentTest.LOAD_XML_DOCUMENT_FROM_STRING_FUNCTION
988             + "</script></head><body onload='test()'>\n"
989             + "  <div id='myId'>abcd</div>\n"
990             + "</body></html>";
991 
992         loadPageVerifyTitle2(html);
993     }
994 
995     /**
996      * @throws Exception if the test fails
997      */
998     @Test
999     @Alerts({"", "a b c"})
1000     public void classList() throws Exception {
1001         final String html = DOCTYPE_HTML
1002             + "<html><head><script>\n"
1003             + LOG_TITLE_FUNCTION
1004             + "function test() {\n"
1005             + "  var text = '<hello><child></child></hello>';\n"
1006             + "  var doc = " + XMLDocumentTest.callLoadXMLDocumentFromString("text") + ";\n"
1007             + "  log(doc.documentElement.classList);\n"
1008             + "  log(document.body.classList);\n"
1009             + "}\n"
1010             + XMLDocumentTest.LOAD_XML_DOCUMENT_FROM_STRING_FUNCTION
1011             + "</script></head><body onload='test()' class='a b c'>\n"
1012             + "  <div id='myId'>abcd</div>\n"
1013             + "</body></html>";
1014 
1015         loadPageVerifyTitle2(html);
1016     }
1017 
1018     /**
1019      * Tests the usage of getAttributeNS, setAttributeNS, removeAttributeNS
1020      * and hasAttributeNS methods.
1021      * @throws Exception if the test fails
1022      */
1023     @Test
1024     @Alerts({"test value", "true", "false", "finished"})
1025     public void attributeNS() throws Exception {
1026         final String html = DOCTYPE_HTML
1027             + "<html>\n"
1028             + "  <head>\n"
1029             + "    <script>\n"
1030             + LOG_TITLE_FUNCTION
1031             + "      function test() {\n"
1032             + "        var doc = document.implementation.createDocument(\"\", \"\", null);\n"
1033             + "        var element = doc.createElementNS(\'uri:test\', \'test:element\');\n"
1034             + "        element.setAttributeNS(\'uri:test\', \'test:attribute\', 'test value');\n"
1035             + "        log(element.getAttributeNS(\'uri:test\', \'attribute\'));\n"
1036             + "        log(element.hasAttributeNS(\'uri:test\', \'attribute\'));\n"
1037             + "        element.removeAttributeNS(\'uri:test\', \'attribute\');\n"
1038             + "        log(element.hasAttributeNS(\'uri:test\', \'attribute\'));\n"
1039             + "        log('finished');\n"
1040             + "      }\n"
1041             + "    </script>\n"
1042             + "  </head>\n"
1043             + "  <body onload='test()'>\n"
1044             + "  </body>\n"
1045             + "</html>";
1046 
1047         loadPageVerifyTitle2(html);
1048     }
1049 
1050     /**
1051      * @throws Exception if the test fails
1052      */
1053     @Test
1054     @Alerts({"ab", "ab"})
1055     public void removeAttribute_case_sensitive() throws Exception {
1056         final String html = DOCTYPE_HTML
1057             + "<html>\n"
1058             + "  <head>\n"
1059             + "    <script>\n"
1060             + LOG_TITLE_FUNCTION
1061             + "      function test() {\n"
1062             + "        var doc = " + XMLDocumentTest.callLoadXMLDocumentFromFile("'foo.xml'") + ";\n"
1063             + "        var e = doc.getElementsByTagName('title')[0];\n"
1064             + "        log(e.getAttribute('normal'));\n"
1065             + "        e.removeAttribute('Normal');\n"
1066             + "        log(e.getAttribute('normal'));\n"
1067             + "      }\n"
1068             + XMLDocumentTest.LOAD_XML_DOCUMENT_FROM_FILE_FUNCTION
1069             + "    </script>\n"
1070             + "  </head>\n"
1071             + "  <body onload='test()'>\n"
1072             + "  </body>\n"
1073             + "</html>";
1074 
1075         final String xml
1076             = "<books>\n"
1077             + "  <book>\n"
1078             + "    <title normal=\"ab\">Immortality</title>\n"
1079             + "    <author>John Smith</author>\n"
1080             + "  </book>\n"
1081             + "</books>";
1082 
1083         getMockWebConnection().setDefaultResponse(xml, MimeType.TEXT_XML);
1084         loadPageVerifyTitle2(html);
1085     }
1086 
1087     /**
1088      * @throws Exception if the test fails
1089      */
1090     @Test
1091     @Alerts("test")
1092     public void setAttributeNode() throws Exception {
1093         final String html = DOCTYPE_HTML
1094             + "<html>\n"
1095             + "  <head>\n"
1096             + "    <script>\n"
1097             + LOG_TITLE_FUNCTION
1098             + "      function test() {\n"
1099             + "        var doc = document.implementation.createDocument('', '', null);\n"
1100             + "        var element = doc.createElement('something');\n"
1101             + "        var attr = doc.createAttribute('name');\n"
1102             + "        attr.value = 'test';\n"
1103             + "        element.setAttributeNode(attr);\n"
1104             + "        log(element.getAttributeNode('name').value);\n"
1105             + "      }\n"
1106             + "    </script>\n"
1107             + "  </head>\n"
1108             + "  <body onload='test()'>\n"
1109             + "  </body>\n"
1110             + "</html>";
1111 
1112         loadPageVerifyTitle2(html);
1113     }
1114 
1115     /**
1116      * @throws Exception if an error occurs
1117      */
1118     @Test
1119     @Alerts({"undefined", "undefined"})
1120     public void currentStyle() throws Exception {
1121         final String html = DOCTYPE_HTML
1122             + "<html>\n"
1123             + "<head>\n"
1124             + "  <script>\n"
1125             + LOG_TITLE_FUNCTION
1126             + "    function test() {\n"
1127             + "      var e = document.getElementById('tester');\n"
1128             + "      log(e.currentStyle ? 'available' : e.currentStyle);\n"
1129             + "      e = document.createElement('div');\n"
1130             + "      log(e.currentStyle ? 'available' : e.currentStyle);\n"
1131             + "    }\n"
1132             + "  </script>\n"
1133             + "</head>\n"
1134             + "<body onload='test()'>\n"
1135             + "  <div id='tester'></div>\n"
1136             + "</body></html>";
1137         loadPageVerifyTitle2(html);
1138     }
1139 
1140     /**
1141      * @throws Exception if an error occurs
1142      */
1143     @Test
1144     @Alerts({"undefined", "undefined"})
1145     public void allowKeyboardInput() throws Exception {
1146         final String html = DOCTYPE_HTML
1147             + "<html>\n"
1148             + "<head>\n"
1149             + "  <script>\n"
1150             + LOG_TITLE_FUNCTION
1151             + "    function test() {\n"
1152             + "      log(Element.ALLOW_KEYBOARD_INPUT);\n"
1153             + "      log(typeof Element.ALLOW_KEYBOARD_INPUT);\n"
1154             + "    }\n"
1155             + "  </script>\n"
1156             + "</head>\n"
1157             + "<body onload='test()'>\n"
1158             + "</body></html>";
1159         loadPageVerifyTitle2(html);
1160     }
1161 
1162     /**
1163      * @throws Exception if an error occurs
1164      */
1165     @Test
1166     @Alerts("")
1167     public void enumeratedPropertiesForNativeFunction() throws Exception {
1168         final String html = DOCTYPE_HTML
1169             + "<html><head>\n"
1170             + "<script>\n"
1171             + LOG_TITLE_FUNCTION
1172             + "  function test() {\n"
1173             + "    var str = '';\n"
1174             + "    for (var i in test)\n"
1175             + "      str += i + ', ';\n"
1176             + "    log(str);\n"
1177             + "  }\n"
1178             + "</script>\n"
1179             + "</head>\n"
1180             + "<body onload='test()'>\n"
1181             + "</body></html>";
1182 
1183         loadPageVerifyTitle2(html);
1184     }
1185 
1186     /**
1187      * @throws Exception if an error occurs
1188      */
1189     @Test
1190     @Alerts({"function Element() { [native code] }", "[object Element]",
1191              "function Element() { [native code] }"})
1192     public void prototypConstructor() throws Exception {
1193         final String html = DOCTYPE_HTML
1194             + "<html><head>\n"
1195             + "<script>\n"
1196             + LOG_TITLE_FUNCTION
1197             + "  function test() {\n"
1198             + "    try {\n"
1199             + "      process(Element);\n"
1200             + "      process(Element.prototype);\n"
1201             + "      process(Element.prototype.constructor);\n"
1202             + "    } catch(e) { logEx(e) }\n"
1203             + "  }\n"
1204             + "  function process(obj) {\n"
1205             + "    try {\n"
1206             + "      log(obj);\n"
1207             + "    } catch(e) { logEx(e) }\n"
1208             + "   }\n"
1209             + "</script>\n"
1210             + "</head>\n"
1211             + "<body onload='test()'>\n"
1212             + "</body></html>";
1213 
1214         loadPageVerifyTitle2(html);
1215     }
1216 
1217     /**
1218      * @throws Exception if an error occurs
1219      */
1220     @Test
1221     @Alerts({"function Element() { [native code] }", "[object Element]",
1222              "function Element() { [native code] }"})
1223     public void prototypConstructorStandards() throws Exception {
1224         final String html = DOCTYPE_HTML
1225             + "<html><head>\n"
1226             + "<script>\n"
1227             + LOG_TITLE_FUNCTION
1228             + "  function test() {\n"
1229             + "    process(Element);\n"
1230             + "    process(Element.prototype);\n"
1231             + "    process(Element.prototype.constructor);\n"
1232             + "  }\n"
1233             + "  function process(obj) {\n"
1234             + "    log(obj);\n"
1235             + "  }\n"
1236             + "</script>\n"
1237             + "</head>\n"
1238             + "<body onload='test()'>\n"
1239             + "</body></html>";
1240 
1241         loadPageVerifyTitle2(html);
1242     }
1243 
1244     /**
1245      * @throws Exception if an error occurs
1246      */
1247     @Test
1248     @Alerts({"0-0", "0-1", "2-5"})
1249     public void childElementCount() throws Exception {
1250         final String html = DOCTYPE_HTML
1251             + "<html><head>\n"
1252             + "<script>\n"
1253             + LOG_TITLE_FUNCTION
1254             + "  function test() {\n"
1255             + "    info(document.getElementById('emptyDiv'));\n"
1256             + "    info(document.getElementById('whitespaceDiv'));\n"
1257             + "    info(document.getElementById('testDiv'));\n"
1258             + "  }\n"
1259             + "  function info(e) {\n"
1260             + "    log(e.childElementCount + '-' + e.childNodes.length);\n"
1261             + "  }\n"
1262             + "</script>\n"
1263             + "</head>\n"
1264             + "<body onload='test()'>\n"
1265             + "  <div id='emptyDiv'></div>\n"
1266             + "  <div id='whitespaceDiv'>\n"
1267             + "  </div>\n"
1268             + "  <div id='testDiv'>\n"
1269             + "    <div>first</div>\n"
1270             + "    <div>\n"
1271             + "      <span>second</span>\n"
1272             + "    </div>\n"
1273             + "  </div>\n"
1274             + "</body></html>";
1275 
1276         loadPageVerifyTitle2(html);
1277     }
1278 
1279     /**
1280      * @throws Exception if an error occurs
1281      */
1282     @Test
1283     @Alerts({"1-2", "3-7"})
1284     public void childElementCountTable() throws Exception {
1285         final String html = DOCTYPE_HTML
1286             + "<html><head>\n"
1287             + "<script>\n"
1288             + LOG_TITLE_FUNCTION
1289             + "  function test() {\n"
1290             + "    info(document.getElementById('myTable'));\n"
1291             + "    info(document.getElementById('myTr'));\n"
1292             + "  }\n"
1293             + "  function info(e) {\n"
1294             + "    log(e.childElementCount + '-' + e.childNodes.length);\n"
1295             + "  }\n"
1296             + "</script>\n"
1297             + "</head>\n"
1298             + "<body onload='test()'>\n"
1299             + "  <table id='myTable'>\n"
1300             + "    <tr id='myTr'>\n"
1301             + "      <td>first</td>\n"
1302             + "      <td><div>second</div></td>\n"
1303             + "      <td>\n"
1304             + "        third\n"
1305             + "      </td>\n"
1306             + "    </tr>\n"
1307             + "  </table>\n"
1308             + "</body></html>";
1309 
1310         loadPageVerifyTitle2(html);
1311     }
1312 
1313     /**
1314      * @throws Exception if an error occurs
1315      */
1316     @Test
1317     @Alerts({"true", "false"})
1318     public void hasAttributes() throws Exception {
1319         final String html = DOCTYPE_HTML
1320             + "<html><head>\n"
1321             + "<script>\n"
1322             + LOG_TITLE_FUNCTION
1323             + "  function test() {\n"
1324             + "    log(document.body.hasAttributes());\n"
1325             + "    log(document.body.childNodes.item(1).hasAttributes());\n"
1326             + "  }\n"
1327             + "</script>\n"
1328             + "</head>\n"
1329             + "<body onload='test()'>\n"
1330             + "  <div></div>\n"
1331             + "</body></html>";
1332 
1333         loadPageVerifyTitle2(html);
1334     }
1335 
1336     /**
1337      * @throws Exception if an error occurs
1338      */
1339     @Test
1340     @Alerts("Philippine eagle")
1341     public void matches() throws Exception {
1342         final String html = DOCTYPE_HTML
1343             + "<html><head>\n"
1344             + "<script>\n"
1345             + LOG_TITLE_FUNCTION
1346             + "  function test() {\n"
1347             + "    var birds = document.getElementsByTagName('li');\n"
1348             + "    var found = false;"
1349             + "    for (var i = 0; i < birds.length; i++) {\n"
1350             + "      if (birds[i].matches && birds[i].matches('.endangered')) {\n"
1351             + "        log(birds[i].textContent);\n"
1352             + "        found = true;"
1353             + "      }\n"
1354             + "    }\n"
1355             + "    if (!found) {\n"
1356             + "      log('not found');\n"
1357             + "    }\n"
1358             + "  }\n"
1359             + "</script>\n"
1360             + "</head>\n"
1361             + "<body onload='test()'>\n"
1362             + "  <ul id='birds'>\n"
1363             + "    <li>Orange-winged parrot</li>\n"
1364             + "    <li class='endangered'>Philippine eagle</li>\n"
1365             + "    <li>Great white pelican</li>\n"
1366             + "  </ul>\n"
1367             + "</body></html>";
1368 
1369         loadPageVerifyTitle2(html);
1370     }
1371 
1372     /**
1373      * @throws Exception if an error occurs
1374      */
1375     @Test
1376     @Alerts({"SyntaxError/DOMException", "done"})
1377     public void matchesInvalidSelector() throws Exception {
1378         final String html = DOCTYPE_HTML
1379             + "<html><head>\n"
1380             + "<script>\n"
1381             + LOG_TITLE_FUNCTION
1382             + "  function test() {\n"
1383             + "    var birds = document.getElementsByTagName('li');\n"
1384             + "    try {\n"
1385             + "      for (var i = 0; i < birds.length; i++) {\n"
1386             + "        if (birds[i].matches && birds[i].matches('invalidSelector!=:::x')) {\n"
1387             + "          log(birds[i].textContent);\n"
1388             + "        }\n"
1389             + "      }\n"
1390             + "    } catch(e) { logEx(e); }\n"
1391             + "    log('done');\n"
1392             + "  }\n"
1393             + "</script>\n"
1394             + "</head>\n"
1395             + "<body onload='test()'>\n"
1396             + "  <ul id='birds'>\n"
1397             + "    <li>Great white pelican</li>\n"
1398             + "  </ul>\n"
1399             + "</body></html>";
1400 
1401         loadPageVerifyTitle2(html);
1402     }
1403 
1404     /**
1405      * @throws Exception if an error occurs
1406      */
1407     @Test
1408     @Alerts({"TypeError", "done"})
1409     public void matchesWindow() throws Exception {
1410         final String html = DOCTYPE_HTML
1411             + "<html><head>\n"
1412             + "<script>\n"
1413             + LOG_TITLE_FUNCTION
1414             + "  function test() {\n"
1415             + "    var docElem = document.documentElement;\n"
1416             + "    var matches = docElem.matchesSelector\n"
1417             + "         || docElem.mozMatchesSelector\n"
1418             + "         || docElem.webkitMatchesSelector\n"
1419             + "         || docElem.msMatchesSelector;\n"
1420             + "    try {\n"
1421             + "      matches.call(window, ':visible')\n"
1422             + "    } catch(e) { logEx(e); }\n"
1423             + "    log('done');\n"
1424             + "  }\n"
1425             + "</script>\n"
1426             + "</head>\n"
1427             + "<body onload='test()'>\n"
1428             + "  <ul id='birds'>\n"
1429             + "    <li>Great white pelican</li>\n"
1430             + "  </ul>\n"
1431             + "</body></html>";
1432 
1433         loadPageVerifyTitle2(html);
1434     }
1435 
1436 
1437     /**
1438      * @throws Exception if an error occurs
1439      */
1440     @Test
1441     @Alerts({"div-02", "div-03", "div-01", "article-01", "null"})
1442     public void closest() throws Exception {
1443         final String html = DOCTYPE_HTML
1444             + "<html><head>\n"
1445             + "<script>\n"
1446             + LOG_TITLE_FUNCTION
1447             + "  function test() {\n"
1448             + "    var el = document.getElementById('div-03');\n"
1449             + "    if (!el.closest) { log('no closest'); return }\n"
1450 
1451             + "    log(el.closest('#div-02').id);\n"
1452             + "    log(el.closest('div div').id);\n"
1453             + "    log(el.closest('article > div').id);\n"
1454             + "    log(el.closest(':not(div)').id);\n"
1455 
1456             + "    log(el.closest('span'));\n"
1457             + "  }\n"
1458             + "</script>\n"
1459             + "</head>\n"
1460             + "<body onload='test()'>\n"
1461             + "  <article id='article-01'>\n"
1462             + "    <div id='div-01'>Here is div-01\n"
1463             + "      <div id='div-02'>Here is div-02\n"
1464             + "        <div id='div-03'>Here is div-03</div>\n"
1465             + "      </div>\n"
1466             + "    </div>\n"
1467             + "  </article>\n"
1468             + "</body></html>";
1469 
1470         loadPageVerifyTitle2(html);
1471     }
1472 
1473     /**
1474      * @throws Exception if the test fails
1475      */
1476     @Test
1477     @Alerts({"false", "true", "true", "true", "false", "false"})
1478     public void toggleAttribute() throws Exception {
1479         final String html = DOCTYPE_HTML
1480             + "<html><head><script>\n"
1481             + LOG_TITLE_FUNCTION
1482             + "  function test() {\n"
1483             + "    var d0 = document.getElementById('div0');\n"
1484 
1485             + "    if (!d0.toggleAttribute) { log('toggleAttribute missing'); return; }\n"
1486             + "    d0.toggleAttribute('hidden');"
1487             + "    log(d0.hidden);\n"
1488 
1489             + "    var d1 = document.getElementById('div1');"
1490             + "    d1.toggleAttribute('hidden');"
1491             + "    log(d1.hidden);\n"
1492             + "    var d2 = document.getElementById('div2');"
1493             + "    d2.toggleAttribute('hidden', true);"
1494             + "    log(d2.hidden);\n"
1495             + "    var d3 = document.getElementById('div3');"
1496             + "    d3.toggleAttribute('hidden', true);"
1497             + "    log(d3.hidden);\n"
1498             + "    var d4 = document.getElementById('div4');"
1499             + "    d4.toggleAttribute('hidden', false);"
1500             + "    log(d4.hidden);\n"
1501             + "    var d5 = document.getElementById('div5');"
1502             + "    d5.toggleAttribute('hidden', false);"
1503             + "    log(d5.hidden);\n"
1504             + "  }\n"
1505             + "</script></head>\n"
1506             + "<body onload='test()'>\n"
1507             + "  <div id='div0' hidden />\n"
1508             + "  <div id='div1' />\n"
1509             + "  <div id='div2' hidden/>\n"
1510             + "  <div id='div3' />\n"
1511             + "  <div id='div4' hidden />\n"
1512             + "  <div id='div5' />\n"
1513             + "</body></html>";
1514 
1515         loadPageVerifyTitle2(html);
1516     }
1517 
1518     /**
1519      * @throws Exception if the test fails
1520      */
1521     @Test
1522     @Alerts({"1", "1", "<div id=\"div1\"></div>"})
1523     public void after_noArgs_empty() throws Exception {
1524         modifySiblings("after", "after();", "");
1525     }
1526 
1527     /**
1528      * @throws Exception if the test fails
1529      */
1530     @Test
1531     @Alerts({"1", "1", "#HtmlUnit"})
1532     public void after_noArgs_notEmpty() throws Exception {
1533         modifySiblings("after", "after();", "HtmlUnit");
1534     }
1535 
1536     /**
1537      * @throws Exception if the test fails
1538      */
1539     @Test
1540     @Alerts({"1", "2", "<div id=\"div1\"></div>", "#HeHo",
1541              "childList", "1", "0", "[object HTMLDivElement]", "null"})
1542     @HtmlUnitNYI(CHROME = {"1", "2", "<div id=\"div1\"></div>", "#HeHo"},
1543             EDGE = {"1", "2", "<div id=\"div1\"></div>", "#HeHo"},
1544             FF = {"1", "2", "<div id=\"div1\"></div>", "#HeHo"},
1545             FF_ESR = {"1", "2", "<div id=\"div1\"></div>", "#HeHo"})
1546     public void after_text_empty() throws Exception {
1547         modifySiblings("after", "after('HeHo');", "");
1548     }
1549 
1550     /**
1551      * @throws Exception if the test fails
1552      */
1553     @Test
1554     @Alerts({"1", "2", "#HtmlUnit", "#HeHo",
1555              "childList", "1", "0", "[object HTMLDivElement]", "null"})
1556     @HtmlUnitNYI(CHROME = {"1", "2", "#HtmlUnit", "#HeHo"},
1557             EDGE = {"1", "2", "#HtmlUnit", "#HeHo"},
1558             FF = {"1", "2", "#HtmlUnit", "#HeHo"},
1559             FF_ESR = {"1", "2", "#HtmlUnit", "#HeHo"})
1560     public void after_text_notEmpty() throws Exception {
1561         modifySiblings("after", "after('HeHo');", "HtmlUnit");
1562     }
1563 
1564     /**
1565      * @throws Exception if the test fails
1566      */
1567     @Test
1568     @Alerts({"1", "2", "<div id=\"div1\"></div>", "<p></p>",
1569              "childList", "1", "0", "[object HTMLDivElement]", "null"})
1570     @HtmlUnitNYI(CHROME =  {"1", "2", "<div id=\"div1\"></div>", "<p></p>"},
1571             EDGE = {"1", "2", "<div id=\"div1\"></div>", "<p></p>"},
1572             FF = {"1", "2", "<div id=\"div1\"></div>", "<p></p>"},
1573             FF_ESR = {"1", "2", "<div id=\"div1\"></div>", "<p></p>"})
1574     public void after_p_empty() throws Exception {
1575         modifySiblings("after", "after(p0);", "");
1576     }
1577 
1578     /**
1579      * @throws Exception if the test fails
1580      */
1581     @Test
1582     @Alerts({"1", "2", "#HtmlUnit", "<p></p>",
1583              "childList", "1", "0", "[object HTMLDivElement]", "null"})
1584     @HtmlUnitNYI(CHROME = {"1", "2", "#HtmlUnit", "<p></p>"},
1585             EDGE = {"1", "2", "#HtmlUnit", "<p></p>"},
1586             FF = {"1", "2", "#HtmlUnit", "<p></p>"},
1587             FF_ESR = {"1", "2", "#HtmlUnit", "<p></p>"})
1588     public void after_p_notEmpty() throws Exception {
1589         modifySiblings("after", "after(p0);", "HtmlUnit");
1590     }
1591 
1592     /**
1593      * @throws Exception if the test fails
1594      */
1595     @Test
1596     @Alerts({"1", "2", "<div id=\"div1\"></div>", "#[object Object]",
1597              "childList", "1", "0", "[object HTMLDivElement]", "null"})
1598     @HtmlUnitNYI(CHROME = {"1", "2", "<div id=\"div1\"></div>", "#[object Object]"},
1599             EDGE = {"1", "2", "<div id=\"div1\"></div>", "#[object Object]"},
1600             FF = {"1", "2", "<div id=\"div1\"></div>", "#[object Object]"},
1601             FF_ESR = {"1", "2", "<div id=\"div1\"></div>", "#[object Object]"})
1602     public void after_o_empty() throws Exception {
1603         modifySiblings("after", "after({o: 1});", "");
1604     }
1605 
1606     /**
1607      * @throws Exception if the test fails
1608      */
1609     @Test
1610     @Alerts({"1", "2", "#HtmlUnit", "#[object Object]",
1611              "childList", "1", "0", "[object HTMLDivElement]", "null"})
1612     @HtmlUnitNYI(CHROME = {"1", "2", "#HtmlUnit", "#[object Object]"},
1613             EDGE = {"1", "2", "#HtmlUnit", "#[object Object]"},
1614             FF = {"1", "2", "#HtmlUnit", "#[object Object]"},
1615             FF_ESR = {"1", "2", "#HtmlUnit", "#[object Object]"})
1616     public void after_o_notEmpty() throws Exception {
1617         modifySiblings("after", "after({o: 1});", "HtmlUnit");
1618     }
1619 
1620     /**
1621      * @throws Exception if the test fails
1622      */
1623     @Test
1624     @Alerts({"1", "4", "#HtmlUnit", "#abcd", "<p></p>", "#[object Object]",
1625              "childList", "3", "0", "[object HTMLDivElement]", "null"})
1626     @HtmlUnitNYI(CHROME = {"1", "4", "#HtmlUnit", "#abcd", "<p></p>", "#[object Object]"},
1627             EDGE = {"1", "4", "#HtmlUnit", "#abcd", "<p></p>", "#[object Object]"},
1628             FF = {"1", "4", "#HtmlUnit", "#abcd", "<p></p>", "#[object Object]"},
1629             FF_ESR = {"1", "4", "#HtmlUnit", "#abcd", "<p></p>", "#[object Object]"})
1630     public void after_many_notEmpty() throws Exception {
1631         modifySiblings("after", "after(p0, 'abcd', p0, {o: 1});", "HtmlUnit");
1632     }
1633 
1634     /**
1635      * @throws Exception if the test fails
1636      */
1637     @Test
1638     @Alerts({"1", "1", "<div id=\"div1\"></div>"})
1639     public void before_noArgs_empty() throws Exception {
1640         modifySiblings("before", "before();", "");
1641     }
1642 
1643     /**
1644      * @throws Exception if the test fails
1645      */
1646     @Test
1647     @Alerts({"1", "1", "#HtmlUnit"})
1648     public void before_noArgs_notEmpty() throws Exception {
1649         modifySiblings("before", "before();", "HtmlUnit");
1650     }
1651 
1652     /**
1653      * @throws Exception if the test fails
1654      */
1655     @Test
1656     @Alerts({"1", "2",  "#HeHo", "<div id=\"div1\"></div>",
1657              "childList", "1", "0", "null", "[object HTMLDivElement]"})
1658     @HtmlUnitNYI(CHROME = {"1", "2",  "#HeHo", "<div id=\"div1\"></div>"},
1659             EDGE = {"1", "2",  "#HeHo", "<div id=\"div1\"></div>"},
1660             FF = {"1", "2",  "#HeHo", "<div id=\"div1\"></div>"},
1661             FF_ESR = {"1", "2",  "#HeHo", "<div id=\"div1\"></div>"})
1662     public void before_text_empty() throws Exception {
1663         modifySiblings("before", "before('HeHo');", "");
1664     }
1665 
1666     /**
1667      * @throws Exception if the test fails
1668      */
1669     @Test
1670     @Alerts({"1", "2", "#HeHo", "#HtmlUnit",
1671              "childList", "1", "0", "null", "[object HTMLDivElement]"})
1672     @HtmlUnitNYI(CHROME = {"1", "2", "#HeHo", "#HtmlUnit"},
1673             EDGE = {"1", "2", "#HeHo", "#HtmlUnit"},
1674             FF = {"1", "2", "#HeHo", "#HtmlUnit"},
1675             FF_ESR = {"1", "2", "#HeHo", "#HtmlUnit"})
1676     public void before_text_notEmpty() throws Exception {
1677         modifySiblings("before", "before('HeHo');", "HtmlUnit");
1678     }
1679 
1680     /**
1681      * @throws Exception if the test fails
1682      */
1683     @Test
1684     @Alerts({"1", "2",  "<p></p>", "<div id=\"div1\"></div>",
1685              "childList", "1", "0", "null", "[object HTMLDivElement]"})
1686     @HtmlUnitNYI(CHROME = {"1", "2",  "<p></p>", "<div id=\"div1\"></div>"},
1687             EDGE = {"1", "2",  "<p></p>", "<div id=\"div1\"></div>"},
1688             FF = {"1", "2",  "<p></p>", "<div id=\"div1\"></div>"},
1689             FF_ESR = {"1", "2",  "<p></p>", "<div id=\"div1\"></div>"})
1690     public void before_p_empty() throws Exception {
1691         modifySiblings("before", "before(p0);", "");
1692     }
1693 
1694     /**
1695      * @throws Exception if the test fails
1696      */
1697     @Test
1698     @Alerts({"1", "2", "<p></p>", "#HtmlUnit",
1699              "childList", "1", "0", "null", "[object HTMLDivElement]"})
1700     @HtmlUnitNYI(CHROME = {"1", "2", "<p></p>", "#HtmlUnit"},
1701             EDGE = {"1", "2", "<p></p>", "#HtmlUnit"},
1702             FF = {"1", "2", "<p></p>", "#HtmlUnit"},
1703             FF_ESR = {"1", "2", "<p></p>", "#HtmlUnit"})
1704     public void before_p_notEmpty() throws Exception {
1705         modifySiblings("before", "before(p0);", "HtmlUnit");
1706     }
1707 
1708     /**
1709      * @throws Exception if the test fails
1710      */
1711     @Test
1712     @Alerts({"1", "2", "#[object Object]", "<div id=\"div1\"></div>",
1713              "childList", "1", "0", "null", "[object HTMLDivElement]"})
1714     @HtmlUnitNYI(CHROME = {"1", "2", "#[object Object]", "<div id=\"div1\"></div>"},
1715             EDGE = {"1", "2", "#[object Object]", "<div id=\"div1\"></div>"},
1716             FF = {"1", "2", "#[object Object]", "<div id=\"div1\"></div>"},
1717             FF_ESR = {"1", "2", "#[object Object]", "<div id=\"div1\"></div>"})
1718     public void before_o_empty() throws Exception {
1719         modifySiblings("before", "before({o: 1});", "");
1720     }
1721 
1722     /**
1723      * @throws Exception if the test fails
1724      */
1725     @Test
1726     @Alerts({"1", "2", "#[object Object]", "#HtmlUnit",
1727              "childList", "1", "0", "null", "[object HTMLDivElement]"})
1728     @HtmlUnitNYI(CHROME = {"1", "2", "#[object Object]", "#HtmlUnit"},
1729             EDGE = {"1", "2", "#[object Object]", "#HtmlUnit"},
1730             FF = {"1", "2", "#[object Object]", "#HtmlUnit"},
1731             FF_ESR = {"1", "2", "#[object Object]", "#HtmlUnit"})
1732     public void before_o_notEmpty() throws Exception {
1733         modifySiblings("before", "before({o: 1});", "HtmlUnit");
1734     }
1735 
1736     /**
1737      * @throws Exception if the test fails
1738      */
1739     @Test
1740     @Alerts({"1", "4", "#abcd", "<p></p>", "#[object Object]", "#HtmlUnit",
1741              "childList", "3", "0", "null", "[object HTMLDivElement]"})
1742     @HtmlUnitNYI(CHROME = {"1", "4", "#abcd", "<p></p>", "#[object Object]", "#HtmlUnit"},
1743             EDGE = {"1", "4", "#abcd", "<p></p>", "#[object Object]", "#HtmlUnit"},
1744             FF = {"1", "4", "#abcd", "<p></p>", "#[object Object]", "#HtmlUnit"},
1745             FF_ESR = {"1", "4", "#abcd", "<p></p>", "#[object Object]", "#HtmlUnit"})
1746     public void before_many_notEmpty() throws Exception {
1747         modifySiblings("before", "before(p0, 'abcd', p0, {o: 1});", "HtmlUnit");
1748     }
1749 
1750     /**
1751      * @throws Exception if the test fails
1752      */
1753     @Test
1754     @Alerts({"1", "0",
1755              "childList", "0", "1", "null", "null"})
1756     @HtmlUnitNYI(CHROME = {"1", "0"},
1757             EDGE = {"1", "0"},
1758             FF = {"1", "0"},
1759             FF_ESR = {"1", "0"})
1760     public void replaceWith_noArgs_empty() throws Exception {
1761         modifySiblings("replaceWith", "replaceWith();", "");
1762     }
1763 
1764     /**
1765      * @throws Exception if the test fails
1766      */
1767     @Test
1768     @Alerts({"1", "1", "#HeHo",
1769              "childList", "1", "1", "null", "null"})
1770     @HtmlUnitNYI(CHROME = {"1", "1", "#HeHo"},
1771             EDGE = {"1", "1", "#HeHo"},
1772             FF = {"1", "1", "#HeHo"},
1773             FF_ESR = {"1", "1", "#HeHo"})
1774     public void replaceWith_text_notEmpty() throws Exception {
1775         modifySiblings("replaceWith", "replaceWith('HeHo');", "HtmlUnit");
1776     }
1777 
1778     /**
1779      * @throws Exception if the test fails
1780      */
1781     @Test
1782     @Alerts({"1", "1", "#HeHo",
1783              "childList", "1", "1", "null", "null"})
1784     @HtmlUnitNYI(CHROME = {"1", "1", "#HeHo"},
1785             EDGE = {"1", "1", "#HeHo"},
1786             FF = {"1", "1", "#HeHo"},
1787             FF_ESR = {"1", "1", "#HeHo"})
1788     public void replaceWith_text_empty() throws Exception {
1789         modifySiblings("replaceWith", "replaceWith('HeHo');", "");
1790     }
1791 
1792     /**
1793      * @throws Exception if the test fails
1794      */
1795     @Test
1796     @Alerts({"1", "1", "<p></p>",
1797              "childList", "1", "1", "null", "null"})
1798     @HtmlUnitNYI(CHROME = {"1", "1", "<p></p>"},
1799             EDGE = {"1", "1", "<p></p>"},
1800             FF = {"1", "1", "<p></p>"},
1801             FF_ESR = {"1", "1", "<p></p>"})
1802     public void replaceWith_p_notEmpty() throws Exception {
1803         modifySiblings("replaceWith", "replaceWith(p0);", "HtmlUnit");
1804     }
1805 
1806     /**
1807      * @throws Exception if the test fails
1808      */
1809     @Test
1810     @Alerts({"1", "1", "<p></p>",
1811              "childList", "1", "1", "null", "null"})
1812     @HtmlUnitNYI(CHROME = {"1", "1", "<p></p>"},
1813             EDGE = {"1", "1", "<p></p>"},
1814             FF = {"1", "1", "<p></p>"},
1815             FF_ESR = {"1", "1", "<p></p>"})
1816     public void replaceWith_p_empty() throws Exception {
1817         modifySiblings("replaceWith", "replaceWith(p0);", "");
1818     }
1819 
1820     /**
1821      * @throws Exception if the test fails
1822      */
1823     @Test
1824     @Alerts({"1", "1", "#[object Object]",
1825              "childList", "1", "1", "null", "null"})
1826     @HtmlUnitNYI(CHROME = {"1", "1", "#[object Object]"},
1827             EDGE = {"1", "1", "#[object Object]"},
1828             FF = {"1", "1", "#[object Object]"},
1829             FF_ESR = {"1", "1", "#[object Object]"})
1830     public void replaceWith_o_notEmpty() throws Exception {
1831         modifySiblings("replaceWith", "replaceWith({o: 1});", "HtmlUnit");
1832     }
1833 
1834     /**
1835      * @throws Exception if the test fails
1836      */
1837     @Test
1838     @Alerts({"1", "1", "#[object Object]",
1839              "childList", "1", "1", "null", "null"})
1840     @HtmlUnitNYI(CHROME = {"1", "1", "#[object Object]"},
1841             EDGE = {"1", "1", "#[object Object]"},
1842             FF = {"1", "1", "#[object Object]"},
1843             FF_ESR = {"1", "1", "#[object Object]"})
1844     public void replaceWith_o_empty() throws Exception {
1845         modifySiblings("replaceWith", "replaceWith({o: 1});", "");
1846     }
1847 
1848     /**
1849      * @throws Exception if the test fails
1850      */
1851     @Test
1852     @Alerts({"1", "4", "<p></p>", "#abcd", "<div></div>", "#[object Object]",
1853              "childList", "4", "1", "null", "null"})
1854     @HtmlUnitNYI(CHROME = {"1", "4", "<p></p>", "#abcd", "<div></div>", "#[object Object]"},
1855             EDGE = {"1", "4", "<p></p>", "#abcd", "<div></div>", "#[object Object]"},
1856             FF = {"1", "4", "<p></p>", "#abcd", "<div></div>", "#[object Object]"},
1857             FF_ESR = {"1", "4", "<p></p>", "#abcd", "<div></div>", "#[object Object]"})
1858     public void replaceWith_many_notEmpty() throws Exception {
1859         modifySiblings("replaceWith", "replaceWith(p0, 'abcd', div1, {o: 1});", "HtmlUnit");
1860     }
1861 
1862     /**
1863      * @throws Exception if the test fails
1864      */
1865     @Test
1866     @Alerts({"1", "3", "<p></p>", "#abcd", "<div></div>",
1867              "childList", "3", "1", "null", "null"})
1868     @HtmlUnitNYI(CHROME = {"1", "3", "<p></p>", "#abcd", "<div></div>"},
1869             EDGE = {"1", "3", "<p></p>", "#abcd", "<div></div>"},
1870             FF = {"1", "3", "<p></p>", "#abcd", "<div></div>"},
1871             FF_ESR = {"1", "3", "<p></p>", "#abcd", "<div></div>"})
1872     public void replaceWith_many_many() throws Exception {
1873         modifySiblings("replaceWith", "replaceWith(p0, 'abcd', div1);", "<p>a</p><p>b</p>");
1874     }
1875 
1876     private void modifySiblings(final String check, final String call, final String content) throws Exception {
1877         final String html = DOCTYPE_HTML
1878             + "<html><head></head>\n"
1879             + "<body>\n"
1880             + "  <div id='div0'><div id='div1'>" + content + "</div></div>\n"
1881 
1882             + "<script>\n"
1883             + LOG_TITLE_FUNCTION
1884 
1885             + "  function test() {\n"
1886 
1887             + "    var config = { attributes: true, childList: true, characterData: true, subtree: true };\n"
1888             + "    var observer = new MutationObserver(function(mutations) {\n"
1889             + "      mutations.forEach(function(mutation) {\n"
1890             + "        log(mutation.type);\n"
1891             + "        log(mutation.addedNodes ? mutation.addedNodes.length : mutation.addedNodes);\n"
1892             + "        log(mutation.removedNodes ? mutation.removedNodes.length : mutation.removedNodes);\n"
1893             + "        log(mutation.previousSibling);\n"
1894             + "        log(mutation.nextSibling);\n"
1895             + "      });\n"
1896             + "    });\n"
1897             + "    observer.observe(document.getElementById('div0'), config);\n"
1898 
1899             + "    var d0 = document.getElementById('div0');\n"
1900             + "    var d1 = document.getElementById('div1');\n"
1901 
1902             + "    if (!d1." + check + ") { log('" + check + " missing'); return; }\n"
1903 
1904             + "    var p0 = document.createElement('p');\n"
1905             + "    var div1 = document.createElement('div');\n"
1906 
1907             + "    var children = d0.childNodes;\n"
1908             + "    log(children.length);\n"
1909             + "    d1." + call + "\n"
1910             + "    log(children.length);\n"
1911             + "    for(var i = 0; i < children.length; i++) {\n"
1912             + "      var child = children[i];\n"
1913             + "      if (child.textContent) {\n"
1914             + "        log('#' + child.textContent);\n"
1915             + "      } else {"
1916             + "        log(child.outerHTML);\n"
1917             + "      }\n"
1918             + "    }\n"
1919 
1920             + "  }\n"
1921 
1922             + "  test();"
1923             + "</script>\n"
1924 
1925             + "</body></html>";
1926 
1927         loadPageVerifyTitle2(html);
1928     }
1929 
1930     /**
1931      * @throws Exception if the test fails
1932      */
1933     @Test
1934     @Alerts({"0", "0"})
1935     public void append_noArgs_empty() throws Exception {
1936         modifyChildren("append", "append();", "");
1937     }
1938 
1939     /**
1940      * @throws Exception if the test fails
1941      */
1942     @Test
1943     @Alerts({"1", "1", "#HtmlUnit"})
1944     public void append_noArgs_notEmpty() throws Exception {
1945         modifyChildren("append", "append();", "HtmlUnit");
1946     }
1947 
1948     /**
1949      * @throws Exception if the test fails
1950      */
1951     @Test
1952     @Alerts({"0", "1", "#HeHo",
1953              "childList", "1", "0", "null", "null"})
1954     @HtmlUnitNYI(CHROME = {"0", "1", "#HeHo"},
1955             EDGE = {"0", "1", "#HeHo"},
1956             FF = {"0", "1", "#HeHo"},
1957             FF_ESR = {"0", "1", "#HeHo"})
1958     public void append_text_empty() throws Exception {
1959         modifyChildren("append", "append('HeHo');", "");
1960     }
1961 
1962     /**
1963      * @throws Exception if the test fails
1964      */
1965     @Test
1966     @Alerts({"1", "2", "#HtmlUnit", "#HeHo",
1967              "childList", "1", "0", "[object Text]", "null"})
1968     @HtmlUnitNYI(CHROME = {"1", "2", "#HtmlUnit", "#HeHo"},
1969             EDGE = {"1", "2", "#HtmlUnit", "#HeHo"},
1970             FF = {"1", "2", "#HtmlUnit", "#HeHo"},
1971             FF_ESR = {"1", "2", "#HtmlUnit", "#HeHo"})
1972     public void append_text_notEmpty() throws Exception {
1973         modifyChildren("append", "append('HeHo');", "HtmlUnit");
1974     }
1975 
1976     /**
1977      * @throws Exception if the test fails
1978      */
1979     @Test
1980     @Alerts({"0", "1", "<p></p>",
1981              "childList", "1", "0", "null", "null"})
1982     @HtmlUnitNYI(CHROME = {"0", "1", "<p></p>"},
1983             EDGE = {"0", "1", "<p></p>"},
1984             FF = {"0", "1", "<p></p>"},
1985             FF_ESR = {"0", "1", "<p></p>"})
1986     public void append_p_empty() throws Exception {
1987         modifyChildren("append", "append(p0);", "");
1988     }
1989 
1990     /**
1991      * @throws Exception if the test fails
1992      */
1993     @Test
1994     @Alerts({"1", "2", "#HtmlUnit", "<p></p>",
1995              "childList", "1", "0", "[object Text]", "null"})
1996     @HtmlUnitNYI(CHROME = {"1", "2", "#HtmlUnit", "<p></p>"},
1997             EDGE = {"1", "2", "#HtmlUnit", "<p></p>"},
1998             FF = {"1", "2", "#HtmlUnit", "<p></p>"},
1999             FF_ESR = {"1", "2", "#HtmlUnit", "<p></p>"})
2000     public void append_p_notEmpty() throws Exception {
2001         modifyChildren("append", "append(p0);", "HtmlUnit");
2002     }
2003 
2004     /**
2005      * @throws Exception if the test fails
2006      */
2007     @Test
2008     @Alerts({"0", "1", "#[object Object]",
2009              "childList", "1", "0", "null", "null"})
2010     @HtmlUnitNYI(CHROME = {"0", "1", "#[object Object]"},
2011             EDGE = {"0", "1", "#[object Object]"},
2012             FF = {"0", "1", "#[object Object]"},
2013             FF_ESR = {"0", "1", "#[object Object]"})
2014     public void append_o_empty() throws Exception {
2015         modifyChildren("append", "append({o: 1});", "");
2016     }
2017 
2018     /**
2019      * @throws Exception if the test fails
2020      */
2021     @Test
2022     @Alerts({"1", "2", "#HtmlUnit", "#[object Object]",
2023              "childList", "1", "0", "[object Text]", "null"})
2024     @HtmlUnitNYI(CHROME = {"1", "2", "#HtmlUnit", "#[object Object]"},
2025             EDGE = {"1", "2", "#HtmlUnit", "#[object Object]"},
2026             FF = {"1", "2", "#HtmlUnit", "#[object Object]"},
2027             FF_ESR = {"1", "2", "#HtmlUnit", "#[object Object]"})
2028     public void append_o_notEmpty() throws Exception {
2029         modifyChildren("append", "append({o: 1});", "HtmlUnit");
2030     }
2031 
2032     /**
2033      * @throws Exception if the test fails
2034      */
2035     @Test
2036     @Alerts({"1", "4", "#HtmlUnit", "#abcd", "<p></p>", "#[object Object]",
2037              "childList", "3", "0", "[object Text]", "null"})
2038     @HtmlUnitNYI(CHROME = {"1", "4", "#HtmlUnit", "#abcd", "<p></p>", "#[object Object]"},
2039             EDGE = {"1", "4", "#HtmlUnit", "#abcd", "<p></p>", "#[object Object]"},
2040             FF = {"1", "4", "#HtmlUnit", "#abcd", "<p></p>", "#[object Object]"},
2041             FF_ESR = {"1", "4", "#HtmlUnit", "#abcd", "<p></p>", "#[object Object]"})
2042     public void append_many_notEmpty() throws Exception {
2043         modifyChildren("append", "append(p0, 'abcd', p0, {o: 1});", "HtmlUnit");
2044     }
2045 
2046     /**
2047      * @throws Exception if the test fails
2048      */
2049     @Test
2050     @Alerts({"0", "0"})
2051     public void prepend_noArgs_empty() throws Exception {
2052         modifyChildren("prepend", "prepend();", "");
2053     }
2054 
2055     /**
2056      * @throws Exception if the test fails
2057      */
2058     @Test
2059     @Alerts({"1", "1", "#HtmlUnit"})
2060     public void prepend_noArgs_notEmpty() throws Exception {
2061         modifyChildren("prepend", "prepend();", "HtmlUnit");
2062     }
2063 
2064     /**
2065      * @throws Exception if the test fails
2066      */
2067     @Test
2068     @Alerts({"0", "1", "#HeHo",
2069              "childList", "1", "0", "null", "null"})
2070     @HtmlUnitNYI(CHROME = {"0", "1", "#HeHo"},
2071             EDGE = {"0", "1", "#HeHo"},
2072             FF = {"0", "1", "#HeHo"},
2073             FF_ESR = {"0", "1", "#HeHo"})
2074     public void prepend_text_empty() throws Exception {
2075         modifyChildren("prepend", "prepend('HeHo');", "");
2076     }
2077 
2078     /**
2079      * @throws Exception if the test fails
2080      */
2081     @Test
2082     @Alerts({"1", "2", "#HeHo", "#HtmlUnit",
2083              "childList", "1", "0", "null", "[object Text]"})
2084     @HtmlUnitNYI(CHROME = {"1", "2", "#HeHo", "#HtmlUnit"},
2085             EDGE = {"1", "2", "#HeHo", "#HtmlUnit"},
2086             FF = {"1", "2", "#HeHo", "#HtmlUnit"},
2087             FF_ESR = {"1", "2", "#HeHo", "#HtmlUnit"})
2088     public void prepend_text_notEmpty() throws Exception {
2089         modifyChildren("prepend", "prepend('HeHo');", "HtmlUnit");
2090     }
2091 
2092     /**
2093      * @throws Exception if the test fails
2094      */
2095     @Test
2096     @Alerts({"0", "1", "<p></p>",
2097              "childList", "1", "0", "null", "null"})
2098     @HtmlUnitNYI(CHROME = {"0", "1", "<p></p>"},
2099             EDGE = {"0", "1", "<p></p>"},
2100             FF = {"0", "1", "<p></p>"},
2101             FF_ESR = {"0", "1", "<p></p>"})
2102     public void prepend_p_empty() throws Exception {
2103         modifyChildren("prepend", "prepend(p0);", "");
2104     }
2105 
2106     /**
2107      * @throws Exception if the test fails
2108      */
2109     @Test
2110     @Alerts({"1", "2", "<p></p>", "#HtmlUnit",
2111              "childList", "1", "0", "null", "[object Text]"})
2112     @HtmlUnitNYI(CHROME = {"1", "2", "<p></p>", "#HtmlUnit"},
2113             EDGE = {"1", "2", "<p></p>", "#HtmlUnit"},
2114             FF = {"1", "2", "<p></p>", "#HtmlUnit"},
2115             FF_ESR = {"1", "2", "<p></p>", "#HtmlUnit"})
2116     public void prepend_p_notEmpty() throws Exception {
2117         modifyChildren("prepend", "prepend(p0);", "HtmlUnit");
2118     }
2119 
2120     /**
2121      * @throws Exception if the test fails
2122      */
2123     @Test
2124     @Alerts({"0", "1", "#[object Object]",
2125              "childList", "1", "0", "null", "null"})
2126     @HtmlUnitNYI(CHROME = {"0", "1", "#[object Object]"},
2127             EDGE = {"0", "1", "#[object Object]"},
2128             FF = {"0", "1", "#[object Object]"},
2129             FF_ESR = {"0", "1", "#[object Object]"})
2130     public void prepend_o_empty() throws Exception {
2131         modifyChildren("prepend", "prepend({o: 1});", "");
2132     }
2133 
2134     /**
2135      * @throws Exception if the test fails
2136      */
2137     @Test
2138     @Alerts({"1", "2", "#[object Object]", "#HtmlUnit",
2139              "childList", "1", "0", "null", "[object Text]"})
2140     @HtmlUnitNYI(CHROME = {"1", "2", "#[object Object]", "#HtmlUnit"},
2141             EDGE = {"1", "2", "#[object Object]", "#HtmlUnit"},
2142             FF = {"1", "2", "#[object Object]", "#HtmlUnit"},
2143             FF_ESR = {"1", "2", "#[object Object]", "#HtmlUnit"})
2144     public void prepend_o_notEmpty() throws Exception {
2145         modifyChildren("prepend", "prepend({o: 1});", "HtmlUnit");
2146     }
2147 
2148     /**
2149      * @throws Exception if the test fails
2150      */
2151     @Test
2152     @Alerts({"1", "4", "#abcd", "<p></p>", "#[object Object]", "#HtmlUnit",
2153              "childList", "3", "0", "null", "[object Text]"})
2154     @HtmlUnitNYI(CHROME = {"1", "4", "#abcd", "<p></p>", "#[object Object]", "#HtmlUnit"},
2155             EDGE = {"1", "4", "#abcd", "<p></p>", "#[object Object]", "#HtmlUnit"},
2156             FF = {"1", "4", "#abcd", "<p></p>", "#[object Object]", "#HtmlUnit"},
2157             FF_ESR = {"1", "4", "#abcd", "<p></p>", "#[object Object]", "#HtmlUnit"})
2158     public void prepend_many_notEmpty() throws Exception {
2159         modifyChildren("prepend", "prepend(p0, 'abcd', p0, {o: 1});", "HtmlUnit");
2160     }
2161 
2162     /**
2163      * @throws Exception if the test fails
2164      */
2165     @Test
2166     @Alerts({"0", "0"})
2167     public void replaceChildren_noArgs_empty() throws Exception {
2168         modifyChildren("replaceChildren", "replaceChildren();", "");
2169     }
2170 
2171     /**
2172      * @throws Exception if the test fails
2173      */
2174     @Test
2175     @Alerts({"1", "1", "#HeHo",
2176              "childList", "1", "1", "null", "null"})
2177     @HtmlUnitNYI(CHROME = {"1", "1", "#HeHo"},
2178             EDGE = {"1", "1", "#HeHo"},
2179             FF = {"1", "1", "#HeHo"},
2180             FF_ESR = {"1", "1", "#HeHo"})
2181     public void replaceChildren_text_notEmpty() throws Exception {
2182         modifyChildren("replaceChildren", "replaceChildren('HeHo');", "HtmlUnit");
2183     }
2184 
2185     /**
2186      * @throws Exception if the test fails
2187      */
2188     @Test
2189     @Alerts({"0", "1", "#HeHo",
2190              "childList", "1", "0", "null", "null"})
2191     @HtmlUnitNYI(CHROME = {"0", "1", "#HeHo"},
2192             EDGE = {"0", "1", "#HeHo"},
2193             FF = {"0", "1", "#HeHo"},
2194             FF_ESR = {"0", "1", "#HeHo"})
2195     public void replaceChildren_text_empty() throws Exception {
2196         modifyChildren("replaceChildren", "replaceChildren('HeHo');", "");
2197     }
2198 
2199     /**
2200      * @throws Exception if the test fails
2201      */
2202     @Test
2203     @Alerts({"1", "1", "<p></p>",
2204              "childList", "1", "1", "null", "null"})
2205     @HtmlUnitNYI(CHROME = {"1", "1", "<p></p>"},
2206             EDGE = {"1", "1", "<p></p>"},
2207             FF = {"1", "1", "<p></p>"},
2208             FF_ESR = {"1", "1", "<p></p>"})
2209     public void replaceChildren_p_notEmpty() throws Exception {
2210         modifyChildren("replaceChildren", "replaceChildren(p0);", "HtmlUnit");
2211     }
2212 
2213     /**
2214      * @throws Exception if the test fails
2215      */
2216     @Test
2217     @Alerts({"0", "1", "<p></p>",
2218              "childList", "1", "0", "null", "null"})
2219     @HtmlUnitNYI(CHROME = {"0", "1", "<p></p>"},
2220             EDGE = {"0", "1", "<p></p>"},
2221             FF = {"0", "1", "<p></p>"},
2222             FF_ESR = {"0", "1", "<p></p>"})
2223     public void replaceChildren_p_empty() throws Exception {
2224         modifyChildren("replaceChildren", "replaceChildren(p0);", "");
2225     }
2226 
2227     /**
2228      * @throws Exception if the test fails
2229      */
2230     @Test
2231     @Alerts({"1", "1", "#[object Object]",
2232              "childList", "1", "1", "null", "null"})
2233     @HtmlUnitNYI(CHROME = {"1", "1", "#[object Object]"},
2234             EDGE = {"1", "1", "#[object Object]"},
2235             FF = {"1", "1", "#[object Object]"},
2236             FF_ESR = {"1", "1", "#[object Object]"})
2237     public void replaceChildren_o_notEmpty() throws Exception {
2238         modifyChildren("replaceChildren", "replaceChildren({o: 1});", "HtmlUnit");
2239     }
2240 
2241     /**
2242      * @throws Exception if the test fails
2243      */
2244     @Test
2245     @Alerts({"0", "1", "#[object Object]",
2246              "childList", "1", "0", "null", "null"})
2247     @HtmlUnitNYI(CHROME = {"0", "1", "#[object Object]"},
2248             EDGE = {"0", "1", "#[object Object]"},
2249             FF = {"0", "1", "#[object Object]"},
2250             FF_ESR = {"0", "1", "#[object Object]"})
2251     public void replaceChildren_o_empty() throws Exception {
2252         modifyChildren("replaceChildren", "replaceChildren({o: 1});", "");
2253     }
2254 
2255     /**
2256      * @throws Exception if the test fails
2257      */
2258     @Test
2259     @Alerts({"1", "4", "<p></p>", "#abcd", "<div></div>", "#[object Object]",
2260              "childList", "4", "1", "null", "null"})
2261     @HtmlUnitNYI(CHROME = {"1", "4", "<p></p>", "#abcd", "<div></div>", "#[object Object]"},
2262             EDGE = {"1", "4", "<p></p>", "#abcd", "<div></div>", "#[object Object]"},
2263             FF = {"1", "4", "<p></p>", "#abcd", "<div></div>", "#[object Object]"},
2264             FF_ESR = {"1", "4", "<p></p>", "#abcd", "<div></div>", "#[object Object]"})
2265     public void replaceChildren_many_notEmpty() throws Exception {
2266         modifyChildren("replaceChildren", "replaceChildren(p0, 'abcd', div1, {o: 1});", "HtmlUnit");
2267     }
2268 
2269     /**
2270      * @throws Exception if the test fails
2271      */
2272     @Test
2273     @Alerts({"2", "3", "<p></p>", "#abcd", "<div></div>",
2274              "childList", "3", "2", "null", "null"})
2275     @HtmlUnitNYI(CHROME = {"2", "3", "<p></p>", "#abcd", "<div></div>"},
2276             EDGE = {"2", "3", "<p></p>", "#abcd", "<div></div>"},
2277             FF = {"2", "3", "<p></p>", "#abcd", "<div></div>"},
2278             FF_ESR = {"2", "3", "<p></p>", "#abcd", "<div></div>"})
2279     public void replaceChildren_many_many() throws Exception {
2280         modifyChildren("replaceChildren", "replaceChildren(p0, 'abcd', div1);", "<p>a</p><p>b</p>");
2281     }
2282 
2283     /**
2284      * @throws Exception if the test fails
2285      */
2286     @Test
2287     @Alerts({"4", "3", "<p></p>", "#abcd", "<div></div>",
2288              "childList", "3", "4", "null", "null"})
2289     @HtmlUnitNYI(CHROME = {"4", "3", "<p></p>", "#abcd", "<div></div>"},
2290             EDGE = {"4", "3", "<p></p>", "#abcd", "<div></div>"},
2291             FF = {"4", "3", "<p></p>", "#abcd", "<div></div>"},
2292             FF_ESR = {"4", "3", "<p></p>", "#abcd", "<div></div>"})
2293     public void replaceChildren_many_many2() throws Exception {
2294         modifyChildren("replaceChildren", "replaceChildren(p0, 'abcd', div1);", "<p>a</p><p>b</p><p>c</p><p>d</p>");
2295     }
2296 
2297     private void modifyChildren(final String check, final String call, final String content) throws Exception {
2298         final String html = DOCTYPE_HTML
2299             + "<html><head></head>\n"
2300             + "<body>\n"
2301             + "  <div id='div0'>" + content + "</div>\n"
2302 
2303             + "<script>\n"
2304             + LOG_TITLE_FUNCTION
2305 
2306             + "  function test() {\n"
2307 
2308             + "    var config = { attributes: true, childList: true, characterData: true, subtree: true };\n"
2309             + "    var observer = new MutationObserver(function(mutations) {\n"
2310             + "      mutations.forEach(function(mutation) {\n"
2311             + "        log(mutation.type);\n"
2312             + "        log(mutation.addedNodes ? mutation.addedNodes.length : mutation.addedNodes);\n"
2313             + "        log(mutation.removedNodes ? mutation.removedNodes.length : mutation.removedNodes);\n"
2314             + "        log(mutation.previousSibling);\n"
2315             + "        log(mutation.nextSibling);\n"
2316             + "      });\n"
2317             + "    });\n"
2318             + "    observer.observe(document.getElementById('div0'), config);\n"
2319 
2320             + "    var d0 = document.getElementById('div0');\n"
2321 
2322             + "    if (!d0." + check + ") { log('" + check + " missing'); return; }\n"
2323 
2324             + "    var p0 = document.createElement('p');\n"
2325             + "    var div1 = document.createElement('div');\n"
2326 
2327             + "    var children = d0.childNodes;\n"
2328             + "    log(children.length);\n"
2329             + "    d0." + call + "\n"
2330             + "    log(children.length);\n"
2331             + "    for(var i = 0; i < children.length; i++) {\n"
2332             + "      var child = children[i];\n"
2333             + "      if (child.textContent) {\n"
2334             + "        log('#' + child.textContent);\n"
2335             + "      } else {"
2336             + "        log(child.outerHTML);\n"
2337             + "      }\n"
2338             + "    }\n"
2339 
2340             + "  }\n"
2341 
2342             + "  test();"
2343             + "</script>\n"
2344 
2345             + "</body></html>";
2346 
2347         loadPageVerifyTitle2(html);
2348     }
2349 
2350     /**
2351      * @throws Exception if the test fails
2352      */
2353     @Test
2354     @Alerts({"0,0", "10,30", "22,64", "5,0", "type error", "5,0", "onscroll 5,0"})
2355     @HtmlUnitNYI(CHROME = {"0,0", "onscroll 10,30", "10,30", "onscroll 22,64", "22,64",
2356                            "onscroll 5,0", "5,0", "type error", "5,0"},
2357             EDGE = {"0,0", "onscroll 10,30", "10,30", "onscroll 22,64", "22,64",
2358                     "onscroll 5,0", "5,0", "type error", "5,0"},
2359             FF = {"0,0", "onscroll 10,30", "10,30", "onscroll 22,64", "22,64",
2360                   "onscroll 5,0", "5,0", "type error", "5,0"},
2361             FF_ESR = {"0,0", "onscroll 10,30", "10,30", "onscroll 22,64", "22,64",
2362                       "onscroll 5,0", "5,0", "type error", "5,0"})
2363     public void scrollBy() throws Exception {
2364         final String html = DOCTYPE_HTML
2365             + "<html><body onload='test()'>\n"
2366             + "<div id='d' style='width: 100px;height: 99px;overflow: scroll;'>\n"
2367             + "<div style='width:10000px;height:10000px;background-color:blue;'></div>\n"
2368             + "</div>"
2369             + "<script>\n"
2370             + LOG_TITLE_FUNCTION
2371             + "function test() {\n"
2372             + "  var d = document.getElementById('d');\n"
2373             + "  d.onscroll = (event) => { log('onscroll ' + d.scrollLeft + ',' + d.scrollTop); };"
2374 
2375             + "  log(d.scrollLeft + ',' + d.scrollTop);\n"
2376 
2377             + "  d.scrollBy(10, 30);\n"
2378             + "  log(d.scrollLeft + ',' + d.scrollTop);\n"
2379 
2380             + "  d.scrollBy(12, 34);\n"
2381             + "  log(d.scrollLeft + ',' + d.scrollTop);\n"
2382 
2383             + "  d.scrollBy(-17, -100);\n"
2384             + "  log(d.scrollLeft + ',' + d.scrollTop);\n"
2385 
2386             + "  try { d.scrollBy(44); } catch(e) { log('type error'); }\n"
2387             + "  log(d.scrollLeft + ',' + d.scrollTop);\n"
2388             + "}\n"
2389             + "</script></body></html>";
2390         loadPageVerifyTitle2(html);
2391     }
2392 
2393     /**
2394      * @throws Exception if the test fails
2395      */
2396     @Test
2397     @Alerts({"0,0", "10,30", "22,64", "5,0", "49,0", "49,0", "onscroll 49,0"})
2398     @HtmlUnitNYI(CHROME = {"0,0", "onscroll 10,30", "10,30", "onscroll 22,64", "22,64",
2399                            "onscroll 5,0", "5,0", "onscroll 49,0", "49,0", "onscroll 49,0", "49,0"},
2400             EDGE = {"0,0", "onscroll 10,30", "10,30", "onscroll 22,64", "22,64",
2401                     "onscroll 5,0", "5,0", "onscroll 49,0", "49,0", "onscroll 49,0", "49,0"},
2402             FF = {"0,0", "onscroll 10,30", "10,30", "onscroll 22,64", "22,64",
2403                   "onscroll 5,0", "5,0", "onscroll 49,0", "49,0", "onscroll 49,0", "49,0"},
2404             FF_ESR = {"0,0", "onscroll 10,30", "10,30", "onscroll 22,64", "22,64",
2405                       "onscroll 5,0", "5,0", "onscroll 49,0", "49,0", "onscroll 49,0", "49,0"})
2406     public void scrollByOptions() throws Exception {
2407         final String html = DOCTYPE_HTML
2408             + "<html><body onload='test()'>\n"
2409             + "<div id='d' style='width: 100px;height: 99px;overflow: scroll;'>\n"
2410             + "<div style='width:10000px;height:10000px;background-color:blue;'></div>\n"
2411             + "</div>"
2412             + "<script>\n"
2413             + LOG_TITLE_FUNCTION
2414             + "function test() {\n"
2415             + "  var d = document.getElementById('d');\n"
2416             + "  d.onscroll = (event) => { log('onscroll ' + d.scrollLeft + ',' + d.scrollTop); };"
2417 
2418             + "  log(d.scrollLeft + ',' + d.scrollTop);\n"
2419 
2420             + "  d.scrollBy({left: 10, top: 30});\n"
2421             + "  log(d.scrollLeft + ',' + d.scrollTop);\n"
2422 
2423             + "  d.scrollBy({left: 12, top: 34});\n"
2424             + "  log(d.scrollLeft + ',' + d.scrollTop);\n"
2425 
2426             + "  d.scrollBy({left: -17, top: -100});\n"
2427             + "  log(d.scrollLeft + ',' + d.scrollTop);\n"
2428 
2429             + "  d.scrollBy({left: 44});\n"
2430             + "  log(d.scrollLeft + ',' + d.scrollTop);\n"
2431 
2432             + "  d.scrollBy({abcd: 7});\n"
2433             + "  log(d.scrollLeft + ',' + d.scrollTop);\n"
2434             + "}\n"
2435             + "</script></body></html>";
2436         loadPageVerifyTitle2(html);
2437     }
2438 
2439     /**
2440      * @throws Exception if the test fails
2441      */
2442     @Test
2443     @Alerts({"0,0", "10,30", "12,34", "0,0", "type error", "0,0", "onscroll 0,0"})
2444     @HtmlUnitNYI(CHROME = {"0,0", "onscroll 10,30", "10,30", "onscroll 12,34", "12,34",
2445                            "onscroll 0,0", "0,0", "type error", "0,0"},
2446             EDGE = {"0,0", "onscroll 10,30", "10,30", "onscroll 12,34", "12,34",
2447                     "onscroll 0,0", "0,0", "type error", "0,0"},
2448             FF = {"0,0", "onscroll 10,30", "10,30", "onscroll 12,34", "12,34",
2449                   "onscroll 0,0", "0,0", "type error", "0,0"},
2450             FF_ESR = {"0,0", "onscroll 10,30", "10,30", "onscroll 12,34", "12,34",
2451                       "onscroll 0,0", "0,0", "type error", "0,0"})
2452     public void scrollTo() throws Exception {
2453         final String html = DOCTYPE_HTML
2454             + "<html><body onload='test()'>\n"
2455             + "<div id='d' style='width: 100px;height: 99px;overflow: scroll;'>\n"
2456             + "<div style='width:10000px;height:10000px;background-color:blue;'></div>\n"
2457             + "</div>"
2458             + "<script>\n"
2459             + LOG_TITLE_FUNCTION
2460             + "function test() {\n"
2461             + "  var d = document.getElementById('d');\n"
2462             + "  d.onscroll = (event) => { log('onscroll ' + d.scrollLeft + ',' + d.scrollTop); };"
2463 
2464             + "  log(d.scrollLeft + ',' + d.scrollTop);\n"
2465 
2466             + "  d.scrollTo(10, 30);\n"
2467             + "  log(d.scrollLeft + ',' + d.scrollTop);\n"
2468 
2469             + "  d.scrollTo(12, 34);\n"
2470             + "  log(d.scrollLeft + ',' + d.scrollTop);\n"
2471 
2472             + "  d.scrollTo(-17, -100);\n"
2473             + "  log(d.scrollLeft + ',' + d.scrollTop);\n"
2474 
2475             + "  try { d.scrollTo(44); } catch(e) { log('type error'); }\n"
2476             + "  log(d.scrollLeft + ',' + d.scrollTop);\n"
2477             + "}\n"
2478             + "</script></body></html>";
2479         loadPageVerifyTitle2(html);
2480     }
2481 
2482     /**
2483      * @throws Exception if the test fails
2484      */
2485     @Test
2486     @Alerts({"0,0", "10,30", "12,34", "0,0", "44,0", "44,0", "onscroll 44,0"})
2487     @HtmlUnitNYI(CHROME = {"0,0", "onscroll 10,30", "10,30", "onscroll 12,34", "12,34",
2488                            "onscroll 0,0", "0,0", "onscroll 44,0", "44,0", "onscroll 44,0", "44,0"},
2489             EDGE = {"0,0", "onscroll 10,30", "10,30", "onscroll 12,34", "12,34",
2490                     "onscroll 0,0", "0,0", "onscroll 44,0", "44,0", "onscroll 44,0", "44,0"},
2491             FF = {"0,0", "onscroll 10,30", "10,30", "onscroll 12,34", "12,34",
2492                   "onscroll 0,0", "0,0", "onscroll 44,0", "44,0", "onscroll 44,0", "44,0"},
2493             FF_ESR = {"0,0", "onscroll 10,30", "10,30", "onscroll 12,34", "12,34",
2494                       "onscroll 0,0", "0,0", "onscroll 44,0", "44,0", "onscroll 44,0", "44,0"})
2495     public void scrollToOptions() throws Exception {
2496         final String html = DOCTYPE_HTML
2497             + "<html><body onload='test()'>\n"
2498             + "<div id='d' style='width: 100px;height: 99px;overflow: scroll;'>\n"
2499             + "<div style='width:10000px;height:10000px;background-color:blue;'></div>\n"
2500             + "</div>"
2501             + "<script>\n"
2502             + LOG_TITLE_FUNCTION
2503             + "function test() {\n"
2504             + "  var d = document.getElementById('d');\n"
2505             + "  d.onscroll = (event) => { log('onscroll ' + d.scrollLeft + ',' + d.scrollTop); };"
2506 
2507             + "  log(d.scrollLeft + ',' + d.scrollTop);\n"
2508 
2509             + "  d.scrollTo({left: 10, top: 30});\n"
2510             + "  log(d.scrollLeft + ',' + d.scrollTop);\n"
2511 
2512             + "  d.scrollTo({left: 12, top: 34});\n"
2513             + "  log(d.scrollLeft + ',' + d.scrollTop);\n"
2514 
2515             + "  d.scrollTo({left: -17, top: -100});\n"
2516             + "  log(d.scrollLeft + ',' + d.scrollTop);\n"
2517 
2518             + "  d.scrollTo({left: 44});\n"
2519             + "  log(d.scrollLeft + ',' + d.scrollTop);\n"
2520 
2521             + "  d.scrollTo({abcd: 7});\n"
2522             + "  log(d.scrollLeft + ',' + d.scrollTop);\n"
2523             + "}\n"
2524             + "</script></body></html>";
2525         loadPageVerifyTitle2(html);
2526     }
2527 
2528     /**
2529      * @throws Exception if the test fails
2530      */
2531     @Test
2532     @Alerts({"0,0", "10,30", "12,34", "0,0", "type error", "0,0", "onscroll 0,0"})
2533     @HtmlUnitNYI(CHROME = {"0,0", "onscroll 10,30", "10,30", "onscroll 12,34", "12,34",
2534                            "onscroll 0,0", "0,0", "type error", "0,0"},
2535             EDGE = {"0,0", "onscroll 10,30", "10,30", "onscroll 12,34", "12,34",
2536                     "onscroll 0,0", "0,0", "type error", "0,0"},
2537             FF = {"0,0", "onscroll 10,30", "10,30", "onscroll 12,34", "12,34",
2538                   "onscroll 0,0", "0,0", "type error", "0,0"},
2539             FF_ESR = {"0,0", "onscroll 10,30", "10,30", "onscroll 12,34", "12,34",
2540                       "onscroll 0,0", "0,0", "type error", "0,0"})
2541     public void scroll() throws Exception {
2542         final String html = DOCTYPE_HTML
2543             + "<html><body onload='test()'>\n"
2544             + "<div id='d' style='width: 100px;height: 99px;overflow: scroll;'>\n"
2545             + "<div style='width:10000px;height:10000px;background-color:blue;'></div>\n"
2546             + "</div>"
2547             + "<script>\n"
2548             + LOG_TITLE_FUNCTION
2549             + "function test() {\n"
2550             + "  var d = document.getElementById('d');\n"
2551             + "  d.onscroll = (event) => { log('onscroll ' + d.scrollLeft + ',' + d.scrollTop); };"
2552 
2553             + "  log(d.scrollLeft + ',' + d.scrollTop);\n"
2554 
2555             + "  d.scroll(10, 30);\n"
2556             + "  log(d.scrollLeft + ',' + d.scrollTop);\n"
2557 
2558             + "  d.scroll(12, 34);\n"
2559             + "  log(d.scrollLeft + ',' + d.scrollTop);\n"
2560 
2561             + "  d.scroll(-17, -100);\n"
2562             + "  log(d.scrollLeft + ',' + d.scrollTop);\n"
2563 
2564             + "  try { d.scroll(44); } catch(e) { log('type error'); }\n"
2565             + "  log(d.scrollLeft + ',' + d.scrollTop);\n"
2566             + "}\n"
2567             + "</script></body></html>";
2568         loadPageVerifyTitle2(html);
2569     }
2570 
2571     /**
2572      * @throws Exception if the test fails
2573      */
2574     @Test
2575     @Alerts({"0,0", "10,30", "12,34", "0,0", "44,0", "44,0", "onscroll 44,0"})
2576     @HtmlUnitNYI(CHROME = {"0,0", "onscroll 10,30", "10,30", "onscroll 12,34", "12,34",
2577                            "onscroll 0,0", "0,0", "onscroll 44,0", "44,0", "onscroll 44,0", "44,0"},
2578             EDGE = {"0,0", "onscroll 10,30", "10,30", "onscroll 12,34", "12,34",
2579                     "onscroll 0,0", "0,0", "onscroll 44,0", "44,0", "onscroll 44,0", "44,0"},
2580             FF = {"0,0", "onscroll 10,30", "10,30", "onscroll 12,34", "12,34",
2581                   "onscroll 0,0", "0,0", "onscroll 44,0", "44,0", "onscroll 44,0", "44,0"},
2582             FF_ESR = {"0,0", "onscroll 10,30", "10,30", "onscroll 12,34", "12,34",
2583                       "onscroll 0,0", "0,0", "onscroll 44,0", "44,0", "onscroll 44,0", "44,0"})
2584     public void scrollOptions() throws Exception {
2585         final String html = DOCTYPE_HTML
2586             + "<html><body onload='test()'>\n"
2587             + "<div id='d' style='width: 100px;height: 99px;overflow: scroll;'>\n"
2588             + "<div style='width:10000px;height:10000px;background-color:blue;'></div>\n"
2589             + "</div>"
2590             + "<script>\n"
2591             + LOG_TITLE_FUNCTION
2592             + "function test() {\n"
2593             + "  var d = document.getElementById('d');\n"
2594             + "  d.onscroll = (event) => { log('onscroll ' + d.scrollLeft + ',' + d.scrollTop); };"
2595 
2596             + "  log(d.scrollLeft + ',' + d.scrollTop);\n"
2597 
2598             + "  d.scroll({left: 10, top: 30});\n"
2599             + "  log(d.scrollLeft + ',' + d.scrollTop);\n"
2600 
2601             + "  d.scroll({left: 12, top: 34});\n"
2602             + "  log(d.scrollLeft + ',' + d.scrollTop);\n"
2603 
2604             + "  d.scroll({left: -17, top: -100});\n"
2605             + "  log(d.scrollLeft + ',' + d.scrollTop);\n"
2606 
2607             + "  d.scroll({left: 44});\n"
2608             + "  log(d.scrollLeft + ',' + d.scrollTop);\n"
2609 
2610             + "  d.scroll({abcd: 7});\n"
2611             + "  log(d.scrollLeft + ',' + d.scrollTop);\n"
2612             + "}\n"
2613             + "</script></body></html>";
2614         loadPageVerifyTitle2(html);
2615     }
2616 }