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