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.dom;
16  
17  import static org.htmlunit.javascript.host.xml.XMLDocumentTest.LOAD_XML_DOCUMENT_FROM_FILE_FUNCTION;
18  import static org.htmlunit.javascript.host.xml.XMLDocumentTest.callLoadXMLDocumentFromFile;
19  
20  import java.net.URL;
21  
22  import org.htmlunit.WebDriverTestCase;
23  import org.htmlunit.junit.annotation.Alerts;
24  import org.htmlunit.junit.annotation.HtmlUnitNYI;
25  import org.htmlunit.util.MimeType;
26  import org.junit.jupiter.api.Test;
27  import org.junit.jupiter.api.condition.EnabledOnJre;
28  import org.junit.jupiter.api.condition.JRE;
29  import org.openqa.selenium.By;
30  import org.openqa.selenium.WebDriver;
31  
32  /**
33   * Tests for {@link Document}.
34   *
35   * @author Mike Bowler
36   * @author David K. Taylor
37   * @author Barnaby Court
38   * @author Chris Erskine
39   * @author Marc Guillemot
40   * @author Michael Ottati
41   * @author George Murnock
42   * @author Ahmed Ashour
43   * @author Rob Di Marco
44   * @author Sudhan Moghe
45   * @author Frank Danek
46   * @author Ronald Brill
47   */
48  public class DocumentTest extends WebDriverTestCase {
49  
50      /**
51       * @throws Exception if the test fails
52       */
53      @Test
54      @Alerts({"2", "form1", "form2"})
55      public void formsAccessor_TwoForms() throws Exception {
56          final String html = DOCTYPE_HTML
57              + "<html><head><script>\n"
58              + LOG_TITLE_FUNCTION
59              + "function doTest() {\n"
60              + "  log(document.forms.length);\n"
61              + "  for(var i = 0; i < document.forms.length; i++) {\n"
62              + "    log(document.forms[i].name);\n"
63              + "  }\n"
64              + "}\n"
65              + "</script></head><body onload='doTest()'>\n"
66              + "<p>hello world</p>\n"
67              + "<form name='form1'>\n"
68              + "  <input type='text' name='textfield1' value='foo' />\n"
69              + "</form>\n"
70              + "<form name='form2'>\n"
71              + "  <input type='text' name='textfield2' value='foo' />\n"
72              + "</form>\n"
73              + "</body></html>";
74  
75          loadPageVerifyTitle2(html);
76      }
77  
78      /**
79       * Previously, forms with no names were not being returned by document.forms.
80       * @throws Exception if the test fails
81       */
82      @Test
83      @Alerts("1")
84      public void formsAccessor_FormWithNoName() throws Exception {
85          final String html = DOCTYPE_HTML
86              + "<html><head><script>\n"
87              + LOG_TITLE_FUNCTION
88              + "function doTest() {\n"
89              + "  log(document.forms.length);\n"
90              + "}\n"
91              + "</script></head><body onload='doTest()'>\n"
92              + "<p>hello world</p>\n"
93              + "<form>\n"
94              + "  <input type='text' name='textfield1' value='foo' />\n"
95              + "</form>\n"
96              + "</body></html>";
97  
98          loadPageVerifyTitle2(html);
99      }
100 
101     /**
102      * @throws Exception if the test fails
103      */
104     @Test
105     @Alerts("0")
106     public void formsAccessor_NoForms() throws Exception {
107         final String html = DOCTYPE_HTML
108             + "<html><head><script>\n"
109             + LOG_TITLE_FUNCTION
110             + "function doTest() {\n"
111             + "  log(document.forms.length);\n"
112             + "  for(var i = 0; i < document.forms.length; i++) {\n"
113             + "    log(document.forms[i].name);\n"
114             + "  }\n"
115             + "}\n"
116             + "</script></head><body onload='doTest()'>\n"
117             + "<p>hello world</p>\n"
118             + "</body></html>";
119 
120         loadPageVerifyTitle2(html);
121     }
122 
123     /**
124      * @throws Exception if the test fails
125      */
126     @Test
127     @Alerts({"", "second"})
128     public void formArray() throws Exception {
129         final String firstHtml = DOCTYPE_HTML
130             + "<html><head><SCRIPT lang='JavaScript'>\n"
131             + "function doSubmit(formName){\n"
132             + "  var form = document.forms[formName];\n"
133             + "  form.submit();\n"
134             + "}\n"
135             + "</SCRIPT></head><body><form name='formName' method='POST' "
136             + "action='" + URL_SECOND + "'>\n"
137             + "<a href='.' id='testJavascript' name='testJavascript' "
138             + "onclick=\" doSubmit('formName');return false;\">\n"
139             + "Test Link </a><input type='submit' value='Login' "
140             + "name='loginButton'></form>\n"
141             + "</body></html> ";
142         final String secondHtml
143             = "<html><head><title>second</title></head><body>\n"
144             + "<p>hello world</p>\n"
145             + "</body></html>";
146 
147         getMockWebConnection().setResponse(URL_SECOND, secondHtml);
148 
149         expandExpectedAlertsVariables(URL_FIRST);
150         final WebDriver driver = loadPage2(firstHtml);
151         assertTitle(driver, getExpectedAlerts()[0]);
152 
153         driver.findElement(By.id("testJavascript")).click();
154         assertTitle(driver, getExpectedAlerts()[1]);
155     }
156 
157     /**
158      * Test that forms is a live collection.
159      * @throws Exception if the test fails
160      */
161     @Test
162     @Alerts({"0", "1", "1", "true"})
163     public void formsLive() throws Exception {
164         final String html = DOCTYPE_HTML
165             + "<html>\n"
166             + "<head>\n"
167             + "<script>\n"
168             + LOG_TITLE_FUNCTION
169             + "var oCol = document.forms;\n"
170             + "log(oCol.length);\n"
171             + "function test() {\n"
172             + "  log(oCol.length);\n"
173             + "  log(document.forms.length);\n"
174             + "  log(document.forms == oCol);\n"
175             + "}\n"
176             + "</script>\n"
177             + "</head>\n"
178             + "<body onload='test()'>\n"
179             + "<form id='myForm' action='foo.html'>\n"
180             + "</form>\n"
181             + "</body>\n"
182             + "</html>";
183 
184         loadPageVerifyTitle2(html);
185     }
186 
187     /**
188      * Tests for <tt>document.anchors</tt>.
189      * @throws Exception if the test fails
190      */
191     @Test
192     @Alerts({"0", "1", "1", "true", "name: end"})
193     public void anchors() throws Exception {
194         final String html = DOCTYPE_HTML
195             + "<html>\n"
196             + "<head>\n"
197             + "<script>\n"
198             + LOG_TITLE_FUNCTION
199             + "var oCol = document.anchors;\n"
200             + "log(oCol.length);\n"
201             + "function test() {\n"
202             + "  log(oCol.length);\n"
203             + "  log(document.anchors.length);\n"
204             + "  log(document.anchors == oCol);\n"
205             + "  if (document.anchors[0].name)\n"
206             + "    log('name: ' + document.anchors[0].name);\n"
207             + "  else\n"
208             + "    log('id: ' + document.anchors[0].id);\n"
209             + "}\n"
210             + "</script>\n"
211             + "</head>\n"
212             + "<body onload='test()'>\n"
213             + "<a href='foo.html' id='firstLink'>foo</a>\n"
214             + "<a href='foo2.html'>foo2</a>\n"
215             + "<a name='end'/>\n"
216             + "<a href=''>null2</a>\n"
217             + "<a id='endId'/>\n"
218             + "</body>\n"
219             + "</html>";
220 
221         loadPageVerifyTitle2(html);
222     }
223 
224     /**
225      * Tests for <tt>document.anchors</tt>.
226      * @throws Exception if the test fails
227      */
228     @Test
229     @Alerts({"0", "0", "0", "true"})
230     public void anchorsEmpty() throws Exception {
231         final String html = DOCTYPE_HTML
232             + "<html>\n"
233             + "<head>\n"
234             + "<script>\n"
235             + LOG_TITLE_FUNCTION
236             + "var oCol = document.anchors;\n"
237             + "log(oCol.length);\n"
238             + "function test() {\n"
239             + "  log(oCol.length);\n"
240             + "  log(document.anchors.length);\n"
241             + "  log(document.anchors == oCol);\n"
242             + "}\n"
243             + "</script>\n"
244             + "</head>\n"
245             + "<body onload='test()'>\n"
246             + "</body>\n"
247             + "</html>";
248 
249         loadPageVerifyTitle2(html);
250     }
251 
252     /**
253      * Tests for <tt>document.applets</tt>.
254      * @throws Exception if the test fails
255      */
256     @Test
257     @Alerts({"0", "0", "0", "true"})
258     public void applets() throws Exception {
259         final String html = DOCTYPE_HTML
260             + "<html>\n"
261             + "<head>\n"
262             + "<script>\n"
263             + LOG_TITLE_FUNCTION
264             + "var oCol = document.applets;\n"
265             + "log(oCol.length);\n"
266             + "function test() {\n"
267             + "  log(oCol.length);\n"
268             + "  log(document.applets.length);\n"
269             + "  log(document.applets == oCol);\n"
270             + "}\n"
271             + "</script>\n"
272             + "</head>\n"
273             + "<body onload='test()'>\n"
274             + "<applet id='firstApplet'></applet>\n"
275             + "<applet name='end'></applet>\n"
276             + "<applet id='endId'></applet>\n"
277             + "</body>\n"
278             + "</html>";
279 
280         loadPageVerifyTitle2(html);
281     }
282 
283     /**
284      * Tests for <tt>document.applets</tt>.
285      * @throws Exception if the test fails
286      */
287     @Test
288     @Alerts({"0", "0", "0", "true"})
289     public void appletsEmpty() throws Exception {
290         final String html = DOCTYPE_HTML
291             + "<html>\n"
292             + "<head>\n"
293             + "<script>\n"
294             + LOG_TITLE_FUNCTION
295             + "var oCol = document.applets;\n"
296             + "log(oCol.length);\n"
297             + "function test() {\n"
298             + "  log(oCol.length);\n"
299             + "  log(document.applets.length);\n"
300             + "  log(document.applets == oCol);\n"
301             + "}\n"
302             + "</script>\n"
303             + "</head>\n"
304             + "<body onload='test()'>\n"
305             + "</body>\n"
306             + "</html>";
307 
308         loadPageVerifyTitle2(html);
309     }
310 
311     /**
312      * Tests for <tt>document.embeds</tt>.
313      * @throws Exception if the test fails
314      */
315     @Test
316     @Alerts({"0", "3", "3", "true", "firstEmbed"})
317     public void embeds() throws Exception {
318         final String html = DOCTYPE_HTML
319             + "<html>\n"
320             + "<head>\n"
321             + "<script>\n"
322             + LOG_TITLE_FUNCTION
323             + "var oCol = document.embeds;\n"
324             + "log(oCol.length);\n"
325             + "function test() {\n"
326             + "  log(oCol.length);\n"
327             + "  log(document.embeds.length);\n"
328             + "  log(document.embeds == oCol);\n"
329             + "  log(document.embeds[0].id);\n"
330             + "}\n"
331             + "</script>\n"
332             + "</head>\n"
333             + "<body onload='test()'>\n"
334             + "<embed id='firstEmbed' />\n"
335             + "<embed name='end' />\n"
336             + "<embed id='endId'/>\n"
337             + "</body>\n"
338             + "</html>";
339 
340         loadPageVerifyTitle2(html);
341     }
342 
343     /**
344      * Tests for <tt>document.embeds</tt>.
345      * @throws Exception if the test fails
346      */
347     @Test
348     @Alerts({"0", "0", "0", "true"})
349     public void embedsEmpty() throws Exception {
350         final String html = DOCTYPE_HTML
351             + "<html>\n"
352             + "<head>\n"
353             + "<script>\n"
354             + LOG_TITLE_FUNCTION
355             + "var oCol = document.embeds;\n"
356             + "log(oCol.length);\n"
357             + "function test() {\n"
358             + "  log(oCol.length);\n"
359             + "  log(document.embeds.length);\n"
360             + "  log(document.embeds == oCol);\n"
361             + "}\n"
362             + "</script>\n"
363             + "</head>\n"
364             + "<body onload='test()'>\n"
365             + "</body>\n"
366             + "</html>";
367 
368         loadPageVerifyTitle2(html);
369     }
370 
371     /**
372      * Tests for <tt>document.embeds</tt>.
373      * @throws Exception if the test fails
374      */
375     @Test
376     @Alerts({"0", "3", "3", "true", "firstEmbed"})
377     public void plugins() throws Exception {
378         final String html = DOCTYPE_HTML
379             + "<html>\n"
380             + "<head>\n"
381             + "<script>\n"
382             + LOG_TITLE_FUNCTION
383             + "var oCol = document.plugins;\n"
384             + "log(oCol.length);\n"
385             + "function test() {\n"
386             + "  log(oCol.length);\n"
387             + "  log(document.plugins.length);\n"
388             + "  log(document.plugins == oCol);\n"
389             + "  log(document.embeds[0].id);\n"
390             + "}\n"
391             + "</script>\n"
392             + "</head>\n"
393             + "<body onload='test()'>\n"
394             + "<embed id='firstEmbed' />\n"
395             + "<embed name='end' />\n"
396             + "<embed id='endId'/>\n"
397             + "</body>\n"
398             + "</html>";
399 
400         loadPageVerifyTitle2(html);
401     }
402 
403     /**
404      * Tests for <tt>document.embeds</tt>.
405      * @throws Exception if the test fails
406      */
407     @Test
408     @Alerts({"0", "0", "0", "true"})
409     public void pluginsEmpty() throws Exception {
410         final String html = DOCTYPE_HTML
411             + "<html>\n"
412             + "<head>\n"
413             + "<script>\n"
414             + LOG_TITLE_FUNCTION
415             + "var oCol = document.plugins;\n"
416             + "log(oCol.length);\n"
417             + "function test() {\n"
418             + "  log(oCol.length);\n"
419             + "  log(document.plugins.length);\n"
420             + "  log(document.plugins == oCol);\n"
421             + "}\n"
422             + "</script>\n"
423             + "</head>\n"
424             + "<body onload='test()'>\n"
425             + "</body>\n"
426             + "</html>";
427 
428         loadPageVerifyTitle2(html);
429     }
430 
431     /**
432      * Tests for <tt>document.links</tt>.
433      * @throws Exception if the test fails
434      */
435     @Test
436     @Alerts({"0", "3", "3", "true", "firstLink"})
437     public void links() throws Exception {
438         final String html = DOCTYPE_HTML
439             + "<html>\n"
440             + "<head>\n"
441             + "<script>\n"
442             + LOG_TITLE_FUNCTION
443             + "var oCol = document.links;\n"
444             + "log(oCol.length);\n"
445             + "function test() {\n"
446             + "  log(oCol.length);\n"
447             + "  log(document.links.length);\n"
448             + "  log(document.links == oCol);\n"
449             + "  log(document.links[0].id);\n"
450             + "}\n"
451             + "</script>\n"
452             + "</head>\n"
453             + "<body onload='test()'>\n"
454             + "<a href='foo.html' id='firstLink'>foo</a>\n"
455             + "<a href='foo2.html'>foo2</a>\n"
456             + "<a name='end'/>\n"
457             + "<a href=''>null2</a>\n"
458             + "</body>\n"
459             + "</html>";
460 
461         loadPageVerifyTitle2(html);
462     }
463 
464     /**
465      * Tests for <tt>document.links</tt>.
466      * @throws Exception if the test fails
467      */
468     @Test
469     @Alerts({"0", "0", "0", "true"})
470     public void linksEmpty() throws Exception {
471         final String html = DOCTYPE_HTML
472             + "<html>\n"
473             + "<head>\n"
474             + "<script>\n"
475             + LOG_TITLE_FUNCTION
476             + "var oCol = document.links;\n"
477             + "log(oCol.length);\n"
478             + "function test() {\n"
479             + "  log(oCol.length);\n"
480             + "  log(document.links.length);\n"
481             + "  log(document.links == oCol);\n"
482             + "}\n"
483             + "</script>\n"
484             + "</head>\n"
485             + "<body onload='test()'>\n"
486             + "</body>\n"
487             + "</html>";
488 
489         loadPageVerifyTitle2(html);
490     }
491 
492     /**
493      * Ensures that <tt>document.createElement()</tt> works correctly.
494      * @throws Exception if the test fails
495      */
496     @Test
497     @Alerts({"parentNode: null", "DIV", "1", "null", "DIV", "button1value", "text1value", "text"})
498     public void createElement() throws Exception {
499         final String html = DOCTYPE_HTML
500             + "<html>\n"
501             + "  <head>\n"
502             + "    <script>\n"
503             + LOG_TITLE_FUNCTION
504             + "      function doTest() {\n"
505             + "        // Create a DIV element.\n"
506             + "        var div1 = document.createElement('div');\n"
507             + "        log('parentNode: ' + div1.parentNode);\n"
508             + "        div1.id = 'div1';\n"
509             + "        document.body.appendChild(div1);\n"
510             + "        log(div1.tagName);\n"
511             + "        log(div1.nodeType);\n"
512             + "        log(div1.nodeValue);\n"
513             + "        log(div1.nodeName);\n"
514             + "        // Create an INPUT element.\n"
515             + "        var input = document.createElement('input');\n"
516             + "        input.id = 'text1id';\n"
517             + "        input.name = 'text1name';\n"
518             + "        input.value = 'text1value';\n"
519             + "        var form = document.getElementById('form1');\n"
520             + "        form.appendChild(input);\n"
521             + "        log(document.getElementById('button1id').value);\n"
522             + "        log(document.getElementById('text1id').value);\n"
523             + "        // The default type of an INPUT element is 'text'.\n"
524             + "        log(document.getElementById('text1id').type);\n"
525             + "      }\n"
526             + "    </script>\n"
527             + "  </head>\n"
528             + "  <body onload='doTest()'>\n"
529             + "    <form name='form1' id='form1'>\n"
530             + "      <input type='button' id='button1id' name='button1name' value='button1value'/>\n"
531             + "      This is form1.\n"
532             + "    </form>\n"
533             + "  </body>\n"
534             + "</html>";
535 
536         loadPageVerifyTitle2(html);
537     }
538 
539     /**
540      * @throws Exception if the test fails
541      */
542     @Test
543     @Alerts({"DIV,DIV,http://www.w3.org/1999/xhtml,null,div",
544                 "HI:DIV,HI:DIV,http://www.w3.org/1999/xhtml,null,hi:div"})
545     public void documentCreateElement2() throws Exception {
546         final String html = DOCTYPE_HTML
547             + "<html>\n"
548             + "  <head>\n"
549             + "    <script>\n"
550             + LOG_TITLE_FUNCTION
551             + "      function doTest() {\n"
552             + "        div = document.createElement('Div');\n"
553             + "        log(div.nodeName + ',' + div.tagName + ',' + div.namespaceURI + ',' + "
554             + "div.prefix + ',' + div.localName);\n"
555             + "        div = document.createElement('Hi:Div');\n"
556             + "        log(div.nodeName + ',' + div.tagName + ',' + div.namespaceURI + ',' + "
557             + "div.prefix + ',' + div.localName);\n"
558             + "      }\n"
559             + "    </script>\n"
560             + "  </head>\n"
561             + "  <body onload='doTest()'>\n"
562             + "  </body>\n"
563             + "</html>";
564 
565         loadPageVerifyTitle2(html);
566     }
567 
568     /**
569      * @throws Exception if the test fails
570      */
571     @Test
572     @Alerts({"[object HTMLUnknownElement]",
573              "InvalidCharacterError/DOMException", "InvalidCharacterError/DOMException",
574              "InvalidCharacterError/DOMException", "InvalidCharacterError/DOMException",
575              "[object HTMLUnknownElement]",
576              "[object HTMLUnknownElement]", "InvalidCharacterError/DOMException"})
577     public void documentCreateElementUnknown() throws Exception {
578         final String html = DOCTYPE_HTML
579             + "<html>\n"
580             + "  <head>\n"
581             + "    <script>\n"
582             + LOG_TITLE_FUNCTION
583             + "      function doTest() {\n"
584             + "        try {"
585             + "          var elem = document.createElement('anchor');\n"
586             + "          log(elem);\n"
587             + "        } catch(e) {logEx(e);}\n"
588 
589             + "        try {"
590             + "          var elem = document.createElement('not known');\n"
591             + "          log(elem);\n"
592             + "        } catch(e) {logEx(e);}\n"
593 
594             + "        try {"
595             + "          var elem = document.createElement('<div');\n"
596             + "          log(elem);\n"
597             + "        } catch(e) {logEx(e);}\n"
598 
599             + "        try {"
600             + "          var elem = document.createElement('div>');\n"
601             + "          log(elem);\n"
602             + "        } catch(e) {logEx(e);}\n"
603 
604             + "        try {"
605             + "          var elem = document.createElement('<div>');\n"
606             + "          log(elem);\n"
607             + "        } catch(e) {logEx(e);}\n"
608 
609             + "        try {"
610             + "          var elem = document.createElement(undefined);\n"
611             + "          log(elem);\n"
612             + "        } catch(e) {logEx(e);}\n"
613 
614             + "        try {"
615             + "          var elem = document.createElement(null);\n"
616             + "          log(elem);\n"
617             + "        } catch(e) {logEx(e);}\n"
618 
619             + "        try {"
620             + "          var elem = document.createElement(42);\n"
621             + "          log(elem);\n"
622             + "        } catch(e) {logEx(e);}\n"
623             + "      }\n"
624             + "    </script>\n"
625             + "  </head>\n"
626             + "  <body onload='doTest()'>\n"
627             + "  </body>\n"
628             + "</html>";
629 
630         loadPageVerifyTitle2(html);
631     }
632 
633     /**
634      * @throws Exception if the test fails
635      */
636     @Test
637     @Alerts(DEFAULT = {"", "/", ">"},
638             FF = {"", "!", "\"", "#", "$", "%", "&", "'", "(", ")", "*", "+", ",",
639                   "/", ";", "<", "=", ">", "?", "@", "[", "§§URL§§", "]", "^", "`",
640                   "{", "|", "}", "~"},
641             FF_ESR = {"", "!", "\"", "#", "$", "%", "&", "'", "(", ")", "*", "+", ",",
642                       "/", ";", "<", "=", ">", "?", "@", "[", "§§URL§§", "]", "^", "`",
643                       "{", "|", "}", "~"})
644     @HtmlUnitNYI(
645             CHROME = {"", "!", "\"", "#", "$", "%", "&", "'", "(", ")", "*", "+", ",",
646                       "/", ";", "<", "=", ">", "?", "@", "[", "§§URL§§", "]", "^", "`",
647                       "{", "|", "}", "~"},
648             EDGE = {"", "!", "\"", "#", "$", "%", "&", "'", "(", ")", "*", "+", ",",
649                     "/", ";", "<", "=", ">", "?", "@", "[", "§§URL§§", "]", "^", "`",
650                     "{", "|", "}", "~"})
651     public void documentCreateElementValidTagNames() throws Exception {
652         expandExpectedAlertsVariables("\\\\");
653 
654         final String html = DOCTYPE_HTML
655             + "<html>\n"
656             + "  <head>\n"
657             + "    <script>\n"
658             + LOG_TITLE_FUNCTION
659             + "      function doTest() {\n"
660             + "        for(var i=32; i < 127; ++i) {\n"
661             + "          var testChar = String.fromCharCode(i);\n"
662             + "          try {"
663             + "            document.createElement('x' + testChar);\n"
664             + "          } catch(ex) {\n"
665             + "            log(testChar);\n"
666             + "          }\n"
667             + "        }\n"
668             + "      }\n"
669             + "    </script>\n"
670             + "  </head>\n"
671             + "  <body onload='doTest()'>\n"
672             + "  </body>\n"
673             + "</html>";
674 
675         loadPageVerifyTitle2(html);
676     }
677 
678     /**
679      * @throws Exception if the test fails
680      */
681     @Test
682     @Alerts({"", "!", "\"", "#", "$", "%", "&", "'", "(", ")",
683              "*", "+", ",", "-", ".", "/",
684              "0", "1", "2", "3", "4", "5", "6", "7", "8", "9",
685              ";", "<", "=", ">", "?", "@", "[", "§§URL§§", "]", "^", "`",
686              "{", "|", "}", "~"})
687     public void documentCreateElementValidTagNamesFirstChar() throws Exception {
688         expandExpectedAlertsVariables("\\\\");
689 
690         final String html = DOCTYPE_HTML
691             + "<html>\n"
692             + "  <head>\n"
693             + "    <script>\n"
694             + LOG_TITLE_FUNCTION
695             + "      function doTest() {\n"
696             + "        for(var i=32; i < 127; ++i) {\n"
697             + "          var testChar = String.fromCharCode(i);\n"
698             + "          try {"
699             + "            document.createElement(testChar);\n"
700             + "          } catch(ex) {\n"
701             + "            log(testChar);\n"
702             + "          }\n"
703             + "        }\n"
704             + "      }\n"
705             + "    </script>\n"
706             + "  </head>\n"
707             + "  <body onload='doTest()'>\n"
708             + "  </body>\n"
709             + "</html>";
710 
711         loadPageVerifyTitle2(html);
712     }
713 
714     /**
715      * @throws Exception if the test fails
716      */
717     @Test
718     @Alerts(DEFAULT = "[128-999]",
719             FF = {"[170]", "[181]", "[186]", "[192-214]", "[216-246]", "[248-305]", "[308-318]", "[321-328]",
720                   "[330-382]", "[384-451]", "[461-496]", "[500-501]", "[506-535]", "[592-680]",
721                   "[699-705]", "[902]", "[904-906]", "[908]", "[910-929]",
722                   "[931-974]", "[976-982]", "[986]", "[988]", "[990]", "[992]", "[994-999]"},
723             FF_ESR = {"[170]", "[181]", "[186]", "[192-214]", "[216-246]", "[248-305]", "[308-318]", "[321-328]",
724                       "[330-382]", "[384-451]", "[461-496]", "[500-501]", "[506-535]", "[592-680]",
725                       "[699-705]", "[902]", "[904-906]", "[908]", "[910-929]",
726                       "[931-974]", "[976-982]", "[986]", "[988]", "[990]", "[992]", "[994-999]"})
727     @HtmlUnitNYI(CHROME = {"[170]", "[181]", "[186]", "[192-214]", "[216-246]",
728                            "[248-687]", "[880-883]", "[886-887]", "[891-893]", "[895]",
729                            "[902]", "[904-906]", "[908]", "[910-929]", "[931-999]"},
730             EDGE = {"[170]", "[181]", "[186]", "[192-214]", "[216-246]",
731                     "[248-687]", "[880-883]", "[886-887]", "[891-893]", "[895]",
732                     "[902]", "[904-906]", "[908]", "[910-929]", "[931-999]"},
733             FF = {"[170]", "[181]", "[186]", "[192-214]", "[216-246]",
734                   "[248-687]", "[880-883]", "[886-887]", "[891-893]", "[895]",
735                   "[902]", "[904-906]", "[908]", "[910-929]", "[931-999]"},
736             FF_ESR = {"[170]", "[181]", "[186]", "[192-214]", "[216-246]",
737                       "[248-687]", "[880-883]", "[886-887]", "[891-893]", "[895]",
738                       "[902]", "[904-906]", "[908]", "[910-929]", "[931-999]"})
739     public void documentCreateElementValidTagNames1000() throws Exception {
740         final String html = DOCTYPE_HTML
741             + "<html>\n"
742             + "  <head>\n"
743             + "    <script>\n"
744             + LOG_TITLE_FUNCTION
745             + "      function doTest() {\n"
746             + "        var lastState = '';\n"
747             + "        var firstValid = 0;\n"
748             + "        for(var i=127; i < 1000; ++i) {\n"
749             + "          var testChar = String.fromCharCode(i);\n"
750             + "          try {"
751             + "            document.createElement(testChar);\n"
752             + "            if ('ok' != lastState) firstValid = i;\n"
753             + "            lastState = 'ok';\n"
754             + "          } catch(ex) {\n"
755             + "            if ('ok' == lastState) {\n"
756             + "              if (firstValid == (i - 1)) {\n"
757             + "                log('[' + firstValid + ']');\n"
758             + "              } else {\n"
759             + "                log('[' + firstValid + '-' + (i - 1) + ']');\n"
760             + "              }\n"
761             + "            }\n"
762             + "            lastState = 'ex';\n"
763             + "          }\n"
764             + "        }\n"
765             + "        if ('ok' == lastState) {\n"
766             + "          if (firstValid == (i - 1)) {\n"
767             + "            log('[' + firstValid + ']');\n"
768             + "          } else {\n"
769             + "            log('[' + firstValid + '-' + (i - 1) + ']');\n"
770             + "          }\n"
771             + "        }\n"
772             + "      }\n"
773             + "    </script>\n"
774             + "  </head>\n"
775             + "  <body onload='doTest()'>\n"
776             + "  </body>\n"
777             + "</html>";
778 
779         loadPageVerifyTitle2(html);
780     }
781 
782     /**
783      * @throws Exception if the test fails
784      */
785     @Test
786     @Alerts(DEFAULT = {"[1000-1007]", "[1011]", "[1015-1016]", "[1018-1153]", "[1162-1327]", "[1329-1366]",
787                        "[1369]", "[1376-1414]", "[1416]", "[1488-1514]", "[1519-1522]", "[1568-1599]",
788                        "[1601-1610]", "[1646-1647]", "[1649-1652]", "[1657-1747]", "[1749]", "[1765-1766]",
789                        "[1774-1775]", "[1786-1788]", "[1791]", "[1808]", "[1810-1839]", "[1869-1957]",
790                        "[1969]", "[1994-1999]"},
791             FF = {"[1000-1011]", "[1025-1036]", "[1038-1103]", "[1105-1116]", "[1118-1153]", "[1168-1220]",
792                   "[1223-1224]", "[1227-1228]", "[1232-1259]", "[1262-1269]", "[1272-1273]", "[1329-1366]",
793                   "[1369]", "[1377-1414]", "[1488-1514]", "[1520-1522]", "[1569-1594]", "[1601-1610]",
794                   "[1649-1719]", "[1722-1726]", "[1728-1742]", "[1744-1747]", "[1749]", "[1765-1766]"},
795             FF_ESR = {"[1000-1011]", "[1025-1036]", "[1038-1103]", "[1105-1116]", "[1118-1153]", "[1168-1220]",
796                       "[1223-1224]", "[1227-1228]", "[1232-1259]", "[1262-1269]", "[1272-1273]", "[1329-1366]",
797                       "[1369]", "[1377-1414]", "[1488-1514]", "[1520-1522]", "[1569-1594]", "[1601-1610]",
798                       "[1649-1719]", "[1722-1726]", "[1728-1742]", "[1744-1747]", "[1749]", "[1765-1766]"})
799     @HtmlUnitNYI(CHROME = {"[1000-1013]", "[1015-1153]", "[1162-1327]", "[1329-1366]", "[1376-1416]",
800                            "[1488-1514]", "[1519-1522]", "[1568-1599]", "[1601-1610]", "[1646-1647]",
801                            "[1649-1747]", "[1749]", "[1774-1775]", "[1786-1788]", "[1791]", "[1808]",
802                            "[1810-1839]", "[1869-1957]", "[1969]", "[1994-1999]"},
803             EDGE = {"[1000-1013]", "[1015-1153]", "[1162-1327]", "[1329-1366]", "[1376-1416]",
804                     "[1488-1514]", "[1519-1522]", "[1568-1599]", "[1601-1610]", "[1646-1647]",
805                     "[1649-1747]", "[1749]", "[1774-1775]", "[1786-1788]", "[1791]", "[1808]",
806                     "[1810-1839]", "[1869-1957]", "[1969]", "[1994-1999]"},
807             FF = {"[1000-1013]", "[1015-1153]", "[1162-1327]", "[1329-1366]", "[1376-1416]",
808                   "[1488-1514]", "[1519-1522]", "[1568-1599]", "[1601-1610]", "[1646-1647]",
809                   "[1649-1747]", "[1749]", "[1774-1775]", "[1786-1788]", "[1791]", "[1808]",
810                   "[1810-1839]", "[1869-1957]", "[1969]", "[1994-1999]"},
811             FF_ESR = {"[1000-1013]", "[1015-1153]", "[1162-1327]", "[1329-1366]", "[1376-1416]",
812                       "[1488-1514]", "[1519-1522]", "[1568-1599]", "[1601-1610]", "[1646-1647]",
813                       "[1649-1747]", "[1749]", "[1774-1775]", "[1786-1788]", "[1791]", "[1808]",
814                       "[1810-1839]", "[1869-1957]", "[1969]", "[1994-1999]"})
815     @EnabledOnJre(JRE.JAVA_17)
816     public void documentCreateElementValidTagNames2000() throws Exception {
817         final String html = DOCTYPE_HTML
818             + "<html>\n"
819             + "  <head>\n"
820             + "    <script>\n"
821             + LOG_TITLE_FUNCTION
822             + "      function doTest() {\n"
823             + "        var lastState = '';\n"
824             + "        var firstValid = 0;\n"
825             + "        for(var i=1000; i < 2000; ++i) {\n"
826             + "          var testChar = String.fromCharCode(i);\n"
827             + "          try {"
828             + "            document.createElement(testChar);\n"
829             + "            if ('ok' != lastState) firstValid = i;\n"
830             + "            lastState = 'ok';\n"
831             + "          } catch(ex) {\n"
832             + "            if ('ok' == lastState) {\n"
833             + "              if (firstValid == (i - 1)) {\n"
834             + "                log('[' + firstValid + ']');\n"
835             + "              } else {\n"
836             + "                log('[' + firstValid + '-' + (i - 1) + ']');\n"
837             + "              }\n"
838             + "            }\n"
839             + "            lastState = 'ex';\n"
840             + "          }\n"
841             + "        }\n"
842             + "        if ('ok' == lastState) {\n"
843             + "          if (firstValid == (i - 1)) {\n"
844             + "            log('[' + firstValid + ']');\n"
845             + "          } else {\n"
846             + "            log('[' + firstValid + '-' + (i - 1) + ']');\n"
847             + "          }\n"
848             + "        }\n"
849             + "      }\n"
850             + "    </script>\n"
851             + "  </head>\n"
852             + "  <body onload='doTest()'>\n"
853             + "  </body>\n"
854             + "</html>";
855 
856         loadPageVerifyTitle2(html);
857     }
858 
859     /**
860      * @throws Exception if the test fails
861      */
862     @Test
863     @Alerts(DEFAULT = {"[2000-2026]", "[2048-2069]", "[2112-2136]", "[2144-2154]", "[2160-2183]",
864                        "[2185-2190]", "[2208-2248]", "[2308-2361]", "[2365]", "[2384]", "[2392-2401]",
865                        "[2418-2432]", "[2437-2444]", "[2447-2448]", "[2451-2472]", "[2474-2480]", "[2482]",
866                        "[2486-2489]", "[2493]", "[2510]", "[2524-2525]", "[2527-2529]", "[2544-2545]",
867                        "[2556]", "[2565-2570]", "[2575-2576]", "[2579-2600]", "[2602-2608]", "[2610-2611]",
868                        "[2613-2614]", "[2616-2617]", "[2649-2652]", "[2654]", "[2674-2676]", "[2693-2701]",
869                        "[2703-2705]", "[2707-2728]", "[2730-2736]", "[2738-2739]", "[2741-2745]", "[2749]",
870                        "[2768]", "[2784-2785]", "[2809]", "[2821-2828]", "[2831-2832]", "[2835-2856]",
871                        "[2858-2864]", "[2866-2867]", "[2869-2873]", "[2877]", "[2908-2909]", "[2911-2913]",
872                        "[2929]", "[2947]", "[2949-2954]", "[2958-2960]", "[2962-2965]", "[2969-2970]",
873                        "[2972]", "[2974-2975]", "[2979-2980]", "[2984-2986]", "[2990-2999]"},
874             FF = {"[2309-2361]", "[2365]", "[2392-2401]", "[2437-2444]", "[2447-2448]", "[2451-2472]",
875                   "[2474-2480]", "[2482]", "[2486-2489]", "[2524-2525]", "[2527-2529]", "[2544-2545]",
876                   "[2565-2570]", "[2575-2576]", "[2579-2600]", "[2602-2608]", "[2610-2611]", "[2613-2614]",
877                   "[2616-2617]", "[2649-2652]", "[2654]", "[2674-2676]", "[2693-2699]", "[2701]", "[2703-2705]",
878                   "[2707-2728]", "[2730-2736]", "[2738-2739]", "[2741-2745]", "[2749]", "[2784]", "[2821-2828]",
879                   "[2831-2832]", "[2835-2856]", "[2858-2864]", "[2866-2867]", "[2870-2873]", "[2877]",
880                   "[2908-2909]", "[2911-2913]", "[2949-2954]", "[2958-2960]", "[2962-2965]", "[2969-2970]",
881                   "[2972]", "[2974-2975]", "[2979-2980]", "[2984-2986]", "[2990-2997]", "[2999]"},
882             FF_ESR = {"[2309-2361]", "[2365]", "[2392-2401]", "[2437-2444]", "[2447-2448]", "[2451-2472]",
883                       "[2474-2480]", "[2482]", "[2486-2489]", "[2524-2525]", "[2527-2529]", "[2544-2545]",
884                       "[2565-2570]", "[2575-2576]", "[2579-2600]", "[2602-2608]", "[2610-2611]", "[2613-2614]",
885                       "[2616-2617]", "[2649-2652]", "[2654]", "[2674-2676]", "[2693-2699]", "[2701]", "[2703-2705]",
886                       "[2707-2728]", "[2730-2736]", "[2738-2739]", "[2741-2745]", "[2749]", "[2784]", "[2821-2828]",
887                       "[2831-2832]", "[2835-2856]", "[2858-2864]", "[2866-2867]", "[2870-2873]", "[2877]",
888                       "[2908-2909]", "[2911-2913]", "[2949-2954]", "[2958-2960]", "[2962-2965]", "[2969-2970]",
889                       "[2972]", "[2974-2975]", "[2979-2980]", "[2984-2986]", "[2990-2997]", "[2999]"})
890     @HtmlUnitNYI(CHROME = {"[2000-2026]", "[2048-2069]", "[2112-2136]", "[2144-2154]", "[2208-2228]", "[2230-2247]",
891                            "[2308-2361]", "[2365]", "[2384]", "[2392-2401]", "[2418-2432]", "[2437-2444]",
892                            "[2447-2448]", "[2451-2472]", "[2474-2480]", "[2482]", "[2486-2489]", "[2493]", "[2510]",
893                            "[2524-2525]", "[2527-2529]", "[2544-2545]", "[2556]", "[2565-2570]", "[2575-2576]",
894                            "[2579-2600]", "[2602-2608]", "[2610-2611]", "[2613-2614]", "[2616-2617]", "[2649-2652]",
895                            "[2654]", "[2674-2676]", "[2693-2701]", "[2703-2705]", "[2707-2728]", "[2730-2736]",
896                            "[2738-2739]", "[2741-2745]", "[2749]", "[2768]", "[2784-2785]", "[2809]", "[2821-2828]",
897                            "[2831-2832]", "[2835-2856]", "[2858-2864]", "[2866-2867]", "[2869-2873]", "[2877]",
898                            "[2908-2909]", "[2911-2913]", "[2929]", "[2947]", "[2949-2954]", "[2958-2960]",
899                            "[2962-2965]", "[2969-2970]", "[2972]", "[2974-2975]", "[2979-2980]",
900                            "[2984-2986]", "[2990-2999]"},
901             EDGE = {"[2000-2026]", "[2048-2069]", "[2112-2136]", "[2144-2154]", "[2208-2228]", "[2230-2247]",
902                     "[2308-2361]", "[2365]", "[2384]", "[2392-2401]", "[2418-2432]", "[2437-2444]",
903                     "[2447-2448]", "[2451-2472]", "[2474-2480]", "[2482]", "[2486-2489]", "[2493]", "[2510]",
904                     "[2524-2525]", "[2527-2529]", "[2544-2545]", "[2556]", "[2565-2570]", "[2575-2576]",
905                     "[2579-2600]", "[2602-2608]", "[2610-2611]", "[2613-2614]", "[2616-2617]", "[2649-2652]",
906                     "[2654]", "[2674-2676]", "[2693-2701]", "[2703-2705]", "[2707-2728]", "[2730-2736]",
907                     "[2738-2739]", "[2741-2745]", "[2749]", "[2768]", "[2784-2785]", "[2809]", "[2821-2828]",
908                     "[2831-2832]", "[2835-2856]", "[2858-2864]", "[2866-2867]", "[2869-2873]", "[2877]",
909                     "[2908-2909]", "[2911-2913]", "[2929]", "[2947]", "[2949-2954]", "[2958-2960]",
910                     "[2962-2965]", "[2969-2970]", "[2972]", "[2974-2975]", "[2979-2980]",
911                     "[2984-2986]", "[2990-2999]"},
912             FF = {"[2000-2026]", "[2048-2069]", "[2112-2136]", "[2144-2154]", "[2208-2228]", "[2230-2247]",
913                   "[2308-2361]", "[2365]", "[2384]", "[2392-2401]", "[2418-2432]", "[2437-2444]",
914                   "[2447-2448]", "[2451-2472]", "[2474-2480]", "[2482]", "[2486-2489]", "[2493]", "[2510]",
915                   "[2524-2525]", "[2527-2529]", "[2544-2545]", "[2556]", "[2565-2570]", "[2575-2576]",
916                   "[2579-2600]", "[2602-2608]", "[2610-2611]", "[2613-2614]", "[2616-2617]", "[2649-2652]",
917                   "[2654]", "[2674-2676]", "[2693-2701]", "[2703-2705]", "[2707-2728]", "[2730-2736]",
918                   "[2738-2739]", "[2741-2745]", "[2749]", "[2768]", "[2784-2785]", "[2809]", "[2821-2828]",
919                   "[2831-2832]", "[2835-2856]", "[2858-2864]", "[2866-2867]", "[2869-2873]", "[2877]",
920                   "[2908-2909]", "[2911-2913]", "[2929]", "[2947]", "[2949-2954]", "[2958-2960]",
921                   "[2962-2965]", "[2969-2970]", "[2972]", "[2974-2975]", "[2979-2980]",
922                   "[2984-2986]", "[2990-2999]"},
923             FF_ESR = {"[2000-2026]", "[2048-2069]", "[2112-2136]", "[2144-2154]", "[2208-2228]", "[2230-2247]",
924                       "[2308-2361]", "[2365]", "[2384]", "[2392-2401]", "[2418-2432]", "[2437-2444]",
925                       "[2447-2448]", "[2451-2472]", "[2474-2480]", "[2482]", "[2486-2489]", "[2493]", "[2510]",
926                       "[2524-2525]", "[2527-2529]", "[2544-2545]", "[2556]", "[2565-2570]", "[2575-2576]",
927                       "[2579-2600]", "[2602-2608]", "[2610-2611]", "[2613-2614]", "[2616-2617]", "[2649-2652]",
928                       "[2654]", "[2674-2676]", "[2693-2701]", "[2703-2705]", "[2707-2728]", "[2730-2736]",
929                       "[2738-2739]", "[2741-2745]", "[2749]", "[2768]", "[2784-2785]", "[2809]", "[2821-2828]",
930                       "[2831-2832]", "[2835-2856]", "[2858-2864]", "[2866-2867]", "[2869-2873]", "[2877]",
931                       "[2908-2909]", "[2911-2913]", "[2929]", "[2947]", "[2949-2954]", "[2958-2960]",
932                       "[2962-2965]", "[2969-2970]", "[2972]", "[2974-2975]", "[2979-2980]",
933                       "[2984-2986]", "[2990-2999]"})
934     @EnabledOnJre(JRE.JAVA_17)
935     public void documentCreateElementValidTagNames3000() throws Exception {
936         final String html = DOCTYPE_HTML
937             + "<html>\n"
938             + "  <head>\n"
939             + "    <script>\n"
940             + LOG_TITLE_FUNCTION
941             + "      function doTest() {\n"
942             + "        var lastState = '';\n"
943             + "        var firstValid = 0;\n"
944             + "        for(var i=2000; i < 3000; ++i) {\n"
945             + "          var testChar = String.fromCharCode(i);\n"
946             + "          try {"
947             + "            document.createElement(testChar);\n"
948             + "            if ('ok' != lastState) firstValid = i;\n"
949             + "            lastState = 'ok';\n"
950             + "          } catch(ex) {\n"
951             + "            if ('ok' == lastState) {\n"
952             + "              if (firstValid == (i - 1)) {\n"
953             + "                log('[' + firstValid + ']');\n"
954             + "              } else {\n"
955             + "                log('[' + firstValid + '-' + (i - 1) + ']');\n"
956             + "              }\n"
957             + "            }\n"
958             + "            lastState = 'ex';\n"
959             + "          }\n"
960             + "        }\n"
961             + "        if ('ok' == lastState) {\n"
962             + "          if (firstValid == (i - 1)) {\n"
963             + "            log('[' + firstValid + ']');\n"
964             + "          } else {\n"
965             + "            log('[' + firstValid + '-' + (i - 1) + ']');\n"
966             + "          }\n"
967             + "        }\n"
968             + "      }\n"
969             + "    </script>\n"
970             + "  </head>\n"
971             + "  <body onload='doTest()'>\n"
972             + "  </body>\n"
973             + "</html>";
974 
975         loadPageVerifyTitle2(html);
976     }
977 
978     /**
979      * @throws Exception if the test fails
980      */
981     @Test
982     @Alerts(DEFAULT = {"[3000-3001]", "[3024]", "[3077-3084]", "[3086-3088]", "[3090-3112]", "[3114-3129]",
983                        "[3133]", "[3160-3162]", "[3165]", "[3168-3169]", "[3200]", "[3205-3212]", "[3214-3216]",
984                        "[3218-3240]", "[3242-3251]", "[3253-3257]", "[3261]", "[3293-3294]", "[3296-3297]",
985                        "[3313-3314]", "[3332-3340]", "[3342-3344]", "[3346-3386]", "[3389]", "[3406]",
986                        "[3412-3414]", "[3423-3425]", "[3450-3455]", "[3461-3478]", "[3482-3505]",
987                        "[3507-3515]", "[3517]", "[3520-3526]", "[3585-3632]", "[3634]", "[3648-3653]",
988                        "[3713-3714]", "[3716]", "[3718-3722]", "[3724-3747]", "[3749]", "[3751-3760]",
989                        "[3762]", "[3773]", "[3776-3780]", "[3806-3807]", "[3840]", "[3904-3911]",
990                        "[3913-3948]", "[3976-3980]"},
991             FF = {"[3000-3001]", "[3077-3084]", "[3086-3088]", "[3090-3112]", "[3114-3123]", "[3125-3129]",
992                   "[3168-3169]", "[3205-3212]", "[3214-3216]", "[3218-3240]", "[3242-3251]", "[3253-3257]",
993                   "[3294]", "[3296-3297]", "[3333-3340]", "[3342-3344]", "[3346-3368]", "[3370-3385]",
994                   "[3424-3425]", "[3585-3630]", "[3632]", "[3634-3635]", "[3648-3653]", "[3713-3714]",
995                   "[3716]", "[3719-3720]", "[3722]", "[3725]", "[3732-3735]", "[3737-3743]", "[3745-3747]",
996                   "[3749]", "[3751]", "[3754-3755]", "[3757-3758]", "[3760]", "[3762-3763]", "[3773]",
997                   "[3776-3780]", "[3904-3911]", "[3913-3945]"},
998             FF_ESR = {"[3000-3001]", "[3077-3084]", "[3086-3088]", "[3090-3112]", "[3114-3123]", "[3125-3129]",
999                       "[3168-3169]", "[3205-3212]", "[3214-3216]", "[3218-3240]", "[3242-3251]", "[3253-3257]",
1000                       "[3294]", "[3296-3297]", "[3333-3340]", "[3342-3344]", "[3346-3368]", "[3370-3385]",
1001                       "[3424-3425]", "[3585-3630]", "[3632]", "[3634-3635]", "[3648-3653]", "[3713-3714]",
1002                       "[3716]", "[3719-3720]", "[3722]", "[3725]", "[3732-3735]", "[3737-3743]", "[3745-3747]",
1003                       "[3749]", "[3751]", "[3754-3755]", "[3757-3758]", "[3760]", "[3762-3763]", "[3773]",
1004                       "[3776-3780]", "[3904-3911]", "[3913-3945]"})
1005     @HtmlUnitNYI(CHROME = {"[3000-3001]", "[3024]", "[3077-3084]", "[3086-3088]", "[3090-3112]",
1006                            "[3114-3129]", "[3133]", "[3160-3162]", "[3168-3169]", "[3200]", "[3205-3212]",
1007                            "[3214-3216]", "[3218-3240]", "[3242-3251]", "[3253-3257]", "[3261]", "[3294]",
1008                            "[3296-3297]", "[3313-3314]", "[3332-3340]", "[3342-3344]", "[3346-3386]",
1009                            "[3389]", "[3406]", "[3412-3414]", "[3423-3425]", "[3450-3455]",
1010                            "[3461-3478]", "[3482-3505]", "[3507-3515]", "[3517]", "[3520-3526]",
1011                            "[3585-3632]", "[3634-3635]", "[3648-3653]", "[3713-3714]", "[3716]",
1012                            "[3718-3722]", "[3724-3747]", "[3749]", "[3751-3760]", "[3762-3763]", "[3773]",
1013                            "[3776-3780]", "[3804-3807]", "[3840]", "[3904-3911]", "[3913-3948]", "[3976-3980]"},
1014             EDGE = {"[3000-3001]", "[3024]", "[3077-3084]", "[3086-3088]", "[3090-3112]",
1015                     "[3114-3129]", "[3133]", "[3160-3162]", "[3168-3169]", "[3200]", "[3205-3212]",
1016                     "[3214-3216]", "[3218-3240]", "[3242-3251]", "[3253-3257]", "[3261]", "[3294]",
1017                     "[3296-3297]", "[3313-3314]", "[3332-3340]", "[3342-3344]", "[3346-3386]",
1018                     "[3389]", "[3406]", "[3412-3414]", "[3423-3425]", "[3450-3455]",
1019                     "[3461-3478]", "[3482-3505]", "[3507-3515]", "[3517]", "[3520-3526]",
1020                     "[3585-3632]", "[3634-3635]", "[3648-3653]", "[3713-3714]", "[3716]",
1021                     "[3718-3722]", "[3724-3747]", "[3749]", "[3751-3760]", "[3762-3763]", "[3773]",
1022                     "[3776-3780]", "[3804-3807]", "[3840]", "[3904-3911]", "[3913-3948]", "[3976-3980]"},
1023             FF = {"[3000-3001]", "[3024]", "[3077-3084]", "[3086-3088]", "[3090-3112]",
1024                   "[3114-3129]", "[3133]", "[3160-3162]", "[3168-3169]", "[3200]", "[3205-3212]",
1025                   "[3214-3216]", "[3218-3240]", "[3242-3251]", "[3253-3257]", "[3261]", "[3294]",
1026                   "[3296-3297]", "[3313-3314]", "[3332-3340]", "[3342-3344]", "[3346-3386]",
1027                   "[3389]", "[3406]", "[3412-3414]", "[3423-3425]", "[3450-3455]",
1028                   "[3461-3478]", "[3482-3505]", "[3507-3515]", "[3517]", "[3520-3526]",
1029                   "[3585-3632]", "[3634-3635]", "[3648-3653]", "[3713-3714]", "[3716]",
1030                   "[3718-3722]", "[3724-3747]", "[3749]", "[3751-3760]", "[3762-3763]", "[3773]",
1031                   "[3776-3780]", "[3804-3807]", "[3840]", "[3904-3911]", "[3913-3948]", "[3976-3980]"},
1032             FF_ESR = {"[3000-3001]", "[3024]", "[3077-3084]", "[3086-3088]", "[3090-3112]",
1033                       "[3114-3129]", "[3133]", "[3160-3162]", "[3168-3169]", "[3200]", "[3205-3212]",
1034                       "[3214-3216]", "[3218-3240]", "[3242-3251]", "[3253-3257]", "[3261]", "[3294]",
1035                       "[3296-3297]", "[3313-3314]", "[3332-3340]", "[3342-3344]", "[3346-3386]",
1036                       "[3389]", "[3406]", "[3412-3414]", "[3423-3425]", "[3450-3455]",
1037                       "[3461-3478]", "[3482-3505]", "[3507-3515]", "[3517]", "[3520-3526]",
1038                       "[3585-3632]", "[3634-3635]", "[3648-3653]", "[3713-3714]", "[3716]",
1039                       "[3718-3722]", "[3724-3747]", "[3749]", "[3751-3760]", "[3762-3763]", "[3773]",
1040                       "[3776-3780]", "[3804-3807]", "[3840]", "[3904-3911]", "[3913-3948]", "[3976-3980]"})
1041     @EnabledOnJre(JRE.JAVA_17)
1042     public void documentCreateElementValidTagNames4000() throws Exception {
1043         final String html = DOCTYPE_HTML
1044             + "<html>\n"
1045             + "  <head>\n"
1046             + "    <script>\n"
1047             + LOG_TITLE_FUNCTION
1048             + "      function doTest() {\n"
1049             + "        var lastState = '';\n"
1050             + "        var firstValid = 0;\n"
1051             + "        for(var i=3000; i < 4000; ++i) {\n"
1052             + "          var testChar = String.fromCharCode(i);\n"
1053             + "          try {"
1054             + "            document.createElement(testChar);\n"
1055             + "            if ('ok' != lastState) firstValid = i;\n"
1056             + "            lastState = 'ok';\n"
1057             + "          } catch(ex) {\n"
1058             + "            if ('ok' == lastState) {\n"
1059             + "              if (firstValid == (i - 1)) {\n"
1060             + "                log('[' + firstValid + ']');\n"
1061             + "              } else {\n"
1062             + "                log('[' + firstValid + '-' + (i - 1) + ']');\n"
1063             + "              }\n"
1064             + "            }\n"
1065             + "            lastState = 'ex';\n"
1066             + "          }\n"
1067             + "        }\n"
1068             + "        if ('ok' == lastState) {\n"
1069             + "          if (firstValid == (i - 1)) {\n"
1070             + "            log('[' + firstValid + ']');\n"
1071             + "          } else {\n"
1072             + "            log('[' + firstValid + '-' + (i - 1) + ']');\n"
1073             + "          }\n"
1074             + "        }\n"
1075             + "      }\n"
1076             + "    </script>\n"
1077             + "  </head>\n"
1078             + "  <body onload='doTest()'>\n"
1079             + "  </body>\n"
1080             + "</html>";
1081 
1082         loadPageVerifyTitle2(html);
1083     }
1084 
1085     /**
1086      * Ensures that <tt>document.createElementNS()</tt> works correctly.
1087      * @throws Exception if the test fails
1088      */
1089     @Test
1090     @Alerts({"Some:Div", "Some:Div", "myNS", "Some", "Div", "svg", "svg", "http://www.w3.org/2000/svg", "null", "svg"})
1091     public void createElementNS() throws Exception {
1092         final String html = DOCTYPE_HTML
1093             + "<html><head>\n"
1094             + "<script>\n"
1095             + LOG_TITLE_FUNCTION
1096             + "  function doTest() {\n"
1097             + "    var div = document.createElementNS('myNS', 'Some:Div');\n"
1098             + "    log(div.nodeName);\n"
1099             + "    log(div.tagName);\n"
1100             + "    log(div.namespaceURI);\n"
1101             + "    log(div.prefix);\n"
1102             + "    log(div.localName);\n"
1103 
1104             + "    var svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');\n"
1105             + "    log(svg.nodeName);\n"
1106             + "    log(svg.tagName);\n"
1107             + "    log(svg.namespaceURI);\n"
1108             + "    log(svg.prefix);\n"
1109             + "    log(svg.localName);\n"
1110             + "  }\n"
1111             + "</script></head>\n"
1112             + "<body onload='doTest()'>\n"
1113             + "</body></html>";
1114 
1115         loadPageVerifyTitle2(html);
1116     }
1117 
1118     /**
1119      * Regression test for <tt>createTextNode</tt>.
1120      * @throws Exception if the test fails
1121      */
1122     @Test
1123     @Alerts({"Some Text", "9", "3", "Some Text", "#text"})
1124     public void createTextNode() throws Exception {
1125         final String html = DOCTYPE_HTML
1126             + "<html><head>\n"
1127             + "<script>\n"
1128             + LOG_TITLE_FUNCTION
1129             + "function doTest() {\n"
1130             + "  var text1=document.createTextNode('Some Text');\n"
1131             + "  var body1=document.getElementById('body');\n"
1132             + "  body1.appendChild(text1);\n"
1133             + "  log(text1.data);\n"
1134             + "  log(text1.length);\n"
1135             + "  log(text1.nodeType);\n"
1136             + "  log(text1.nodeValue);\n"
1137             + "  log(text1.nodeName);\n"
1138             + "}\n"
1139             + "</script></head><body onload='doTest()' id='body'>\n"
1140             + "</body></html>";
1141 
1142         loadPageVerifyTitle2(html);
1143     }
1144 
1145     /**
1146      * Regression test for RFE 741930.
1147      * @throws Exception if the test fails
1148      */
1149     @Test
1150     @Alerts("1")
1151     public void appendChild() throws Exception {
1152         final String html = DOCTYPE_HTML
1153             + "<html><head><script>\n"
1154             + LOG_TITLE_FUNCTION
1155             + "  function doTest() {\n"
1156             + "    var form = document.forms['form1'];\n"
1157             + "    var div = document.createElement('DIV');\n"
1158             + "    form.appendChild(div);\n"
1159             + "    var elements = document.getElementsByTagName('DIV');\n"
1160             + "    log(elements.length);\n"
1161             + "  }\n"
1162             + "</script></head><body onload='doTest()'>\n"
1163             + "<p>hello world</p>\n"
1164             + "<form name='form1'>\n"
1165             + "</form>\n"
1166             + "</body></html>";
1167 
1168         loadPageVerifyTitle2(html);
1169     }
1170 
1171     /**
1172      * Verifies that <tt>document.appendChild()</tt>doesn't work.
1173      * @throws Exception if an error occurs
1174      */
1175     @Test
1176     @Alerts({"2", "HierarchyRequestError/DOMException"})
1177     public void appendChildAtDocumentLevel() throws Exception {
1178         final String html = DOCTYPE_HTML
1179             + "<html>\n"
1180             + "<head>\n"
1181             + "  <script>\n"
1182             + LOG_TITLE_FUNCTION
1183             + "    function test() {\n"
1184             + "      var div = document.createElement('div');\n"
1185             + "      div.innerHTML = 'test';\n"
1186             + "      try {\n"
1187             + "        log(document.childNodes.length);\n"
1188             + "        document.appendChild(div); // Error\n"
1189             + "        log(document.childNodes.length);\n"
1190             + "        log(document.childNodes[0].tagName);\n"
1191             + "        log(document.childNodes[1].tagName);\n"
1192             + "        log(document.getElementsByTagName('div').length);\n"
1193             + "      } catch(e) { logEx(e); }\n"
1194             + "    }\n"
1195             + "  </script>\n"
1196             + "</head>\n"
1197             + "<body onload='test()'></body>\n"
1198             + "</html>";
1199 
1200         loadPageVerifyTitle2(html);
1201     }
1202 
1203     /**
1204      * Regression test for appendChild of a text node.
1205      * @throws Exception if the test fails
1206      */
1207     @Test
1208     @Alerts("Some Text")
1209     public void appendChild_textNode() throws Exception {
1210         final String html = DOCTYPE_HTML
1211             + "<html><head>\n"
1212             + "<script>\n"
1213             + LOG_TITLE_FUNCTION
1214             + "  function doTest() {\n"
1215             + "    var form = document.forms['form1'];\n"
1216             + "    var child = document.createTextNode('Some Text');\n"
1217             + "    form.appendChild(child);\n"
1218             + "    log(form.lastChild.data);\n"
1219             + "  }\n"
1220             + "</script></head><body onload='doTest()'>\n"
1221             + "<p>hello world</p>\n"
1222             + "<form name='form1'>\n"
1223             + "</form>\n"
1224             + "</body></html>";
1225 
1226         loadPageVerifyTitle2(html);
1227     }
1228 
1229     /**
1230      * Regression test for <tt>cloneNode</tt>.
1231      * @throws Exception if the test fails
1232      */
1233     @Test
1234     @Alerts({"true", "true", "true", "true"})
1235     public void cloneNode() throws Exception {
1236         final String html = DOCTYPE_HTML
1237             + "<html><head>\n"
1238             + "<script>\n"
1239             + LOG_TITLE_FUNCTION
1240             + "  function doTest() {\n"
1241             + "    var form = document.forms['form1'];\n"
1242             + "    var cloneShallow = form.cloneNode(false);\n"
1243             + "    log(cloneShallow != null);\n"
1244             + "    log(cloneShallow.firstChild == null);\n"
1245             + "    var cloneDeep = form.cloneNode(true);\n"
1246             + "    log(cloneDeep != null);\n"
1247             + "    log(cloneDeep.firstChild != null);\n"
1248             + "  }\n"
1249             + "</script></head><body onload='doTest()'>\n"
1250             + "<form name='form1'>\n"
1251             + "<p>hello world</p>\n"
1252             + "</form>\n"
1253             + "</body></html>";
1254 
1255         loadPageVerifyTitle2(html);
1256     }
1257 
1258     /**
1259      * Regression test for <tt>insertBefore</tt>.
1260      * @throws Exception if the test fails
1261      */
1262     @Test
1263     @Alerts("true")
1264     public void insertBefore() throws Exception {
1265         final String html = DOCTYPE_HTML
1266             + "<html><head>\n"
1267             + "<script>\n"
1268             + LOG_TITLE_FUNCTION
1269             + "  function doTest() {\n"
1270             + "    var form = document.forms['form1'];\n"
1271             + "    var oldChild = document.getElementById('oldChild');\n"
1272             + "    var div = document.createElement('DIV');\n"
1273             + "    form.insertBefore(div, oldChild);\n"
1274             + "    log(form.firstChild == div);\n"
1275             + "  }\n"
1276             + "</script></head><body onload='doTest()'>\n"
1277             + "<form name='form1'><div id='oldChild'/></form>\n"
1278             + "</body></html>";
1279 
1280         loadPageVerifyTitle2(html);
1281     }
1282 
1283     /**
1284      * Regression test for bug 740665.
1285      * @throws Exception if the test fails
1286      */
1287     @Test
1288     @Alerts("text/javascript")
1289     public void getElementById_scriptType() throws Exception {
1290         final String html = DOCTYPE_HTML
1291             + "<html><head>\n"
1292             + "<script id='script1' type='text/javascript'>\n"
1293             + LOG_TITLE_FUNCTION
1294             + "  doTest=function() {\n"
1295             + "  log(top.document.getElementById('script1').type);\n"
1296             + "}\n"
1297             + "</script></head><body onload='doTest()'>\n"
1298             + "</body></html>";
1299 
1300         loadPageVerifyTitle2(html);
1301     }
1302 
1303     /**
1304      * Regression test for bug 740665.
1305      * @throws Exception if the test fails
1306      */
1307     @Test
1308     @Alerts("§§URL§§script/")
1309     public void getElementById_scriptSrc() throws Exception {
1310         final String html = DOCTYPE_HTML
1311             + "<html><head>\n"
1312             + "<script>\n"
1313             + LOG_TITLE_FUNCTION
1314             + "</script>\n"
1315             + "<script id='script1' src='" + URL_FIRST + "script/'>\n"
1316             + "</script></head>\n"
1317             + "<body onload='doTest()'>\n"
1318             + "</body></html>";
1319 
1320         final String script
1321             = "doTest = function() {\n"
1322             + "  log(top.document.getElementById('script1').src);\n"
1323             + "}";
1324         getMockWebConnection().setResponse(new URL(URL_FIRST, "script/"), script, "text/javascript");
1325 
1326         expandExpectedAlertsVariables(URL_FIRST);
1327         loadPageVerifyTitle2(html);
1328     }
1329 
1330     /**
1331      * Regression test for <tt>parentNode</tt> with nested elements.
1332      * @throws Exception if the test fails
1333      */
1334     @Test
1335     @Alerts("parentDiv")
1336     public void parentNode_Nested() throws Exception {
1337         final String html = DOCTYPE_HTML
1338             + "<html><head>\n"
1339             + "<script>\n"
1340             + LOG_TITLE_FUNCTION
1341             + "  function doTest() {\n"
1342             + "    var div1=document.getElementById('childDiv');\n"
1343             + "    log(div1.parentNode.id);\n"
1344             + "  }\n"
1345             + "</script></head><body onload='doTest()'>\n"
1346             + "<div id='parentDiv'><div id='childDiv'></div></div>\n"
1347             + "</body></html>";
1348 
1349         loadPageVerifyTitle2(html);
1350     }
1351 
1352     /**
1353      * Regression test for <tt>parentNode</tt> of document.
1354      * @throws Exception if the test fails
1355      */
1356     @Test
1357     @Alerts("true")
1358     public void parentNode_Document() throws Exception {
1359         final String html = DOCTYPE_HTML
1360             + "<html><head>\n"
1361             + "<script>\n"
1362             + LOG_TITLE_FUNCTION
1363             + "  function doTest() {\n"
1364             + "    log(document.parentNode == null);\n"
1365             + "  }\n"
1366             + "</script></head><body onload='doTest()'>\n"
1367             + "</body></html>";
1368 
1369         loadPageVerifyTitle2(html);
1370     }
1371 
1372     /**
1373      * Regression test for <tt>parentNode</tt> and <tt>createElement</tt>.
1374      * @throws Exception if the test fails
1375      */
1376     @Test
1377     @Alerts("true")
1378     public void parentNode_CreateElement() throws Exception {
1379         final String html = DOCTYPE_HTML
1380             + "<html><head>\n"
1381             + "<script>\n"
1382             + LOG_TITLE_FUNCTION
1383             + "  function doTest() {\n"
1384             + "    var div1=document.createElement('div');\n"
1385             + "    log(div1.parentNode == null);\n"
1386             + "  }\n"
1387             + "</script></head><body onload='doTest()'>\n"
1388             + "</body></html>";
1389 
1390         loadPageVerifyTitle2(html);
1391     }
1392 
1393     /**
1394      * Regression test for <tt>parentNode</tt> and <tt>appendChild</tt>.
1395      * @throws Exception if the test fails
1396      */
1397     @Test
1398     @Alerts("parentDiv")
1399     public void parentNode_AppendChild() throws Exception {
1400         final String html = DOCTYPE_HTML
1401             + "<html><head>\n"
1402             + "<script>\n"
1403             + LOG_TITLE_FUNCTION
1404             + "  function doTest() {\n"
1405             + "    var childDiv=document.getElementById('childDiv');\n"
1406             + "    var parentDiv=document.getElementById('parentDiv');\n"
1407             + "    parentDiv.appendChild(childDiv);\n"
1408             + "    log(childDiv.parentNode.id);\n"
1409             + "  }\n"
1410             + "</script></head><body onload='doTest()'>\n"
1411             + "<div id='parentDiv'></div><div id='childDiv'></div>\n"
1412             + "</body></html>";
1413 
1414         loadPageVerifyTitle2(html);
1415     }
1416 
1417     /**
1418      * Regression test for <tt>documentElement</tt> of document.
1419      * @throws Exception if the test fails
1420      */
1421     @Test
1422     @Alerts({"true", "HTML", "true"})
1423     public void documentElement() throws Exception {
1424         final String html = DOCTYPE_HTML
1425             + "<html><head>\n"
1426             + "<script>\n"
1427             + LOG_TITLE_FUNCTION
1428             + "  function doTest() {\n"
1429             + "    log(document.documentElement != null);\n"
1430             + "    log(document.documentElement.tagName);\n"
1431             + "    log(document.documentElement.parentNode == document);\n"
1432             + "  }\n"
1433             + "</script></head>\n"
1434             + "<body onload='doTest()'>\n"
1435             + "</body></html>";
1436 
1437         loadPageVerifyTitle2(html);
1438     }
1439 
1440     /**
1441      * Regression test for <tt>firstChild</tt> with nested elements.
1442      * @throws Exception if the test fails
1443      */
1444     @Test
1445     @Alerts("childDiv")
1446     public void firstChild_Nested() throws Exception {
1447         final String html = DOCTYPE_HTML
1448             + "<html><head>\n"
1449             + "<script>\n"
1450             + LOG_TITLE_FUNCTION
1451             + "  function doTest() {\n"
1452             + "    var div1=document.getElementById('parentDiv');\n"
1453             + "    log(div1.firstChild.id);\n"
1454             + "  }\n"
1455             + "</script></head><body onload='doTest()'>\n"
1456             + "<div id='parentDiv'><div id='childDiv'/><div id='childDiv2'/></div>\n"
1457             + "</body></html>";
1458 
1459         loadPageVerifyTitle2(html);
1460     }
1461 
1462     /**
1463      * Regression test for <tt>firstChild</tt> and <tt>appendChild</tt>.
1464      * @throws Exception if the test fails
1465      */
1466     @Test
1467     @Alerts("childDiv")
1468     public void firstChild_AppendChild() throws Exception {
1469         final String html = DOCTYPE_HTML
1470             + "<html><head>\n"
1471             + "<script>\n"
1472             + LOG_TITLE_FUNCTION
1473             + "  function doTest() {\n"
1474             + "    var childDiv=document.getElementById('childDiv');\n"
1475             + "    var parentDiv=document.getElementById('parentDiv');\n"
1476             + "    parentDiv.appendChild(childDiv);\n"
1477             + "    var childDiv2=document.getElementById('childDiv2');\n"
1478             + "    parentDiv.appendChild(childDiv2);\n"
1479             + "    log(parentDiv.firstChild.id);\n"
1480             + "  }\n"
1481             + "</script></head><body onload='doTest()'>\n"
1482             + "<div id='parentDiv'/><div id='childDiv'/><div id='childDiv2'/>\n"
1483             + "</body></html>";
1484 
1485         loadPageVerifyTitle2(html);
1486     }
1487 
1488     /**
1489      * Regression test for lastChild with nested elements.
1490      * @throws Exception if the test fails
1491      */
1492     @Test
1493     @Alerts("childDiv")
1494     public void lastChild_Nested() throws Exception {
1495         final String html = DOCTYPE_HTML
1496             + "<html><head>\n"
1497             + "<script>\n"
1498             + LOG_TITLE_FUNCTION
1499             + "  function doTest() {\n"
1500             + "    var div1=document.getElementById('parentDiv');\n"
1501             + "    log(div1.lastChild.id);\n"
1502             + "  }\n"
1503             + "</script></head><body onload='doTest()'>\n"
1504             + "<div id='parentDiv'><div id='childDiv1'></div><div id='childDiv'></div></div>\n"
1505             + "</body></html>";
1506 
1507         loadPageVerifyTitle2(html);
1508     }
1509 
1510     /**
1511      * Regression test for lastChild and appendChild.
1512      * @throws Exception if the test fails
1513      */
1514     @Test
1515     @Alerts("childDiv")
1516     public void lastChild_AppendChild() throws Exception {
1517         final String html = DOCTYPE_HTML
1518             + "<html><head><script>\n"
1519             + LOG_TITLE_FUNCTION
1520             + "  function doTest() {\n"
1521             + "    var childDiv1=document.getElementById('childDiv1');\n"
1522             + "    var parentDiv=document.getElementById('parentDiv');\n"
1523             + "    parentDiv.appendChild(childDiv1);\n"
1524             + "    var childDiv=document.getElementById('childDiv');\n"
1525             + "    parentDiv.appendChild(childDiv);\n"
1526             + "    log(parentDiv.lastChild.id);\n"
1527             + "  }\n"
1528             + "</script></head><body onload='doTest()'>\n"
1529             + "<div id='parentDiv'/><div id='childDiv1'/><div id='childDiv'/>\n"
1530             + "</body></html>";
1531 
1532         loadPageVerifyTitle2(html);
1533     }
1534 
1535     /**
1536      * Regression test for nextSibling with nested elements.
1537      * @throws Exception if the test fails
1538      */
1539     @Test
1540     @Alerts("nextDiv")
1541     public void nextSibling_Nested() throws Exception {
1542         final String html = DOCTYPE_HTML
1543             + "<html><head><script>\n"
1544             + LOG_TITLE_FUNCTION
1545             + "  function doTest() {\n"
1546             + "    var div1 = document.getElementById('previousDiv');\n"
1547             + "    log(div1.nextSibling.id);\n"
1548             + "  }\n"
1549             + "</script></head>\n"
1550             + "<body onload='doTest()'>\n"
1551             + "<div id='parentDiv'><div id='previousDiv'></div><div id='nextDiv'></div></div>\n"
1552             + "</body></html>";
1553 
1554         loadPageVerifyTitle2(html);
1555     }
1556 
1557     /**
1558      * Regression test for nextSibling and appendChild.
1559      * @throws Exception if the test fails
1560      */
1561     @Test
1562     @Alerts("nextDiv")
1563     public void nextSibling_AppendChild() throws Exception {
1564         final String html = DOCTYPE_HTML
1565             + "<html><head>\n"
1566             + "<script>\n"
1567             + LOG_TITLE_FUNCTION
1568             + "  function doTest() {\n"
1569             + "    var previousDiv=document.getElementById('previousDiv');\n"
1570             + "    var parentDiv=document.getElementById('parentDiv');\n"
1571             + "    parentDiv.appendChild(previousDiv);\n"
1572             + "    var nextDiv=document.getElementById('nextDiv');\n"
1573             + "    parentDiv.appendChild(nextDiv);\n"
1574             + "    log(previousDiv.nextSibling.id);\n"
1575             + "  }\n"
1576             + "</script></head><body onload='doTest()'>\n"
1577             + "<div id='parentDiv'/><div id='junk1'/><div id='previousDiv'/><div id='junk2'/><div id='nextDiv'/>\n"
1578             + "</body></html>";
1579 
1580         loadPageVerifyTitle2(html);
1581     }
1582 
1583     /**
1584      * Regression test for previousSibling with nested elements.
1585      * @throws Exception if the test fails
1586      */
1587     @Test
1588     @Alerts("previousDiv")
1589     public void previousSibling_Nested() throws Exception {
1590         final String html = DOCTYPE_HTML
1591             + "<html><head>\n"
1592             + "<script>\n"
1593             + LOG_TITLE_FUNCTION
1594             + "  function doTest() {\n"
1595             + "    var div1 = document.getElementById('nextDiv');\n"
1596             + "    log(div1.previousSibling.id);\n"
1597             + "  }\n"
1598             + "</script></head><body onload='doTest()'>\n"
1599             + "<div id='parentDiv'><div id='previousDiv'></div><div id='nextDiv'></div></div>\n"
1600             + "</body></html>";
1601 
1602         loadPageVerifyTitle2(html);
1603     }
1604 
1605     /**
1606      * Regression test for previousSibling and appendChild.
1607      * @throws Exception if the test fails
1608      */
1609     @Test
1610     @Alerts("previousDiv")
1611     public void previousSibling_AppendChild() throws Exception {
1612         final String html = DOCTYPE_HTML
1613             + "<html><head>\n"
1614             + "<script>\n"
1615             + LOG_TITLE_FUNCTION
1616             + "  function doTest() {\n"
1617             + "    var previousDiv=document.getElementById('previousDiv');\n"
1618             + "    var parentDiv=document.getElementById('parentDiv');\n"
1619             + "    parentDiv.appendChild(previousDiv);\n"
1620             + "    var nextDiv=document.getElementById('nextDiv');\n"
1621             + "    parentDiv.appendChild(nextDiv);\n"
1622             + "    log(nextDiv.previousSibling.id);\n"
1623             + "  }\n"
1624             + "</script></head><body onload='doTest()'>\n"
1625             + "<div id='parentDiv'/><div id='junk1'/><div id='previousDiv'/><div id='junk2'/><div id='nextDiv'/>\n"
1626             + "</body></html>";
1627 
1628         loadPageVerifyTitle2(html);
1629     }
1630 
1631     /**
1632      * @throws Exception if the test fails
1633      */
1634     @Test
1635     @Alerts({"tangerine", "ginger"})
1636     public void allProperty_KeyByName() throws Exception {
1637         final String html = DOCTYPE_HTML
1638             + "<html>\n"
1639             + "<head>\n"
1640             + "  <script>\n"
1641             + LOG_TITLE_FUNCTION
1642             + "    function doTest() {\n"
1643             + "      log(document.all['input1'].value);\n"
1644             + "      log(document.all['foo2'].value);\n"
1645             + "    }\n"
1646             + "  </script>\n"
1647             + "</head>\n"
1648             + "<body onload='doTest()'>\n"
1649             + "  <form id='form1'>\n"
1650             + "    <input id='input1' name='foo1' type='text' value='tangerine' />\n"
1651             + "    <input id='input2' name='foo2' type='text' value='ginger' />\n"
1652             + "  </form>\n"
1653             + "</body></html>";
1654 
1655         loadPageVerifyTitle2(html);
1656     }
1657 
1658     /**
1659      * Regression test for bug 707750.
1660      * @throws Exception if the test fails
1661      */
1662     @Test
1663     @Alerts("DIV")
1664     public void allProperty_CalledDuringPageLoad() throws Exception {
1665         final String html = DOCTYPE_HTML
1666             + "<html><body>\n"
1667             + "<div id='ARSMenuDiv1' style='VISIBILITY: hidden; POSITION: absolute; z-index: 1000000'></div>\n"
1668             + "<script language='Javascript'>\n"
1669             + LOG_TITLE_FUNCTION
1670             + "  var divObj = document.all['ARSMenuDiv1'];\n"
1671             + "  log(divObj.tagName);\n"
1672             + "</script></body></html>";
1673 
1674         loadPageVerifyTitle2(html);
1675     }
1676 
1677     /**
1678      * @throws Exception if the test fails
1679      */
1680     @Test
1681     @Alerts("§§URL§§")
1682     public void referrer() throws Exception {
1683         final String firstHtml = DOCTYPE_HTML
1684             + "<html><head><title>First</title></head><body>\n"
1685             + "<a href='" + URL_SECOND + "'>click me</a></body></html>";
1686 
1687         final String secondHtml = DOCTYPE_HTML
1688             + "<html><head><title>Second</title></head><body onload='alert(document.referrer);'>\n"
1689             + "</form></body></html>";
1690         getMockWebConnection().setResponse(URL_SECOND, secondHtml);
1691 
1692         final WebDriver driver = loadPage2(firstHtml);
1693         driver.findElement(By.linkText("click me")).click();
1694 
1695         expandExpectedAlertsVariables(URL_FIRST);
1696 
1697         verifyAlerts(driver, getExpectedAlerts());
1698     }
1699 
1700     /**
1701      * @throws Exception if the test fails
1702      */
1703     @Test
1704     @Alerts("")
1705     public void referrer_NoneSpecified() throws Exception {
1706         final String html
1707             = "<html><head>\n"
1708             + "<script>\n"
1709             + LOG_TITLE_FUNCTION
1710             + "</script>\n"
1711             + "</head>\n"
1712             + "<body onload='log(document.referrer);'>\n"
1713             + "</form></body></html>";
1714 
1715         loadPageVerifyTitle2(html);
1716     }
1717 
1718     /**
1719      * @throws Exception if the test fails
1720      */
1721     @Test
1722     @Alerts("§§URL§§")
1723     public void url() throws Exception {
1724         final String html
1725             = "<html><head>\n"
1726             + "<script>\n"
1727             + LOG_TITLE_FUNCTION
1728             + "</script>\n"
1729             + "</head>\n"
1730             + "<body onload='log(document.URL);'>\n"
1731             + "</form></body></html>";
1732 
1733         expandExpectedAlertsVariables(URL_FIRST);
1734         loadPageVerifyTitle2(html);
1735     }
1736 
1737     /**
1738      * @throws Exception if the test fails
1739      */
1740     @Test
1741     @Alerts({"button", "button", "true"})
1742     public void getElementsByTagName() throws Exception {
1743         final String html
1744             = "<html><head>\n"
1745             + "<script>\n"
1746             + LOG_TITLE_FUNCTION
1747             + "  function doTest() {\n"
1748             + "    var elements = document.getElementsByTagName('input');\n"
1749             + "    for (var i = 0; i < elements.length; i++) {\n"
1750             + "      log(elements[i].type);\n"
1751             + "      log(elements.item(i).type);\n"
1752             + "    }\n"
1753             + "    log(elements == document.getElementsByTagName('input'));\n"
1754             + "  }\n"
1755             + "</script></head><body onload='doTest()'>\n"
1756             + "<form><input type='button' name='button1' value='pushme'></form>\n"
1757             + "</body></html>";
1758 
1759         loadPageVerifyTitle2(html);
1760     }
1761 
1762     /**
1763      * Regression test for bug 740636.
1764      * @throws Exception if the test fails
1765      */
1766     @Test
1767     @Alerts("button")
1768     public void getElementsByTagName_CaseInsensitive() throws Exception {
1769         final String html = DOCTYPE_HTML
1770             + "<html><head>\n"
1771             + "<script>\n"
1772             + LOG_TITLE_FUNCTION
1773             + "  function doTest() {\n"
1774             + "    var elements = document.getElementsByTagName('InPuT');\n"
1775             + "    for(i = 0; i < elements.length; i++) {\n"
1776             + "      log(elements[i].type);\n"
1777             + "    }\n"
1778             + "  }\n"
1779             + "</script></head><body onload='doTest()'>\n"
1780             + "<form><input type='button' name='button1' value='pushme'></form>\n"
1781             + "</body></html>";
1782 
1783         loadPageVerifyTitle2(html);
1784     }
1785 
1786     /**
1787      * Regression test for bug 740605.
1788      * @throws Exception if the test fails
1789      */
1790     @Test
1791     @Alerts("1")
1792     public void getElementsByTagName_Inline() throws Exception {
1793         final String html = DOCTYPE_HTML
1794             + "<html><body>\n"
1795             + "<script type=\"text/javascript\">\n"
1796             + LOG_TITLE_FUNCTION
1797             + "log(document.getElementsByTagName('script').length);\n"
1798             + "</script></body></html>";
1799 
1800         loadPageVerifyTitle2(html);
1801     }
1802 
1803     /**
1804      * Regression test for bug 740605.
1805      * @throws Exception if the test fails
1806      */
1807     @Test
1808     @Alerts("1")
1809     public void getElementsByTagName_LoadScript() throws Exception {
1810         final String html = DOCTYPE_HTML
1811                 + "<html><body><script src=\"" + URL_FIRST + "script\"></script></body></html>";
1812 
1813         final String script = "alert(document.getElementsByTagName('script').length);\n";
1814         getMockWebConnection().setResponse(new URL(URL_FIRST, "script"), script, "text/javascript");
1815 
1816         loadPageWithAlerts2(html);
1817     }
1818 
1819     /**
1820      * @throws Exception if an error occurs
1821      */
1822     @Test
1823     @Alerts({"2", "<nested>Three</nested>", "Four", "1", "Two", "0", "0"})
1824     public void getElementsByTagNameXml() throws Exception {
1825         final String html = DOCTYPE_HTML
1826             + "<html><head>\n"
1827             + "</head><body>\n"
1828             + "<script>\n"
1829             + LOG_TITLE_FUNCTION
1830 
1831             + "  var xmlString = [\n"
1832             + "                 '<ResultSet>',\n"
1833             + "                 '<Result>One</Result>',\n"
1834             + "                 '<RESULT>Two</RESULT>',\n"
1835             + "                 '<result><nested>Three</nested></result>',\n"
1836             + "                 '<result>Four</result>',\n"
1837             + "                 '</ResultSet>'\n"
1838             + "                ].join('');\n"
1839             + "  var parser = new DOMParser();\n"
1840             + "  xml = parser.parseFromString(xmlString, 'text/xml');\n"
1841             + "  var xmlDoc = parser.parseFromString(xmlString, 'text/xml');\n"
1842             + "  try {\n"
1843 
1844             + "    var res = xmlDoc.getElementsByTagName('result');\n"
1845             + "    log(res.length);\n"
1846             + "    log(res[0].innerHTML);\n"
1847             + "    log(res[1].innerHTML);\n"
1848 
1849             + "    res = xmlDoc.getElementsByTagName('RESULT');\n"
1850             + "    log(res.length);\n"
1851             + "    log(res[0].innerHTML);\n"
1852 
1853             + "    res = xmlDoc.getElementsByTagName('resulT');\n"
1854             + "    log(res.length);\n"
1855 
1856             + "    res = xmlDoc.getElementsByTagName('rEsulT');\n"
1857             + "    log(res.length);\n"
1858             + "  } catch(e) { logEx(e); }\n"
1859             + "</script></body></html>";
1860 
1861         loadPageVerifyTitle2(html);
1862     }
1863 
1864     /**
1865      * @throws Exception if the test fails
1866      */
1867     @Test
1868     @Alerts({"HTML", "HEAD", "TITLE", "SCRIPT", "BODY"})
1869     public void all_WithParentheses() throws Exception {
1870         final String html = DOCTYPE_HTML
1871             + "<html><head><title></title>\n"
1872             + "<script>\n"
1873             + LOG_TITLE_FUNCTION
1874             + "function doTest() {\n"
1875             + "  var length = document.all.length;\n"
1876             + "  for(i = 0; i < length; i++) {\n"
1877             + "    try {\n"
1878             + "      var all = document.all(i);\n"
1879             + "      if (all == null) {\n"
1880             + "        log('all == null');\n"
1881             + "      } else {\n"
1882             + "        log(all.tagName);\n"
1883             + "      }\n"
1884             + "    } catch(e) { log(e); }\n"
1885             + "  }\n"
1886             + "}\n"
1887             + "</script></head><body onload='doTest()'>\n"
1888             + "</body></html>";
1889 
1890         loadPageVerifyTitle2(html);
1891     }
1892 
1893     /**
1894      * @throws Exception if the test fails
1895      */
1896     @Test
1897     @Alerts({"HTML", "HEAD", "TITLE", "SCRIPT", "BODY"})
1898     public void all_IndexByInt() throws Exception {
1899         final String html = DOCTYPE_HTML
1900             + "<html><head><title></title>\n"
1901             + "<script>\n"
1902             + LOG_TITLE_FUNCTION
1903             + "function doTest() {\n"
1904             + "  var length = document.all.length;\n"
1905             + "  for(i = 0; i < length; i++) {\n"
1906             + "    log(document.all[i].tagName);\n"
1907             + "  }\n"
1908             + "}\n"
1909             + "</script></head><body onload='doTest()'>\n"
1910             + "</body></html>";
1911 
1912         loadPageVerifyTitle2(html);
1913     }
1914 
1915     /**
1916      * @throws Exception if the test fails
1917      */
1918     @Test
1919     @Alerts("HTML")
1920     public void all_Item() throws Exception {
1921         final String html = DOCTYPE_HTML
1922             + "<html><head>\n"
1923             + "<script>\n"
1924             + LOG_TITLE_FUNCTION
1925             + "function doTest() {\n"
1926             + "  log(document.all.item(0).tagName);\n"
1927             + "}\n"
1928             + "</script></head><body onload='doTest()'>\n"
1929             + "</body></html>";
1930 
1931         loadPageVerifyTitle2(html);
1932     }
1933 
1934     /**
1935      * @throws Exception if the test fails
1936      */
1937     @Test
1938     @Alerts("null")
1939     public void all_NamedItem_Unknown() throws Exception {
1940         namedItem("foo");
1941     }
1942 
1943     /**
1944      * @throws Exception if the test fails
1945      */
1946     @Test
1947     @Alerts("form1<->")
1948     public void all_NamedItem_ById() throws Exception {
1949         namedItem("form1");
1950     }
1951 
1952     /**
1953      * @throws Exception if the test fails
1954      */
1955     @Test
1956     @Alerts("<->form2")
1957     public void all_NamedItem_ByName_formWithoutId() throws Exception {
1958         namedItem("form2");
1959     }
1960 
1961     /**
1962      * @throws Exception if the test fails
1963      */
1964     @Test
1965     @Alerts("f3<->form3")
1966     public void all_NamedItem_ByName() throws Exception {
1967         namedItem("form3");
1968     }
1969 
1970     /**
1971      * @throws Exception if the test fails
1972      */
1973     @Test
1974     @Alerts({"coll 2", "f4<->form4_1", "f4<->form4_2"})
1975     public void all_NamedItem_DuplicateId() throws Exception {
1976         namedItem("f4");
1977     }
1978 
1979     /**
1980      * @throws Exception if the test fails
1981      */
1982     @Test
1983     @Alerts({"coll 2", "f5_1<->form5", "f5_2<->form5"})
1984     public void all_NamedItem_DuplicateName() throws Exception {
1985         namedItem("form5");
1986     }
1987 
1988     /**
1989      * @throws Exception if the test fails
1990      */
1991     @Test
1992     @Alerts({"coll 2", "f6<->form6", "form6<->form6_2"})
1993     public void all_NamedItem_DuplicateIdName() throws Exception {
1994         namedItem("form6");
1995     }
1996 
1997     private void namedItem(final String name) throws Exception {
1998         final String html = DOCTYPE_HTML
1999             + "<html><head>\n"
2000             + "<script>\n"
2001             + "  var res = '';"
2002             + "  function log(msg) { res += msg + '§';}\n"
2003             + "  function doTest() {\n"
2004             + "    var result = document.all.namedItem('" + name + "');\n"
2005             + "    if (result == null) {\n"
2006             + "      log(result);\n"
2007             + "    } else if (result.id || result.name) {\n"
2008             + "      log(result.id + '<->' + result.name);\n"
2009             + "    } else {\n"
2010             + "      log('coll ' + result.length);\n"
2011             + "      for(i = 0; i < result.length; i++) {\n"
2012             + "        log(result.item(i).id + '<->' + result.item(i).name);\n"
2013             + "      }\n"
2014             + "    }\n"
2015             + "    window.document.title = res;"
2016             + "  }\n"
2017             + "</script></head>\n"
2018             + "<body onload='doTest()'>\n"
2019             + "  <form id='form1'></form>\n"
2020             + "  <form name='form2'></form>\n"
2021             + "  <form id='f3' name='form3'></form>\n"
2022             + "  <form id='f4' name='form4_1'></form>\n"
2023             + "  <form id='f4' name='form4_2'></form>\n"
2024             + "  <form id='f5_1' name='form5'></form>\n"
2025             + "  <form id='f5_2' name='form5'></form>\n"
2026             + "  <form id='f6' name='form6'></form>\n"
2027             + "  <form id='form6' name='form6_2'></form>\n"
2028             + "</body></html>";
2029 
2030         loadPageVerifyTitle2(html);
2031     }
2032 
2033     /**
2034      * @throws Exception if the test fails
2035      */
2036     @Test
2037     @Alerts("TypeError")
2038     public void all_tags() throws Exception {
2039         final String html = DOCTYPE_HTML
2040             + "<html><head>\n"
2041             + "<script>\n"
2042             + LOG_TITLE_FUNCTION
2043             + "function doTest() {\n"
2044             + "  try {\n"
2045             + "    var inputs = document.all.tags('input');\n"
2046             + "    var inputCount = inputs.length;\n"
2047             + "    for(i = 0; i < inputCount; i++) {\n"
2048             + "      log(inputs[i].name);\n"
2049             + "    }\n"
2050             + "    // Make sure tags() returns an element array that you can call item() on.\n"
2051             + "    log(document.all.tags('input').item(0).name);\n"
2052             + "    log(document.all.tags('input').item(1).name);\n"
2053             + "    // Make sure tags() returns an empty element array if there are no matches.\n"
2054             + "    log(document.all.tags('xxx').length);\n"
2055             + "  } catch(e) { logEx(e) }\n"
2056             + "}\n"
2057             + "</script></head><body onload='doTest()'>\n"
2058             + "<input type='text' name='a' value='1'>\n"
2059             + "<input type='text' name='b' value='1'>\n"
2060             + "</body></html>";
2061 
2062         loadPageVerifyTitle2(html);
2063     }
2064 
2065     /**
2066      * {@code document.all} is "hidden".
2067      * @throws Exception if the test fails
2068      */
2069     @Test
2070     @Alerts({"false", "false", "undefined"})
2071     public void all() throws Exception {
2072         final String html = DOCTYPE_HTML
2073             + "<html><head>\n"
2074             + "<script>\n"
2075             + LOG_TITLE_FUNCTION
2076             + "function doTest() {\n"
2077             + "  log(document.all ? true : false);\n"
2078             + "  log(Boolean(document.all));\n"
2079             + "  log(typeof document.all);\n"
2080             + "}\n"
2081             + "</script><body onload='doTest()'>\n"
2082             + "</body></html>";
2083 
2084         loadPageVerifyTitle2(html);
2085     }
2086 
2087     /**
2088      * Makes sure that the document.all collection contents are not cached if the
2089      * collection is accessed before the page has finished loading.
2090      * @throws Exception if the test fails
2091      */
2092     @Test
2093     @Alerts({"1", "2"})
2094     public void all_Caching() throws Exception {
2095         final String html = DOCTYPE_HTML
2096             + "<html><head>\n"
2097             + "<script>\n"
2098             + LOG_TITLE_FUNCTION
2099             + "</script>\n"
2100             + "</head>\n"
2101             + "<body onload='log(document.all.b.value)'>\n"
2102             + "<input type='text' name='a' value='1'>\n"
2103             + "<script>log(document.all.a.value)</script>\n"
2104             + "<input type='text' name='b' value='2'>\n"
2105             + "</body></html>";
2106 
2107         loadPageVerifyTitle2(html);
2108     }
2109 
2110     /**
2111      * @throws Exception if the test fails
2112      */
2113     @Test
2114     @Alerts({"null", "null", "null"})
2115     public void all_NotExisting() throws Exception {
2116         final String html = DOCTYPE_HTML
2117             + "<html><head>\n"
2118             + "<script>\n"
2119             + LOG_TITLE_FUNCTION
2120             + "function doTest() {\n"
2121             + "  log(document.all('notExisting'));\n"
2122             + "  log(document.all.item('notExisting'));\n"
2123             + "  log(document.all.namedItem('notExisting'));\n"
2124             + "}\n"
2125             + "</script><body onload='doTest()'>\n"
2126             + "</body></html>";
2127 
2128         loadPageVerifyTitle2(html);
2129     }
2130 
2131     /**
2132      * @throws Exception if the test fails
2133      */
2134     @Test
2135     @Alerts({"value1", "value1", "value2", "value2"})
2136     public void getElementsByName() throws Exception {
2137         final String html = DOCTYPE_HTML
2138             + "<html><head>\n"
2139             + "<script>\n"
2140             + LOG_TITLE_FUNCTION
2141             + "function doTest() {\n"
2142             + "  var elements = document.getElementsByName('name1');\n"
2143             + "  for (var i = 0; i < elements.length; i++) {\n"
2144             + "    log(elements[i].value);\n"
2145             + "    log(elements.item(i).value);\n"
2146             + "  }\n"
2147             + "}\n"
2148             + "</script></head><body onload='doTest()'>\n"
2149             + "<form>\n"
2150             + "<input type='radio' name='name1' value='value1'>\n"
2151             + "<input type='radio' name='name1' value='value2'>\n"
2152             + "<input type='button' name='name2' value='value3'>\n"
2153             + "</form>\n"
2154             + "</body></html>";
2155 
2156         loadPageVerifyTitle2(html);
2157     }
2158 
2159     /**
2160      * @throws Exception if the test fails
2161      */
2162     @Test
2163     @Alerts("IAmTheBody")
2164     public void body_read() throws Exception {
2165         final String html = DOCTYPE_HTML
2166             + "<html><head>\n"
2167             + "<script>\n"
2168             + LOG_TITLE_FUNCTION
2169             + "</script>\n"
2170             + "</head>\n"
2171             + "<body id='IAmTheBody' onload='log(document.body.id)'>\n"
2172             + "</body></html>";
2173 
2174         loadPageVerifyTitle2(html);
2175     }
2176 
2177     /**
2178      * @throws Exception if the test fails
2179      */
2180     @Test
2181     @Alerts("FRAMESET")
2182     public void body_readFrameset() throws Exception {
2183         final String html = DOCTYPE_HTML
2184             + "<html>\n"
2185             + "<frameset onload='alert(document.body.tagName)'>\n"
2186             + "<frame src='about:blank' name='foo'>\n"
2187             + "</frameset></html>";
2188 
2189         loadPageWithAlerts2(html);
2190     }
2191 
2192     /**
2193      * Tests for <tt>document.images</tt>.
2194      * @throws Exception if the test fails
2195      */
2196     @Test
2197     @Alerts({"0", "3", "3", "true", "firstImage"})
2198     public void images() throws Exception {
2199         final String html = DOCTYPE_HTML
2200             + "<html>\n"
2201             + "<head>\n"
2202             + "<script>\n"
2203             + LOG_TITLE_FUNCTION
2204             + "var oCol = document.images;\n"
2205             + "log(oCol.length);\n"
2206             + "function test() {\n"
2207             + "  log(oCol.length);\n"
2208             + "  log(document.images.length);\n"
2209             + "  log(document.images == oCol);\n"
2210             + "  log(document.images[0].id);\n"
2211             + "}\n"
2212             + "</script>\n"
2213             + "</head>\n"
2214             + "<body onload='test()'>\n"
2215             + "<img id='firstImage' />\n"
2216             + "<img name='end' />\n"
2217             + "<img id='endId'/>\n"
2218             + "</body>\n"
2219             + "</html>";
2220 
2221         loadPageVerifyTitle2(html);
2222     }
2223 
2224     /**
2225      * Tests for <tt>document.embeds</tt>.
2226      * @throws Exception if the test fails
2227      */
2228     @Test
2229     @Alerts({"0", "0", "0", "true"})
2230     public void imagesEmpty() throws Exception {
2231         final String html = DOCTYPE_HTML
2232             + "<html>\n"
2233             + "<head>\n"
2234             + "<script>\n"
2235             + LOG_TITLE_FUNCTION
2236             + "var oCol = document.images;\n"
2237             + "log(oCol.length);\n"
2238             + "function test() {\n"
2239             + "  log(oCol.length);\n"
2240             + "  log(document.images.length);\n"
2241             + "  log(document.images == oCol);\n"
2242             + "}\n"
2243             + "</script>\n"
2244             + "</head>\n"
2245             + "<body onload='test()'>\n"
2246             + "</body>\n"
2247             + "</html>";
2248 
2249         loadPageVerifyTitle2(html);
2250     }
2251 
2252     /**
2253      * Test the access to the images value. This should return the 2 images in the document
2254      * @throws Exception if the test fails
2255      */
2256     @Test
2257     @Alerts({"1", "2", "2", "true"})
2258     public void allImages() throws Exception {
2259         final String html = DOCTYPE_HTML
2260             + "<html><head>\n"
2261             + "<script>\n"
2262             + LOG_TITLE_FUNCTION
2263             + "function doTest() {\n"
2264             + "  log(document.images.length);\n"
2265             + "  log(allImages.length);\n"
2266             + "  log(document.images == allImages);\n"
2267             + "}\n"
2268             + "</script></head><body onload='doTest()'>\n"
2269             + "<img src='firstImage'>\n"
2270             + "<script>\n"
2271             + "var allImages = document.images;\n"
2272             + "log(allImages.length);\n"
2273             + "</script>\n"
2274             + "<form>\n"
2275             + "<img src='2ndImage'>\n"
2276             + "</form>\n"
2277             + "</body></html>";
2278 
2279         getMockWebConnection().setDefaultResponse("Error: not found", 404, "Not Found", MimeType.TEXT_HTML);
2280 
2281         loadPageVerifyTitle2(html);
2282     }
2283 
2284     /**
2285      * Test setting and reading the title for an existing title.
2286      * @throws Exception if the test fails
2287      */
2288     @Test
2289     @Alerts("correct title")
2290     public void settingTitle() throws Exception {
2291         final String html = DOCTYPE_HTML
2292             + "<html><head><title>Bad Title</title></head>\n"
2293             + "<body>\n"
2294             + "<script>\n"
2295             + "  document.title = 'correct title';\n"
2296             + "  alert(document.title);\n"
2297             + "</script>\n"
2298             + "</body></html>";
2299 
2300         final WebDriver driver = loadPageWithAlerts2(html);
2301         assertTitle(driver, getExpectedAlerts()[0]);
2302     }
2303 
2304     /**
2305      * Test setting and reading the title for when the is not in the page to begin.
2306      * @throws Exception if the test fails
2307      */
2308     @Test
2309     @Alerts("correct title")
2310     public void settingMissingTitle() throws Exception {
2311         final String html = DOCTYPE_HTML
2312             + "<html><head></head>\n"
2313             + "<body>\n"
2314             + "<script>\n"
2315             + "  document.title = 'correct title';\n"
2316             + "  alert(document.title);\n"
2317             + "</script>\n"
2318             + "</body></html>";
2319 
2320         loadPageWithAlerts2(html);
2321     }
2322 
2323     /**
2324      * Test setting and reading the title for when the is not in the page to begin.
2325      * @throws Exception if the test fails
2326      */
2327     @Test
2328     @Alerts("correct title")
2329     public void settingBlankTitle() throws Exception {
2330         final String html = DOCTYPE_HTML
2331             + "<html><head><title></title></head>\n"
2332             + "<body>\n"
2333             + "<script>\n"
2334             + "  document.title = 'correct title';\n"
2335             + "  alert(document.title);\n"
2336             + "</script>\n"
2337             + "</body></html>";
2338 
2339         final WebDriver driver = loadPageWithAlerts2(html);
2340         assertTitle(driver, getExpectedAlerts()[0]);
2341     }
2342 
2343     /**
2344      * @throws Exception if the test fails
2345      */
2346     @Test
2347     @Alerts("foo")
2348     public void title() throws Exception {
2349         final String html = DOCTYPE_HTML
2350             + "<html><head><title>foo</title><script>\n"
2351             + "function doTest() {\n"
2352             + "  alert(document.title);\n"
2353             + "}\n"
2354             + "</script></head>\n"
2355             + "<body onload='doTest()'>\n"
2356             + "</body></html>";
2357 
2358         final WebDriver driver = loadPageWithAlerts2(html);
2359         assertTitle(driver, getExpectedAlerts()[0]);
2360     }
2361 
2362     /**
2363      * Test the ReadyState.
2364      * <a href="http://sourceforge.net/tracker/?func=detail&aid=3030247&group_id=47038&atid=448266">issue 1139</a>
2365      * @throws Exception if the test fails
2366      */
2367     @Test
2368     @Alerts({"loading", "complete"})
2369     public void readyState() throws Exception {
2370         final String html = DOCTYPE_HTML
2371             + "<html><head>\n"
2372             + "<script>\n"
2373             + LOG_TITLE_FUNCTION
2374             + "function testIt() {\n"
2375             + "  log(document.readyState);\n"
2376             + "}\n"
2377             + "log(document.readyState);\n"
2378             + "</script>\n"
2379             + "</head>\n"
2380             + "<body onLoad='testIt()'></body></html>";
2381 
2382         loadPageVerifyTitle2(html);
2383     }
2384 
2385     /**
2386      * Calling document.body before the page is fully loaded used to cause an exception.
2387      * @throws Exception if the test fails
2388      */
2389     @Test
2390     @Alerts("null")
2391     public void documentWithNoBody() throws Exception {
2392         final String html = DOCTYPE_HTML
2393             + "<html><head>\n"
2394             + "<script>\n"
2395             + LOG_TITLE_FUNCTION
2396             + "  log(document.body);\n"
2397             + "</script></head><body></body></html>";
2398 
2399         loadPageVerifyTitle2(html);
2400     }
2401 
2402     /**
2403      * IE has a bug which returns the element by name if it cannot find it by ID.
2404      * @throws Exception if the test fails
2405      */
2406     @Test
2407     @Alerts({"null", "byId"})
2408     public void getElementById_findByName() throws Exception {
2409         final String html = DOCTYPE_HTML
2410             + "<html><head></head>\n"
2411             + "<body>\n"
2412             + "<input type='text' name='findMe'>\n"
2413             + "<input type='text' id='findMe2' name='byId'>\n"
2414             + "<script>\n"
2415             + LOG_TITLE_FUNCTION
2416             + "  var o = document.getElementById('findMe');\n"
2417             + "  log(o ? o.name : 'null');\n"
2418             + "  log(document.getElementById('findMe2').name);\n"
2419             + "</script></body></html>";
2420 
2421         loadPageVerifyTitle2(html);
2422     }
2423 
2424     /**
2425      * Test that <tt>img</tt> and <tt>form</tt> can be retrieved directly by name, but not <tt>a</tt>, <tt>input</tt>
2426      * or <tt>button</tt>.
2427      *
2428      * @throws Exception if the test fails
2429      */
2430     @Test
2431     @Alerts({"myImageId", "2", "FORM", "undefined", "undefined", "undefined", "undefined"})
2432     public void directAccessByName() throws Exception {
2433         final String html = DOCTYPE_HTML
2434             + "<html><head>\n"
2435             + "<script>\n"
2436             + LOG_TITLE_FUNCTION
2437             + "function doTest() {\n"
2438             + "  log(document.myImage.id);\n"
2439             + "  log(document.myImage2.length);\n"
2440             + "  log(document.myForm.tagName);\n"
2441             + "  log(document.myAnchor);\n"
2442             + "  log(document.myInput);\n"
2443             + "  log(document.myInputImage);\n"
2444             + "  log(document.myButton);\n"
2445             + "}\n"
2446             + "</script></head>\n"
2447             + "<body onload='doTest()'>\n"
2448             + "  <img src='foo' name='myImage' id='myImageId'>\n"
2449             + "  <img src='foo' name='myImage2'>\n"
2450             + "  <img src='foo' name='myImage2'>\n"
2451             + "  <a name='myAnchor'/>\n"
2452             + "  <form name='myForm'>\n"
2453             + "    <input name='myInput' type='text'>\n"
2454             + "    <input name='myInputImage' type='image' src='foo'>\n"
2455             + "    <button name='myButton'>foo</button>\n"
2456             + "  </form>\n"
2457             + "</body></html>";
2458 
2459         getMockWebConnection().setDefaultResponse("Error: not found", 404, "Not Found", MimeType.TEXT_HTML);
2460 
2461         loadPageVerifyTitle2(html);
2462     }
2463 
2464      /**
2465       * @throws Exception if the test fails
2466       */
2467     @Test
2468     @Alerts({"[object HTMLCollection]", "2"})
2469     public void scriptsArray() throws Exception {
2470         final String html = DOCTYPE_HTML
2471             + "<html><head>\n"
2472             + "<script lang='JavaScript'>\n"
2473             + LOG_TITLE_FUNCTION
2474             + "  function doTest() {\n"
2475             + "    log(document.scripts);\n"
2476             + "    try {\n"
2477             + "      log(document.scripts.length);\n" // This line used to blow up
2478             + "    } catch(e) { logEx(e); }\n"
2479             + "}\n"
2480             + "</script></head><body onload='doTest();'>\n"
2481             + "<script>var scriptTwo = 1;</script>\n"
2482             + "</body></html> ";
2483 
2484         loadPageVerifyTitle2(html);
2485     }
2486 
2487     /**
2488      * Any document.foo should first look at elements named "foo" before using standard functions.
2489      * @throws Exception if the test fails
2490      */
2491     @Test
2492     @Alerts({"object", "FORM"})
2493     public void precedence() throws Exception {
2494         final String html = DOCTYPE_HTML
2495             + "<html><head>\n"
2496             + "<script>\n"
2497             + LOG_TITLE_FUNCTION
2498             + "</script>\n"
2499             + "</head>\n"
2500             + "<body>\n"
2501             + "  <form name='writeln'>foo</form>\n"
2502             + "  <script>log(typeof document.writeln);</script>\n"
2503             + "  <script>log(document.writeln.tagName);</script>\n"
2504             + "</body></html>";
2505 
2506         loadPageVerifyTitle2(html);
2507     }
2508 
2509     /**
2510      * @throws Exception if the test fails
2511      */
2512     @Test
2513     @Alerts({"true", "false"})
2514     public void defaultViewAndParentWindow() throws Exception {
2515         final String html = DOCTYPE_HTML
2516             + "<html><head><script>\n"
2517             + LOG_TITLE_FUNCTION
2518             + "function test() {\n"
2519             + "  log(document.defaultView == window);\n"
2520             + "  log(document.parentWindow == window);\n"
2521             + "}\n"
2522             + "</script></head><body onload='test()'>\n"
2523             + "</body></html> ";
2524 
2525         loadPageVerifyTitle2(html);
2526     }
2527 
2528     /**
2529      * @throws Exception if the test fails
2530      */
2531     @Test
2532     @Alerts({"undefined", "123"})
2533     public void put() throws Exception {
2534         final String html = DOCTYPE_HTML
2535                 + "<html><body>\n"
2536                 + "<script>\n"
2537                 + LOG_TITLE_FUNCTION
2538                 + "  log(document.foo);\n"
2539                 + "  if (!document.foo) document.foo = 123;\n"
2540                 + "  log(document.foo);\n"
2541                 + "</script>\n"
2542                 + "</form>\n" + "</body>\n" + "</html>";
2543 
2544         loadPageVerifyTitle2(html);
2545     }
2546 
2547     /**
2548      * Tests <tt>document.cloneNode()</tt>.
2549      * IE specific.
2550      * @throws Exception if the test fails
2551      */
2552     @Test
2553     @Alerts({"[object HTMLDocument]", "[object HTMLBodyElement]",
2554                 "true", "true", "true", "false", "true", "false"})
2555     public void documentCloneNode() throws Exception {
2556         final String html = DOCTYPE_HTML
2557                 + "<html><body id='hello' onload='doTest()'>\n"
2558                 + "  <script id='jscript'>\n"
2559                 + LOG_TITLE_FUNCTION
2560                 + "    function doTest() {\n"
2561                 + "      var clone = document.cloneNode(true);\n"
2562                 + "      log(clone);\n"
2563                 + "      if (clone != null) {\n"
2564                 + "        log(clone.body);\n"
2565                 + "        log(clone.body !== document.body);\n"
2566                 + "        log(clone.getElementById(\"id1\") !== document.getElementById(\"id1\"));\n"
2567                 + "        log(document.ownerDocument == null);\n"
2568                 + "        log(clone.ownerDocument == document);\n"
2569                 + "        log(document.getElementById(\"id1\").ownerDocument === document);\n"
2570                 + "        log(clone.getElementById(\"id1\").ownerDocument === document);\n"
2571                 + "      }\n"
2572                 + "    }\n"
2573                 + "  </script>\n"
2574                 + "  <div id='id1'>hello</div>\n"
2575                 + "</body></html>";
2576 
2577         loadPageVerifyTitle2(html);
2578     }
2579 
2580     /**
2581      * @throws Exception if the test fails
2582      */
2583     @Test
2584     @Alerts("TypeError")
2585     public void createStyleSheet() throws Exception {
2586         final String html = DOCTYPE_HTML
2587             + "<html><head>\n"
2588             + "<script>\n"
2589             + LOG_TITLE_FUNCTION
2590             + "try {\n"
2591             + "  var s = document.createStyleSheet('foo.css', 1);\n"
2592             + "  log(s);\n"
2593             + "} catch(e) {logEx(e);}\n"
2594             + "</script></head><body>\n"
2595             + "</body></html>";
2596 
2597         loadPageVerifyTitle2(html);
2598     }
2599 
2600     /**
2601      * @throws Exception if the test fails
2602      */
2603     @Test
2604     @Alerts({"#document-fragment", "null", "11", "null", "0"})
2605     public void createDocumentFragment() throws Exception {
2606         final String html = DOCTYPE_HTML
2607             + "<html><head>\n"
2608             + "<title>foo</title><script>\n"
2609             + LOG_TEXTAREA_FUNCTION
2610             + "  function test() {\n"
2611             + "    var fragment = document.createDocumentFragment();\n"
2612             + "    log(fragment.nodeName);\n"
2613             + "    log(fragment.nodeValue);\n"
2614             + "    log(fragment.nodeType);\n"
2615             + "    log(fragment.parentNode);\n"
2616             + "    log(fragment.childNodes.length);\n"
2617             + "  }\n"
2618             + "</script></head><body onload='test()'>\n"
2619             + LOG_TEXTAREA
2620             + "</body></html>";
2621 
2622         loadPageVerifyTextArea2(html);
2623     }
2624 
2625     /**
2626      * @throws Exception if an error occurs
2627      */
2628     @Test
2629     @Alerts({"true", "object", "[object Event]", "false"})
2630     public void createEvent_Event() throws Exception {
2631         createEvent("Event");
2632     }
2633 
2634     /**
2635      * @throws Exception if an error occurs
2636      */
2637     @Test
2638     @Alerts({"true", "object", "[object Event]", "false"})
2639     public void createEvent_Events() throws Exception {
2640         createEvent("Events");
2641     }
2642 
2643     /**
2644      * @throws Exception if an error occurs
2645      */
2646     @Test
2647     @Alerts({"true", "object", "[object Event]", "false"})
2648     public void createEvent_HTMLEvents() throws Exception {
2649         createEvent("HTMLEvents");
2650     }
2651 
2652     /**
2653      * @throws Exception if an error occurs
2654      */
2655     @Test
2656     @Alerts("NotSupportedError/DOMException")
2657     public void createEvent_Bogus() throws Exception {
2658         createEvent("Bogus");
2659     }
2660 
2661     private void createEvent(final String eventType) throws Exception {
2662         final String html = DOCTYPE_HTML
2663             + "<html><head>\n"
2664             + "<script>\n"
2665             + LOG_TITLE_FUNCTION
2666             + "try {\n"
2667             + "  var e = document.createEvent('" + eventType + "');\n"
2668             + "  log(e != null);\n"
2669             + "  log(typeof e);\n"
2670             + "  log(e);\n"
2671             + "  log(e.cancelable);\n"
2672             + "}\n"
2673             + "catch(e) { logEx(e) }\n"
2674             + "</script></head><body>\n"
2675             + "</body></html>";
2676 
2677         loadPageVerifyTitle2(html);
2678     }
2679 
2680     /**
2681      * @throws Exception if an error occurs
2682      */
2683     @Test
2684     @Alerts({"null", "null", "[object HTMLDivElement]"})
2685     public void createEvent_target() throws Exception {
2686         final String html = DOCTYPE_HTML
2687             + "<html>\n"
2688             + "  <body onload='test()'>\n"
2689             + "    <div id='d' onclick='log(event.target)'>abc</div>\n"
2690             + "    <script>\n"
2691             + LOG_TITLE_FUNCTION
2692             + "      function test() {\n"
2693             + "        try {\n"
2694             + "          var event = document.createEvent('MouseEvents');\n"
2695             + "          log(event.target);\n"
2696             + "          event.initMouseEvent('click', true, true, window,\n"
2697             + "               1, 0, 0, 0, 0, false, false, false, false, 0, null);\n"
2698             + "          log(event.target);\n"
2699             + "          document.getElementById('d').dispatchEvent(event);\n"
2700             + "        } catch(e) { logEx(e) }\n"
2701             + "      }\n"
2702             + "    </script>\n"
2703             + "  </body>\n"
2704             + "</html>";
2705 
2706         loadPageVerifyTitle2(html);
2707     }
2708 
2709     /**
2710      * @throws Exception if an error occurs
2711      */
2712     @Test
2713     @Alerts("function onload(event) { log(\"hi\") }")
2714     public void createEvent_overridden() throws Exception {
2715         final String html = DOCTYPE_HTML
2716             + "<html>\n"
2717             + "  <body onload='test()'>\n"
2718             + "    <div id='d' onclick='log(onload)' onload='log(\"hi\")'>abc</div>\n"
2719             + "    <script>\n"
2720             + LOG_TITLE_FUNCTION
2721             + "      function test() {\n"
2722             + "        try {\n"
2723             + "          var event = document.createEvent('MouseEvents');\n"
2724             + "          event.initMouseEvent('click', true, true, window,\n"
2725             + "               1, 0, 0, 0, 0, false, false, false, false, 0, null);\n"
2726             + "          document.getElementById('d').dispatchEvent(event);\n"
2727             + "        } catch(e) { logEx(e) }\n"
2728             + "      }\n"
2729             + "    </script>\n"
2730             + "  </body>\n"
2731             + "</html>";
2732 
2733         loadPageVerifyTitle2(html);
2734     }
2735 
2736     /**
2737      * @throws Exception if an error occurs
2738      */
2739     @Test
2740     @Alerts("test")
2741     @HtmlUnitNYI(CHROME = "undefined",
2742             EDGE = "undefined",
2743             FF = "undefined",
2744             FF_ESR = "undefined")
2745     public void createEvent_caller() throws Exception {
2746         final String html = DOCTYPE_HTML
2747             + "<html>\n"
2748             + "  <body onload='test()'>\n"
2749             + "    <div id='d' onclick='var c = arguments.callee.caller; log(c ? c.name : c)'>abc</div>\n"
2750             + "    <script>\n"
2751             + LOG_TITLE_FUNCTION
2752             + "      function test() {\n"
2753             + "        try {\n"
2754             + "          var event = document.createEvent('MouseEvents');\n"
2755             + "          event.initMouseEvent('click', true, true, window,\n"
2756             + "               1, 0, 0, 0, 0, false, false, false, false, 0, null);\n"
2757             + "          document.getElementById('d').dispatchEvent(event);\n"
2758             + "        } catch(e) { logEx(e) }\n"
2759             + "      }\n"
2760             + "    </script>\n"
2761             + "  </body>\n"
2762             + "</html>";
2763         loadPageVerifyTitle2(html);
2764     }
2765 
2766     /**
2767      * @throws Exception if an error occurs
2768      */
2769     @Test
2770     @Alerts("null")
2771     @HtmlUnitNYI(CHROME = "undefined",
2772             EDGE = "undefined",
2773             FF = "undefined",
2774             FF_ESR = "undefined")
2775     public void caller() throws Exception {
2776         final String html = DOCTYPE_HTML
2777             + "<html>\n"
2778             + "  <body>\n"
2779             + "    <script>\n"
2780             + LOG_TITLE_FUNCTION
2781             + "      function test() {\n"
2782             + "        var c = arguments.callee.caller;\n"
2783             + "        log(c ? c.name : c);\n"
2784             + "      }\n"
2785             + "      test();\n"
2786             + "    </script>\n"
2787             + "  </body>\n"
2788             + "</html>";
2789         loadPageVerifyTitle2(html);
2790     }
2791 
2792     /**
2793      * @throws Exception if an error occurs
2794      */
2795     @Test
2796     @Alerts("onload")
2797     public void caller_event() throws Exception {
2798         final String html = DOCTYPE_HTML
2799             + "<html>\n"
2800             + "  <body onload='test()'>\n"
2801             + "    <script>\n"
2802             + LOG_TITLE_FUNCTION
2803             + "      function test() {\n"
2804             + "        var c = arguments.callee.caller;\n"
2805             + "        log(c ? c.name : c);\n"
2806             + "      }\n"
2807             + "    </script>\n"
2808             + "  </body>\n"
2809             + "</html>";
2810 
2811         loadPageVerifyTitle2(html);
2812     }
2813 
2814     /**
2815      * @throws Exception if an error occurs
2816      */
2817     @Test
2818     @Alerts("TypeError")
2819     public void createEventObject_IE() throws Exception {
2820         final String html = DOCTYPE_HTML
2821             + "<html><head>\n"
2822             + "<script>\n"
2823             + LOG_TITLE_FUNCTION
2824             + "try {\n"
2825             + "  var e = document.createEventObject();\n"
2826             + "  log(e != null);\n"
2827             + "  log(typeof e);\n"
2828             + "  log(e);\n"
2829             + "} catch(e) {logEx(e);}\n"
2830             + "</script></head><body>\n"
2831             + "</body></html>";
2832 
2833         loadPageVerifyTitle2(html);
2834     }
2835 
2836     /**
2837      * @throws Exception if the test fails
2838      */
2839     @Test
2840     @Alerts("null")
2841     public void elementFromPoint() throws Exception {
2842         final String html = DOCTYPE_HTML
2843             + "<html><head>\n"
2844             + "<script>\n"
2845             + LOG_TITLE_FUNCTION
2846             + "  function test() {\n"
2847             + "    var e = document.elementFromPoint(-1,-1);\n"
2848             + "    log(e != null ? e.nodeName : null);\n"
2849             + "  }\n"
2850             + "</script></head><body onload='test()'>\n"
2851             + "</body></html>";
2852         loadPageVerifyTitle2(html);
2853     }
2854 
2855     /**
2856      * @throws Exception if the test fails
2857      */
2858     @Test
2859     @Alerts({"[object StyleSheetList]", "0", "true"})
2860     public void styleSheets() throws Exception {
2861         final String html = DOCTYPE_HTML
2862             + "<html><head>\n"
2863             + "<script>\n"
2864             + LOG_TITLE_FUNCTION
2865             + "  function test() {\n"
2866             + "    log(document.styleSheets);\n"
2867             + "    log(document.styleSheets.length);\n"
2868             + "    log(document.styleSheets == document.styleSheets);\n"
2869             + "  }\n"
2870             + "</script></head><body onload='test()'>\n"
2871             + "</body></html>";
2872 
2873         loadPageVerifyTitle2(html);
2874     }
2875 
2876     /**
2877      * Various <tt>document.designMode</tt> tests when the document is in the root HTML page.
2878      * @throws Exception if an error occurs
2879      */
2880     @Test
2881     @Alerts({"off", "off", "on", "on", "on", "off", "off", "off", "off"})
2882     public void designMode_root() throws Exception {
2883         designMode("document");
2884     }
2885 
2886     /**
2887      * Various <tt>document.designMode</tt> tests when the document is in an <tt>iframe</tt>.
2888      * @throws Exception if an error occurs
2889      */
2890     @Test
2891     @Alerts({"off", "off", "on", "on", "on", "off", "off", "off", "off"})
2892     public void designMode_iframe() throws Exception {
2893         designMode("window.frames['f'].document");
2894     }
2895 
2896     private void designMode(final String doc) throws Exception {
2897         final String html = DOCTYPE_HTML
2898             + "<html><body><iframe name='f' id='f'></iframe><script>\n"
2899             + LOG_TITLE_FUNCTION
2900             + "var d = " + doc + ";\n"
2901             + "log(d.designMode);\n"
2902             + "try{d.designMode = 'abc';}catch(e){log('!');}\n"
2903             + "log(d.designMode);\n"
2904             + "try{d.designMode = 'on';}catch(e){log('!');}\n"
2905             + "log(d.designMode);\n"
2906             + "try{d.designMode = 'On';}catch(e){log('!');}\n"
2907             + "log(d.designMode);\n"
2908             + "try{d.designMode = 'abc';}catch(e){log('!');}\n"
2909             + "log(d.designMode);\n"
2910             + "try{d.designMode = 'Off';}catch(e){log('!');}\n"
2911             + "log(d.designMode);\n"
2912             + "try{d.designMode = 'off';}catch(e){log('!');}\n"
2913             + "log(d.designMode);\n"
2914             + "try{d.designMode = 'Inherit';}catch(e){log('!');}\n"
2915             + "log(d.designMode);\n"
2916             + "try{d.designMode = 'inherit';}catch(e){log('!');}\n"
2917             + "log(d.designMode);\n"
2918             + "</script></body></html>";
2919 
2920         loadPageVerifyTitle2(html);
2921     }
2922 
2923     /**
2924      * Verifies that enabling design mode on a document in Firefox implicitly creates a selection range.
2925      * Required for YUI rich text editor unit tests.
2926      * @throws Exception if an error occurs
2927      */
2928     @Test
2929     @Alerts(DEFAULT = {"0", "0", "0"},
2930             FF = {"0", "1", "1"},
2931             FF_ESR = {"0", "1", "1"})
2932     public void designMode_createsSelectionRange() throws Exception {
2933         final String html1 = DOCTYPE_HTML
2934             + "<html><body><iframe id='i' src='" + URL_SECOND + "'></iframe></body></html>";
2935         final String html2 = DOCTYPE_HTML
2936             + "<html><body onload='test()'>\n"
2937             + "<script>\n"
2938             + LOG_WINDOW_NAME_FUNCTION
2939             + "  var selection = document.selection;\n"
2940             + "  if(!selection) selection = window.getSelection();\n"
2941             + "  function test() {\n"
2942             + "    log(selection.rangeCount);\n"
2943             + "    document.designMode = 'on';\n"
2944             + "    log(selection.rangeCount);\n"
2945             + "    document.designMode = 'off';\n"
2946             + "    log(selection.rangeCount);\n"
2947             + "  }\n"
2948             + "</script>\n"
2949             + "</body></html>";
2950 
2951         getMockWebConnection().setResponse(URL_SECOND, html2);
2952 
2953         loadPage2(html1);
2954         verifyWindowName2(getWebDriver(), getExpectedAlerts());
2955     }
2956 
2957     /**
2958      * Minimal test for {@code execCommand}.
2959      * @throws Exception if the test fails
2960      */
2961     @Test
2962     @Alerts(DEFAULT = {"true", "false"},
2963             CHROME = {"false", "false"},
2964             EDGE = {"false", "false"})
2965     public void execCommand() throws Exception {
2966         final String html = DOCTYPE_HTML
2967             + "<html><head>\n"
2968             + "<script>\n"
2969             + LOG_TITLE_FUNCTION
2970             + "  function test() {\n"
2971             + "    document.designMode = 'On';\n"
2972             + "    log(document.execCommand('Bold', false, null));\n"
2973             + "    try {\n"
2974             + "      log(document.execCommand('foo', false, null));\n"
2975             + "    }\n"
2976             + "    catch(e) {\n"
2977             + "      log('command foo not supported');\n"
2978             + "    }\n"
2979             + "    document.designMode = 'Off';\n"
2980             + "  }\n"
2981             + "</script></head><body onload='test()'>\n"
2982             + "</body></html>";
2983 
2984         loadPageVerifyTitle2(html);
2985     }
2986 
2987     /**
2988      * @throws Exception if the test fails
2989      */
2990     @Test
2991     @Alerts("[object HTMLHeadingElement]")
2992     public void evaluate_caseInsensitiveAttribute() throws Exception {
2993         final String html = DOCTYPE_HTML
2994             + "<html><head>\n"
2995             + "<script>\n"
2996             + LOG_TITLE_FUNCTION
2997             + "function test() {\n"
2998             + "  if(document.evaluate) {\n"
2999             + "    var expr = './/*[@CLASS]';\n"
3000             + "    var result = document.evaluate(expr, document.documentElement, null, XPathResult.ANY_TYPE, null);\n"
3001             + "    log(result.iterateNext());\n"
3002             + "  } else { log('not available'); }\n"
3003             + "}\n"
3004             + "</script></head><body onload='test()'>\n"
3005             + "  <h1 class='title'>Some text</h1>\n"
3006             + "</body></html>";
3007 
3008         loadPageVerifyTitle2(html);
3009     }
3010 
3011     /**
3012      * @throws Exception if the test fails
3013      */
3014     @Test
3015     @Alerts("[object HTMLHtmlElement]")
3016     public void evaluate_caseInsensitiveTagName() throws Exception {
3017         final String html = DOCTYPE_HTML
3018             + "<html><head>\n"
3019             + "<script>\n"
3020             + LOG_TITLE_FUNCTION
3021             + "  function test() {\n"
3022             + "    if(document.evaluate) {\n"
3023             + "      var expr = '/hTmL';\n"
3024             + "      var result = document.evaluate(expr, "
3025                         + "document.documentElement, null, XPathResult.ANY_TYPE, null);\n"
3026             + "      log(result.iterateNext());\n"
3027             + "    } else { log('not available'); }\n"
3028             + "  }\n"
3029             + "</script></head>\n"
3030             + "<body onload='test()'>\n"
3031             + "  <h1 class='title'>Some text</h1>\n"
3032             + "</body></html>";
3033 
3034         loadPageVerifyTitle2(html);
3035     }
3036 
3037     /**
3038      * Verifies that HtmlUnit behaves correctly when a document is missing the <tt>body</tt> tag (it
3039      * needs to be added once the document has finished loading).
3040      *
3041      * @throws Exception if an error occurs
3042      */
3043     @Test
3044     @Alerts({"1: null", "2: null", "3: [object HTMLBodyElement]"})
3045     public void noBodyTag() throws Exception {
3046         final String html = DOCTYPE_HTML
3047             + "<html>\n"
3048             + "  <head>\n"
3049             + "    <script>\n"
3050             + LOG_TITLE_FUNCTION
3051             + "    </script>\n"
3052             + "    <script>log('1: ' + document.body);</script>\n"
3053             + "    <script defer=''>log('2: ' + document.body);</script>\n"
3054             + "    <script>window.onload = function() { log('3: ' + document.body); }</script>\n"
3055             + "  </head>\n"
3056             + "</html>";
3057 
3058         loadPageVerifyTitle2(html);
3059     }
3060 
3061     /**
3062      * Verifies that HtmlUnit behaves correctly when an iframe's document is missing the <tt>body</tt> tag (it
3063      * needs to be added once the document has finished loading).
3064      *
3065      * @throws Exception if an error occurs
3066      */
3067     @Test
3068     @Alerts({"1: [object HTMLBodyElement]", "2: [object HTMLBodyElement]"})
3069     public void noBodyTag_IFrame() throws Exception {
3070         final String html = DOCTYPE_HTML
3071             + "<html>\n"
3072             + "  <head>\n"
3073             + "<script>\n"
3074             + LOG_TITLE_FUNCTION
3075             + "</script>\n"
3076             + "  </head>\n"
3077             + "  <body>\n"
3078             + "    <iframe id='i'></iframe>\n"
3079             + "    <script>\n"
3080             + "      log('1: ' + document.getElementById('i').contentWindow.document.body);\n"
3081             + "      window.onload = function() {\n"
3082             + "        log('2: ' + document.getElementById('i').contentWindow.document.body);\n"
3083             + "      };\n"
3084             + "    </script>\n"
3085             + "  </body>\n"
3086             + "</html>";
3087 
3088         loadPageVerifyTitle2(html);
3089     }
3090 
3091     /**
3092      * Verifies that the document object has a <tt>fireEvent</tt> method and that it works correctly (IE only).
3093      *
3094      * @throws Exception if an error occurs
3095      */
3096     @Test
3097     public void fireEvent() throws Exception {
3098         final String html = DOCTYPE_HTML
3099             + "<html><body>\n"
3100             + "  <span id='s' onclick='\n"
3101             + "  if(document.fireEvent) {\n"
3102             + "    document.onkeydown = function() {log(\"x\")};\n"
3103             + "    document.fireEvent(\"onkeydown\");\n"
3104             + "  }\n"
3105             + " '>abc</span>\n"
3106             + "</body></html>";
3107 
3108         final WebDriver driver = loadPage2(html);
3109         driver.findElement(By.id("s")).click();
3110 
3111         verifyAlerts(driver, getExpectedAlerts());
3112     }
3113 
3114     /**
3115      * Test the value of document.ownerDocument.
3116      * @throws Exception if an error occurs
3117      */
3118     @Test
3119     @Alerts("null")
3120     public void ownerDocument() throws Exception {
3121         final String html = DOCTYPE_HTML
3122                 + "<html>\n"
3123                 + "<body id='hello' onload='doTest()'>\n"
3124                 + "  <script>\n"
3125                 + LOG_TITLE_FUNCTION
3126                 + "    function doTest() {\n"
3127                 + "      log(document.ownerDocument);\n"
3128                 + "    }\n"
3129                 + "  </script>\n"
3130                 + "</body>\n" + "</html>";
3131 
3132         loadPageVerifyTitle2(html);
3133     }
3134 
3135     /**
3136      * @throws Exception if an error occurs
3137      */
3138     @Test
3139     @Alerts({"[object HTMLDocument]", "true"})
3140     public void getRootNode() throws Exception {
3141         final String html = DOCTYPE_HTML
3142                 + "<html>\n"
3143                 + "<body id='hello' onload='doTest()'>\n"
3144                 + "  <script>\n"
3145                 + LOG_TITLE_FUNCTION
3146                 + "    function doTest() {\n"
3147                 + "      if (document.getRootNode) {\n"
3148                 + "        log(document.getRootNode());\n"
3149                 + "        log(document === document.getRootNode());\n"
3150                 + "      } else log('-');\n"
3151                 + "    }\n"
3152                 + "  </script>\n"
3153                 + "</body>\n" + "</html>";
3154 
3155         loadPageVerifyTitle2(html);
3156     }
3157 
3158     /**
3159      * @throws Exception if the test fails
3160      */
3161     @Test
3162     @Alerts({"null", "text1", "not available"})
3163     // the execution order is not yet correct: the onfocus is called during onload not after it
3164     public void setActive() throws Exception {
3165         final String html = DOCTYPE_HTML
3166             + "<html><head>\n"
3167             + "<script>\n"
3168             + LOG_TITLE_FUNCTION
3169             + "  log(document.activeElement);\n"
3170             + "  function test() {\n"
3171             + "    log(document.activeElement.id);\n"
3172             + "    var inp = document.getElementById('text2');\n"
3173             + "    if (inp.setActive) {\n"
3174             + "      inp.setActive();\n"
3175             + "      log(document.activeElement.id);\n"
3176             + "    } else { log('not available'); }\n"
3177             + "  }\n"
3178             + "</script></head>\n"
3179             + "<body>\n"
3180             + "  <input id='text1' onclick='test()'>\n"
3181             + "  <input id='text2' onfocus='log(\"onfocus text2\")'>\n"
3182             + "</body></html>";
3183 
3184         final WebDriver driver = loadPage2(html);
3185         verifyTitle2(driver, getExpectedAlerts()[0]);
3186         Thread.sleep(100);
3187 
3188         driver.findElement(By.id("text1")).click();
3189         verifyTitle2(driver, getExpectedAlerts());
3190     }
3191 
3192     /**
3193      * Test for bug #658 (we were missing the document.captureEvents(...) method).
3194      * @throws Exception if the test fails
3195      */
3196     @Test
3197     @Alerts({"123", "captured"})
3198     public void captureEvents() throws Exception {
3199         final String content = DOCTYPE_HTML
3200             + "<html><head>\n"
3201             + "<script>\n"
3202             + LOG_TITLE_FUNCTION
3203             + "  function t() { log('captured'); }\n"
3204 
3205             + "  if(document.captureEvents) {\n"
3206             + "    document.captureEvents(Event.CLICK);\n"
3207             + "    document.onclick = t;\n"
3208             + "  } else { log('not available'); }\n"
3209             + "</script></head><body>\n"
3210             + "<div id='theDiv' onclick='log(123)'>foo</div>\n"
3211             + "</body></html>";
3212 
3213         final WebDriver driver = loadPage2(content);
3214         driver.findElement(By.id("theDiv")).click();
3215 
3216         verifyTitle2(driver, getExpectedAlerts());
3217     }
3218 
3219     /**
3220      * @throws Exception if the test fails
3221      */
3222     @Test
3223     @Alerts({"true", "false", "true", "true", "true", "false", "false"})
3224     public void contains() throws Exception {
3225         final String html = DOCTYPE_HTML
3226             + "<html><head><script>\n"
3227             + LOG_TITLE_FUNCTION
3228             + "  function test() {\n"
3229             + "    var testnode = document.getElementById('myNode');\n"
3230             + "    log(document.contains ? document.contains(testnode) : '-');\n"
3231 
3232             + "    var newnode = document.createComment('some comment');\n"
3233             + "    log(document.contains ? document.contains(newnode) : '-');\n"
3234 
3235             + "    log(document.contains ? document.contains(document.documentElement) : '-');\n"
3236             + "    log(document.contains ? document.contains(document.body) : '-');\n"
3237             + "    log(document.contains ? document.contains(document.firstElementChild) : '-');\n"
3238 
3239             + "    log(document.contains ? document.contains(null) : '-');\n"
3240             + "    log(document.contains ? document.contains(undefined) : '-');\n"
3241             + "  }\n"
3242             + "</script></head>\n"
3243             + "<body onload='test()'>\n"
3244             + "  <div id='myNode'></div>\n"
3245             + "</body></html>";
3246         loadPageVerifyTitle2(html);
3247     }
3248 
3249     /**
3250      * @throws Exception if the test fails
3251      */
3252     @Test
3253     @Alerts({"[object Comment]", "false"})
3254     public void createComment() throws Exception {
3255         final String html = DOCTYPE_HTML
3256             + "<html>\n"
3257             + "<head>\n"
3258             + "<script>\n"
3259             + LOG_TITLE_FUNCTION
3260             + "function test() {\n"
3261             + "  var elt = document.createComment('some comment');\n"
3262             + "  log(elt);\n"
3263             + "  log(document.contains ? document.contains(elt) : '-');\n"
3264             + "}\n"
3265             + "</script>\n"
3266             + "</head>\n"
3267             + "<body onload='test()'>\n"
3268             + "</body>\n"
3269             + "</html>";
3270 
3271         loadPageVerifyTitle2(html);
3272     }
3273 
3274     /**
3275      * @throws Exception if the test fails
3276      */
3277     @Test
3278     @Alerts({"books", "books", "3", "#text", "0"})
3279     public void createAttribute() throws Exception {
3280         final String html = DOCTYPE_HTML
3281             + "<html><head>\n"
3282             + "<script>\n"
3283             + LOG_TITLE_FUNCTION
3284             + "  function test() {\n"
3285             + "    var doc = " + callLoadXMLDocumentFromFile("'" + URL_SECOND + "'") + ";\n"
3286             + "    var cid = document.createAttribute('id');\n"
3287             + "    cid.nodeValue = 'a1';\n"
3288             + "    log(doc.documentElement.nodeName);\n"
3289             + "    log(doc.childNodes[0].nodeName);\n"
3290             + "    log(doc.childNodes[0].childNodes.length);\n"
3291             + "    log(doc.childNodes[0].childNodes[0].nodeName);\n"
3292             + "    log(doc.getElementsByTagName('books').item(0).attributes.length);\n"
3293             + "  }\n"
3294             + LOAD_XML_DOCUMENT_FROM_FILE_FUNCTION
3295             + "</script></head><body onload='test()'>\n"
3296             + "</body></html>";
3297 
3298         final String xml
3299             = "<books>\n"
3300             + "  <book>\n"
3301             + "    <title>Immortality</title>\n"
3302             + "    <author>John Smith</author>\n"
3303             + "  </book>\n"
3304             + "</books>";
3305 
3306         getMockWebConnection().setResponse(URL_SECOND, xml, MimeType.TEXT_XML);
3307 
3308         loadPageVerifyTitle2(html);
3309     }
3310 
3311     /**
3312      * @throws Exception if the test fails
3313      */
3314     @Test
3315     @Alerts({"0", "1"})
3316     public void getElementsByTagNameNS() throws Exception {
3317         final String html = DOCTYPE_HTML
3318             + "<html><head>\n"
3319             + "<script>\n"
3320             + LOG_TITLE_FUNCTION
3321             + "  function test() {\n"
3322             + "    var doc = " + callLoadXMLDocumentFromFile("'" + URL_SECOND + "'") + ";\n"
3323             + "    if (!document.all) {\n"
3324             + "      log(document.getElementsByTagNameNS('*', 'books').length);\n"
3325             + "      log(doc.getElementsByTagNameNS('*', 'books').length);\n"
3326             + "    }\n"
3327             + "  }\n"
3328             + LOAD_XML_DOCUMENT_FROM_FILE_FUNCTION
3329             + "</script></head><body onload='test()'>\n"
3330             + "</body></html>";
3331 
3332         final String xml
3333             = "<soap:Envelope xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'>\n"
3334             + "  <books xmlns='http://www.example.com/ns1'>\n"
3335             + "    <book>\n"
3336             + "      <title>Immortality</title>\n"
3337             + "      <author>John Smith</author>\n"
3338             + "    </book>\n"
3339             + "  </books>\n"
3340             + "</soap:Envelope>";
3341 
3342         getMockWebConnection().setResponse(URL_SECOND, xml, MimeType.TEXT_XML);
3343 
3344         loadPageVerifyTitle2(html);
3345     }
3346 
3347     /**
3348      * @throws Exception if the test fails
3349      */
3350     @Test
3351     @Alerts("true")
3352     public void oninput() throws Exception {
3353         final String html = DOCTYPE_HTML
3354             + "<html>\n"
3355             + "<head>\n"
3356             + "  <script>\n"
3357             + LOG_TITLE_FUNCTION
3358             + "    function test() {\n"
3359             + "      log('oninput' in document);\n"
3360             + "    }\n"
3361             + "  </script>\n"
3362             + "</head>\n"
3363             + "<body onload='test()'>\n"
3364             + "</body>\n"
3365             + "</html>";
3366 
3367         loadPageVerifyTitle2(html);
3368     }
3369 
3370     /**
3371      * @throws Exception if the test fails
3372      */
3373     @Test
3374     @Alerts({"undefined", "42"})
3375     public void documentDefineProperty() throws Exception {
3376         final String html = DOCTYPE_HTML
3377             + "<html>\n"
3378             + "<head>\n"
3379             + "  <script>\n"
3380             + LOG_TITLE_FUNCTION
3381             + "    function test() {\n"
3382             + "      log(document.testProp);\n"
3383 
3384             + "      Object.defineProperty(document, 'testProp', {\n"
3385             + "        value: 42,\n"
3386             + "        writable: true,\n"
3387             + "        enumerable: true,\n"
3388             + "        configurable: true\n"
3389             + "      });\n"
3390             + "      log(document.testProp);\n"
3391             + "    }\n"
3392             + "  </script>\n"
3393             + "</head>\n"
3394             + "<body onload='test()'>\n"
3395             + "</body>\n"
3396             + "</html>";
3397 
3398         loadPageVerifyTitle2(html);
3399     }
3400 
3401     /**
3402      * @throws Exception if the test fails
3403      */
3404     @Test
3405     @Alerts({"§§URL§§", "undefined"})
3406     public void urlUnencoded() throws Exception {
3407         final String html = DOCTYPE_HTML
3408             + "<html>\n"
3409             + "<head>\n"
3410             + "  <script>\n"
3411             + LOG_TITLE_FUNCTION
3412             + "    function test() {\n"
3413             + "      log(document.URL);\n"
3414             + "      log(document.URLUnencoded);\n"
3415             + "    }\n"
3416             + "  </script>\n"
3417             + "</head>\n"
3418             + "<body onload='test()'>\n"
3419             + "</body>\n"
3420             + "</html>";
3421 
3422         final URL url = new URL(URL_FIRST, "abc%20def");
3423         expandExpectedAlertsVariables(url);
3424 
3425         final WebDriver driver = loadPage2(html, url);
3426         verifyTitle2(driver, getExpectedAlerts());
3427     }
3428 
3429     /**
3430      * @throws Exception if the test fails
3431      */
3432     @Test
3433     @Alerts({"1", "[object HTMLHtmlElement]"})
3434     public void children() throws Exception {
3435         final String html = DOCTYPE_HTML
3436             + "<html>\n"
3437             + "<head>\n"
3438             + "  <script>\n"
3439             + LOG_TITLE_FUNCTION
3440             + "    function test() {\n"
3441             + "      if (document.children) {\n"
3442             + "        log(document.children.length);\n"
3443             + "        log(document.children.item(0));\n"
3444             + "      }\n"
3445             + "      else {\n"
3446             + "        log('not found');\n"
3447             + "      }\n"
3448             + "    }\n"
3449             + "  </script>\n"
3450             + "</head>\n"
3451             + "<body onload='test()'></body>\n"
3452             + "</html>";
3453 
3454         final URL url = new URL(URL_FIRST, "abc%20def");
3455         expandExpectedAlertsVariables(url);
3456 
3457         final WebDriver driver = loadPage2(html, url);
3458         verifyTitle2(driver, getExpectedAlerts());
3459     }
3460 
3461     /**
3462      * @throws Exception if the test fails
3463      */
3464     @Test
3465     @Alerts({"application/xml", "text/html"})
3466     public void contentType() throws Exception {
3467         final String html = DOCTYPE_HTML
3468             + "<html>\n"
3469             + "<head>\n"
3470             + "  <script>\n"
3471             + LOG_TITLE_FUNCTION
3472             + "    function test() {\n"
3473             + "      var xmlDocument = document.implementation.createDocument('', '', null);\n"
3474             + "      log(xmlDocument.contentType);\n"
3475             + "      log(document.contentType);\n"
3476             + "    }\n"
3477             + "  </script>\n"
3478             + "</head>\n"
3479             + "<body onload='test()'></body>\n"
3480             + "</html>";
3481 
3482         loadPageVerifyTitle2(html);
3483     }
3484 
3485     /**
3486      * @throws Exception if the test fails
3487      */
3488     @Test
3489     @Alerts(DEFAULT = {"null", "null"},
3490             FF = {"undefined", "undefined"},
3491             FF_ESR = {"undefined", "undefined"})
3492     public void xmlEncoding() throws Exception {
3493         final String html = DOCTYPE_HTML
3494             + "<html>\n"
3495             + "<head>\n"
3496             + "  <script>\n"
3497             + LOG_TITLE_FUNCTION
3498             + "    function test() {\n"
3499             + "      var xmlDocument = document.implementation.createDocument('', '', null);\n"
3500             + "      log(xmlDocument.xmlEncoding);\n"
3501             + "      log(document.xmlEncoding);\n"
3502             + "    }\n"
3503             + "  </script>\n"
3504             + "</head>\n"
3505             + "<body onload='test()'></body>\n"
3506             + "</html>";
3507 
3508         loadPageVerifyTitle2(html);
3509     }
3510 
3511     /**
3512      * @throws Exception if the test fails
3513      */
3514     @Test
3515     @Alerts(DEFAULT = {"false", "false"},
3516             FF = {"undefined", "undefined"},
3517             FF_ESR = {"undefined", "undefined"})
3518     public void xmlStandalone() throws Exception {
3519         final String html = DOCTYPE_HTML
3520             + "<html>\n"
3521             + "<head>\n"
3522             + "  <script>\n"
3523             + LOG_TITLE_FUNCTION
3524             + "    function test() {\n"
3525             + "      var xmlDocument = document.implementation.createDocument('', '', null);\n"
3526             + "      log(xmlDocument.xmlStandalone);\n"
3527             + "      log(document.xmlStandalone);\n"
3528             + "    }\n"
3529             + "  </script>\n"
3530             + "</head>\n"
3531             + "<body onload='test()'></body>\n"
3532             + "</html>";
3533 
3534         loadPageVerifyTitle2(html);
3535     }
3536 
3537     /**
3538      * @throws Exception if the test fails
3539      */
3540     @Test
3541     @Alerts(DEFAULT = {"1.0", "null"},
3542             FF = {"undefined", "undefined"},
3543             FF_ESR = {"undefined", "undefined"})
3544     public void xmlVersion() throws Exception {
3545         final String html = DOCTYPE_HTML
3546             + "<html>\n"
3547             + "<head>\n"
3548             + "  <script>\n"
3549             + LOG_TITLE_FUNCTION
3550             + "    function test() {\n"
3551             + "      var xmlDocument = document.implementation.createDocument('', '', null);\n"
3552             + "      log(xmlDocument.xmlVersion);\n"
3553             + "      log(document.xmlVersion);\n"
3554             + "    }\n"
3555             + "  </script>\n"
3556             + "</head>\n"
3557             + "<body onload='test()'></body>\n"
3558             + "</html>";
3559 
3560         loadPageVerifyTitle2(html);
3561     }
3562 
3563     /**
3564      * @throws Exception if the test fails
3565      */
3566     @Test
3567     @Alerts({"null", "null"})
3568     public void rootElement() throws Exception {
3569         final String html = DOCTYPE_HTML
3570             + "<html>\n"
3571             + "<head>\n"
3572             + "  <script>\n"
3573             + LOG_TITLE_FUNCTION
3574             + "    function test() {\n"
3575             + "      var xmlDocument = document.implementation.createDocument('', '', null);\n"
3576             + "      log(xmlDocument.rootElement);\n"
3577             + "      log(document.rootElement);\n"
3578             + "    }\n"
3579             + "  </script>\n"
3580             + "</head>\n"
3581             + "<body onload='test()'></body>\n"
3582             + "</html>";
3583 
3584         loadPageVerifyTitle2(html);
3585     }
3586 
3587     /**
3588      * @throws Exception if the test fails
3589      */
3590     @Test
3591     @Alerts({"1", "[object HTMLHtmlElement]", "[object HTMLHtmlElement]"})
3592     public void firstElementChild() throws Exception {
3593         final String html = DOCTYPE_HTML
3594             + "<html>\n"
3595             + "<head>\n"
3596             + "  <script>\n"
3597             + LOG_TITLE_FUNCTION
3598             + "    function test() {\n"
3599             + "      log(document.childElementCount);\n"
3600             + "      log(document.firstElementChild);\n"
3601             + "      log(document.lastElementChild);\n"
3602             + "    }\n"
3603             + "  </script>\n"
3604             + "</head>\n"
3605             + "<body onload='test()'></body>\n"
3606             + "</html>";
3607 
3608         loadPageVerifyTitle2(html);
3609     }
3610 
3611     /**
3612      * @throws Exception if the test fails
3613      */
3614     @Test
3615     @Alerts({"1", "[object HTMLHtmlElement]", "[object HTMLHtmlElement]"})
3616     public void firstElementChildDoctype() throws Exception {
3617         final String html = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"\n"
3618             + "    \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n"
3619             + "<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" lang=\"en\">\n"
3620             + "<head>\n"
3621             + "  <script>\n"
3622             + LOG_TITLE_FUNCTION
3623             + "    function test() {\n"
3624             + "      log(document.childElementCount);\n"
3625             + "      log(document.firstElementChild);\n"
3626             + "      log(document.lastElementChild);\n"
3627             + "    }\n"
3628             + "  </script>\n"
3629             + "</head>\n"
3630             + "<body onload='test()'></body>\n"
3631             + "</html>";
3632 
3633         loadPageVerifyTitle2(html);
3634     }
3635 
3636     /**
3637      * @throws Exception if the test fails
3638      */
3639     @Test
3640     @Alerts({"true", "test"})
3641     public void useInMap() throws Exception {
3642         final String html = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"\n"
3643             + "    \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n"
3644             + "<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" lang=\"en\">\n"
3645             + "<head>\n"
3646             + "  <script>\n"
3647             + LOG_TITLE_FUNCTION
3648             + "    function test() {\n"
3649             + "      var map = new Map();\n"
3650             + "      map.set(document, 'test');\n"
3651             + "      log(map.has(document));\n"
3652             + "      log(map.get(document));\n"
3653             + "    }\n"
3654             + "  </script>\n"
3655             + "</head>\n"
3656             + "<body onload='test()'></body>\n"
3657             + "</html>";
3658 
3659         loadPageVerifyTitle2(html);
3660     }
3661 
3662     /**
3663      * @throws Exception if the test fails
3664      */
3665     @Test
3666     @Alerts({"true", "test"})
3667     public void useInWeakMap() throws Exception {
3668         final String html = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"\n"
3669             + "    \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n"
3670             + "<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" lang=\"en\">\n"
3671             + "<head>\n"
3672             + "  <script>\n"
3673             + LOG_TITLE_FUNCTION
3674             + "    function test() {\n"
3675             + "      var map = new WeakMap();\n"
3676             + "      map.set(document, 'test');\n"
3677             + "      log(map.has(document));\n"
3678             + "      log(map.get(document));\n"
3679             + "    }\n"
3680             + "  </script>\n"
3681             + "</head>\n"
3682             + "<body onload='test()'></body>\n"
3683             + "</html>";
3684 
3685         loadPageVerifyTitle2(html);
3686     }
3687 
3688     /**
3689      * @throws Exception if the test fails
3690      */
3691     @Test
3692     @Alerts("true")
3693     public void useInSet() throws Exception {
3694         final String html = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"\n"
3695             + "    \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n"
3696             + "<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" lang=\"en\">\n"
3697             + "<head>\n"
3698             + "  <script>\n"
3699             + LOG_TITLE_FUNCTION
3700             + "    function test() {\n"
3701             + "      var set = new Set();\n"
3702             + "      set.add(document, 'test');\n"
3703             + "      log(set.has(document));\n"
3704             + "    }\n"
3705             + "  </script>\n"
3706             + "</head>\n"
3707             + "<body onload='test()'></body>\n"
3708             + "</html>";
3709 
3710         loadPageVerifyTitle2(html);
3711     }
3712 
3713     /**
3714      * @throws Exception if the test fails
3715      */
3716     @Test
3717     @Alerts("true")
3718     public void useInWeakSet() throws Exception {
3719         final String html = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"\n"
3720             + "    \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n"
3721             + "<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" lang=\"en\">\n"
3722             + "<head>\n"
3723             + "  <script>\n"
3724             + LOG_TITLE_FUNCTION
3725             + "    function test() {\n"
3726             + "      if (window.WeakSet) {\n"
3727             + "        var set = new WeakSet();\n"
3728             + "        set.add(document, 'test');\n"
3729             + "        log(set.has(document));\n"
3730             + "      } else {\n"
3731             + "        log('no WeakSet');\n"
3732             + "      }\n"
3733             + "    }\n"
3734             + "  </script>\n"
3735             + "</head>\n"
3736             + "<body onload='test()'></body>\n"
3737             + "</html>";
3738 
3739         loadPageVerifyTitle2(html);
3740     }
3741 
3742     /**
3743      * @throws Exception if the test fails
3744      */
3745     @Test
3746     @Alerts({"about:blank", "about:blank", "undefined", "null", "null"})
3747     @HtmlUnitNYI(CHROME = "TypeError",
3748             EDGE = "TypeError",
3749             FF = "TypeError",
3750             FF_ESR = "TypeError")
3751     public void newDoc() throws Exception {
3752         final String html = DOCTYPE_HTML
3753             + "<html>\n"
3754             + "<head>\n"
3755             + "  <script>\n"
3756             + LOG_TITLE_FUNCTION
3757             + "    function test() {\n"
3758             + "      if (typeof Document === 'object') { log('no'); return ; }\n"
3759 
3760             + "      try {\n"
3761             + "        var doc = new Document();"
3762             + "        log(doc.documentURI);\n"
3763             + "        log(doc.URL);\n"
3764             + "        log(doc.origin);\n"
3765             + "        log(doc.firstElementChild);\n"
3766             + "        log(doc.defaultView);\n"
3767             + "      } catch(e) { logEx(e); }\n"
3768             + "    }\n"
3769             + "  </script>\n"
3770             + "</head>\n"
3771             + "<body onload='test()'></body>\n"
3772             + "</html>";
3773 
3774         loadPageVerifyTitle2(html);
3775     }
3776 
3777     /**
3778      * @throws Exception if the test fails
3779      */
3780     @Test
3781     @Alerts(DEFAULT = {"0", "0", "8", "1256"},
3782             EDGE = {"0", "0", "8", "1248"})
3783     @HtmlUnitNYI(EDGE = {"0", "0", "8", "1256"})
3784     public void documentElementBoundingClientRect() throws Exception {
3785         final String html = DOCTYPE_HTML
3786             + "<html>"
3787             + "<body>\n"
3788             + "<script>\n"
3789             + LOG_TITLE_FUNCTION
3790             + "  let rect = document.documentElement.getBoundingClientRect();\n"
3791             + "  log(rect.top);\n"
3792             + "  log(rect.left);\n"
3793             + "  log(rect.bottom);\n"
3794             + "  log(rect.right);\n"
3795             + "</script>\n"
3796             + "</body></html>";
3797 
3798         loadPageVerifyTitle2(html);
3799     }
3800 
3801     /**
3802      * @throws Exception if the test fails
3803      */
3804     @Test
3805     @Alerts(DEFAULT = {"0", "0", "621", "1256"},
3806             EDGE = {"0", "0", "630", "1248"},
3807             FF = {"0", "0", "8", "1256"},
3808             FF_ESR = {"0", "0", "8", "1256"})
3809     @HtmlUnitNYI(CHROME = {"0", "0", "613", "1256"},
3810             EDGE = {"0", "0", "613", "1256"},
3811             FF = {"0", "0", "613", "1256"},
3812             FF_ESR = {"0", "0", "613", "1256"})
3813     public void documentElementBoundingClientRectQuirks() throws Exception {
3814         final String html =
3815             "<html>"
3816             + "<body>\n"
3817             + "<script>\n"
3818             + LOG_TITLE_FUNCTION
3819             + "  let rect = document.documentElement.getBoundingClientRect();\n"
3820             + "  log(rect.top);\n"
3821             + "  log(rect.left);\n"
3822             + "  log(rect.bottom);\n"
3823             + "  log(rect.right);\n"
3824             + "</script>\n"
3825             + "</body></html>";
3826 
3827         loadPageVerifyTitle2(html);
3828     }
3829 
3830 
3831     /**
3832      * @throws Exception if the test fails
3833      */
3834     @Test
3835     @Alerts(DEFAULT = {"0", "0", "8", "1256"},
3836             EDGE = {"0", "0", "8", "1248"})
3837     @HtmlUnitNYI(EDGE = {"0", "0", "8", "1256"})
3838     public void documentElementOffset() throws Exception {
3839         final String html = DOCTYPE_HTML
3840             + "<html>"
3841             + "<body>\n"
3842             + "<script>\n"
3843             + LOG_TITLE_FUNCTION
3844             + "  let doc = document.documentElement;\n"
3845             + "  log(doc.offsetTop);\n"
3846             + "  log(doc.offsetLeft);\n"
3847             + "  log(doc.offsetHeight);\n"
3848             + "  log(doc.offsetWidth);\n"
3849             + "</script>\n"
3850             + "</body></html>";
3851 
3852         loadPageVerifyTitle2(html);
3853     }
3854 
3855     /**
3856      * @throws Exception if the test fails
3857      */
3858     @Test
3859     @Alerts(DEFAULT = {"0", "0", "621", "1256"},
3860             EDGE = {"0", "0", "630", "1248"},
3861             FF = {"0", "0", "8", "1256"},
3862             FF_ESR = {"0", "0", "8", "1256"})
3863     @HtmlUnitNYI(CHROME = {"0", "0", "613", "1256"},
3864             EDGE = {"0", "0", "613", "1256"},
3865             FF = {"0", "0", "613", "1256"},
3866             FF_ESR = {"0", "0", "613", "1256"})
3867     public void documentElementOffsetQuirks() throws Exception {
3868         final String html =
3869             "<html>"
3870             + "<body>\n"
3871             + "<script>\n"
3872             + LOG_TITLE_FUNCTION
3873             + "  let doc = document.documentElement;\n"
3874             + "  log(doc.offsetTop);\n"
3875             + "  log(doc.offsetLeft);\n"
3876             + "  log(doc.offsetHeight);\n"
3877             + "  log(doc.offsetWidth);\n"
3878             + "</script>\n"
3879             + "</body></html>";
3880 
3881         loadPageVerifyTitle2(html);
3882     }
3883 
3884     /**
3885      * @throws Exception if the test fails
3886      */
3887     @Test
3888     @Alerts(DEFAULT = {"0", "0", "621", "1256"},
3889             EDGE = {"0", "0", "630", "1248"},
3890             FF = {"0", "0", "674", "1256"},
3891             FF_ESR = {"0", "0", "674", "1256"})
3892     @HtmlUnitNYI(CHROME = {"0", "0", "605", "1256"},
3893             EDGE = {"0", "0", "605", "1256"},
3894             FF = {"0", "0", "605", "1256"},
3895             FF_ESR = {"0", "0", "605", "1256"})
3896     public void documentElementClientWidthHeight() throws Exception {
3897         final String html = DOCTYPE_HTML
3898             + "<html>"
3899             + "<body>\n"
3900             + "<script>\n"
3901             + LOG_TITLE_FUNCTION
3902             + "  log(document.documentElement.clientTop);\n"
3903             + "  log(document.documentElement.clientLeft);\n"
3904             + "  log(document.documentElement.clientHeight);\n"
3905             + "  log(document.documentElement.clientWidth);\n"
3906             + "</script>\n"
3907             + "</body></html>";
3908 
3909         loadPageVerifyTitle2(html);
3910     }
3911 
3912     /**
3913      * @throws Exception if the test fails
3914      */
3915     @Test
3916     @Alerts(DEFAULT = {"0", "0", "621", "1256"},
3917             EDGE = {"0", "0", "630", "1248"},
3918             FF = {"0", "0", "8", "1256"},
3919             FF_ESR = {"0", "0", "8", "1256"})
3920     @HtmlUnitNYI(CHROME = {"0", "0", "605", "1256"},
3921             EDGE = {"0", "0", "605", "1256"},
3922             FF = {"0", "0", "605", "1256"},
3923             FF_ESR = {"0", "0", "605", "1256"})
3924     public void documentElementClientWidthHeightQuirks() throws Exception {
3925         final String html =
3926             "<html>"
3927             + "<body>\n"
3928             + "<script>\n"
3929             + LOG_TITLE_FUNCTION
3930             + "  log(document.documentElement.clientTop);\n"
3931             + "  log(document.documentElement.clientLeft);\n"
3932             + "  log(document.documentElement.clientHeight);\n"
3933             + "  log(document.documentElement.clientWidth);\n"
3934             + "</script>\n"
3935             + "</body></html>";
3936 
3937         loadPageVerifyTitle2(html);
3938     }
3939 }