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.html;
16  
17  import java.net.URL;
18  
19  import org.htmlunit.WebDriverTestCase;
20  import org.htmlunit.junit.annotation.Alerts;
21  import org.htmlunit.junit.annotation.HtmlUnitNYI;
22  import org.htmlunit.util.MimeType;
23  import org.junit.jupiter.api.Test;
24  import org.openqa.selenium.By;
25  import org.openqa.selenium.WebDriver;
26  import org.openqa.selenium.WebElement;
27  
28  /**
29   * Tests for {@link HTMLElement}.
30   *
31   * @author Brad Clarke
32   * @author Chris Erskine
33   * @author David D. Kilzer
34   * @author Daniel Gredler
35   * @author Marc Guillemot
36   * @author Hans Donner
37   * @author George Murnock
38   * @author Bruce Faulkner
39   * @author Ahmed Ashour
40   * @author Sudhan Moghe
41   * @author Ethan Glasser-Camp
42   * @author Ronald Brill
43   * @author Frank Danek
44   */
45  public class HTMLElementTest extends WebDriverTestCase {
46  
47      /**
48       * @throws Exception if the test fails
49       */
50      @Test
51      @Alerts({"all is not supported", "all is not supported",
52               "all is not supported", "all is not supported", "all is not supported"})
53      public void all_IndexByInt() throws Exception {
54          final String html = DOCTYPE_HTML
55              + "<html><head>\n"
56              + "<script>\n"
57              + LOG_TITLE_FUNCTION
58              + "function test() {\n"
59              + "  dumpAll('body');\n"
60              + "  dumpAll('testDiv');\n"
61              + "  dumpAll('testA');\n"
62              + "  dumpAll('testImg');\n"
63              + "  dumpAll('testDiv2');\n"
64              + "}\n"
65              + "function dumpAll(_id) {\n"
66              + "  var oNode = document.getElementById(_id);\n"
67              + "  var col = oNode.all;\n"
68              + "  if (col) {\n"
69              + "    var str = 'all node for ' + _id + ': ';\n"
70              + "    for (var i = 0; i < col.length; i++) {\n"
71              + "      str += col[i].tagName + ' ';\n"
72              + "    }\n"
73              + "    log(str);\n"
74              + "  } else {\n"
75              + "    log('all is not supported');\n"
76              + "  }\n"
77              + "}\n"
78              + "</script>\n"
79              + "</head>\n"
80              + "<body onload='test()' id='body'>\n"
81              + "  <div id='testDiv'>foo<a href='foo.html' id='testA'><img src='foo.png' id='testImg'></a></div>\n"
82              + "  <div id='testDiv2'>foo</div>\n"
83              + "</body></html>";
84  
85          getMockWebConnection().setDefaultResponse("Error: not found", 404, "Not Found", MimeType.TEXT_HTML);
86  
87          loadPageVerifyTitle2(html);
88      }
89  
90      /**
91       * @throws Exception on test failure
92       */
93      @Test
94      @Alerts({"a", "a", "undefined", "null"})
95      public void getAttribute() throws Exception {
96          final String html = DOCTYPE_HTML
97                  + "<html>\n"
98                  + "<head>\n"
99                  + "  <title>test</title>\n"
100                 + "  <script>\n"
101                 + LOG_TEXTAREA_FUNCTION
102                 + "  function doTest() {\n"
103                 + "    var myNode = document.getElementById('myNode');\n"
104                 + "    log(myNode.title);\n"
105                 + "    log(myNode.getAttribute('title'));\n"
106                 + "    log(myNode.Title);\n"
107                 + "    log(myNode.getAttribute('class'));\n"
108                 + "  }\n"
109                 + "  </script>\n"
110                 + "</head>\n"
111                 + "<body onload='doTest()'>\n"
112                 + "<p id='myNode' title='a'></p>\n"
113                 + LOG_TEXTAREA
114                 + "</body>\n"
115                 + "</html>";
116 
117         loadPageVerifyTextArea2(html);
118     }
119 
120     /**
121      * @throws Exception if the test fails
122      */
123     @Test
124     @Alerts("null")
125     public void getAttribute_styleAttribute() throws Exception {
126         final String html = DOCTYPE_HTML
127             + "<html><head><script>\n"
128             + LOG_TITLE_FUNCTION
129             + "  function test() {\n"
130             + "    var elem = document.getElementById('tester');\n"
131             + "    log(elem.getAttribute('style'));\n"
132             + "  }\n"
133             + "</script>\n"
134             + "<body onload='test()'>\n"
135             + "  <div id='tester'>tester</div>\n"
136             + "</body></html>";
137 
138         loadPageVerifyTitle2(html);
139     }
140 
141     /**
142      * @throws Exception on test failure
143      */
144     @Test
145     @Alerts("color: green;")
146     public void getAttribute_styleAttributeWithFlag() throws Exception {
147         final String html = DOCTYPE_HTML
148             + "<html><body onload='test()'><div id='div' style='color: green;'>abc</div>\n"
149             + "<script>\n"
150             + LOG_TITLE_FUNCTION
151             + "  function test() {\n"
152             + "    var div = document.getElementById('div');\n"
153             + "    log(div.getAttribute('style', 2));\n"
154             + "  }\n"
155             + "</script>\n"
156             + "</body></html>";
157         loadPageVerifyTitle2(html);
158     }
159 
160     /**
161      * Some libraries like MochiKit looks after the number of attributes of a freshly created node.
162      * When this is fixed for IE, all {@link org.htmlunit.libraries.mochikit.MochiKitTest}
163      * working for FF will work for IE too.
164      * @throws Exception on test failure
165      */
166     @Test
167     @Alerts("0 attribute")
168     public void attributes() throws Exception {
169         final String html = DOCTYPE_HTML
170                 + "<html>\n"
171                 + "<head>\n"
172                 + "  <script>\n"
173                 + LOG_TITLE_FUNCTION
174                 + "  function doTest() {\n"
175                 + "    var myNode = document.body.firstChild;\n"
176                 + "    if (myNode.attributes.length == 0)\n"
177                 + "      log('0 attribute');\n"
178                 + "    else\n"
179                 + "      log('at least 1 attribute');\n"
180                 + "  }\n"
181                 + "  </script>\n"
182                 + "</head>\n"
183                 + "<body onload='doTest()'>" // no \n here!
184                 + "<span>test span</span>\n"
185                 + "</body>\n"
186                 + "</html>";
187 
188         loadPageVerifyTitle2(html);
189     }
190 
191     /**
192      * @throws Exception on test failure
193      */
194     @Test
195     @Alerts({"null", "bla", "true"})
196     public void getSetAttributeNS() throws Exception {
197         final String html = DOCTYPE_HTML
198                 + "<html>\n"
199                 + "<head>\n"
200                 + "<script>\n"
201                 + LOG_TITLE_FUNCTION
202                 + "function doTest() {\n"
203                 + "  var myNode = document.getElementById('myNode');\n"
204                 + "  log(myNode.getAttributeNS('myNamespaceURI', 'my:foo'));\n"
205                 + "  myNode.setAttributeNS('myNamespaceURI', 'my:foo', 'bla');\n"
206                 + "  log(myNode.getAttributeNS('myNamespaceURI', 'foo'));\n"
207                 + "  log(myNode.getAttributeNodeNS('myNamespaceURI', 'foo').specified);\n"
208                 + "}\n"
209                 + "</script>\n"
210                 + "</head>\n"
211                 + "<body onload='doTest()'>\n"
212                 + "<p id='myNode' title='a'>\n"
213                 + "</p>\n"
214                 + "</body>\n"
215                 + "</html>";
216 
217         loadPageVerifyTitle2(html);
218     }
219 
220     /**
221      * @throws Exception if the test fails
222      */
223     @Test
224     @Alerts(DEFAULT = {"text", "i", "i", "[object CSSStyleDeclaration]", "function", "undefined", "undefined"},
225             FF = {"text", "i", "i", "[object CSSStyleProperties]", "function", "undefined", "undefined"},
226             FF_ESR = {"text", "i", "i", "[object CSS2Properties]", "function", "undefined", "undefined"})
227     @HtmlUnitNYI(FF = {"text", "i", "i", "[object CSSStyleDeclaration]", "function", "undefined", "undefined"},
228             FF_ESR = {"text", "i", "i", "[object CSSStyleDeclaration]", "function", "undefined", "undefined"})
229     public void attributesAccess() throws Exception {
230         final String html = DOCTYPE_HTML
231             + "<html><head>\n"
232             + "  <script>\n"
233             + LOG_TITLE_FUNCTION
234             + "  </script>\n"
235             + "</head>\n"
236             + "<body>\n"
237             + "  <input type='text' id='i' name='i' style='color:red' onclick='log(1)' custom1='a' />\n"
238             + "  <script>\n"
239             + "    var i = document.getElementById('i');\n"
240             + "    log(i.type);\n"
241             + "    log(i.id);\n"
242             + "    log(i.name);\n"
243             + "    log(i.style);\n"
244             + "    log(typeof i.onclick);\n"
245             + "    log(i.custom1);\n"
246             + "    log(i.custom2);\n"
247             + "  </script>\n"
248             + "</body></html>";
249         loadPageVerifyTitle2(html);
250     }
251 
252     /**
253      * @throws Exception on test failure
254      */
255     @Test
256     @Alerts({"a", "b", "undefined", "foo"})
257     public void setAttribute() throws Exception {
258         final String html = DOCTYPE_HTML
259             + "<html>\n"
260             + "<head>\n"
261             + "  <script>\n"
262             + LOG_TITLE_FUNCTION
263             + "  function doTest() {\n"
264             + "    var myNode = document.getElementById('myNode');\n"
265             + "    log(myNode.title);\n"
266             + "    myNode.setAttribute('title', 'b');\n"
267             + "    log(myNode.title);\n"
268             + "    log(myNode.Title);\n"
269             + "    myNode.Title = 'foo';\n"
270             + "    log(myNode.Title);\n"
271             + "  }\n"
272             + "  </script>\n"
273             + "</head>\n"
274             + "<body onload='doTest()'>\n"
275             + "<p id='myNode' title='a'>\n"
276             + "</p>\n"
277             + "</body>\n"
278             + "</html>";
279 
280         loadPageVerifyTitle2(html);
281     }
282 
283     /**
284      * Caution: with IE if you get a node with some lowercase letters, the node will be retrieved
285      * and will get as name the value passed as attribute to getAttributeNode.
286      * The consequence for IE: x.getAttributeNode("Foo").nodeName != x.getAttributeNode("foo").nodeName
287      * @throws Exception on test failure
288      */
289     @Test
290     @Alerts({"null",
291              "expando=undefined",
292              "firstChild=null",
293              "lastChild=null",
294              "name=custom_attribute",
295              "nextSibling=null",
296              "nodeName=custom_attribute",
297              "nodeType=2",
298              "nodeValue=bleh",
299              "(ownerDocument === document) = true",
300              "(getRootNode() === att) = true",
301              "parentNode=null",
302              "previousSibling=null",
303              "specified=true",
304              "value=bleh"})
305     public void getAttributeNode() throws Exception {
306         final String html = DOCTYPE_HTML
307             + "<html>\n"
308             + "<head>\n"
309             + "  <script>\n"
310             + LOG_TITLE_FUNCTION
311             + "    function test() {\n"
312             + "      var div = document.getElementById('div2');\n"
313             + "      log(div.getAttributeNode('notExisting'));\n"
314             + "      var customAtt = div.getAttributeNode('custom_attribute');\n"
315             + "      alertAttributeProperties(customAtt);\n"
316             + "    }\n"
317             + "    function alertAttributeProperties(att) {\n"
318             + "      log('expando=' + att.expando);\n"
319             + "      log('firstChild=' + att.firstChild);\n"
320             + "      log('lastChild=' + att.lastChild);\n"
321             + "      log('name=' + att.name);\n"
322             + "      log('nextSibling=' + att.nextSibling);\n"
323             + "      log('nodeName=' + att.nodeName);\n"
324             + "      log('nodeType=' + att.nodeType);\n"
325             + "      log('nodeValue=' + att.nodeValue);\n"
326             + "      log('(ownerDocument === document) = ' + (att.ownerDocument === document));\n"
327             + "      if(att.getRootNode) {\n"
328             + "        log('(getRootNode() === att) = ' + (att.getRootNode() === att));\n"
329             + "      } else log('-');\n"
330             + "      log('parentNode=' + att.parentNode);\n"
331             + "      log('previousSibling=' + att.previousSibling);\n"
332             + "      log('specified=' + att.specified);\n"
333             + "      log('value=' + att.value);\n"
334             + "    }\n"
335             + "  </script>\n"
336             + "</head>\n"
337             + "<body onload='test()'>\n"
338             + "  <div id='div1'></div>\n"
339             + "  <div id='div2' name='blah' custom_attribute='bleh'></div>\n"
340             + "  <div id='div3'></div>\n"
341             + "</body>\n"
342             + "</html>";
343 
344         loadPageVerifyTitle2(html);
345     }
346 
347     /**
348      * Tests setAttribute() with name of event handler.
349      * @throws Exception if the test fails
350      */
351     @Test
352     @Alerts({"onfocus1-onclick1-", "onfocus1-onclick1-onblur1-onfocus2-"})
353     public void setAttribute_eventHandler() throws Exception {
354         final String html = DOCTYPE_HTML
355             + "<html><head><title></title><script>\n"
356             + "  function inform(msg) {\n"
357             + "    document.title += msg;\n"
358             + "    document.title += '-';\n"
359             + "  }\n"
360             + "  function test() {\n"
361             + "    var text = document.getElementById('login');\n"
362             + "    var password = document.getElementById('password');\n"
363 
364             + "    text.setAttribute('onclick', \"inform('onclick1');\");\n"
365             + "    text.setAttribute('onFocus', \"inform('onfocus1');\");\n"
366             + "    text.setAttribute('ONBLUR', \"inform('onblur1');\");\n"
367 
368             + "    password.setAttribute('onfocus', \"inform('onfocus2');\");\n"
369             + "    password.setAttribute('onblur', \"inform('onblur2');\");\n"
370             + "  }\n"
371             + "</script></head>\n"
372             + "<body onload='test()'>\n"
373             + "  <form>\n"
374             + "    <input type='text' id='login' name='login'>\n"
375             + "    <input type='password' id='password' name='password'>\n"
376             + "  </form>\n"
377             + "</body></html>";
378 
379         final String[] alerts = getExpectedAlerts();
380         int i = 0;
381 
382         final WebDriver driver = loadPage2(html);
383 
384         driver.findElement(By.id("login")).click();
385         assertTitle(driver, alerts[i++]);
386 
387         driver.findElement(By.id("password")).click();
388         assertTitle(driver, alerts[i++]);
389     }
390 
391     /**
392      * @throws Exception if the test fails
393      */
394     @Test
395     @Alerts({"null", "inform('newHandler')", "null"})
396     public void setAttribute_eventHandlerNull() throws Exception {
397         final String html = DOCTYPE_HTML
398             + "<html><head><script>\n"
399             + LOG_TEXTAREA_FUNCTION
400             + "  function inform(msg) {\n"
401             + "    document.title += msg;\n"
402             + "    document.title += '-';\n"
403             + "  }\n"
404             + "  function test() {\n"
405             + "    var text = document.getElementById('login');\n"
406             + "    var password = document.getElementById('password');\n"
407 
408             + "    log(text.getAttribute('onclick'));\n"
409             + "    text.setAttribute('onclick', \"inform('newHandler')\");\n"
410             + "    log(text.getAttribute('onclick'));\n"
411 
412             + "    text.setAttribute('onclick', null);\n"
413             + "    log(text.getAttribute('onclick'));\n"
414             + "  }\n"
415             + "</script></head>\n"
416             + "<body onload='test()'>\n"
417             + "  <form>\n"
418             + "    <input type='text' id='login' name='login'>\n"
419             + "  </form>\n"
420             + LOG_TEXTAREA
421             + "</body></html>";
422 
423         final WebDriver driver = loadPageVerifyTextArea2(html);
424 
425         driver.findElement(By.id("login")).click();
426         assertTitle(driver, "");
427     }
428 
429     /**
430      * @throws Exception if the test fails
431      */
432     @Test
433     @Alerts({"null", "inform('newHandler')", ""})
434     public void setAttribute_eventHandlerEmptyString() throws Exception {
435         final String html = DOCTYPE_HTML
436             + "<html><head><script>\n"
437             + LOG_TEXTAREA_FUNCTION
438             + "  function inform(msg) {\n"
439             + "    document.title += msg;\n"
440             + "    document.title += '-';\n"
441             + "  }\n"
442             + "  function test() {\n"
443             + "    var text = document.getElementById('login');\n"
444             + "    var password = document.getElementById('password');\n"
445 
446             + "    log(text.getAttribute('onclick'));\n"
447             + "    text.setAttribute('onclick', \"inform('newHandler')\");\n"
448             + "    log(text.getAttribute('onclick'));\n"
449 
450             + "    text.setAttribute('onclick', '');\n"
451             + "    log(text.getAttribute('onclick'));\n"
452             + "  }\n"
453             + "</script></head>\n"
454             + "<body onload='test()'>\n"
455             + "  <form>\n"
456             + "    <input type='text' id='login' name='login'>\n"
457             + "  </form>\n"
458             + LOG_TEXTAREA
459             + "</body></html>";
460 
461         final WebDriver driver = loadPageVerifyTextArea2(html);
462 
463         driver.findElement(By.id("login")).click();
464         assertTitle(driver, "");
465     }
466 
467     /**
468      * @throws Exception if the test fails
469      */
470     @Test
471     @Alerts({"null", "inform('newHandler')", "undefined"})
472     public void setAttribute_eventHandlerUndefined() throws Exception {
473         final String html = DOCTYPE_HTML
474             + "<html><head><script>\n"
475             + LOG_TEXTAREA_FUNCTION
476             + "  function inform(msg) {\n"
477             + "    document.title += msg;\n"
478             + "    document.title += '-';\n"
479             + "  }\n"
480             + "  function test() {\n"
481             + "    var text = document.getElementById('login');\n"
482             + "    var password = document.getElementById('password');\n"
483 
484             + "    log(text.getAttribute('onclick'));\n"
485             + "    text.setAttribute('onclick', \"inform('newHandler')\");\n"
486             + "    log(text.getAttribute('onclick'));\n"
487 
488             + "    text.setAttribute('onclick', undefined);\n"
489             + "    log(text.getAttribute('onclick'));\n"
490             + "  }\n"
491             + "</script></head>\n"
492             + "<body onload='test()'>\n"
493             + "  <form>\n"
494             + "    <input type='text' id='login' name='login'>\n"
495             + "  </form>\n"
496             + LOG_TEXTAREA
497             + "</body></html>";
498 
499         final WebDriver driver = loadPageVerifyTextArea2(html);
500 
501         driver.findElement(By.id("login")).click();
502         assertTitle(driver, "");
503     }
504 
505     /**
506      * @throws Exception if the test fails
507      */
508     @Test
509     @Alerts({"focus-click-", "focus-click-blur-"})
510     public void setAttribute_eventHandlerEventArgument() throws Exception {
511         final String html = DOCTYPE_HTML
512             + "<html><head><title></title><script>\n"
513             + "  function inform(msg) {\n"
514             + "    document.title += msg;\n"
515             + "    document.title += '-';\n"
516             + "  }\n"
517             + "  function test() {\n"
518             + "    var text = document.getElementById('login');\n"
519 
520             + "    text.setAttribute('onclick', 'inform(event.type);');\n"
521             + "    text.setAttribute('onFocus', 'inform(event.type);');\n"
522             + "    text.setAttribute('ONBLUR', 'inform(event.type);');\n"
523 
524             + "  }\n"
525             + "</script></head>\n"
526             + "<body onload='test()'>\n"
527             + "  <form>\n"
528             + "    <input type='text' id='login' name='login'>\n"
529             + "    <input type='password' id='password' name='password'>\n"
530             + "  </form>\n"
531             + "</body></html>";
532 
533         final String[] alerts = getExpectedAlerts();
534         int i = 0;
535 
536         final WebDriver driver = loadPage2(html);
537 
538         driver.findElement(By.id("login")).click();
539         assertTitle(driver, alerts[i++]);
540 
541         driver.findElement(By.id("password")).click();
542         assertTitle(driver, alerts[i++]);
543     }
544 
545     /**
546      * @throws Exception if the test fails
547      */
548     @Test
549     @Alerts({"inform(\"onclick\")", "inform('newHandler')", "newHandler"})
550     public void getAttribute_eventHandler() throws Exception {
551         final String html = DOCTYPE_HTML
552             + "<html><head><script>\n"
553             + LOG_TITLE_FUNCTION
554             + "  function test() {\n"
555             + "    var text = document.getElementById('login');\n"
556 
557             + "    log(text.getAttribute('onclick'));\n"
558             + "    text.setAttribute('onclick', \"inform('newHandler')\");\n"
559             + "    log(text.getAttribute('onclick'));\n"
560             + "  }\n"
561             + "  function inform(msg) {\n"
562             + "    log(msg);\n"
563             + "  }\n"
564             + "</script></head>\n"
565             + "<body onload='test()'>\n"
566             + "  <form>\n"
567             + "    <input type='text' id='login' name='login' onclick='inform(\"onclick\")'>\n"
568             + "  </form>\n"
569             + "</body></html>";
570 
571         final String[] alerts = getExpectedAlerts();
572 
573         final WebDriver webDriver = loadPage2(html);
574         verifyTitle2(webDriver, alerts[0], alerts[1]);
575 
576         webDriver.findElement(By.id("login")).click();
577         verifyTitle2(webDriver, alerts);
578     }
579 
580     /**
581      * @throws Exception on test failure
582      */
583     @Test
584     @Alerts({"left", "left", "right", "right"})
585     public void setAttributeNode() throws Exception {
586         final String html = DOCTYPE_HTML
587             + "<html>\n"
588             + "<head>\n"
589             + "  <script>\n"
590             + LOG_TITLE_FUNCTION
591             + "    function test() {\n"
592             + "      // Get the old alignment.\n"
593             + "      var div1 = document.getElementById('div1');\n"
594             + "      var a1 = div1.getAttributeNode('align');\n"
595             + "      log(a1.value);\n"
596             + "      // Set the new alignment.\n"
597             + "      var a2 = document.createAttribute('align');\n"
598             + "      a2.value = 'right';\n"
599             + "      a1 = div1.setAttributeNode(a2);\n"
600             + "      log(a1.value);\n"
601             + "      log(div1.getAttributeNode('align').value);\n"
602             + "      log(div1.getAttribute('align'));\n"
603             + "    }\n"
604             + "  </script>\n"
605             + "</head>\n"
606             + "<body onload='test()'>\n"
607             + "  <div id='div1' align='left'></div>\n"
608             + "</body>\n"
609             + "</html>";
610 
611         loadPageVerifyTitle2(html);
612     }
613 
614     /**
615      * Test for <tt>getElementsByTagName</tt>.
616      * @throws Exception if the test fails
617      */
618     @Test
619     @Alerts({"all = 4", "row = 2", "by wrong name: 0"})
620     public void getElementsByTagName() throws Exception {
621         final String html = DOCTYPE_HTML
622             + "<html><head><script>\n"
623             + LOG_TITLE_FUNCTION
624             + "function doTest() {\n"
625             + "  var a1 = document.getElementsByTagName('td');\n"
626             + "  log('all = ' + a1.length);\n"
627             + "  var firstRow = document.getElementById('r1');\n"
628             + "  var rowOnly = firstRow.getElementsByTagName('td');\n"
629             + "  log('row = ' + rowOnly.length);\n"
630             + "  log('by wrong name: ' + firstRow.getElementsByTagName('>').length);\n"
631             + "}\n"
632             + "</script></head><body onload='doTest()'>\n"
633             + "<table>\n"
634             + "<tr id='r1'><td>1</td><td>2</td></tr>\n"
635             + "<tr id='r2'><td>3</td><td>4</td></tr>\n"
636             + "</table>\n"
637             + "</body></html>";
638         loadPageVerifyTitle2(html);
639     }
640 
641     /**
642      * @throws Exception if the test fails
643      */
644     @Test
645     @Alerts({"div1", "div2"})
646     public void getElementsByTagName2() throws Exception {
647         final String html = DOCTYPE_HTML
648             + "<html><head><script>\n"
649             + LOG_TITLE_FUNCTION
650             + "  function test() {\n"
651             + "    for (var f = 0; (formnode = document.getElementsByTagName('form').item(f)); f++)\n"
652             + "      for (var i = 0; (node = formnode.getElementsByTagName('div').item(i)); i++)\n"
653             + "        log(node.id);\n"
654             + "  }\n"
655             + "</script></head><body onload='test()'>\n"
656             + "  <form>\n"
657             + "    <div id='div1'/>\n"
658             + "    <div id='div2'/>\n"
659             + "  </form>\n"
660             + "</body></html>";
661 
662         loadPageVerifyTitle2(html);
663     }
664 
665     /**
666      * Test that {@link HTMLElement#getElementsByTagName} returns an associative array.
667      * Test for Bug #321.
668      * @throws Exception if the test fails
669      */
670     @Test
671     @Alerts({"first", "second", "third"})
672     public void getElementsByTagNameCollection() throws Exception {
673         final String html = DOCTYPE_HTML
674             + "<html><head>\n"
675             + "<script>\n"
676             + LOG_TITLE_FUNCTION
677             + "function test() {\n"
678             + "  var form1 = document.getElementById('form1');\n"
679             + "  var elements = form1.getElementsByTagName('input');\n"
680             + "  log(elements['one'].name);\n"
681             + "  log(elements['two'].name);\n"
682             + "  log(elements['three'].name);\n"
683             + "}\n"
684             + "</script></head>\n"
685             + "<body onload='test()'>\n"
686             + "<form id='form1'>\n"
687             + "<input id='one' name='first' type='text'>\n"
688             + "<input id='two' name='second' type='text'>\n"
689             + "<input id='three' name='third' type='text'>\n"
690             + "</form>\n"
691             + "</body></html>";
692 
693         loadPageVerifyTitle2(html);
694     }
695 
696     /**
697      * Tests that getElementsByTagName('*') returns all child elements, both
698      * at the document level and at the element level.
699      * @throws Exception if the test fails
700      */
701     @Test
702     @Alerts({"8", "3"})
703     public void getElementsByTagNameAsterisk() throws Exception {
704         final String html = DOCTYPE_HTML
705             + "<html><body onload='test()'><script>\n"
706             + LOG_TITLE_FUNCTION
707             + "  function test() {\n"
708             + "    log(document.getElementsByTagName('*').length);\n"
709             + "    log(document.getElementById('div').getElementsByTagName('*').length);\n"
710             + "  }\n"
711             + "</script>\n"
712             + "<div id='div'><p>a</p><p>b</p><p>c</p></div>\n"
713             + "</body></html>";
714         loadPageVerifyTitle2(html);
715     }
716 
717     /**
718      * @throws Exception if an error occurs
719      */
720     @Test
721     @Alerts({"true", "true", "true", "false", "false"})
722     public void getElementsByTagNameEquality() throws Exception {
723         final String html = DOCTYPE_HTML
724             + "<html><body><div id='d'><script>\n"
725             + LOG_TITLE_FUNCTION
726             + "var div = document.getElementById('d');\n"
727             + "log(document.getElementsByTagName('*') == document.getElementsByTagName('*'));\n"
728             + "log(document.getElementsByTagName('script') == document.getElementsByTagName('script'));\n"
729             + "log(document.getElementsByTagName('foo') == document.getElementsByTagName('foo'));\n"
730             + "log(document.getElementsByTagName('script') == document.getElementsByTagName('body'));\n"
731             + "log(document.getElementsByTagName('script') == div.getElementsByTagName('script'));\n"
732             + "</script></div></body></html>";
733         loadPageVerifyTitle2(html);
734     }
735 
736     /**
737      * Test getting the class for the element.
738      * @throws Exception if the test fails
739      */
740     @Test
741     @Alerts("the class is x")
742     public void getClassName() throws Exception {
743         final String html = DOCTYPE_HTML
744             + "<html><head><style>.x { font: 8pt Arial bold; }</style>\n"
745             + "<script>\n"
746             + LOG_TITLE_FUNCTION
747             + "function doTest() {\n"
748             + "  var ele = document.getElementById('pid');\n"
749             + "  var aClass = ele.className;\n"
750             + "  log('the class is ' + aClass);\n"
751             + "}\n"
752             + "</script></head><body onload='doTest()'>\n"
753             + "<p id='pid' class='x'>text</p>\n"
754             + "</body></html>";
755 
756         loadPageVerifyTitle2(html);
757     }
758 
759     /**
760      * Test getting the class for the element.
761      * @throws Exception if the test fails
762      */
763     @Test
764     @Alerts({"* x # x *", "*\tx\t#\tx\t*", "*  #  *", "*\t\t#\t\t*", "*\t \n \n#\t \n \n*", "*x\ty#x\ty*"})
765     public void getClassNameWhitespace() throws Exception {
766         final String html = DOCTYPE_HTML
767             + "<html><head>\n"
768             + "<script>\n"
769             + LOG_TEXTAREA_FUNCTION
770             + "function doTest() {\n"
771             + "  var elem = document.getElementById('pid1');\n"
772             + "  log('*' + elem.className + '#' + elem.getAttribute('class') + '*');\n"
773             + "  elem = document.getElementById('pid2');\n"
774             + "  log('*' + elem.className + '#' + elem.getAttribute('class') + '*');\n"
775             + "  elem = document.getElementById('pid3');\n"
776             + "  log('*' + elem.className + '#' + elem.getAttribute('class') + '*');\n"
777             + "  elem = document.getElementById('pid4');\n"
778             + "  log('*' + elem.className + '#' + elem.getAttribute('class') + '*');\n"
779             + "  elem = document.getElementById('pid5');\n"
780             + "  log('*' + elem.className + '#' + elem.getAttribute('class') + '*');\n"
781             + "  elem = document.getElementById('pid6');\n"
782             + "  log('*' + elem.className + '#' + elem.getAttribute('class') + '*');\n"
783             + "}\n"
784             + "</script></head>\n"
785             + "<body onload='doTest()'>\n"
786             + "  <p id='pid1' class=' x '>text</p>\n"
787             + "  <p id='pid2' class='\tx\t'>text</p>\n"
788             + "  <p id='pid3' class='  '>text</p>\n"
789             + "  <p id='pid4' class='\t\t'>text</p>\n"
790             + "  <p id='pid5' class='\t \r \n'>text</p>\n"
791             + "  <p id='pid6' class='x\ty'>text</p>\n"
792             + LOG_TEXTAREA
793             + "</body></html>";
794 
795         loadPageVerifyTextArea2(html);
796     }
797 
798     /**
799      * Test setting the class for the element.
800      * @throws Exception if the test fails
801      */
802     @Test
803     @Alerts("the class is z")
804     public void setClassName() throws Exception {
805         final String html = DOCTYPE_HTML
806             + "<html><head><style>.x { font: 8pt Arial bold; }</style>\n"
807             + "<script>\n"
808             + LOG_TITLE_FUNCTION
809             + "function doTest() {\n"
810             + "  var ele = document.getElementById('pid');\n"
811             + "  ele.className = 'z';\n"
812             + "  var aClass = ele.className;\n"
813             + "  log('the class is ' + aClass);\n"
814             + "}\n"
815             + "</script></head><body onload='doTest()'>\n"
816             + "<p id='pid' class='x'>text</p>\n"
817             + "</body></html>";
818 
819         loadPageVerifyTitle2(html);
820     }
821 
822     /**
823      * @throws Exception if the test fails
824      */
825     @Test
826     @Alerts("if (1 > 2 & 3 < 2) willNotHappen('yo');")
827     public void getInnerHTML() throws Exception {
828         final String html = DOCTYPE_HTML
829             + "<html>\n"
830             + "<head>\n"
831             + "  <script id='theScript'>if (1 > 2 & 3 < 2) willNotHappen('yo');</script>\n"
832             + "  <script>\n"
833             + LOG_TITLE_FUNCTION
834             + "  function doTest() {\n"
835             + "    var myNode = document.getElementById('theScript');\n"
836             + "    log(myNode.innerHTML);\n"
837             + "  }\n"
838             + "  </script>\n"
839             + "</head>\n"
840             + "<body onload='doTest()'>\n"
841             + "<form id='myNode'></form>\n"
842             + "</body>\n"
843             + "</html>";
844         loadPageVerifyTitle2(html);
845     }
846 
847     /**
848      * @throws Exception if the test fails
849      */
850     @Test
851     @Alerts("getInnerHTML() not available")
852     public void getGetInnerHTML() throws Exception {
853         final String html = DOCTYPE_HTML
854             + "<html>\n"
855             + "<head>\n"
856             + "  <script>\n"
857             + LOG_TITLE_FUNCTION
858             + "  function doTest() {\n"
859             + "    var myNode = document.getElementById('myNode');\n"
860             + "    if (myNode.getInnerHTML) {\n"
861             + "      log(myNode.getInnerHTML());\n"
862             + "    } else {\n"
863             + "      log('getInnerHTML() not available');\n"
864             + "    }\n"
865             + "  }\n"
866             + "  </script>\n"
867             + "</head>\n"
868             + "<body onload='doTest()'>\n"
869             + "</body>\n"
870             + "<p id='myNode'><b>inner HTML</b></p>\n"
871             + "</html>";
872         loadPageVerifyTitle2(html);
873     }
874 
875     /**
876      * @throws Exception if an error occurs
877      */
878     @Test
879     @Alerts("<div id=\"i\" foo=\"\" name=\"\"></div>")
880     public void getInnerHTML_EmptyAttributes() throws Exception {
881         final String html = "<body onload='alert(document.body.innerHTML)'><div id='i' foo='' name=''></div></body>";
882         loadPageWithAlerts2(html);
883     }
884 
885     /**
886      * @throws Exception if the test fails
887      */
888     @Test
889     @Alerts({"Old#=#<b>Old#innerHTML</b>", "New#=#New##cell#value"})
890     public void getSetInnerHTMLSimple_FF() throws Exception {
891         final String html = DOCTYPE_HTML
892             + "<html>\n"
893             + "<head>\n"
894             + "  <script>\n"
895             + "function log(msg) { window.document.title += msg.replace(/\\s/g, '#') + '§';}\n"
896             + "  function doTest() {\n"
897             + "    var myNode = document.getElementById('myNode');\n"
898             + "    log('Old = ' + myNode.innerHTML);\n"
899             + "    myNode.innerHTML = 'New  cell value';\n"
900             + "    log('New = ' + myNode.innerHTML);\n"
901             + "  }\n"
902             + "  </script>\n"
903             + "</head>\n"
904             + "<body onload='doTest()'>\n"
905             + "<p id='myNode'><b>Old innerHTML</b></p>\n"
906             + "</body>\n"
907             + "</html>";
908         loadPageVerifyTitle2(html);
909     }
910 
911     /**
912      * Test the use of innerHTML to set a new input.
913      * @throws Exception if the test fails
914      */
915     @Test
916     @Alerts("true")
917     public void getSetInnerHTMLNewInput() throws Exception {
918         final String html = DOCTYPE_HTML
919             + "<html>\n"
920             + "<head>\n"
921             + "  <script>\n"
922             + LOG_TITLE_FUNCTION
923             + "  function doTest() {\n"
924             + "    var myNode = document.getElementById('myNode');\n"
925             + "    myNode.innerHTML = '<input type=\"checkbox\" name=\"myCb\" checked>';\n"
926             + "    log(myNode.myCb.checked);\n"
927             + "  }\n"
928             + "  </script>\n"
929             + "</head>\n"
930             + "<body onload='doTest()'>\n"
931             + "<form id='myNode'></form>\n"
932             + "</body>\n"
933             + "</html>";
934         loadPageVerifyTitle2(html);
935     }
936 
937     /**
938      * @throws Exception if the test fails
939      */
940     @Test
941     @Alerts({"Old#=#<b>Old#innerHTML</b>",
942              "New#=#New##cell#value#&amp;#\u0110#\u0110"})
943     public void getSetInnerHTMLChar_FF() throws Exception {
944         final String html = DOCTYPE_HTML
945             + "<html>\n"
946             + "<head>\n"
947             + "  <script>\n"
948             + "function log(msg) { window.document.title += msg.replace(/\\s/g, '#') + '§';}\n"
949             + "  function doTest() {\n"
950             + "    var myNode = document.getElementById('myNode');\n"
951             + "    log('Old = ' + myNode.innerHTML);\n"
952             + "    myNode.innerHTML = 'New  cell value &amp; \\u0110 &#272;';\n"
953             + "    log('New = ' + myNode.innerHTML);\n"
954             + "  }\n"
955             + "  </script>\n"
956             + "</head>\n"
957             + "<body onload='doTest()'>\n"
958             + "<p id='myNode'><b>Old innerHTML</b></p>\n"
959             + "</body>\n"
960             + "</html>";
961         loadPageVerifyTitle2(html);
962     }
963 
964     /**
965      * @throws Exception if the test fails
966      */
967     @Test
968     public void setInnerHTMLExecuteJavaScript() throws Exception {
969         final String html = DOCTYPE_HTML
970             + "<html><head><script>\n"
971             + LOG_TITLE_FUNCTION
972             + "  function test() {\n"
973             + "    var newnode = '<scr'+'ipt>alerter();</scr'+'ipt>';\n"
974             + "    var outernode = document.getElementById('myNode');\n"
975             + "    outernode.innerHTML = newnode;\n"
976             + "  }\n"
977             + "  function alerter() {\n"
978             + "    log('executed');\n"
979             + "  }\n"
980             + "</script></head><body onload='test()'>\n"
981             + "  <div id='myNode'></div>\n"
982             + "</body></html>";
983         loadPageVerifyTitle2(html);
984     }
985 
986     /**
987      * @throws Exception if the test fails
988      */
989     @Test
990     public void setInnerHTMLExecuteNestedJavaScript() throws Exception {
991         final String html = DOCTYPE_HTML
992             + "<html><head><script>\n"
993             + "  function test() {\n"
994             + LOG_TITLE_FUNCTION
995             + "    var newnode = '<div><scr'+'ipt>alerter();</scr'+'ipt></div>';\n"
996             + "    var outernode = document.getElementById('myNode');\n"
997             + "    outernode.innerHTML = newnode;\n"
998             + "  }\n"
999             + "  function alerter() {\n"
1000             + "    log('executed');\n"
1001             + "  }\n"
1002             + "</script></head><body onload='test()'>\n"
1003             + "  <div id='myNode'></div>\n"
1004             + "</body></html>";
1005         loadPageVerifyTitle2(html);
1006     }
1007 
1008     /**
1009      * @throws Exception if the test fails
1010      */
1011     @Test
1012     @Alerts("ReferenceError")
1013     public void setInnerHTMLDeclareJavaScript() throws Exception {
1014         final String html = DOCTYPE_HTML
1015             + "<html><head><script>\n"
1016             + LOG_TITLE_FUNCTION
1017             + "  function test() {\n"
1018             + "    var newnode = '<scr'+'ipt>function tester() { alerter(); }</scr'+'ipt>';\n"
1019             + "    var outernode = document.getElementById('myNode');\n"
1020             + "    outernode.innerHTML = newnode;\n"
1021             + "    try {\n"
1022             + "      tester();\n"
1023             + "    } catch(e) { logEx(e); }\n"
1024             + "  }\n"
1025             + "  function alerter() {\n"
1026             + "    log('declared');\n"
1027             + "  }\n"
1028             + "</script></head><body onload='test()'>\n"
1029             + "  <div id='myNode'></div>\n"
1030             + "</body></html>";
1031         loadPageVerifyTitle2(html);
1032     }
1033 
1034     /**
1035      * Verifies outerHTML, innerHTML and innerText for newly created div.
1036      * @throws Exception if the test fails
1037      */
1038     @Test
1039     @Alerts({"true", "true", "true"})
1040     public void outerHTMLinNewDiv() throws Exception {
1041         final String html = DOCTYPE_HTML
1042             + "<html><body onload='test()'><script>\n"
1043             + LOG_TITLE_FUNCTION
1044             + "  function test() {\n"
1045             + "    var div = document.createElement('div');\n"
1046             + "    log('outerHTML' in div);\n"
1047             + "    log('innerHTML' in div);\n"
1048             + "    log('innerText' in div);\n"
1049             + "  }\n"
1050             + "</script>\n"
1051             + "<div id='div'><span class='a b'></span></div>\n"
1052             + "</body></html>";
1053         loadPageVerifyTitle2(html);
1054     }
1055 
1056     /**
1057      * Verifies that empty tags are not abbreviated into their &lt;tag/&gt; form.
1058      * @throws Exception if the test fails
1059      */
1060     @Test
1061     @Alerts({"<div id=\"div\"><ul></ul></div>", "<ul></ul>", ""})
1062     public void getSetInnerHtmlEmptyTag_FF() throws Exception {
1063         final String html = DOCTYPE_HTML
1064             + "<html><body onload='test()'><script>\n"
1065             + LOG_TITLE_FUNCTION
1066             + "  function test() {\n"
1067             + "    var div = document.getElementById('div');\n"
1068             + "    log(div.outerHTML);\n"
1069             + "    log(div.innerHTML);\n"
1070             + "    log(div.innerText);\n"
1071             + "  }\n"
1072             + "</script>\n"
1073             + "<div id='div'><ul/></div>"
1074             + "</body></html>";
1075         loadPageVerifyTitle2(html);
1076     }
1077 
1078     /**
1079      * Verifies that attributes containing whitespace are always quoted.
1080      * @throws Exception if the test fails
1081      */
1082     @Test
1083     @Alerts({"<div id=\"div\"><span class=\"a b\"></span></div>", "<span class=\"a b\"></span>", ""})
1084     public void getSetInnerHtmlAttributeWithWhitespace_FF() throws Exception {
1085         final String html = DOCTYPE_HTML
1086             + "<html><body onload='test()'><script>\n"
1087             + LOG_TITLE_FUNCTION
1088             + "  function test() {\n"
1089             + "    var div = document.getElementById('div');\n"
1090             + "    log(div.outerHTML);\n"
1091             + "    log(div.innerHTML);\n"
1092             + "    log(div.innerText);\n"
1093             + "  }\n"
1094             + "</script>\n"
1095             + "<div id='div'><span class='a b'></span></div>\n"
1096             + "</body></html>";
1097         loadPageVerifyTitle2(html);
1098     }
1099 
1100     /**
1101      * Test setting innerHTML to empty string.
1102      * @throws Exception if the test fails
1103      */
1104     @Test
1105     @Alerts("Empty ChildrenLength: 0")
1106     public void setInnerHTMLEmpty() throws Exception {
1107         final String html = DOCTYPE_HTML
1108                 + "<html><head></head><body>\n"
1109                 + "<div id='testDiv'>foo</div>\n"
1110                 + "<script language='javascript'>\n"
1111                 + LOG_TITLE_FUNCTION
1112                 + "    var node = document.getElementById('testDiv');\n"
1113                 + "    node.innerHTML = '';\n"
1114                 + "    log('Empty ChildrenLength: ' + node.childNodes.length);\n"
1115                 + "</script></body></html>";
1116         loadPageVerifyTitle2(html);
1117     }
1118 
1119     /**
1120      * Test setting innerHTML to null.
1121      * @throws Exception if the test fails
1122      */
1123     @Test
1124     @Alerts("Null ChildrenLength: 0")
1125     public void setInnerHTMLNull() throws Exception {
1126         final String html = DOCTYPE_HTML
1127                 + "<html><head></head><body>\n"
1128                 + "<div id='testDiv'>foo</div>\n"
1129                 + "<script language='javascript'>\n"
1130                 + LOG_TITLE_FUNCTION
1131                 + "    var node = document.getElementById('testDiv');\n"
1132                 + "    node.innerHTML = null;\n"
1133                 + "    log('Null ChildrenLength: ' + node.childNodes.length);\n"
1134                 + "</script></body></html>";
1135 
1136         loadPageVerifyTitle2(html);
1137     }
1138 
1139     /**
1140      * Test setting innerHTML should reset style cache.
1141      * @throws Exception if the test fails
1142      */
1143     @Test
1144     @Alerts("true")
1145     public void setInnerHTMLResetsStyle() throws Exception {
1146         final String html = DOCTYPE_HTML
1147                 + "<html><head></head>\n"
1148                 + "<body>\n"
1149                 + "<div id='testDiv'></div>\n"
1150                 + "<script language='javascript'>\n"
1151                 + LOG_TITLE_FUNCTION
1152                 + "    var node = document.getElementById('testDiv');\n"
1153                 + "    var height = node.offsetHeight;\n"
1154                 + "    node.innerHTML = 'HtmlUnit';\n"
1155                 + "    log(height < node.offsetHeight);\n"
1156                 + "</script></body></html>";
1157 
1158         loadPageVerifyTitle2(html);
1159     }
1160 
1161     /**
1162      * Test getting <code>outerHTML</code> of a <code>div</code> (block).
1163      * @throws Exception if the test fails
1164      */
1165     @Test
1166     @Alerts("Outer = <div id=\"myNode\">New  cell value</div>")
1167     public void getOuterHTMLFromBlock() throws Exception {
1168         final String html = createPageForGetOuterHTML("div", "New  cell value", false);
1169         loadPageVerifyTextArea2(html);
1170     }
1171 
1172     /**
1173      * Test getting <code>outerHTML</code> of a <code>span</code> (inline).
1174      * @throws Exception if the test fails
1175      */
1176     @Test
1177     @Alerts("Outer = <span id=\"myNode\">New  cell value</span>")
1178     public void getOuterHTMLFromInline() throws Exception {
1179         final String html = createPageForGetOuterHTML("span", "New  cell value", false);
1180         loadPageVerifyTextArea2(html);
1181     }
1182 
1183     /**
1184      * Test getting <code>outerHTML</code> of a <code>br</code> (empty).
1185      * @throws Exception if the test fails
1186      */
1187     @Test
1188     @Alerts("Outer = <br id=\"myNode\">")
1189     public void getOuterHTMLFromEmpty() throws Exception {
1190         final String html = createPageForGetOuterHTML("br", "", true);
1191         loadPageVerifyTextArea2(html);
1192     }
1193 
1194     /**
1195      * Test getting <code>outerHTML</code> of an unclosed <code>p</code>.<br>
1196      * Closing <code>p</code> is optional.
1197      * @throws Exception if the test fails
1198      */
1199     @Test
1200     @Alerts("Outer = <p id=\"myNode\">New  cell value\n"
1201                     + "  <textarea id=\"myLog\" cols=\"80\" rows=\"22\"></textarea>\n\n</p>")
1202     @HtmlUnitNYI(CHROME = "Outer = <p id=\"myNode\">New  cell value\n"
1203                             + "  <textarea id=\"myLog\" cols=\"80\" rows=\"22\"></textarea>\n</p>",
1204             EDGE = "Outer = <p id=\"myNode\">New  cell value\n"
1205                     + "  <textarea id=\"myLog\" cols=\"80\" rows=\"22\"></textarea>\n</p>",
1206             FF = "Outer = <p id=\"myNode\">New  cell value\n"
1207                     + "  <textarea id=\"myLog\" cols=\"80\" rows=\"22\"></textarea>\n</p>",
1208             FF_ESR = "Outer = <p id=\"myNode\">New  cell value\n"
1209                     + "  <textarea id=\"myLog\" cols=\"80\" rows=\"22\"></textarea>\n</p>")
1210     public void getOuterHTMLFromUnclosedParagraph() throws Exception {
1211         final String html = createPageForGetOuterHTML("p", "New  cell value", true);
1212         loadPageVerifyTextArea2(html);
1213     }
1214 
1215     private static String createPageForGetOuterHTML(final String nodeTag, final String value, final boolean unclosed) {
1216         return DOCTYPE_HTML
1217                 + "<html>\n"
1218                 + "<head>\n"
1219                 + "  <script>\n"
1220                 + LOG_TEXTAREA_FUNCTION
1221                 + "  function doTest() {\n"
1222                 + "    var myNode = document.getElementById('myNode');\n"
1223                 + "    log('Outer = ' + myNode.outerHTML);\n"
1224                 + "  }\n"
1225                 + "  </script>\n"
1226                 + "</head>\n"
1227                 + "<body onload='doTest()'>\n"
1228                 + "  <" + nodeTag + " id='myNode'>" + value + (unclosed ? "" : "</" + nodeTag + ">") + "\n"
1229                 + LOG_TEXTAREA
1230                 + "</body>\n"
1231                 + "</html>";
1232     }
1233 
1234     /**
1235      * Test setting outerHTML to null.
1236      * @throws Exception if the test fails
1237      */
1238     @Test
1239     @Alerts({"Old = <span id=\"innerNode\">Old outerHTML</span>", "New = ", "Children: 0"})
1240     public void setOuterHTMLNull() throws Exception {
1241         final String html = createPageForSetOuterHTML("div", null);
1242         loadPageVerifyTextArea2(html);
1243     }
1244 
1245     /**
1246      * Test setting outerHTML to null.
1247      * @throws Exception if the test fails
1248      */
1249     @Test
1250     @Alerts({"Old = <span id=\"innerNode\">Old outerHTML</span>", "New = undefined", "Children: 1"})
1251     public void setOuterHTMLUndefined() throws Exception {
1252         final String html = createPageForSetOuterHTML("div", "undefined");
1253         loadPageVerifyTextArea2(html);
1254     }
1255 
1256     /**
1257      * Test setting outerHTML to ''.
1258      * @throws Exception if the test fails
1259      */
1260     @Test
1261     @Alerts({"Old = <span id=\"innerNode\">Old outerHTML</span>", "New = ", "Children: 0"})
1262     public void setOuterHTMLEmpty() throws Exception {
1263         final String html = createPageForSetOuterHTML("div", "");
1264         loadPageVerifyTextArea2(html);
1265     }
1266 
1267     /**
1268      * Test setting outerHTML to ''.
1269      * @throws Exception if the test fails
1270      */
1271     @Test
1272     @Alerts({"Old = <span id=\"innerNode\">Old outerHTML</span>", "New =   ", "Children: 1"})
1273     public void setOuterHTMLBlank() throws Exception {
1274         final String html = createPageForSetOuterHTML("div", "  ");
1275         loadPageVerifyTextArea2(html);
1276     }
1277 
1278     /**
1279      * Test setting <code>outerHTML</code> of a <code>div</code> (block) to a text.
1280      * @throws Exception if the test fails
1281      */
1282     @Test
1283     @Alerts({"Old = <span id=\"innerNode\">Old outerHTML</span>", "New = New  cell value", "Children: 1"})
1284     public void setOuterHTMLAddTextToBlock() throws Exception {
1285         final String html = createPageForSetOuterHTML("div", "New  cell value");
1286         loadPageVerifyTextArea2(html);
1287     }
1288 
1289     /**
1290      * Test setting <code>outerHTML</code> of a <code>span</code> (inline) to a text.
1291      * @throws Exception if the test fails
1292      */
1293     @Test
1294     @Alerts({"Old = <span id=\"innerNode\">Old outerHTML</span>", "New = New  cell value", "Children: 1"})
1295     public void setOuterHTMLAddTextToInline() throws Exception {
1296         final String html = createPageForSetOuterHTML("span", "New  cell value");
1297         loadPageVerifyTextArea2(html);
1298     }
1299 
1300     /**
1301      * Test setting <code>outerHTML</code> of a <code>div</code> (block) to a <code>div</code> (block).
1302      * @throws Exception if the test fails
1303      */
1304     @Test
1305     @Alerts({"Old = <span id=\"innerNode\">Old outerHTML</span>", "New = <div>test</div>", "Children: 1"})
1306     public void setOuterHTMLAddBlockToBlock() throws Exception {
1307         final String html = createPageForSetOuterHTML("div", "<div>test</div>");
1308         loadPageVerifyTextArea2(html);
1309     }
1310 
1311     /**
1312      * Test setting <code>outerHTML</code> of a <code>span</code> (inline) to a <code>div</code> (block).
1313      * @throws Exception if the test fails
1314      */
1315     @Test
1316     @Alerts({"Old = <span id=\"innerNode\">Old outerHTML</span>", "New = <div>test</div>", "Children: 1"})
1317     public void setOuterHTMLAddBlockToInline() throws Exception {
1318         final String html = createPageForSetOuterHTML("span", "<div>test</div>");
1319         loadPageVerifyTextArea2(html);
1320     }
1321 
1322     /**
1323      * Test setting <code>outerHTML</code> of a <code>span</code> (inline) to a <code>span</code> (inline).
1324      * @throws Exception if the test fails
1325      */
1326     @Test
1327     @Alerts({"Old = <span id=\"innerNode\">Old outerHTML</span>", "New = <span>test</span>", "Children: 1"})
1328     public void setOuterHTMLAddInlineToInline() throws Exception {
1329         final String html = createPageForSetOuterHTML("span", "<span>test</span>");
1330         loadPageVerifyTextArea2(html);
1331     }
1332 
1333     /**
1334      * Test setting <code>outerHTML</code> of a <code>div</code> (block) to a <code>span</code> (inline).
1335      * @throws Exception if the test fails
1336      */
1337     @Test
1338     @Alerts({"Old = <span id=\"innerNode\">Old outerHTML</span>", "New = <span>test</span>", "Children: 1"})
1339     public void setOuterHTMLAddInlineToBlock() throws Exception {
1340         final String html = createPageForSetOuterHTML("div", "<span>test</span>");
1341         loadPageVerifyTextArea2(html);
1342     }
1343 
1344     /**
1345      * Test setting <code>outerHTML</code> to a <code>br</code> (empty).
1346      * @throws Exception if the test fails
1347      */
1348     @Test
1349     @Alerts({"Old = <span id=\"innerNode\">Old outerHTML</span>", "New = <br>", "Children: 1"})
1350     public void setOuterHTMLAddEmpty() throws Exception {
1351         final String html = createPageForSetOuterHTML("div", "<br>");
1352         loadPageVerifyTextArea2(html);
1353     }
1354 
1355     /**
1356      * Test setting <code>outerHTML</code> to <code>tr</code> (read-only).
1357      * @throws Exception if the test fails
1358      */
1359     @Test
1360     @Alerts({"-0", "1", "2", "3", "-4", "5", "6", "7", "8", "9", "10", "11"})
1361     public void setOuterHTMLToReadOnly() throws Exception {
1362         final String html =  DOCTYPE_HTML
1363             + "<html>\n"
1364             + "<head>n"
1365             + "  <script>\n"
1366             + LOG_WINDOW_NAME_FUNCTION
1367             + "  function doTest() {\n"
1368             + "    var nodeTypes = ['body', 'caption', 'col', 'colgroup', 'head', 'html',\n"
1369             + "                     'tbody', 'td', 'tfoot', 'th', 'thead', 'tr'];\n"
1370             + "    for (var i = 0; i < nodeTypes.length; i++) {\n"
1371             + "      var nodeType = nodeTypes[i];\n"
1372             + "      var myNode = document.getElementsByTagName(nodeType)[0];\n"
1373             + "      try {\n"
1374             + "        myNode.outerHTML = 'test';\n"
1375             + "        log('-' + i);\n"
1376             + "      } catch(e) { log(i); }\n"
1377             + "    }\n"
1378             + "  }\n"
1379             + "  </script>\n"
1380             + "</head>\n"
1381             + "<body onload='doTest()'>\n"
1382             + "  <table>\n"
1383             + "    <caption></caption>\n"
1384             + "    <colgroup><col></colgroup>\n"
1385             + "    <thead><tr><td></td><th></th></tr></thead>\n"
1386             + "    <tbody></tbody>\n"
1387             + "    <tfoot></tfoot>\n"
1388             + "  </table>\n"
1389             + "  </table>\n"
1390             + "</body>\n"
1391             + "</html>";
1392 
1393         loadPage2(html);
1394         verifyWindowName2(getWebDriver(), getExpectedAlerts());
1395     }
1396 
1397     /**
1398      * Test setting <code>outerHTML</code> of a <code>p</code> to a <code>div</code> (block).<br>
1399      * <code>p</code> allows no block elements inside.
1400      * @throws Exception if the test fails
1401      */
1402     @Test
1403     @Alerts({"Old = <span id=\"innerNode\">Old outerHTML</span>",
1404              "New = <div>test</div>", "Children: 1"})
1405     public void setOuterHTMLAddBlockToParagraph() throws Exception {
1406         final String html = createPageForSetOuterHTML("p", "<div>test</div>");
1407         loadPageVerifyTextArea2(html);
1408     }
1409 
1410     /**
1411      * Test setting <code>outerHTML</code> of a <code>p</code> to a <code>p</code>.<br>
1412      * A following <code>p</code> closes the one before.
1413      * @throws Exception if the test fails
1414      */
1415     @Test
1416     @Alerts({"Old = <span id=\"innerNode\">Old outerHTML</span>",
1417              "New = <p>test</p>", "Children: 1"})
1418     public void setOuterHTMLAddParagraphToParagraph() throws Exception {
1419         final String html = createPageForSetOuterHTML("p", "<p>test</p>");
1420         loadPageVerifyTextArea2(html);
1421     }
1422 
1423     /**
1424      * Test setting <code>outerHTML</code> to an unclosed <code>p</code>.<br>
1425      * Closing <code>p</code> is optional.
1426      * @throws Exception if the test fails
1427      */
1428     @Test
1429     @Alerts({"Old = <span id=\"innerNode\">Old outerHTML</span>", "New = <p>test</p>", "Children: 1"})
1430     public void setOuterHTMLAddUnclosedParagraph() throws Exception {
1431         final String html = createPageForSetOuterHTML("div", "<p>test");
1432         loadPageVerifyTextArea2(html);
1433     }
1434 
1435     /**
1436      * Test setting <code>outerHTML</code> of an <code>a</code> to an <code>a</code>.<br>
1437      * <code>a</code> allows no <code>a</code> inside.
1438      * @throws Exception if the test fails
1439      */
1440     @Test
1441     @Alerts({"Old = <span id=\"innerNode\">Old outerHTML</span>",
1442              "New = <a>test</a>", "Children: 1"})
1443     public void setOuterHTMLAddAnchorToAnchor() throws Exception {
1444         final String html = createPageForSetOuterHTML("a", "<a>test</a>");
1445         loadPageVerifyTextArea2(html);
1446     }
1447 
1448     /**
1449      * Test setting <code>outerHTML</code> to an XHTML self-closing <code>div</code> (block).
1450      * @throws Exception if the test fails
1451      */
1452     @Test
1453     @Alerts({"Old = <span id=\"innerNode\">Old outerHTML</span>", "New = <div></div>", "Children: 1"})
1454     public void setOuterHTMLAddSelfClosingBlock() throws Exception {
1455         final String html = createPageForSetOuterHTML("div", "<div/>");
1456         loadPageVerifyTextArea2(html);
1457     }
1458 
1459     /**
1460      * Test setting <code>outerHTML</code> to two XHTML self-closing <code>div</code> (block).
1461      * @throws Exception if the test fails
1462      */
1463     @Test
1464     @Alerts({"Old = <span id=\"innerNode\">Old outerHTML</span>",
1465              "New = <div><div></div></div>", "Children: 1"})
1466     @HtmlUnitNYI(CHROME = {"Old = <span id=\"innerNode\">Old outerHTML</span>",
1467                            "New = <div></div><div></div>", "Children: 2"},
1468             EDGE = {"Old = <span id=\"innerNode\">Old outerHTML</span>",
1469                     "New = <div></div><div></div>", "Children: 2"},
1470             FF = {"Old = <span id=\"innerNode\">Old outerHTML</span>",
1471                   "New = <div></div><div></div>", "Children: 2"},
1472             FF_ESR = {"Old = <span id=\"innerNode\">Old outerHTML</span>",
1473                       "New = <div></div><div></div>", "Children: 2"})
1474     public void setOuterHTMLAddMultipleSelfClosingBlock() throws Exception {
1475         final String html = createPageForSetOuterHTML("div", "<div/><div>");
1476         loadPageVerifyTextArea2(html);
1477     }
1478 
1479     /**
1480      * Test setting <code>outerHTML</code> to an XHTML self-closing <code>span</code> (inline).
1481      * @throws Exception if the test fails
1482      */
1483     @Test
1484     @Alerts({"Old = <span id=\"innerNode\">Old outerHTML</span>", "New = <span></span>", "Children: 1"})
1485     public void setOuterHTMLAddSelfClosingInline() throws Exception {
1486         final String html = createPageForSetOuterHTML("div", "<span/>");
1487         loadPageVerifyTextArea2(html);
1488     }
1489 
1490     /**
1491      * Test setting <code>outerHTML</code> to an XHTML self-closing <code>br</code> (empty).
1492      * @throws Exception if the test fails
1493      */
1494     @Test
1495     @Alerts({"Old = <span id=\"innerNode\">Old outerHTML</span>", "New = <br>", "Children: 1"})
1496     public void setOuterHTMLAddSelfClosingEmpty() throws Exception {
1497         final String html = createPageForSetOuterHTML("div", "<br/>");
1498         loadPageVerifyTextArea2(html);
1499     }
1500 
1501     private static String createPageForSetOuterHTML(final String nodeTag, final String newValue) {
1502         String newVal = "null";
1503         if ("undefined".equals(newValue)) {
1504             newVal = "undefined";
1505         }
1506         else if (newValue != null) {
1507             newVal = "'" + newValue + "'";
1508         }
1509         return DOCTYPE_HTML
1510             + "<html>\n"
1511             + "<head>\n"
1512             + "  <script>\n"
1513             + LOG_TEXTAREA_FUNCTION
1514             + "  function doTest() {\n"
1515             + "    var myNode = document.getElementById('myNode');\n"
1516             + "    var innerNode = document.getElementById('innerNode');\n"
1517             + "    log('Old = ' + myNode.innerHTML);\n"
1518             + "    innerNode.outerHTML = " + newVal + ";\n"
1519             + "    log('New = ' + myNode.innerHTML);\n"
1520             + "    log('Children: ' + myNode.childNodes.length);\n"
1521             + "  }\n"
1522             + "  </script>\n"
1523             + "</head>\n"
1524             + "<body onload='doTest()'>\n"
1525             + "  <" + nodeTag + " id='myNode'><span id='innerNode'>Old outerHTML</span></" + nodeTag + ">\n"
1526             + LOG_TEXTAREA
1527             + "</body>\n"
1528             + "</html>";
1529     }
1530 
1531     /**
1532      * Test setting <code>outerHTML</code> to two XHTML self-closing <code>div</code> (block).
1533      * @throws Exception if the test fails
1534      */
1535     @Test
1536     @Alerts(DEFAULT = {"Old = <span id=\"innerNode\">Old outerHTML</span>",
1537                        "New = <span id=\"innerNode\">Old outerHTML</span>", "Children: 1"},
1538             CHROME = {"Old = <span id=\"innerNode\">Old outerHTML</span>", "NoModificationAllowedError/DOMException"},
1539             EDGE = {"Old = <span id=\"innerNode\">Old outerHTML</span>", "NoModificationAllowedError/DOMException"})
1540     public void setOuterHTMLDetachedElementNull() throws Exception {
1541         final String html = DOCTYPE_HTML
1542                 + "<html>\n"
1543                 + "<head>\n"
1544                 + "  <script>\n"
1545                 + LOG_TITLE_FUNCTION
1546                 + "  function doTest() {\n"
1547                 + "    var myNode = document.getElementById('myNode');\n"
1548                 + "    document.body.removeChild(myNode);\n"
1549                 + "    log('Old = ' + myNode.innerHTML);\n"
1550                 + "    try {\n"
1551                 + "      myNode.outerHTML = null;\n"
1552                 + "      log('New = ' + myNode.innerHTML);\n"
1553                 + "      log('Children: ' + myNode.childNodes.length);\n"
1554                 + "    } catch(e) { logEx(e); }\n"
1555                 + "  }\n"
1556                 + "  </script>\n"
1557                 + "</head>\n"
1558                 + "<body onload='doTest()'>\n"
1559                 + "  <div id='myNode'><span id='innerNode'>Old outerHTML</span></div>\n"
1560                 + "</body>\n"
1561                 + "</html>";
1562         loadPageVerifyTitle2(html);
1563     }
1564 
1565     /**
1566      * Test setting <code>outerHTML</code> to two XHTML self-closing <code>div</code> (block).
1567      * @throws Exception if the test fails
1568      */
1569     @Test
1570     @Alerts(DEFAULT = {"Old = <span id=\"innerNode\">Old outerHTML</span>",
1571                        "New = <span id=\"innerNode\">Old outerHTML</span>", "Children: 1"},
1572             CHROME = {"Old = <span id=\"innerNode\">Old outerHTML</span>", "NoModificationAllowedError/DOMException"},
1573             EDGE = {"Old = <span id=\"innerNode\">Old outerHTML</span>", "NoModificationAllowedError/DOMException"})
1574     public void setOuterHTMLDetachedElementUndefined() throws Exception {
1575         final String html = DOCTYPE_HTML
1576                 + "<html>\n"
1577                 + "<head>\n"
1578                 + "  <script>\n"
1579                 + LOG_TITLE_FUNCTION
1580                 + "  function doTest() {\n"
1581                 + "    var myNode = document.getElementById('myNode');\n"
1582                 + "    document.body.removeChild(myNode);\n"
1583                 + "    log('Old = ' + myNode.innerHTML);\n"
1584                 + "    try {\n"
1585                 + "      myNode.outerHTML = undefined;\n"
1586                 + "      log('New = ' + myNode.innerHTML);\n"
1587                 + "      log('Children: ' + myNode.childNodes.length);\n"
1588                 + "    } catch(e) { logEx(e); }\n"
1589                 + "  }\n"
1590                 + "  </script>\n"
1591                 + "</head>\n"
1592                 + "<body onload='doTest()'>\n"
1593                 + "  <div id='myNode'><span id='innerNode'>Old outerHTML</span></div>\n"
1594                 + "</body>\n"
1595                 + "</html>";
1596         loadPageVerifyTitle2(html);
1597     }
1598 
1599     /**
1600      * Test setting <code>outerHTML</code> to two XHTML self-closing <code>div</code> (block).
1601      * @throws Exception if the test fails
1602      */
1603     @Test
1604     @Alerts(DEFAULT = {"Old = <span id=\"innerNode\">Old outerHTML</span>",
1605                        "New = <span id=\"innerNode\">Old outerHTML</span>", "Children: 1"},
1606             CHROME = {"Old = <span id=\"innerNode\">Old outerHTML</span>", "exception"},
1607             EDGE = {"Old = <span id=\"innerNode\">Old outerHTML</span>", "exception"})
1608     public void setOuterHTMLDetachedElementEmpty() throws Exception {
1609         final String html = DOCTYPE_HTML
1610                 + "<html>\n"
1611                 + "<head>\n"
1612                 + "  <script>\n"
1613                 + LOG_TITLE_FUNCTION
1614                 + "  function doTest() {\n"
1615                 + "    var myNode = document.getElementById('myNode');\n"
1616                 + "    document.body.removeChild(myNode);\n"
1617                 + "    log('Old = ' + myNode.innerHTML);\n"
1618                 + "    try {\n"
1619                 + "      myNode.outerHTML = '';\n"
1620                 + "      log('New = ' + myNode.innerHTML);\n"
1621                 + "      log('Children: ' + myNode.childNodes.length);\n"
1622                 + "    } catch(e) { logEx(e); }\n"
1623                 + "  }\n"
1624                 + "  </script>\n"
1625                 + "</head>\n"
1626                 + "<body onload='doTest()'>\n"
1627                 + "  <div id='myNode'><span id='innerNode'>Old outerHTML</span></div>\n"
1628                 + "</body>\n"
1629                 + "</html>";
1630         loadPage2(html);
1631     }
1632 
1633     /**
1634      * Test setting <code>outerHTML</code> to two XHTML self-closing <code>div</code> (block).
1635      * @throws Exception if the test fails
1636      */
1637     @Test
1638     @Alerts(DEFAULT = {"Old = <span id=\"innerNode\">Old outerHTML</span>",
1639                        "New = <span id=\"innerNode\">Old outerHTML</span>", "Children: 1"},
1640             CHROME = {"Old = <span id=\"innerNode\">Old outerHTML</span>", "NoModificationAllowedError/DOMException"},
1641             EDGE = {"Old = <span id=\"innerNode\">Old outerHTML</span>", "NoModificationAllowedError/DOMException"})
1642     public void setOuterHTMLDetachedElementBlank() throws Exception {
1643         final String html = DOCTYPE_HTML
1644                 + "<html>\n"
1645                 + "<head>\n"
1646                 + "  <script>\n"
1647                 + LOG_TITLE_FUNCTION
1648                 + "  function doTest() {\n"
1649                 + "    var myNode = document.getElementById('myNode');\n"
1650                 + "    document.body.removeChild(myNode);\n"
1651                 + "    log('Old = ' + myNode.innerHTML);\n"
1652                 + "    try {\n"
1653                 + "      myNode.outerHTML = '';\n"
1654                 + "      log('New = ' + myNode.innerHTML);\n"
1655                 + "      log('Children: ' + myNode.childNodes.length);\n"
1656                 + "    } catch(e) { logEx(e); }\n"
1657                 + "  }\n"
1658                 + "  </script>\n"
1659                 + "</head>\n"
1660                 + "<body onload='doTest()'>\n"
1661                 + "  <div id='myNode'><span id='innerNode'>Old outerHTML</span></div>\n"
1662                 + "</body>\n"
1663                 + "</html>";
1664         loadPageVerifyTitle2(html);
1665     }
1666 
1667     /**
1668      * Test setting <code>outerHTML</code> to two XHTML self-closing <code>div</code> (block).
1669      * @throws Exception if the test fails
1670      */
1671     @Test
1672     @Alerts(DEFAULT = {"Old = <span id=\"innerNode\">Old outerHTML</span>",
1673                        "New = <span id=\"innerNode\">Old outerHTML</span>", "Children: 1"},
1674             CHROME = {"Old = <span id=\"innerNode\">Old outerHTML</span>", "NoModificationAllowedError/DOMException"},
1675             EDGE = {"Old = <span id=\"innerNode\">Old outerHTML</span>", "NoModificationAllowedError/DOMException"})
1676     public void setOuterHTMLDetachedElement() throws Exception {
1677         final String html = DOCTYPE_HTML
1678                 + "<html>\n"
1679                 + "<head>\n"
1680                 + "  <script>\n"
1681                 + LOG_TITLE_FUNCTION
1682                 + "  function doTest() {\n"
1683                 + "    var myNode = document.getElementById('myNode');\n"
1684                 + "    document.body.removeChild(myNode);\n"
1685                 + "    log('Old = ' + myNode.innerHTML);\n"
1686                 + "    try {\n"
1687                 + "      myNode.outerHTML = '<p>test</p>';\n"
1688                 + "      log('New = ' + myNode.innerHTML);\n"
1689                 + "      log('Children: ' + myNode.childNodes.length);\n"
1690                 + "    } catch(e) { logEx(e); }\n"
1691                 + "  }\n"
1692                 + "  </script>\n"
1693                 + "</head>\n"
1694                 + "<body onload='doTest()'>\n"
1695                 + "  <div id='myNode'><span id='innerNode'>Old outerHTML</span></div>\n"
1696                 + "</body>\n"
1697                 + "</html>";
1698         loadPageVerifyTitle2(html);
1699     }
1700 
1701     /**
1702      * @throws Exception if the test fails
1703      */
1704     @Test
1705     public void setOuterHTMLExecuteJavaScript() throws Exception {
1706         final String html = DOCTYPE_HTML
1707             + "<html><head><script>\n"
1708             + LOG_TITLE_FUNCTION
1709             + "  function test() {\n"
1710             + "    var newnode = '<scr'+'ipt>alerter();</scr'+'ipt>';\n"
1711             + "    var oldnode = document.getElementById('myNode');\n"
1712             + "    oldnode.outerHTML = newnode;\n"
1713             + "  }\n"
1714             + "  function alerter() {\n"
1715             + "    log('executed');\n"
1716             + "  }\n"
1717             + "</script></head><body onload='test()'>\n"
1718             + "  <div id='myNode'></div>\n"
1719             + "</body></html>";
1720         loadPageVerifyTitle2(html);
1721     }
1722 
1723     /**
1724      * @throws Exception if the test fails
1725      */
1726     @Test
1727     public void setOuterHTMLExecuteNestedJavaScript() throws Exception {
1728         final String html = DOCTYPE_HTML
1729             + "<html><head><script>\n"
1730             + LOG_TITLE_FUNCTION
1731             + "  function test() {\n"
1732             + "    var newnode = '<div><scr'+'ipt>alerter();</scr'+'ipt></div>';\n"
1733             + "    var oldnode = document.getElementById('myNode');\n"
1734             + "    oldnode.outerHTML = newnode;\n"
1735             + "  }\n"
1736             + "  function alerter() {\n"
1737             + "    log('executed');\n"
1738             + "  }\n"
1739             + "</script></head><body onload='test()'>\n"
1740             + "  <div id='myNode'></div>\n"
1741             + "</body></html>";
1742         loadPageVerifyTitle2(html);
1743     }
1744 
1745     /**
1746      * @throws Exception if the test fails
1747      */
1748     @Test
1749     @Alerts("ReferenceError")
1750     public void setOuterHTMLDeclareJavaScript() throws Exception {
1751         final String html = DOCTYPE_HTML
1752             + "<html><head><script>\n"
1753             + LOG_TITLE_FUNCTION
1754             + "  function test() {\n"
1755             + "    var newnode = '<scr'+'ipt>function tester() { alerter(); }</scr'+'ipt>';\n"
1756             + "    var oldnode = document.getElementById('myNode');\n"
1757             + "    oldnode.outerHTML = newnode;\n"
1758             + "    try {\n"
1759             + "      tester();\n"
1760             + "    } catch(e) { logEx(e); }\n"
1761             + "  }\n"
1762             + "  function alerter() {\n"
1763             + "    log('declared');\n"
1764             + "  }\n"
1765             + "</script></head><body onload='test()'>\n"
1766             + "  <div id='myNode'></div>\n"
1767             + "</body></html>";
1768         loadPageVerifyTitle2(html);
1769     }
1770 
1771     /**
1772      * Test the <tt>#default#clientCaps</tt> default IE behavior.
1773      *
1774      * @throws Exception if the test fails
1775      */
1776     @Test
1777     @Alerts({"body.cpuClass = undefined", "TypeError"})
1778     public void addBehaviorDefaultClientCaps() throws Exception {
1779         final String html = DOCTYPE_HTML
1780             + "<html><body><script>\n"
1781             + LOG_TITLE_FUNCTION
1782             + "try {\n"
1783             + "  var body = document.body;\n"
1784             + "  log('body.cpuClass = ' + body.cpuClass);\n"
1785             + "  var id = body.addBehavior('#default#clientCaps');\n"
1786             + "  log('body.cpuClass = ' + body.cpuClass);\n"
1787             + "  var id2 = body.addBehavior('#default#clientCaps');\n"
1788             + "  body.removeBehavior(id);\n"
1789             + "  log('body.cpuClass = ' + body.cpuClass);\n"
1790             + "} catch(e) { logEx(e); }\n"
1791             + "</script></body></html>";
1792         loadPageVerifyTitle2(html);
1793     }
1794 
1795     /**
1796      * Test the removal of behaviors.
1797      *
1798      * @throws Exception if the test fails
1799      */
1800     @Test
1801     @Alerts({"body.isHomePage = undefined", "!addBehavior", "!removeBehavior", "TypeError"})
1802     public void removeBehavior() throws Exception {
1803         final String html = DOCTYPE_HTML
1804             + "<html><body><script>\n"
1805             + LOG_TITLE_FUNCTION
1806             + "try {\n"
1807             + "  var body = document.body;\n"
1808             + "  log('body.isHomePage = ' + body.isHomePage);\n"
1809 
1810             + "  if(!body.addBehavior) { log('!addBehavior'); }\n"
1811             + "  if(!body.removeBehavior) { log('!removeBehavior'); }\n"
1812 
1813             + "  var id = body.addBehavior('#default#homePage');\n"
1814             + "  log('body.isHomePage = ' + body.isHomePage('not the home page'));\n"
1815             + "  body.removeBehavior(id);\n"
1816             + "  log('body.isHomePage = ' + body.isHomePage);\n"
1817             + "} catch(e) { logEx(e); }\n"
1818             + "</script></body></html>";
1819         loadPageVerifyTitle2(html);
1820     }
1821 
1822     /**
1823      * @throws Exception if the test fails
1824      */
1825     @Test
1826     @Alerts({"BR", "DIV", "2", "3"})
1827     public void children() throws Exception {
1828         final String html = DOCTYPE_HTML
1829             + "<html><body>\n"
1830             + "<div id='myDiv'><br/><div><span>test</span></div></div>\n"
1831             + "<script>\n"
1832             + LOG_TITLE_FUNCTION
1833             + "  var oDiv = document.getElementById('myDiv');\n"
1834             + "  for (var i = 0; i < oDiv.children.length; i++) {\n"
1835             + "    log(oDiv.children[i].tagName);\n"
1836             + "  }\n"
1837             + "  var oCol = oDiv.children;\n"
1838             + "  log(oCol.length);\n"
1839             + "  oDiv.insertAdjacentHTML('beforeEnd', '<br>');\n"
1840             + "  log(oCol.length);\n"
1841             + "</script></body></html>";
1842         loadPageVerifyTitle2(html);
1843     }
1844 
1845     /**
1846      * @throws Exception if the test fails
1847      */
1848     @Test
1849     @Alerts({"1", "0"})
1850     public void childrenDoesNotCountTextNodes() throws Exception {
1851         final String html = DOCTYPE_HTML
1852             + "<html><head><script>\n"
1853             + LOG_TITLE_FUNCTION
1854             + "function test() {\n"
1855             + "  children = document.getElementById('myBody').children;\n"
1856             + "  log(children.length);\n"
1857 
1858             + "  children = document.getElementById('myId').children;\n"
1859             + "  log(children.length);\n"
1860             + "}\n"
1861             + "</script></head><body id='myBody' onload='test()'>\n"
1862             + "  <div id='myId'>abcd</div>\n"
1863             + "</body></html>";
1864 
1865         loadPageVerifyTitle2(html);
1866     }
1867 
1868     /**
1869      * @throws Exception if the test fails
1870      */
1871     @Test
1872     @Alerts({"2", "TypeError"})
1873     public void childrenFunctionAccess() throws Exception {
1874         final String html = DOCTYPE_HTML
1875             + "<html><body>\n"
1876             + "<div id='myDiv'><br/><div>\n"
1877             + "<script>\n"
1878             + LOG_TITLE_FUNCTION
1879             + "try {\n"
1880             + "  var oDiv = document.getElementById('myDiv');\n"
1881             + "  log(oDiv.children.length);\n"
1882             + "  log(oDiv.children(0).tagName);\n"
1883             + "} catch(e) { logEx(e); }\n"
1884             + "</script></body></html>";
1885         loadPageVerifyTitle2(html);
1886     }
1887 
1888     /**
1889      * @throws Exception if the test fails
1890      */
1891     @Test
1892     @Alerts({"Old = Old\n\ninnerText", "New = New cell value"})
1893     @HtmlUnitNYI(CHROME = {"Old = Old\ninnerText", "New = New cell value"},
1894             EDGE =  {"Old = Old\ninnerText", "New = New cell value"},
1895             FF = {"Old = Old\ninnerText", "New = New cell value"},
1896             FF_ESR = {"Old = Old\ninnerText", "New = New cell value"})
1897     public void getSetInnerTextSimple() throws Exception {
1898         final String html = DOCTYPE_HTML
1899             + "<html>\n"
1900             + "<head>\n"
1901             + "  <script>\n"
1902             + LOG_TEXTAREA_FUNCTION
1903             + "  function doTest() {\n"
1904             + "    var myNode = document.getElementById('myNode');\n"
1905             + "    log('Old = ' + myNode.innerText);\n"
1906             + "    myNode.innerText = 'New cell value';\n"
1907             + "    log('New = ' + myNode.innerText);\n"
1908             + "  }\n"
1909             + "  </script>\n"
1910             + "</head>\n"
1911             + "<body onload='doTest()'>\n"
1912             + "<div id='myNode'><b>Old <p>innerText</p></b></div>\n"
1913             + LOG_TEXTAREA
1914             + "</body>\n"
1915             + "</html>";
1916 
1917         loadPageVerifyTextArea2(html);
1918     }
1919 
1920     /**
1921      * Test the removal of attributes from HTMLElements.
1922      *
1923      * @throws Exception if the test fails
1924      */
1925     @Test
1926     @Alerts({"removeMe", "null"})
1927     public void removeAttribute() throws Exception {
1928         final String html = DOCTYPE_HTML
1929             + "<html>\n"
1930             + "<head>\n"
1931             + "  <script>\n"
1932             + LOG_TITLE_FUNCTION
1933             + "  function doTest() {\n"
1934             + "    var myDiv = document.getElementById('aDiv');\n"
1935             + "    log(myDiv.getAttribute('name'));\n"
1936             + "    myDiv.removeAttribute('name');\n"
1937             + "    log(myDiv.getAttribute('name'));\n"
1938             + "  }\n"
1939             + "  </script>\n"
1940             + "</head>\n"
1941             + "<body onload='doTest()'><div id='aDiv' name='removeMe'>\n"
1942             + "</div></body>\n"
1943             + "</html>";
1944         loadPageVerifyTitle2(html);
1945     }
1946 
1947     /**
1948      * IE doesn't really make a distinction between property and attribute...
1949      *
1950      * @throws Exception if the test fails
1951      */
1952     @Test
1953     @Alerts({"hello", "null", "hello"})
1954     public void removeAttribute_property() throws Exception {
1955         final String html = DOCTYPE_HTML
1956             + "<html>\n"
1957             + "<head>\n"
1958             + "  <script>\n"
1959             + LOG_TITLE_FUNCTION
1960             + "  function doTest() {\n"
1961             + "    var myDiv = document.getElementById('aDiv');\n"
1962             + "    myDiv.foo = 'hello';\n"
1963             + "    log(myDiv.foo);\n"
1964             + "    log(myDiv.getAttribute('foo'));\n"
1965             + "    myDiv.removeAttribute('foo');\n"
1966             + "    log(myDiv.foo);\n"
1967             + "  }\n"
1968             + "  </script>\n"
1969             + "</head>\n"
1970             + "<body onload='doTest()'><div id='aDiv' name='removeMe'>\n"
1971             + "</div></body>\n"
1972             + "</html>";
1973         loadPageVerifyTitle2(html);
1974     }
1975 
1976     /**
1977      * Test scrolls (real values don't matter currently).
1978      *
1979      * @throws Exception if the test fails
1980      */
1981     @Test
1982     @Alerts({"number", "number", "number", "number", "number", "number", "number", "number"})
1983     public void scrolls() throws Exception {
1984         final String html = DOCTYPE_HTML
1985               + "<html>\n"
1986               + "<body>\n"
1987               + "</div></body>\n"
1988               + "<div id='div1'>foo</div>\n"
1989               + "<script>\n"
1990               + LOG_TITLE_FUNCTION
1991               + "function alertScrolls(_oElt) {\n"
1992               + "  log(typeof _oElt.scrollHeight);\n"
1993               + "  log(typeof _oElt.scrollWidth);\n"
1994               + "  log(typeof _oElt.scrollLeft);\n"
1995               + "  _oElt.scrollLeft = 123;\n"
1996               + "  log(typeof _oElt.scrollTop);\n"
1997               + "  _oElt.scrollTop = 123;\n"
1998               + "}\n"
1999               + "alertScrolls(document.body);\n"
2000               + "alertScrolls(document.getElementById('div1'));\n"
2001               + "</script></body></html>";
2002         loadPageVerifyTitle2(html);
2003     }
2004 
2005     /**
2006      * @throws Exception if an error occurs
2007      */
2008     @Test
2009     @Alerts({"0", "0", "0", "0", "0", "17", "0", "0"})
2010     public void scrollLeft_overflowScroll() throws Exception {
2011         scrollLeft("scroll");
2012     }
2013 
2014     /**
2015      * @throws Exception if an error occurs
2016      */
2017     @Test
2018     @Alerts({"0", "0", "0", "0", "0", "17", "0", "0"})
2019     public void scrollLeft_overflowAuto() throws Exception {
2020         scrollLeft("auto");
2021     }
2022 
2023     /**
2024      * NOTE: When running this test with Firefox (3.6, at least), it's important to reload the page with Ctrl+F5
2025      * in order to completely clear the cache; otherwise, Firefox appears to incorrectly cache some style attributes.
2026      * @throws Exception if an error occurs
2027      */
2028     private void scrollLeft(final String overflow) throws Exception {
2029         final String html = DOCTYPE_HTML
2030             + "<html><body onload='test()'>\n"
2031             + "<div id='d1' style='width:100px;height:100px;background-color:green;'>\n"
2032             + "  <div id='d2' style='width:50px;height:50px;background-color:blue;'></div>\n"
2033             + "</div>\n"
2034             + "<script>\n"
2035             + LOG_TITLE_FUNCTION
2036             + "function test() {\n"
2037             + "  var d1 = document.getElementById('d1'), d2 = document.getElementById('d2');\n"
2038             + "  log(d1.scrollLeft);\n"
2039             + "  d1.scrollLeft = -1;\n"
2040             + "  log(d1.scrollLeft);\n"
2041             + "  d1.scrollLeft = 5;\n"
2042             + "  log(d1.scrollLeft);\n"
2043             + "  d2.style.width = '200px';\n"
2044             + "  d2.style.height = '200px';\n"
2045             + "  d1.scrollLeft = 7;\n"
2046             + "  log(d1.scrollLeft);\n"
2047             + "  d1.style.overflow = '" + overflow + "';\n"
2048             + "  log(d1.scrollLeft);\n"
2049             + "  d1.scrollLeft = 17;\n"
2050             + "  log(d1.scrollLeft);\n"
2051             + "  d1.style.overflow = 'visible';\n"
2052             + "  log(d1.scrollLeft);\n"
2053             + "  d1.scrollLeft = 19;\n"
2054             + "  log(d1.scrollLeft);\n"
2055             + "}\n"
2056             + "</script></body></html>";
2057         loadPageVerifyTitle2(html);
2058     }
2059 
2060     /**
2061      * @throws Exception if an error occurs
2062      */
2063     @Test
2064     @Alerts({"0", "10", "0"})
2065     public void scrollLeft() throws Exception {
2066         final String html = DOCTYPE_HTML
2067             + "<html>\n"
2068             + "<head>\n"
2069             + "  <script>\n"
2070             + LOG_TITLE_FUNCTION
2071             + "  function doTest() {\n"
2072             + "    var outer = document.getElementById('outer');\n"
2073             + "    var inner = document.getElementById('inner');\n"
2074             + "    log(outer.scrollLeft);\n"
2075 
2076             + "    outer.scrollLeft = 10;\n"
2077             + "    log(outer.scrollLeft);\n"
2078 
2079             + "    outer.scrollLeft = -4;\n"
2080             + "    log(outer.scrollLeft);\n"
2081             + "  }\n"
2082             + "  </script>\n"
2083             + "</head>\n"
2084             + "<body onload='doTest()'>\n"
2085             + "  <div id='outer' style='overflow: scroll; width: 100px'>\n"
2086             + "    <div id='inner' style='width: 250px'>abcdefg hijklmnop qrstuvw xyz</div>\n"
2087             + "  </div>\n"
2088             + "</body>\n"
2089             + "</html>";
2090         loadPageVerifyTitle2(html);
2091     }
2092 
2093     /**
2094      * @throws Exception if an error occurs
2095      */
2096     @Test
2097     @Alerts({"0", "0", "0", "0", "0", "17", "0", "0"})
2098     public void scrollTop_overflowScroll() throws Exception {
2099         scrollTop("scroll");
2100     }
2101 
2102     /**
2103      * @throws Exception if an error occurs
2104      */
2105     @Test
2106     @Alerts({"0", "0", "0", "0", "0", "17", "0", "0"})
2107     public void scrollTop_overflowAuto() throws Exception {
2108         scrollTop("auto");
2109     }
2110 
2111     /**
2112      * NOTE: When running this test with Firefox (3.6, at least), it's important to reload the page with Ctrl+F5
2113      * in order to completely clear the cache; otherwise, Firefox appears to incorrectly cache some style attributes.
2114      * @throws Exception if an error occurs
2115      */
2116     private void scrollTop(final String overflow) throws Exception {
2117         final String html = DOCTYPE_HTML
2118             + "<html><body onload='test()'>\n"
2119             + "<div id='d1' style='width:100px;height:100px;background-color:green;'>\n"
2120             + "  <div id='d2' style='width:50px;height:50px;background-color:blue;'></div>\n"
2121             + "</div>\n"
2122             + "<script>\n"
2123             + LOG_TITLE_FUNCTION
2124             + "function test() {\n"
2125             + "  var d1 = document.getElementById('d1'), d2 = document.getElementById('d2');\n"
2126             + "  log(d1.scrollTop);\n"
2127             + "  d1.scrollTop = -1;\n"
2128             + "  log(d1.scrollTop);\n"
2129             + "  d1.scrollTop = 5;\n"
2130             + "  log(d1.scrollTop);\n"
2131             + "  d2.style.width = '200px';\n"
2132             + "  d2.style.height = '200px';\n"
2133             + "  d1.scrollTop = 7;\n"
2134             + "  log(d1.scrollTop);\n"
2135             + "  d1.style.overflow = '" + overflow + "';\n"
2136             + "  log(d1.scrollTop);\n"
2137             + "  d1.scrollTop = 17;\n"
2138             + "  log(d1.scrollTop);\n"
2139             + "  d1.style.overflow = 'visible';\n"
2140             + "  log(d1.scrollTop);\n"
2141             + "  d1.scrollTop = 19;\n"
2142             + "  log(d1.scrollTop);\n"
2143             + "}\n"
2144             + "</script></body></html>";
2145 
2146         loadPageVerifyTitle2(html);
2147     }
2148 
2149     /**
2150      * Tests that JavaScript scrollIntoView() function doesn't fail.
2151      * @throws Exception if the test fails
2152      */
2153     @Test
2154     @Alerts("ok")
2155     public void scrollIntoView() throws Exception {
2156         final String html = DOCTYPE_HTML
2157               + "<html>\n"
2158               + "<body>\n"
2159               + "<script id='me'>\n"
2160               + LOG_TITLE_FUNCTION
2161               + "document.getElementById('me').scrollIntoView(); log('ok');</script>\n"
2162               + "</body></html>";
2163 
2164         loadPageVerifyTitle2(html);
2165     }
2166 
2167     /**
2168      * @throws Exception if the test fails
2169      */
2170     @Test
2171     @Alerts("container [object HTMLDivElement]")
2172     @HtmlUnitNYI(CHROME = {"container [object HTMLDivElement]", "body [object HTMLBodyElement]"},
2173             EDGE = {"container [object HTMLDivElement]", "body [object HTMLBodyElement]"},
2174             FF = {"container [object HTMLDivElement]", "body [object HTMLBodyElement]"},
2175             FF_ESR = {"container [object HTMLDivElement]", "body [object HTMLBodyElement]"})
2176     public void scrollIntoViewTriggersOnScroll() throws Exception {
2177         final String html = DOCTYPE_HTML
2178             + "<html>\n"
2179             + "<head>\n"
2180             + "<script>\n"
2181             + LOG_TITLE_FUNCTION
2182             + "</script>\n"
2183             + "</head>\n"
2184 
2185             + "<body>\n"
2186             + "  <div id='container' style='overflow-y: scroll; height: 100px;'>\n"
2187             + "    <div style='height: 1000px;'>spacer</div>\n"
2188             + "    <div id='target' style='background: red;'>Target</div>"
2189             + "  </div>\n"
2190 
2191             + "  <script>\n"
2192             + "    document.addEventListener('scroll', function(e) { log('document ' + e.target) });\n"
2193             + "    document.body.addEventListener('scroll', function(e) { log('body ' + e.target) });\n"
2194 
2195             + "    var c = document.getElementById('container');\n"
2196             + "    c.addEventListener('scroll', function(e) { log('container ' + e.target) });\n"
2197 
2198             + "    var s = document.getElementById('target');"
2199             + "    s.addEventListener('scroll', function(e) { log('target ' + e.target) });\n"
2200 
2201             + "    s.scrollIntoView();\n"
2202             + "  </script>\n"
2203             + "</body>\n"
2204             + "</html>";
2205 
2206         loadPageVerifyTitle2(html);
2207     }
2208 
2209     /**
2210      * @throws Exception if the test fails
2211      */
2212     @Test
2213     @Alerts({"target-1 [object HTMLDivElement]", "container [object HTMLDivElement]"})
2214     @HtmlUnitNYI(CHROME = {"target-1 [object HTMLDivElement]",
2215                            "container [object HTMLDivElement]", "body [object HTMLBodyElement]"},
2216             EDGE = {"target-1 [object HTMLDivElement]",
2217                     "container [object HTMLDivElement]", "body [object HTMLBodyElement]"},
2218             FF = {"target-1 [object HTMLDivElement]",
2219                   "container [object HTMLDivElement]", "body [object HTMLBodyElement]"},
2220             FF_ESR = {"target-1 [object HTMLDivElement]",
2221                       "container [object HTMLDivElement]", "body [object HTMLBodyElement]"})
2222     public void scrollIntoViewTriggersOnScrollBubbling() throws Exception {
2223         final String html = DOCTYPE_HTML
2224             + "<html>\n"
2225             + "<head>\n"
2226             + "<script>\n"
2227             + LOG_TITLE_FUNCTION
2228             + "</script>\n"
2229             + "</head>\n"
2230 
2231             + "<body>\n"
2232             + "  <div id='container' style='overflow-y: scroll; height: 100px;'>\n"
2233             + "    <div style='height: 1000px;'>spacer</div>\n"
2234             + "    <div id='target-1' style='overflow-y: scroll; height: 100px;'>\n"
2235             + "      <div style='height: 1000px;'>spacer</div>\n"
2236             + "      <div id='target' style='background: red;'>Target</div>"
2237             + "    </div>\n"
2238             + "  </div>\n"
2239 
2240             + "  <script>\n"
2241             + "    document.addEventListener('scroll', function(e) { log('document ' + e.target) });\n"
2242             + "    document.body.addEventListener('scroll', function(e) { log('body ' + e.target) });\n"
2243 
2244             + "    var c = document.getElementById('container');\n"
2245             + "    c.onscroll = (e) => { log('container ' + e.target); };\n"
2246 
2247             + "    var t = document.getElementById('target-1');\n"
2248             + "    t.onscroll = (e) => { log('target-1 ' + e.target); };\n"
2249 
2250             + "    var s = document.getElementById('target');"
2251             + "    s.onscroll = (e) => { log('target ' + e.target); };\n"
2252 
2253             + "    s.scrollIntoView();\n"
2254             + "  </script>\n"
2255             + "</body>\n"
2256             + "</html>";
2257 
2258         loadPageVerifyTitle2(html);
2259     }
2260 
2261     /**
2262      * @throws Exception if the test fails
2263      */
2264     @Test
2265     @Alerts("window [object HTMLDocument]")
2266     public void scrollIntoViewTriggersWindowOnScroll() throws Exception {
2267         final String html = DOCTYPE_HTML
2268             + "<html>\n"
2269             + "<head>\n"
2270             + "<script>\n"
2271             + LOG_TITLE_FUNCTION
2272             + "</script>\n"
2273             + "</head>\n"
2274 
2275             + "<body>\n"
2276             + "  <div style='height: 10000px;'>spacer</div>\n"
2277             + "  <div id='target' style='background: red;'>Target</div>"
2278 
2279             + "  <script>\n"
2280             + "    window.addEventListener('scroll', function(e) { log('window ' + e.target) });\n"
2281 
2282             + "    var s = document.getElementById('target');"
2283             + "    s.scrollIntoView();\n"
2284             + "  </script>\n"
2285             + "</body>\n"
2286             + "</html>";
2287 
2288         loadPageVerifyTitle2(html);
2289     }
2290 
2291     /**
2292      * Test for issue #942.
2293      * @throws Exception if the test fails
2294      */
2295     @Test
2296     @Alerts({"50", "100"})
2297     public void scrollIntoViewIssue() throws Exception {
2298         final String html = DOCTYPE_HTML
2299             + "<html>\n"
2300             + "<head>\n"
2301             + "<script>\n"
2302             + LOG_TITLE_FUNCTION
2303             + "</script>\n"
2304             + "</head>\n"
2305 
2306             + "<body>\n"
2307             + "  <button id='myButton' onClick='tester();'>Press</button>\n"
2308             + "  <div id='table-container' style='max-height: 400px; overflow-y: auto;'>\n"
2309             + "    <table>\n"
2310             + "      <thead><tr><th>ID</th><th>Name</th></tr></thead>\n"
2311             + "      <tbody id='table-body'></tbody>\n"
2312             + "    </table>\n"
2313             + "  </div>\n"
2314 
2315             + "  <script>\n"
2316             + "    let counter = 1;\n"
2317             + "    const tableBody = document.getElementById('table-body');\n"
2318             + "    const container = document.getElementById('table-container');\n"
2319 
2320             + "    function tester() {\n"
2321             + "      const xPathLast = \"//tbody[@id='table-body']//tr[last()]\";\n"
2322             + "      const last = document.evaluate(xPathLast, document, null, "
2323                             + "XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;\n"
2324             + "      last.scrollIntoView();\n"
2325             + "    }\n"
2326 
2327             + "    function loadMoreRows() {\n"
2328             + "      for (let i = 0; i < 50; i++) {\n"
2329             + "        const row = document.createElement('tr');\n"
2330             + "        row.innerHTML = `<td>${counter}</td><td>Item ${counter}</td>`;\n"
2331             + "        tableBody.appendChild(row);\n"
2332             + "        counter++;\n"
2333             + "      }\n"
2334             + "    }\n"
2335 
2336             + "    container.addEventListener('scroll', function() {\n"
2337             + "      if (container.scrollTop + container.clientHeight >= container.scrollHeight) {\n"
2338             + "        loadMoreRows();\r\n"
2339             + "      };\n"
2340             + "    });\n"
2341 
2342             + "    // Initial load\n"
2343             + "    loadMoreRows();"
2344             + "  </script>\n"
2345             + "</body>\n"
2346             + "</html>";
2347 
2348         final WebDriver driver = loadPage2(html);
2349 
2350         final By tableRows = By.xpath("//tbody[@id='table-body']//tr");
2351         int rowCount = driver.findElements(tableRows).size();
2352         assertEquals(Integer.parseInt(getExpectedAlerts()[0]), rowCount);
2353 
2354         driver.findElement(By.id("myButton")).click();
2355 
2356         rowCount = driver.findElements(tableRows).size();
2357         assertEquals(Integer.parseInt(getExpectedAlerts()[1]), rowCount);
2358     }
2359 
2360     /**
2361      * Tests the offsetParent property.
2362      * @throws Exception if the test fails
2363      */
2364     @Test
2365     @Alerts({"element: span3 offsetParent: td2", "element: td2 offsetParent: table2",
2366              "element: tr2 offsetParent: table2", "element: table2 offsetParent: td1",
2367              "element: td1 offsetParent: table1", "element: tr1 offsetParent: table1",
2368              "element: table1 offsetParent: body1", "element: span2 offsetParent: body1",
2369              "element: span1 offsetParent: body1", "element: div1 offsetParent: body1",
2370              "element: body1 offsetParent: null"})
2371     public void offsetParent_Basic() throws Exception {
2372         final String html = DOCTYPE_HTML
2373             + "<html><head>\n"
2374             + "<script type='text/javascript'>\n"
2375             + LOG_TITLE_FUNCTION
2376             + "function alertOffsetParent(id) {\n"
2377             + "  var element = document.getElementById(id);\n"
2378             + "  var offsetParent = element.offsetParent;\n"
2379             + "  var alertMessage = 'element: ' + element.id + ' offsetParent: ';\n"
2380             + "  if (offsetParent) {\n"
2381             + "    alertMessage += offsetParent.id;\n"
2382             + "  }\n"
2383             + "  else {\n"
2384             + "    alertMessage += offsetParent;\n"
2385             + "  }\n"
2386             + "  log(alertMessage);\n"
2387             + "}\n"
2388             + "function test() {\n"
2389             + "  alertOffsetParent('span3');\n"
2390             + "  alertOffsetParent('td2');\n"
2391             + "  alertOffsetParent('tr2');\n"
2392             + "  alertOffsetParent('table2');\n"
2393             + "  alertOffsetParent('td1');\n"
2394             + "  alertOffsetParent('tr1');\n"
2395             + "  alertOffsetParent('table1');\n"
2396             + "  alertOffsetParent('span2');\n"
2397             + "  alertOffsetParent('span1');\n"
2398             + "  alertOffsetParent('div1');\n"
2399             + "  alertOffsetParent('body1');\n"
2400             + "}\n"
2401             + "</script></head>\n"
2402             + "<body id='body1' onload='test()'>\n"
2403             + "<div id='div1'>\n"
2404             + "  <span id='span1'>\n"
2405             + "    <span id='span2'>\n"
2406             + "      <table id='table1'>\n"
2407             + "        <tr id='tr1'>\n"
2408             + "          <td id='td1'>\n"
2409             + "            <table id='table2'>\n"
2410             + "              <tr id='tr2'>\n"
2411             + "                <td id='td2'>\n"
2412             + "                  <span id='span3'>some text</span>\n"
2413             + "                </td>\n"
2414             + "              </tr>\n"
2415             + "            </table>\n"
2416             + "          </td>\n"
2417             + "        </tr>\n"
2418             + "      </table>\n"
2419             + "    </span>\n"
2420             + "  </span>\n"
2421             + "</div>\n"
2422             + "</body></html>";
2423         loadPageVerifyTitle2(html);
2424     }
2425 
2426     /**
2427      * Tests the offsetParent property.
2428      * @throws Exception if the test fails
2429      */
2430     @Test
2431     @Alerts({"null", "null"})
2432     public void offsetParent_newElement() throws Exception {
2433         final String html = DOCTYPE_HTML
2434             + "<html><body>\n"
2435             + "<script>\n"
2436             + LOG_TITLE_FUNCTION
2437             + "  var oNew = document.createElement('span');\n"
2438             + "  log(oNew.offsetParent);\n"
2439             + "  var fragment = document.createDocumentFragment();\n"
2440             + "  fragment.appendChild(oNew);\n"
2441             + "  log(oNew.offsetParent);\n"
2442             + "</script>\n"
2443             + "</body></html>";
2444         loadPageVerifyTitle2(html);
2445     }
2446 
2447     /**
2448      * Tests the offsetParent property, including the effects of CSS "position" attributes.
2449      * Based on <a href="http://dump.testsuite.org/2006/dom/style/offset/spec#offsetparent">this work</a>.
2450      * @throws Exception if an error occurs
2451      */
2452     @Test
2453     @Alerts(DEFAULT = {"null", "body", "TypeError", "body", "body", "body",
2454                        "f1", "body", "h1", "i1", "td", "TypeError", "td", "body", "body"},
2455             FF_ESR = {"null", "body", "body", "body", "body", "body",
2456                       "f1", "body", "h1", "i1", "td", "body", "td", "body", "body"})
2457     public void offsetParent_WithCSS() throws Exception {
2458         final String html = DOCTYPE_HTML
2459             + "<html>\n"
2460             + "  <body id='body' onload='test()'>\n"
2461             + "    <div id='a1'><div id='a2'>x</div></div>\n"
2462             + "    <div id='b1'><div id='b2' style='position:fixed'>x</div></div>\n"
2463             + "    <div id='c1'><div id='c2' style='position:static'>x</div></div>\n"
2464             + "    <div id='d1'><div id='d2' style='position:absolute'>x</div></div>\n"
2465             + "    <div id='e1'><div id='e2' style='position:relative'>x</div></div>\n"
2466             + "    <div id='f1' style='position:fixed'><div id='f2'>x</div></div>\n"
2467             + "    <div id='g1' style='position:static'><div id='g2'>x</div></div>\n"
2468             + "    <div id='h1' style='position:absolute'><div id='h2'>x</div></div>\n"
2469             + "    <div id='i1' style='position:relative'><div id='i2'>x</div></div>\n"
2470             + "    <table id='table'>\n"
2471             + "      <tr id='tr'>\n"
2472             + "        <td id='td'>\n"
2473             + "          <div id='j1'><div id='j2'>x</div></div>\n"
2474             + "          <div id='k1'><div id='k2' style='position:fixed'>x</div></div>\n"
2475             + "          <div id='l1'><div id='l2' style='position:static'>x</div></div>\n"
2476             + "          <div id='m1'><div id='m2' style='position:absolute'>x</div></div>\n"
2477             + "          <div id='n1'><div id='n2' style='position:relative'>x</div></div>\n"
2478             + "        </td>\n"
2479             + "      </tr>\n"
2480             + "    </table>\n"
2481             + "    <script>\n"
2482             + LOG_TITLE_FUNCTION
2483             + "      function alertOffsetParentId(id) {\n"
2484             + "        try {\n"
2485             + "          log(document.getElementById(id).offsetParent.id);\n"
2486             + "        } catch(e) { logEx(e); }\n"
2487             + "      }\n"
2488             + "      function test() {\n"
2489             + "        log(document.getElementById('body').offsetParent);\n"
2490             + "        alertOffsetParentId('a2');\n"
2491             + "        alertOffsetParentId('b2');\n"
2492             + "        alertOffsetParentId('c2');\n"
2493             + "        alertOffsetParentId('d2');\n"
2494             + "        alertOffsetParentId('e2');\n"
2495             + "        alertOffsetParentId('f2');\n"
2496             + "        alertOffsetParentId('g2');\n"
2497             + "        alertOffsetParentId('h2');\n"
2498             + "        alertOffsetParentId('i2');\n"
2499             + "        alertOffsetParentId('j2');\n"
2500             + "        alertOffsetParentId('k2');\n"
2501             + "        alertOffsetParentId('l2');\n"
2502             + "        alertOffsetParentId('m2');\n"
2503             + "        alertOffsetParentId('n2');\n"
2504             + "      }\n"
2505             + "    </script>\n"
2506             + "  </body>\n"
2507             + "</html>";
2508         loadPageVerifyTitle2(html);
2509     }
2510 
2511     /**
2512      * Test for Bug #616.
2513      * @throws Exception if the test fails
2514      */
2515     @Test
2516     public void offsetParent_withSelectors() throws Exception {
2517         final String html = DOCTYPE_HTML
2518             + "<html><head><style>\n"
2519             + "div ul > li {\n"
2520             + "  font-size: xx-small;\n"
2521             + "}\n"
2522             + "</style><script>\n"
2523             + "function test() {\n"
2524             + "  var divThing = document.getElementById('outer');\n"
2525             + "  while (divThing) {\n"
2526             + "    divThing = divThing.offsetParent;\n"
2527             + "  }\n"
2528             + "}\n"
2529             + "</script></head>\n"
2530             + "<body onload='test()'>\n"
2531             + "<div id='outer'></div>\n"
2532             + "</body>\n"
2533             + "</html>";
2534         loadPageWithAlerts2(html);
2535     }
2536 
2537     /**
2538      * @throws Exception if the test fails
2539      */
2540     @Test
2541     @Alerts({"undefined", "undefined", "undefined", "undefined",
2542              "undefined", "123", "from myFunction", "123", "from myFunction"})
2543     public void prototype() throws Exception {
2544         final String html = DOCTYPE_HTML
2545             + "<html><head>\n"
2546             + "<script>\n"
2547             + LOG_TITLE_FUNCTION
2548             + "function test() {\n"
2549             + "  var d = document.getElementById('foo');\n"
2550             + "  log(d.foo);\n"
2551             + "  log(d.myFunction);\n"
2552             + "  var link = document.getElementById('testLink');\n"
2553             + "  log(link.foo);\n"
2554             + "  log(link.myFunction);\n"
2555             + "  HTMLElement.prototype.foo = 123;\n"
2556             + "  log(HTMLElement.foo);\n"
2557             + "  HTMLElement.prototype.myFunction = function() { return 'from myFunction'; };\n"
2558             + "  log(d.foo);\n"
2559             + "  log(d.myFunction());\n"
2560             + "  log(link.foo);\n"
2561             + "  log(link.myFunction());\n"
2562             + "}\n"
2563             + "</script></head><body onload='test()''>\n"
2564             + "<div id='foo'>bla</div>\n"
2565             + "<a id='testLink' href='foo'>bla</a>\n"
2566             + "</body></html>";
2567         loadPageVerifyTitle2(html);
2568     }
2569 
2570     /**
2571      * 'Element' and 'HTMLElement' prototypes are synonyms.
2572      *
2573      * @throws Exception if the test fails
2574      */
2575     @Test
2576     @Alerts("in selectNodes")
2577     public void prototype_Element() throws Exception {
2578         final String html = DOCTYPE_HTML
2579             + "<html><head><script>\n"
2580             + LOG_TITLE_FUNCTION
2581             + "function test() {\n"
2582             + "  Element.prototype.selectNodes = function(sExpr){\n"
2583             + "    log('in selectNodes');\n"
2584             + "  }\n"
2585             + "  document.getElementById('myDiv').selectNodes();\n"
2586             + "}\n"
2587             + "</script></head><body onload='test()'>\n"
2588             + "  <div id='myDiv'></div>\n"
2589             + "</body></html>";
2590         loadPageVerifyTitle2(html);
2591     }
2592 
2593     /**
2594      * @throws Exception if the test fails
2595      */
2596     @Test
2597     @Alerts({"true", "true"})
2598     public void instanceOf() throws Exception {
2599         final String html = DOCTYPE_HTML
2600             + "<html><head>\n"
2601             + "<script>\n"
2602             + LOG_TITLE_FUNCTION
2603             + "function test() {\n"
2604             + "  var d = document.getElementById('foo');\n"
2605             + "  log(d instanceof HTMLDivElement);\n"
2606             + "  var link = document.getElementById('testLink');\n"
2607             + "  log(link instanceof HTMLAnchorElement);\n"
2608             + "}\n"
2609             + "</script></head><body onload='test()''>\n"
2610             + "<div id='foo'>bla</div>\n"
2611             + "<a id='testLink' href='foo'>bla</a>\n"
2612             + "</body></html>";
2613         loadPageVerifyTitle2(html);
2614     }
2615 
2616     /**
2617      * @throws Exception if the test fails
2618      */
2619     @Test
2620     @Alerts({"null", "[object HTMLBodyElement]"})
2621     public void parentElement() throws Exception {
2622         final String html = DOCTYPE_HTML
2623             + "<html id='htmlID'>\n"
2624             + "<head>\n"
2625             + "</head>\n"
2626             + "<body>\n"
2627             + "<div id='divID'/>\n"
2628             + "<script language=\"javascript\">\n"
2629             + LOG_TITLE_FUNCTION
2630             + "  log(document.getElementById('htmlID').parentElement);\n"
2631             + "  log(document.getElementById('divID' ).parentElement);\n"
2632             + "</script>\n"
2633             + "</body>\n"
2634             + "</html>";
2635         loadPageVerifyTitle2(html);
2636     }
2637 
2638     /**
2639      * @throws Exception if the test fails
2640      */
2641     @Test
2642     @Alerts("undefined")
2643     public void currentStyle() throws Exception {
2644         style("currentStyle");
2645     }
2646 
2647     /**
2648      * @throws Exception if the test fails
2649      */
2650     @Test
2651     @Alerts("undefined")
2652     public void runtimeStyle() throws Exception {
2653         style("runtimeStyle");
2654     }
2655 
2656     private void style(final String styleProperty) throws Exception {
2657         final String html = DOCTYPE_HTML
2658             + "<html>\n"
2659             + "<head>\n"
2660             + "<script>\n"
2661             + LOG_TITLE_FUNCTION
2662             + "  function test() {\n"
2663             + "    var elem = document.getElementById('myDiv');\n"
2664             + "    var style = elem." + styleProperty + ";\n"
2665             + "    log(style);\n"
2666             + "    if (style) { log(style.color); }\n"
2667             + "  }\n"
2668             + "</script>\n"
2669             + "</head>\n"
2670             + "<body onload='test()'>\n"
2671             + "<div id='myDiv'></div>\n"
2672             + "</body></html>";
2673         loadPageVerifyTitle2(html);
2674     }
2675 
2676     /**
2677      * @throws Exception if the test fails
2678      */
2679     @Test
2680     @Alerts({"0", "0"})
2681     public void clientLeftTop() throws Exception {
2682         final String html = DOCTYPE_HTML
2683             + "<html><body>"
2684             + "<div id='div1'>hello</div><script>\n"
2685             + LOG_TITLE_FUNCTION
2686             + "  var d1 = document.getElementById('div1');\n"
2687             + "  log(d1.clientLeft);\n"
2688             + "  log(d1.clientTop);\n"
2689             + "</script></body></html>";
2690         loadPageVerifyTitle2(html);
2691     }
2692 
2693     /**
2694      * Another nice feature of the IE.
2695      * @throws Exception if the test fails
2696      */
2697     @Test
2698     @Alerts({"0", "0"})
2699     public void clientLeftTop_documentElement() throws Exception {
2700         final String html =
2701               "<!DOCTYPE HTML "
2702             +      "PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">\n"
2703             + "<html>\n"
2704             + "<body>"
2705             + "<div id='div1'>hello</div><script>\n"
2706             + LOG_TITLE_FUNCTION
2707             + "  var d1 = document.documentElement;\n"
2708             + "  log(d1.clientLeft);\n"
2709             + "  log(d1.clientTop);\n"
2710             + "</script></body></html>";
2711         loadPageVerifyTitle2(html);
2712     }
2713 
2714     /**
2715      * @throws Exception if the test fails
2716      */
2717     @Test
2718     @Alerts({"4", "4"})
2719     public void clientLeftTopWithBorder() throws Exception {
2720         final String html = DOCTYPE_HTML
2721             + "<html><body>"
2722             + "<div id='div1' style='border: 4px solid black;'>hello</div><script>\n"
2723             + LOG_TITLE_FUNCTION
2724             + "  var d1 = document.getElementById('div1');\n"
2725             + "  log(d1.clientLeft);\n"
2726             + "  log(d1.clientTop);\n"
2727             + "</script></body></html>";
2728         loadPageVerifyTitle2(html);
2729     }
2730 
2731     /**
2732      * @throws Exception if the test fails
2733      */
2734     @Test
2735     @Alerts({"[object DOMRect]", "true", "true"})
2736     public void getBoundingClientRect() throws Exception {
2737         final String html = DOCTYPE_HTML
2738             + "<html><body>\n"
2739             + "<div id='div1'>hello</div><script>\n"
2740             + LOG_TITLE_FUNCTION
2741             + "  var d1 = document.getElementById('div1');\n"
2742             + "  var rect = d1.getBoundingClientRect();\n"
2743             + "  log(rect);\n"
2744             + "  log(rect instanceof DOMRect);\n"
2745             + "  log(rect instanceof DOMRectReadOnly);\n"
2746             + "</script></body></html>";
2747         loadPageVerifyTitle2(html);
2748     }
2749 
2750     /**
2751      * @throws Exception if the test fails
2752      */
2753     @Test
2754     @Alerts({"400", "100"})
2755     public void getBoundingClientRect2() throws Exception {
2756         final String html = DOCTYPE_HTML
2757             + "<html><head><script>\n"
2758             + LOG_TITLE_FUNCTION
2759             + "  function test() {\n"
2760             + "    var d1 = document.getElementById('div1');\n"
2761             + "    var pos = d1.getBoundingClientRect();\n"
2762             + "    log(pos.left);\n"
2763             + "    log(pos.top);\n"
2764             + "  }\n"
2765             + "</script></head><body onload='test()'>\n"
2766             + "<div id='outer' style='position: absolute; left: 400px; top: 100px; width: 50px; height: 80px;'>"
2767             + "<div id='div1'></div></div>"
2768             + "</body></html>";
2769         loadPageVerifyTitle2(html);
2770     }
2771 
2772     /**
2773      * @throws Exception if the test fails
2774      */
2775     @Test
2776     @Alerts({"0", "100", "100", "50"})
2777     public void getBoundingClientRect_Scroll() throws Exception {
2778         final String html = DOCTYPE_HTML
2779             + "<html><head><script>\n"
2780             + LOG_TITLE_FUNCTION
2781             + "  function test() {\n"
2782             + "    var d1 = document.getElementById('outer');\n"
2783             + "    d1.scrollTop = 150;\n"
2784             + "    var pos = d1.getBoundingClientRect();\n"
2785             + "    log(pos.left);\n"
2786             + "    log(pos.top);\n"
2787 
2788             + "    d1 = document.getElementById('div1');\n"
2789             + "    pos = d1.getBoundingClientRect();\n"
2790             + "    log(pos.left);\n"
2791             + "    log(pos.top);\n"
2792             + "  }\n"
2793             + "</script></head>\n"
2794             + "<body onload='test()'>\n"
2795             + "  <div id='outer' "
2796                + "style='position: absolute; height: 500px; width: 500px; top: 100px; left: 0px; overflow:auto'>\n"
2797             + "  <div id='div1' "
2798                + "style='position: absolute; height: 100px; width: 100px; top: 100px; left: 100px; z-index:99;'>"
2799                + "</div>\n"
2800             + "  <div id='div2' "
2801               + "style='position: absolute; height: 100px; width: 100px; top: 100px; left: 300px; z-index:99;'></div>\n"
2802             + "  <div style='position: absolute; top: 1000px;'>way down</div>\n"
2803             + "</div>"
2804             + "</body></html>";
2805         loadPageVerifyTitle2(html);
2806     }
2807 
2808     /**
2809      * @throws Exception if the test fails
2810      */
2811     @Test
2812     @Alerts({"[object DOMRect]", "0", "0"})
2813     public void getBoundingClientRectDisconnected() throws Exception {
2814         final String html = DOCTYPE_HTML
2815             + "<html>\n"
2816             + "<head><script>\n"
2817             + LOG_TITLE_FUNCTION
2818             + "  function test() {\n"
2819             + "    var d1 = document.createElement('div');\n"
2820             + "    try {\n"
2821             + "      var pos = d1.getBoundingClientRect();\n"
2822             + "      log(pos);\n"
2823             + "      log(pos.left);\n"
2824             + "      log(pos.top);\n"
2825             + "    } catch(e) { logEx(e);}\n"
2826             + "  }\n"
2827             + "</script>\n"
2828             + "</head>\n"
2829             + "<body onload='test()'>\n"
2830             + "</body></html>";
2831         loadPageVerifyTitle2(html);
2832     }
2833 
2834     /**
2835      * @throws Exception if the test fails
2836      */
2837     @Test
2838     @Alerts({"true", "true"})
2839     public void getBoundingClientRect_WidthPercent() throws Exception {
2840         final String html = DOCTYPE_HTML
2841             + "<html>\n"
2842             + "<head>\n"
2843             + "  <script>\n"
2844             + LOG_TITLE_FUNCTION
2845             + "    function test() {\n"
2846             + "      var input = document.getElementById('myInput');\n"
2847             + "      log(input.getBoundingClientRect().height > 10);\n"
2848             + "      log(input.getBoundingClientRect().width > 100);\n"
2849             + "    }\n"
2850             + "  </script>\n"
2851             + "</head>\n"
2852             + "<body onload='test()'>\n"
2853             + "<style>.full { width:100%; }</style>\n"
2854             + "<div class='foo bar'>\n"
2855             + "  <form action='javascript:void(0)' method='post'>\n"
2856             + "    <div class='full'>\n"
2857             + "      <input class='full' type='text' id='myInput'>\n"
2858             + "    </div>\n"
2859             + "  </form>\n"
2860             + "</div>\n"
2861             + "</body></html>";
2862         loadPageVerifyTitle2(html);
2863     }
2864 
2865     /**
2866      * @throws Exception if the test fails
2867      */
2868     @Test
2869     @Alerts({"[object DOMRectList]", "1"})
2870     public void getClientRects() throws Exception {
2871         final String html = DOCTYPE_HTML
2872             + "<html><head><script>\n"
2873             + LOG_TITLE_FUNCTION
2874             + "  function test() {\n"
2875             + "    var d1 = document.getElementById('div1');\n"
2876             + "    var rects = d1.getClientRects();\n"
2877             + "    log(rects);\n"
2878             + "    log(rects.length);\n"
2879             + "  }\n"
2880             + "</script></head>\n"
2881             + "<body onload='test()'>\n"
2882             + "  <div id='div1'/>\n"
2883             + "</body></html>";
2884         loadPageVerifyTitle2(html);
2885     }
2886 
2887     /**
2888      * @throws Exception if the test fails
2889      */
2890     @Test
2891     @Alerts({"[object DOMRectList]", "0"})
2892     public void getClientRectsDisconnected() throws Exception {
2893         final String html = DOCTYPE_HTML
2894             + "<html><head><script>\n"
2895             + LOG_TITLE_FUNCTION
2896             + "  function test() {\n"
2897             + "    var d1 = document.createElement('div');\n"
2898             + "    log(d1.getClientRects());\n"
2899             + "    log(d1.getClientRects().length);\n"
2900             + "  }\n"
2901             + "</script></head>\n"
2902             + "<body onload='test()'>\n"
2903             + "</body></html>";
2904         loadPageVerifyTitle2(html);
2905     }
2906 
2907     /**
2908      * @throws Exception if the test fails
2909      */
2910     @Test
2911     @Alerts({"[object DOMRectList]", "0", "[object DOMRectList]", "0"})
2912     public void getClientRectsDisplayNone() throws Exception {
2913         final String html = DOCTYPE_HTML
2914             + "<html><head><script>\n"
2915             + LOG_TITLE_FUNCTION
2916             + "  function test() {\n"
2917             + "    var d1 = document.getElementById('div1');\n"
2918             + "    display(d1);\n"
2919             + "    var d2 = document.getElementById('div2');\n"
2920             + "    display(d2);\n"
2921             + "  }\n"
2922             + "\n"
2923             + "  function display(elem) {\n"
2924             + "    log(elem.getClientRects());\n"
2925             + "    log(elem.getClientRects().length);\n"
2926             + "  }\n"
2927             + "</script></head>\n"
2928             + "<body onload='test()'>\n"
2929             + "  <div id='div1' style='display: none'>\n"
2930             + "    <div id='div2' />\n"
2931             + "  </div>\n"
2932             + "</body></html>";
2933         loadPageVerifyTitle2(html);
2934     }
2935 
2936     /**
2937      * @throws Exception if the test fails
2938      */
2939     @Test
2940     @Alerts({"[object DOMRectList]", "0"})
2941     public void getClientRectsInputHidden() throws Exception {
2942         final String html = DOCTYPE_HTML
2943             + "<html><head><script>\n"
2944             + LOG_TITLE_FUNCTION
2945             + "  function test() {\n"
2946             + "    var d1 = document.getElementById('hidden1');\n"
2947             + "    display(d1);\n"
2948             + "  }\n"
2949             + "\n"
2950             + "  function display(elem) {\n"
2951             + "    log(elem.getClientRects());\n"
2952             + "    log(elem.getClientRects().length);\n"
2953             + "  }\n"
2954             + "</script></head>\n"
2955             + "<body onload='test()'>\n"
2956             + "  <form>\n"
2957             + "    <input type='hidden' name='hidden' id='hidden1'></input>\n"
2958             + "  </form>\n"
2959             + "</body></html>";
2960         loadPageVerifyTitle2(html);
2961     }
2962 
2963     /**
2964      * @throws Exception if the test fails
2965      */
2966     @Test
2967     @Alerts({"[object DOMRectList]", "1"})
2968     public void getClientRectsInputText() throws Exception {
2969         final String html = DOCTYPE_HTML
2970             + "<html><head><script>\n"
2971             + LOG_TITLE_FUNCTION
2972             + "  function test() {\n"
2973             + "    var d1 = document.getElementById('text1');\n"
2974             + "    display(d1);\n"
2975             + "  }\n"
2976             + "\n"
2977             + "  function display(elem) {\n"
2978             + "    log(elem.getClientRects());\n"
2979             + "    log(elem.getClientRects().length);\n"
2980             + "  }\n"
2981             + "</script></head>\n"
2982             + "<body onload='test()'>\n"
2983             + "  <form>\n"
2984             + "    <input type='text' name='text' id='text1'></input>\n"
2985             + "  </form>\n"
2986             + "</body></html>";
2987         loadPageVerifyTitle2(html);
2988     }
2989 
2990     /**
2991      * @throws Exception if the test fails
2992      */
2993     @Test
2994     @Alerts({"[object DOMRectList]", "1"})
2995     @HtmlUnitNYI(FF = {"[object DOMRectList]", "0"},
2996             FF_ESR = {"[object DOMRectList]", "0"})
2997     public void getClientRectsArea() throws Exception {
2998         final String html = DOCTYPE_HTML
2999             + "<html><head><script>\n"
3000             + LOG_TITLE_FUNCTION
3001             + "  function test() {\n"
3002             + "    var d1 = document.getElementById('area1');\n"
3003             + "    display(d1);\n"
3004             + "  }\n"
3005             + "\n"
3006             + "  function display(elem) {\n"
3007             + "    log(elem.getClientRects());\n"
3008             + "    log(elem.getClientRects().length);\n"
3009             + "  }\n"
3010             + "</script></head>\n"
3011             + "<body onload='test()'>\n"
3012             + "  <img id='myImg' usemap='#imgmap'"
3013                     + " src='data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAA"
3014                     + "HElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg=='>\n"
3015             + "  <map id='myMap' name='imgmap'>\n"
3016             + "    <area id='area1' shape='rect' coords='0,0,1,1'>\n"
3017             + "  </map>\n"
3018             + "</body></html>";
3019         loadPageVerifyTitle2(html);
3020     }
3021 
3022     /**
3023      * @throws Exception if the test fails
3024      */
3025     @Test
3026     @Alerts({"null", "null"})
3027     public void innerHTML_parentNode() throws Exception {
3028         final String html = DOCTYPE_HTML
3029             + "<html><head><script>\n"
3030             + LOG_TITLE_FUNCTION
3031             + "  function test() {\n"
3032             + "    var div1 = document.createElement('div');\n"
3033             + "    log(div1.parentNode);\n"
3034             + "    div1.innerHTML = '<p>hello</p>';\n"
3035             + "    if(div1.parentNode)\n"
3036             + "      log(div1.parentNode.nodeName);\n"
3037             + "    else\n"
3038             + "      log(div1.parentNode);\n"
3039             + "  }\n"
3040             + "</script></head><body onload='test()'>\n"
3041             + "</body></html>";
3042         loadPageVerifyTitle2(html);
3043     }
3044 
3045     /**
3046      * @throws Exception if the test fails
3047      */
3048     @Test
3049     @Alerts({"null", "null"})
3050     public void innerText_parentNode() throws Exception {
3051         final String html = DOCTYPE_HTML
3052             + "<html><head><script>\n"
3053             + LOG_TITLE_FUNCTION
3054             + "  function test() {\n"
3055             + "    var div1 = document.createElement('div');\n"
3056             + "    log(div1.parentNode);\n"
3057             + "    div1.innerText = '<p>hello</p>';\n"
3058             + "    if(div1.parentNode)\n"
3059             + "      log(div1.parentNode.nodeName);\n"
3060             + "    else\n"
3061             + "      log(div1.parentNode);\n"
3062             + "  }\n"
3063             + "</script></head><body onload='test()'>\n"
3064             + "</body></html>";
3065         loadPageVerifyTitle2(html);
3066     }
3067 
3068     /**
3069      * @throws Exception if the test fails
3070      */
3071     @Test
3072     @Alerts({"true", "true", "true"})
3073     public void uniqueID() throws Exception {
3074         final String html = DOCTYPE_HTML
3075             + "<html><head><script>\n"
3076             + LOG_TITLE_FUNCTION
3077             + "  function test() {\n"
3078             + "    var div1 = document.getElementById('div1');\n"
3079             + "    var div2 = document.getElementById('div2');\n"
3080             + "    log(div1.uniqueID == undefined);\n"
3081             + "    log(div1.uniqueID == div1.uniqueID);\n"
3082             + "    log(div1.uniqueID == div2.uniqueID);\n"
3083             + "  }\n"
3084             + "</script></head><body onload='test()'>\n"
3085             + "  <div id='div1'/>\n"
3086             + "  <div id='div2'/>\n"
3087             + "</body></html>";
3088 
3089         loadPageVerifyTitle2(html);
3090     }
3091 
3092     /**
3093      * Tests if element.uniqueID starts with 'ms__id', and is lazily created.
3094      *
3095      * @throws Exception if the test fails
3096      */
3097     @Test
3098     @Alerts("undefined")
3099     public void uniqueIDFormatIE() throws Exception {
3100         final String html = DOCTYPE_HTML
3101             + "<html><head><script>\n"
3102             + LOG_TITLE_FUNCTION
3103             + "  function test() {\n"
3104             + "    var div1 = document.getElementById('div1');\n"
3105             + "    var div2 = document.getElementById('div2');\n"
3106             + "    var id2 = div2.uniqueID;\n"
3107             + "    //as id2 is retrieved before getting id1, id2 should be < id1;\n"
3108             + "    var id1 = div1.uniqueID;\n"
3109             + "    if (id1 === undefined) { log('undefined'); return }\n"
3110             + "    log(id1.substring(0, 6) == 'ms__id');\n"
3111             + "    var id1Int = parseInt(id1.substring(6, id1.length));\n"
3112             + "    var id2Int = parseInt(id2.substring(6, id2.length));\n"
3113             + "    log(id2Int < id1Int);\n"
3114             + "  }\n"
3115             + "</script></head><body onload='test()'>\n"
3116             + "  <div id='div1'/>\n"
3117             + "  <div id='div2'/>\n"
3118             + "</body></html>";
3119         loadPageVerifyTitle2(html);
3120     }
3121 
3122     /**
3123      * @throws Exception if an error occurs
3124      */
3125     @Test
3126     @Alerts("TypeError")
3127     public void setExpression() throws Exception {
3128         final String html = DOCTYPE_HTML
3129             + "<html><head><script>\n"
3130             + LOG_TITLE_FUNCTION
3131             + "  function test() {\n"
3132             + "    try {\n"
3133             + "      var div1 = document.getElementById('div1');\n"
3134             + "      div1.setExpression('title','id');\n"
3135             + "    } catch(e) { logEx(e); }\n"
3136             + "  }\n"
3137             + "</script></head><body onload='test()'>\n"
3138             + "  <div id='div1'/>\n"
3139             + "</body></html>";
3140         loadPageVerifyTitle2(html);
3141     }
3142 
3143     /**
3144      * @throws Exception if an error occurs
3145      */
3146     @Test
3147     @Alerts({"ex setExpression", "ex removeExpression"})
3148     public void removeExpression() throws Exception {
3149         final String html = DOCTYPE_HTML
3150             + "<html><head><script>\n"
3151             + LOG_TITLE_FUNCTION
3152             + "  function test() {\n"
3153             + "    var div1 = document.getElementById('div1');\n"
3154 
3155             + "    try {\n"
3156             + "      div1.setExpression('title','id');\n"
3157             + "    } catch(e) { log('ex setExpression'); }\n"
3158 
3159             + "    try {\n"
3160             + "      div1.removeExpression('title');\n"
3161             + "    } catch(e) { log('ex removeExpression'); }\n"
3162 
3163             + "  }\n"
3164             + "</script></head><body onload='test()'>\n"
3165             + "  <div id='div1'/>\n"
3166             + "</body></html>";
3167         loadPageVerifyTitle2(html);
3168     }
3169 
3170     /**
3171      * @throws Exception if an error occurs
3172      */
3173     @Test
3174     @Alerts("clicked")
3175     public void dispatchEvent() throws Exception {
3176         final String html = DOCTYPE_HTML
3177             + "<html><head>\n"
3178             + "<script>\n"
3179             + LOG_TITLE_FUNCTION
3180             + "function foo() {\n"
3181             + "  var e = document.createEvent('MouseEvents');\n"
3182             + "  e.initMouseEvent('click', true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);\n"
3183             + "  var d = document.getElementById('d');\n"
3184             + "  var canceled = !d.dispatchEvent(e);\n"
3185             + "}\n"
3186             + "</script></head>\n"
3187             + "<body onload='foo()'><div id='d' onclick='log(\"clicked\")'>foo</div></body>\n"
3188             + "</html>";
3189 
3190         loadPageVerifyTitle2(html);
3191     }
3192 
3193     /**
3194      * @throws Exception if an error occurs
3195      */
3196     @Test
3197     @Alerts(DEFAULT = {},
3198             FF = "page2 loaded",
3199             FF_ESR = "page2 loaded")
3200     public void dispatchEvent_submitOnForm() throws Exception {
3201         final String html = DOCTYPE_HTML
3202             + "<html>\n"
3203             + "<head><title>page 1</title></head>\n"
3204             + "<body>\n"
3205             + "<form action='page2' id='theForm'>\n"
3206             + "  <span id='foo'/>\n"
3207             + "</form>\n"
3208             + "<script>\n"
3209             + "  var e = document.createEvent('HTMLEvents');\n"
3210             + "  e.initEvent('submit', true, false);\n"
3211             + "  document.getElementById('theForm').dispatchEvent(e);\n"
3212             + "</script>\n"
3213             + "</body></html>";
3214 
3215         final String page2 = DOCTYPE_HTML
3216             + "<html><body><script>alert('page2 loaded');</script></body></html>";
3217 
3218         getMockWebConnection().setResponse(new URL(URL_FIRST, "page2"), page2);
3219         loadPageWithAlerts2(html);
3220     }
3221 
3222     /**
3223      * @throws Exception if an error occurs
3224      */
3225     @Test
3226     public void dispatchEvent_submitOnFormChild() throws Exception {
3227         final String html = DOCTYPE_HTML
3228             + "<html><head><title>page 1</title></head><body>\n"
3229             + "<form action='page2'><span id='foo'/></form>\n"
3230             + "<script>\n"
3231             + "try {\n"
3232             + "  var e = document.createEvent('HTMLEvents');\n"
3233             + "  e.initEvent('submit', true, false);\n"
3234             + "  document.getElementById('foo').dispatchEvent(e);\n"
3235             + "} catch(e) { alert('exception'); }\n"
3236             + "</script></body></html>";
3237 
3238         final WebDriver driver = loadPageWithAlerts2(html);
3239         assertTitle(driver, "page 1");
3240     }
3241 
3242     /**
3243      * @throws Exception if an error occurs
3244      */
3245     @Test
3246     @Alerts({"true", "true", "false"})
3247     public void hasAttribute() throws Exception {
3248         final String html = DOCTYPE_HTML
3249             + "<html>\n"
3250             + "<head>\n"
3251             + "<script>\n"
3252             + LOG_TITLE_FUNCTION
3253             + "  function test() {\n"
3254             + "    var elt = document.body;\n"
3255             + "    log(elt.hasAttribute('onload'));\n"
3256             + "    log(elt.hasAttribute('onLoad'));\n"
3257             + "    log(elt.hasAttribute('foo'));\n"
3258             + "  }\n"
3259             + "</script>\n"
3260             + "</head>\n"
3261             + "<body onload='test()'></body>\n"
3262             + "</html>";
3263         loadPageVerifyTitle2(html);
3264     }
3265 
3266     /**
3267      * @throws Exception if an error occurs
3268      */
3269     @Test
3270     @Alerts("function")
3271     public void hasAttributeTypeOf() throws Exception {
3272         final String html = DOCTYPE_HTML
3273             + "<html>\n"
3274             + "<head>\n"
3275             + "<script>\n"
3276             + LOG_TITLE_FUNCTION
3277             + "  function test() {\n"
3278             + "    var elt = document.body;\n"
3279             + "    log(typeof elt.hasAttribute);\n"
3280             + "  }\n"
3281             + "</script>\n"
3282             + "</head>\n"
3283             + "<body onload='test()'></body>\n"
3284             + "</html>";
3285         loadPageVerifyTitle2(html);
3286     }
3287 
3288     /**
3289      * @throws Exception if an error occurs
3290      */
3291     @Test
3292     @Alerts({"function", "true", "true", "false"})
3293     public void hasAttributeQuirksMode() throws Exception {
3294         final String html =
3295               "<html>\n"
3296             + "<head>\n"
3297             + "<script>\n"
3298             + LOG_TITLE_FUNCTION
3299             + "  function test() {\n"
3300             + "    var elt = document.body;\n"
3301             + "    log(typeof elt.hasAttribute);\n"
3302             + "    log(elt.hasAttribute('onload'));\n"
3303             + "    log(elt.hasAttribute('onLoad'));\n"
3304             + "    log(elt.hasAttribute('foo'));\n"
3305             + "  }\n"
3306             + "</script>\n"
3307             + "</head>\n"
3308             + "<body onload='test()'></body>\n"
3309             + "</html>";
3310         loadPageVerifyTitle2(html);
3311     }
3312 
3313     /**
3314      * @throws Exception if the test fails
3315      */
3316     @Test
3317     @Alerts({"undefined", "undefined", "undefined"})
3318     public void getComponentVersion() throws Exception {
3319         final String html = DOCTYPE_HTML
3320             + "<html><head><script>\n"
3321             + LOG_TITLE_FUNCTION
3322             + "function test() {\n"
3323             + "  log(document.body.cpuClass);\n"
3324             + "  document.body.style.behavior = 'url(#default#clientCaps)';\n"
3325             + "  log(document.body.cpuClass);\n"
3326             + "  if (document.body.getComponentVersion) {\n"
3327             + "    var ver=document.body.getComponentVersion('{E5D12C4E-7B4F-11D3-B5C9-0050045C3C96}','ComponentID');\n"
3328             + "    log(ver.length);\n"
3329             + "  }\n"
3330             + "  document.body.style.behavior = '';\n"
3331             + "  log(document.body.cpuClass);\n"
3332             + "}\n"
3333             + "</script></head><body onload='test()'>\n"
3334             + "</body></html>";
3335         loadPageVerifyTitle2(html);
3336     }
3337 
3338     /**
3339      * @throws Exception if an error occurs
3340      */
3341     @Test
3342     @Alerts({"36", "46"})
3343     public void clientWidthAndHeight() throws Exception {
3344         final String html = DOCTYPE_HTML
3345             + "<html><head><script>\n"
3346             + LOG_TITLE_FUNCTION
3347             + "  function test() {\n"
3348             + "    var myDiv = document.getElementById('myDiv');\n"
3349             + "    log(myDiv.clientWidth);\n"
3350             + "    log(myDiv.clientHeight);\n"
3351             + "  }\n"
3352             + "</script>\n"
3353             + "<style>#myDiv { width:30px; height:40px; padding:3px; border:5px; margin:7px; }</style>\n"
3354             + "</head>\n"
3355             + "<body onload='test()'>\n"
3356             + "  <div id='myDiv'/>\n"
3357             + "</body></html>";
3358         loadPageVerifyTitle2(html);
3359     }
3360 
3361     /**
3362      * @throws Exception if an error occurs
3363      */
3364     @Test
3365     @Alerts({"true", "true", "true", "true", "true"})
3366     public void clientWidthAndHeightPositionAbsolute() throws Exception {
3367         final String html = DOCTYPE_HTML
3368             + "<html><head><script>\n"
3369             + LOG_TITLE_FUNCTION
3370             + "  function test() {\n"
3371             + "    var div = document.getElementById('myDiv');\n"
3372             + "    var absDiv = document.getElementById('myAbsDiv');\n"
3373 
3374             // + "    log(div.clientWidth +', ' + absDiv.clientWidth);\n"
3375             + "    log(div.clientWidth > 100);\n"
3376             + "    log(absDiv.clientWidth > 10);\n"
3377             + "    log(absDiv.clientWidth < 100);\n"
3378 
3379             // + "    log(div.clientHeight +', ' + absDiv.clientHeight);\n"
3380             + "    log(div.clientHeight > 10);\n"
3381             + "    log(div.clientHeight == absDiv.clientHeight);\n"
3382             + "  }\n"
3383             + "</script>\n"
3384             + "</head>\n"
3385             + "<body onload='test()'>\n"
3386             + "  <div id='myDiv'>Test</div>\n"
3387             + "  <div id='myAbsDiv' style='position: absolute'>Test</div>\n"
3388             + "</body></html>";
3389         loadPageVerifyTitle2(html);
3390     }
3391 
3392     /**
3393      * @throws Exception if an error occurs
3394      */
3395     @Test
3396     @Alerts({"0", "0"})
3397     public void clientWidthAndHeightPositionAbsoluteEmpty() throws Exception {
3398         final String html = DOCTYPE_HTML
3399             + "<html><head><script>\n"
3400             + LOG_TITLE_FUNCTION
3401             + "  function test() {\n"
3402             + "    var absDiv = document.getElementById('myAbsDiv');\n"
3403             + "    log(absDiv.clientWidth);\n"
3404             + "    log(absDiv.clientHeight);\n"
3405             + "  }\n"
3406             + "</script>\n"
3407             + "</head>\n"
3408             + "<body onload='test()'>\n"
3409             + "  <div id='myAbsDiv' style='position: absolute'></div>\n"
3410             + "</body></html>";
3411         loadPageVerifyTitle2(html);
3412     }
3413 
3414     /**
3415      * @throws Exception if an error occurs
3416      */
3417     @Test
3418     @Alerts({"true", "true", "false", "true", "true", "true", "true", "true", "true", "true"})
3419     public void scrollWidthAndHeight() throws Exception {
3420         final String html = DOCTYPE_HTML
3421             + "<html><head><script>\n"
3422             + LOG_TITLE_FUNCTION
3423             + "  function test() {\n"
3424             + "    var myDiv = document.getElementById('myDiv');\n"
3425             + "    log(myDiv1.scrollWidth >= myDiv1.clientWidth);\n"
3426             + "    log(myDiv1.scrollHeight >= myDiv1.clientHeight);\n"
3427 
3428             + "    log(myDiv2.scrollWidth >= myDiv1.scrollWidth);\n"
3429             + "    log(myDiv2.scrollHeight >= myDiv1.scrollHeight);\n"
3430             + "    log(myDiv2.scrollWidth >= myDiv2.clientWidth);\n"
3431             + "    log(myDiv2.scrollHeight >= myDiv2.clientHeight);\n"
3432 
3433             + "    log(myDiv3.scrollWidth >= myDiv2.scrollWidth);\n"
3434             + "    log(myDiv3.scrollHeight >= myDiv2.scrollHeight);\n"
3435             + "    log(myDiv3.scrollWidth >= myDiv3.clientWidth);\n"
3436             + "    log(myDiv3.scrollHeight >= myDiv3.clientHeight);\n"
3437             + "  }\n"
3438             + "</script>\n"
3439             + "</head>\n"
3440             + "<body onload='test()'>\n"
3441             + "  <div id='myDiv1'/>\n"
3442             + "  <div id='myDiv2' style='height: 42px; width: 42px' />\n"
3443             + "  <div id='myDiv3' style='height: 7em; width: 7em' />\n"
3444             + "</body></html>";
3445         loadPageVerifyTitle2(html);
3446     }
3447 
3448     /**
3449      * @throws Exception if an error occurs
3450      */
3451     @Test
3452     @Alerts({"0", "0"})
3453     public void scrollWidthAndHeightDisplayNone() throws Exception {
3454         final String html = DOCTYPE_HTML
3455             + "<html><head><script>\n"
3456             + LOG_TITLE_FUNCTION
3457             + "  function test() {\n"
3458             + "    var myDiv = document.getElementById('myDiv');\n"
3459             + "    log(myDiv.scrollWidth);\n"
3460             + "    log(myDiv.scrollHeight);\n"
3461             + "  }\n"
3462             + "</script>\n"
3463             + "</head>\n"
3464             + "<body onload='test()'>\n"
3465             + "  <div id='myDiv' style='display: none;' />\n"
3466             + "</body></html>";
3467         loadPageVerifyTitle2(html);
3468     }
3469 
3470     /**
3471      * @throws Exception if an error occurs
3472      */
3473     @Test
3474     @Alerts({"0", "0"})
3475     public void scrollWidthAndHeightDetached() throws Exception {
3476         final String html = DOCTYPE_HTML
3477             + "<html><head><script>\n"
3478             + LOG_TITLE_FUNCTION
3479             + "  function test() {\n"
3480             + "    var myDiv = document.createElement('div');\n"
3481             + "    log(myDiv.scrollWidth);\n"
3482             + "    log(myDiv.scrollHeight);\n"
3483             + "  }\n"
3484             + "</script>\n"
3485             + "</head>\n"
3486             + "<body onload='test()'>\n"
3487             + "</body></html>";
3488         loadPageVerifyTitle2(html);
3489     }
3490 
3491     /**
3492      * Regression test for Bug #655.
3493      * @throws Exception if the test fails
3494      */
3495     @Test
3496     public void stackOverflowWithInnerHTML() throws Exception {
3497         final String html = DOCTYPE_HTML
3498             + "<html><head><title>Recursion</title></head>\n"
3499             + "<body>\n"
3500             + "<script>\n"
3501             + "     document.body.innerHTML = unescape(document.body.innerHTML);\n"
3502             + "</script></body></html>";
3503         final WebDriver driver = loadPageWithAlerts2(html);
3504         assertTitle(driver, "Recursion");
3505     }
3506 
3507     /**
3508      * Test setting the class for the element.
3509      * @throws Exception if the test fails
3510      */
3511     @Test
3512     @Alerts({"x", "null", "[object Attr]", "null", "x", "byClassname"})
3513     public void class_className_attribute() throws Exception {
3514         final String html = DOCTYPE_HTML
3515             + "<html><head>\n"
3516             + "<script>\n"
3517             + LOG_TITLE_FUNCTION
3518             + "function doTest() {\n"
3519             + "  var e = document.getElementById('pid');\n"
3520             + "  log(e.getAttribute('class'));\n"
3521             + "  log(e.getAttribute('className'));\n"
3522             + "  log(e.getAttributeNode('class'));\n"
3523             + "  log(e.getAttributeNode('className'));\n"
3524             + "  e.setAttribute('className', 'byClassname');\n"
3525             + "  log(e.getAttribute('class'));\n"
3526             + "  log(e.getAttribute('className'));\n"
3527             + "}\n"
3528             + "</script></head><body onload='doTest()'>\n"
3529             + "<p id='pid' class='x'>text</p>\n"
3530             + "</body></html>";
3531 
3532         loadPageVerifyTitle2(html);
3533     }
3534 
3535     /**
3536      * @throws Exception if the test fails
3537      */
3538     @Test
3539     @Alerts({"-undefined-x", "null-x-null", "null-[object Attr]-null", "null-[object Attr]-null",
3540              "x-byClassname", "[object Attr]-[object Attr]", "byClassname-byClassname", "[object Attr]-[object Attr]"})
3541     public void class_className_attribute2() throws Exception {
3542         final String html = DOCTYPE_HTML
3543             + "<html><head>\n"
3544             + "<script>\n"
3545             + LOG_TITLE_FUNCTION
3546             + "function doTest() {\n"
3547             + "  var e = document.getElementById('pid');\n"
3548             + "  log(e['lang'] + '-' + e['class'] + '-' + e['className']);\n"
3549             + "  log(e.getAttribute('lang') + '-' + e.getAttribute('class') + '-' + e.getAttribute('className'));\n"
3550             + "  log(e.getAttributeNode('lang') + '-' + e.getAttributeNode('class') + '-' + "
3551             + "e.getAttributeNode('className'));\n"
3552             + "  log(e.attributes.getNamedItem('lang') + '-' + e.attributes.getNamedItem('class') + '-' + "
3553             + "e.attributes.getNamedItem('className'));\n"
3554             + "  e.setAttribute('className', 'byClassname');\n"
3555             + "  log(e.getAttribute('class') + '-' + e.getAttribute('className'));\n"
3556             + "  log(e.getAttributeNode('class') + '-' + e.getAttributeNode('className'));\n"
3557             + "  e.setAttribute('class', 'byClassname');\n"
3558             + "  log(e.getAttribute('class') + '-' + e.getAttribute('className'));\n"
3559             + "  log(e.getAttributeNode('class') + '-' + e.getAttributeNode('className'));\n"
3560             + "}\n"
3561             + "</script></head><body onload='doTest()'>\n"
3562             + "<p id='pid' class='x'>text</p>\n"
3563             + "</body></html>";
3564 
3565         loadPageVerifyTitle2(html);
3566     }
3567 
3568     /**
3569      * @throws Exception if the test fails
3570      */
3571     @Test
3572     @Alerts({"true", "true", "true", "false", "false", "false", "false", "true", "true", "false", "false"})
3573     public void contains() throws Exception {
3574         final String html = DOCTYPE_HTML
3575             + "<html><head>\n"
3576             + "<script>\n"
3577             + LOG_TITLE_FUNCTION
3578             + "function test() {\n"
3579             + "try {\n"
3580             + "  var div1 = document.getElementById('div1');\n"
3581             + "  var div2 = document.getElementById('div2');\n"
3582             + "  var text = div2.firstChild;\n"
3583             + "  var div3 = document.getElementById('div3');\n"
3584             + "  log(div1.contains(div1));\n"
3585             + "  log(div1.contains(div2));\n"
3586             + "  log(div1.contains(div3));\n"
3587             + "  log(div1.contains(div4));\n"
3588             + "  log(div2.contains(div1));\n"
3589             + "  log(div3.contains(div1));\n"
3590             + "  log(div4.contains(div1));\n"
3591             + "  log(div2.contains(div3));\n"
3592             + "  log(div2.contains(text));\n"
3593             + "  log(div3.contains(text));\n"
3594             + "  log(text.contains(div3));\n"
3595             + "} catch(e) { logEx(e); }\n"
3596             + "}\n"
3597             + "</script></head><body onload='test()'>\n"
3598             + "<div id='div1'>\n"
3599             + "  <div id='div2'>hello\n"
3600             + "    <div id='div3'>\n"
3601             + "    </div>\n"
3602             + "  </div>\n"
3603             + "</div>\n"
3604             + "<div id='div4'>\n"
3605             + "</div>\n"
3606             + "</body></html>";
3607 
3608         loadPageVerifyTitle2(html);
3609     }
3610 
3611     /**
3612      * @throws Exception if the test fails
3613      */
3614     @Test
3615     @Alerts({"exception[]", "false", "false"})
3616     public void contains_invalid_argument() throws Exception {
3617         final String html = DOCTYPE_HTML
3618             + "<html><body><script>\n"
3619             + LOG_TITLE_FUNCTION
3620 
3621             + "try {\n"
3622             + "  log(document.body.contains([]));\n"
3623             + "} catch(e) { log('exception[]'); }\n"
3624 
3625             + "try {\n"
3626             + "  log(document.body.contains(null));\n"
3627             + "} catch(e) { log('exception null'); }\n"
3628 
3629             + "try {\n"
3630             + "  log(document.body.contains(undefined));\n"
3631             + "} catch(e) { log('exception undefined'); }\n"
3632 
3633             + "</script></body></html>";
3634 
3635         loadPageVerifyTitle2(html);
3636     }
3637 
3638     /**
3639      * @throws Exception if the test fails
3640      */
3641     @Test
3642     @Alerts("undefined")
3643     public void filters() throws Exception {
3644         final String html = DOCTYPE_HTML
3645             + "<html><head>\n"
3646             + "<script>\n"
3647             + LOG_TITLE_FUNCTION
3648             + "function test() {\n"
3649             + "  var div1 = document.getElementById('div1');\n"
3650             + "  var defined = typeof(div1.filters) != 'undefined';\n"
3651             + "  log(defined ? 'defined' : 'undefined');\n"
3652             + "}\n"
3653             + "</script></head><body onload='test()'>\n"
3654             + "<div id='div1'>\n"
3655             + "</div>\n"
3656             + "</body></html>";
3657 
3658         loadPageVerifyTitle2(html);
3659     }
3660 
3661     /**
3662      * @throws Exception if the test fails
3663      */
3664     @Test
3665     @Alerts({">#myClass#<", ">#myId##<"})
3666     public void attributes_trimmed() throws Exception {
3667         final String html = DOCTYPE_HTML
3668             + "<html><head>\n"
3669             + "<script>\n"
3670             + "function log(msg) { window.document.title += msg.replace(/\\s/g, '#') + '§';}\n"
3671             + "function test() {\n"
3672             + "  var div1 = document.body.firstChild;\n"
3673             + "  log('>' + div1.className + '<');\n"
3674             + "  log('>' + div1.id + '<');\n"
3675             + "}\n"
3676             + "</script></head><body onload='test()'>"
3677             + "<div id=' myId  ' class=' myClass '>\n"
3678             + "hello"
3679             + "</div>\n"
3680             + "</body></html>";
3681 
3682         loadPageVerifyTitle2(html);
3683     }
3684 
3685     /**
3686      * @throws Exception if the test fails
3687      */
3688     @Test
3689     @Alerts({"function", "* => body: 0, div1: 0", "foo => body: 3, div1: 1", "foo red => body: 1, div1: 0",
3690              "red foo => body: 1, div1: 0", "blue foo => body: 0, div1: 0", "null => body: 0, div1: 0"})
3691     public void getElementsByClassName() throws Exception {
3692         final String html = DOCTYPE_HTML
3693             + "<html><head><script>\n"
3694             + LOG_TITLE_FUNCTION
3695             + "function test(x) {\n"
3696             + "  var b = document.body;\n"
3697             + "  var div1 = document.getElementById('div1');\n"
3698             + "  var s = x + ' => body: ' + b.getElementsByClassName(x).length;\n"
3699             + "  s += ', div1: ' + div1.getElementsByClassName(x).length;\n"
3700             + "  log(s);\n"
3701             + "}\n"
3702             + "function doTest() {\n"
3703             + "  var b = document.body;\n"
3704             + "  var div1 = document.getElementById('div1');\n"
3705             + "  log(typeof document.body.getElementsByClassName);\n"
3706             + "  test('*');\n"
3707             + "  test('foo');\n"
3708             + "  test('foo red');\n"
3709             + "  test('red foo');\n"
3710             + "  test('blue foo');\n"
3711             + "  test(null);\n"
3712             + "}\n"
3713             + "</script></head><body onload='doTest()'>\n"
3714             + "<div class='foo' id='div1'>\n"
3715             + "  <span class='c2'>hello</span>\n"
3716             + "  <span class='foo' id='span2'>World!</span>\n"
3717             + "</div>\n"
3718             + "<span class='foo red' id='span3'>again</span>\n"
3719             + "<span class='red' id='span4'>bye</span>\n"
3720             + "</body></html>";
3721 
3722         loadPageVerifyTitle2(html);
3723     }
3724 
3725     /**
3726      * @throws Exception if the test fails
3727      */
3728     @Test
3729     @Alerts({"null", "[object HTMLDivElement]"})
3730     public void parentElement2() throws Exception {
3731         final String html = DOCTYPE_HTML
3732             + "<html><head>\n"
3733             + "<script>\n"
3734             + LOG_TITLE_FUNCTION
3735             + "function test() {\n"
3736             + "  var fragment = document.createDocumentFragment();\n"
3737             + "  var div = document.createElement('div');\n"
3738             + "  var bold = document.createElement('b');\n"
3739             + "  fragment.appendChild(div);\n"
3740             + "  div.appendChild(bold);\n"
3741             + "  log(div.parentElement);\n"
3742             + "  log(bold.parentElement);\n"
3743             + "}\n"
3744             + "</script></head><body onload='test()'>\n"
3745             + "</body></html>";
3746 
3747         loadPageVerifyTitle2(html);
3748     }
3749 
3750     /**
3751      * The method doScroll() should throw an exception if document is not yet loaded,
3752      * have a look into <a href="http://javascript.nwbox.com/IEContentLoaded/">this</a>.
3753      * @throws Exception if the test fails
3754      */
3755     @Test
3756     @Alerts({"TypeError", "TypeError"})
3757     public void doScroll() throws Exception {
3758         final String html = DOCTYPE_HTML
3759             + "<html><head>\n"
3760             + "<script>\n"
3761             + LOG_TITLE_FUNCTION
3762             + "function test() {\n"
3763             + "  try {\n"
3764             + "    document.documentElement.doScroll('left');\n"
3765             + "    log('success');\n"
3766             + "  } catch(e) { logEx(e); }\n"
3767             + "}\n"
3768             + "test();\n"
3769             + "</script></head><body onload='test()'>\n"
3770             + "</body></html>";
3771 
3772         loadPageVerifyTitle2(html);
3773     }
3774 
3775     /**
3776      * @throws Exception if the test fails
3777      */
3778     @Test
3779     @Alerts("removeNode not available")
3780     public void removeNode() throws Exception {
3781         final String html = DOCTYPE_HTML
3782             + "<html><head>\n"
3783             + "<script>\n"
3784             + LOG_TITLE_FUNCTION
3785             + "function test() {\n"
3786             + "  var div1 = document.getElementById('div1');\n"
3787             + "  var div2 = document.getElementById('div2');\n"
3788             + "  if (!div2.removeNode) { log('removeNode not available'); return }\n"
3789 
3790             + "  log(div1.firstChild.id);\n"
3791             + "  log(div2.removeNode().firstChild);\n"
3792             + "  log(div1.firstChild.id);\n"
3793             + "  log(div1.firstChild.nextSibling.id);\n"
3794             + "\n"
3795             + "  var div5 = document.getElementById('div5');\n"
3796             + "  var div6 = document.getElementById('div6');\n"
3797             + "  log(div5.firstChild.id);\n"
3798             + "  log(div6.removeNode(true).firstChild.id);\n"
3799             + "  log(div5.firstChild);\n"
3800             + "}\n"
3801             + "</script></head><body onload='test()'>\n"
3802             + "  <div id='div1'><div id='div2'><div id='div3'></div><div id='div4'></div></div></div>\n"
3803             + "  <div id='div5'><div id='div6'><div id='div7'></div><div id='div8'></div></div></div>\n"
3804             + "</body></html>";
3805 
3806         loadPageVerifyTitle2(html);
3807     }
3808 
3809     /**
3810      * @throws Exception if the test fails
3811      */
3812     @Test
3813     @Alerts({"undefined", "false", "hello", "true"})
3814     public void access__proto__() throws Exception {
3815         final String html = DOCTYPE_HTML
3816             + "<html><head>\n"
3817             + "<script>\n"
3818             + LOG_TITLE_FUNCTION
3819             + "function test() {\n"
3820             + "  var div1 = document.createElement('div');\n"
3821             + "  log(div1.myProp);\n"
3822             + "  var p1 = div1['__proto__'];\n"
3823             + "  log(p1 == undefined);\n"
3824             + "  if (p1)\n"
3825             + "    p1.myProp = 'hello';\n"
3826             + "  log(div1.myProp);\n"
3827             + "  log(p1 !== document.createElement('form')['__proto__']);\n"
3828             + "}\n"
3829             + "</script></head><body onload='test()'>\n"
3830             + "</body></html>";
3831 
3832         loadPageVerifyTitle2(html);
3833     }
3834 
3835     /**
3836      * @throws Exception if the test fails
3837      */
3838     @Test
3839     @Alerts({"false,false,false,false,false,true,false", "clearAttributes not available"})
3840     public void clearAttributes() throws Exception {
3841         final String html = DOCTYPE_HTML
3842             + "<html><head>\n"
3843             + "<script>\n"
3844             + LOG_TITLE_FUNCTION
3845             + "  function u(o) { return typeof o == 'undefined'; }\n"
3846             + "</script></head>\n"
3847             + "<body>\n"
3848             + "  <input type='text' id='i' name='i' style='color:red' onclick='log(1)' custom1='a' />\n"
3849             + "  <script>\n"
3850             + "    var i = document.getElementById('i');\n"
3851             + "    i.custom2 = 'b';\n"
3852             + "    log([u(i.type), u(i.id), u(i.name), u(i.style), u(i.onclick),"
3853             + "           u(i.custom1), u(i.custom2)].join(','));\n"
3854             + "    if(i.clearAttributes) {\n"
3855             + "      log([u(i.type), u(i.id), u(i.name), u(i.style), u(i.onclick),"
3856             + "             u(i.custom1), u(i.custom2)].join(','));\n"
3857             + "    } else {\n"
3858             + "      log('clearAttributes not available');\n"
3859             + "    }\n"
3860             + "  </script>\n"
3861             + "</body></html>";
3862         loadPageVerifyTitle2(html);
3863     }
3864 
3865     /**
3866      * @throws Exception if the test fails
3867      */
3868     @Test
3869     @Alerts("mergeAttributes not available")
3870     public void mergeAttributes() throws Exception {
3871         mergeAttributesTest("i2");
3872     }
3873 
3874     /**
3875      * @throws Exception if the test fails
3876      */
3877     @Test
3878     @Alerts("mergeAttributes not available")
3879     public void mergeAttributesTrue() throws Exception {
3880         mergeAttributesTest("i2, true");
3881     }
3882 
3883     /**
3884      * @throws Exception if the test fails
3885      */
3886     @Test
3887     @Alerts("mergeAttributes not available")
3888     public void mergeAttributesfalse() throws Exception {
3889         mergeAttributesTest("i2, false");
3890     }
3891 
3892     private void mergeAttributesTest(final String params) throws Exception {
3893         final String html = DOCTYPE_HTML
3894             + "<html><head><script>\n"
3895             + LOG_TITLE_FUNCTION
3896             + "  function u(o) { return typeof o == 'undefined'; }\n"
3897             + "</script></head>\n"
3898             + "<body>"
3899             + "<input type='text' id='i' />\n"
3900             + "<input type='text' id='i2' name='i2' style='color:red' onclick='log(1)' custom1='a' />\n"
3901             + "<script>\n"
3902             + "function u(o) { return typeof o == 'undefined'; }\n"
3903             + "  var i = document.getElementById('i');\n"
3904             + "  if (i.mergeAttributes) {\n"
3905             + "    var i2 = document.getElementById('i2');\n"
3906             + "    i2.custom2 = 'b';\n"
3907             + "    log([u(i.type), u(i.id), u(i.name), u(i.style), u(i.onclick),"
3908             + "           u(i.custom1), u(i.custom2)].join(','));\n"
3909             + "    log(i.id);\n"
3910             + "    log(i.name);\n"
3911             + "    i.mergeAttributes(" + params + ");\n"
3912             + "    log([u(i.type), u(i.id), u(i.name), u(i.style), u(i.onclick),"
3913             + "           u(i.custom1), u(i.custom2)].join(','));\n"
3914             + "    log(i.id);\n"
3915             + "    log(i.name);\n"
3916             + "  } else {\n"
3917             + "    log('mergeAttributes not available');\n"
3918             + "  }\n"
3919             + "</script>";
3920 
3921         loadPageVerifyTitle2(html);
3922     }
3923 
3924     /**
3925      * @throws Exception if the test fails
3926      */
3927     @Test
3928     @Alerts("false")
3929     public void document() throws Exception {
3930         final String html = DOCTYPE_HTML
3931             + "<html><head>\n"
3932             + "<script>\n"
3933             + LOG_TITLE_FUNCTION
3934             + "function test() {\n"
3935             + "  log(document.body.document === document);\n"
3936             + "}\n"
3937             + "</script></head><body onload='test()'>\n"
3938             + "</body></html>";
3939 
3940         loadPageVerifyTitle2(html);
3941     }
3942 
3943     /**
3944      * @throws Exception if the test fails
3945      */
3946     @Test
3947     @Alerts({"TypeError", "TypeError"})
3948     public void prototype_innerHTML() throws Exception {
3949         final String html = DOCTYPE_HTML
3950             + "<html><body>\n"
3951             + "<script>\n"
3952             + LOG_TITLE_FUNCTION
3953             + "try {\n"
3954             + "  log(HTMLElement.prototype.innerHTML);\n"
3955             + "} catch(e) { logEx(e); }\n"
3956             + "try {\n"
3957             + "  var myFunc = function() {};\n"
3958             + "  HTMLElement.prototype.innerHTML = myFunc;\n"
3959             + "  log(HTMLElement.prototype.innerHTML == myFunc);\n"
3960             + "} catch(e) { logEx(e); }\n"
3961             + "</script>\n"
3962             + "</body></html>";
3963         loadPageVerifyTitle2(html);
3964     }
3965 
3966     /**
3967      * @throws Exception if an error occurs
3968      */
3969     @Test
3970     @Alerts({"", "#0000aa", "x", "BlanchedAlmond", "aBlue", "bluex"})
3971     public void setColorAttribute() throws Exception {
3972         final String html = DOCTYPE_HTML
3973             + "<html>\n"
3974             + "  <head>\n"
3975             + "    <script>\n"
3976             + LOG_TITLE_FUNCTION
3977             + "      function test() {\n"
3978             + "        var b = document.getElementById('body');\n"
3979             + "        log(b.vLink);\n"
3980             + "        document.vlinkColor = '#0000aa';\n"
3981             + "        log(b.vLink);\n"
3982             + "        document.vlinkColor = 'x';\n"
3983             + "        log(b.vLink);\n"
3984             + "        document.vlinkColor = 'BlanchedAlmond';\n"
3985             + "        log(b.vLink);\n"
3986             + "        document.vlinkColor = 'aBlue';\n"
3987             + "        log(b.vLink);\n"
3988             + "        document.vlinkColor = 'bluex';\n"
3989             + "        log(b.vLink);\n"
3990             + "      }\n"
3991             + "    </script>\n"
3992             + "  </head>\n"
3993             + "  <body id='body' onload='test()'>blah</body>\n"
3994             + "</html>";
3995         loadPageVerifyTitle2(html);
3996     }
3997 
3998     /**
3999      * @throws Exception if the test fails
4000      */
4001     @Test
4002     @Alerts("<span onclick=\"var f = &quot;hello&quot; + 'world'\">test span</span>")
4003     public void innerHTMLwithQuotes() throws Exception {
4004         final String html = DOCTYPE_HTML
4005             + "<html>\n"
4006             + "<head>\n"
4007             + "  <script>\n"
4008             + LOG_TITLE_FUNCTION
4009             + "    function test() {\n"
4010             + "      log(document.getElementById('foo').innerHTML);\n"
4011             + "    }\n"
4012             + "  </script>\n"
4013             + "</head><body onload='test()'>\n"
4014             + "  <div id='foo'><span onclick=\"var f = &quot;hello&quot; + 'world'\">test span</span></div>\n"
4015             + "</body></html>";
4016 
4017         loadPageVerifyTitle2(html);
4018     }
4019 
4020     /**
4021      * @throws Exception if the test fails
4022      */
4023     @Test
4024     @Alerts({"button", "null", "false", "true"})
4025     public void attributeNS() throws Exception {
4026         final String html = DOCTYPE_HTML
4027             + "<html><head>\n"
4028             + "<script>\n"
4029             + LOG_TITLE_FUNCTION
4030             + "  function test() {\n"
4031             + "    var e = document.getElementById('foo');\n"
4032             + "    log(e.getAttribute('type'));\n"
4033             + "    try {\n"
4034             + "      log(e.getAttributeNS('bar', 'type'));\n"
4035             + "      log(e.hasAttributeNS('bar', 'type'));\n"
4036             + "      e.removeAttributeNS('bar', 'type');\n"
4037             + "      log(e.hasAttribute('type'));\n"
4038             + "    } catch(e) { log('getAttributeNS() not supported') }\n"
4039             + "  }\n"
4040             + "</script>\n"
4041             + "</head>\n"
4042             + "<body onload='test()'>\n"
4043             + "  <input id='foo' type='button' value='someValue'>\n"
4044             + "</body></html>";
4045 
4046         loadPageVerifyTitle2(html);
4047     }
4048 
4049     /**
4050      * @throws Exception if the test fails
4051      */
4052     @Test
4053     @Alerts("[object DOMStringMap]")
4054     public void dataset() throws Exception {
4055         final String html = DOCTYPE_HTML
4056             + "<html><head>\n"
4057             + "<script>\n"
4058             + LOG_TITLE_FUNCTION
4059             + "  function test() {\n"
4060             + "    log(document.body.dataset);\n"
4061             + "  }\n"
4062             + "</script>\n"
4063             + "</head>\n"
4064             + "<body onload='test()'>\n"
4065             + "</body></html>";
4066 
4067         loadPageVerifyTitle2(html);
4068     }
4069 
4070     /**
4071      * @throws Exception on test failure
4072      */
4073     @Test
4074     @Alerts("")
4075     public void setAttribute_className() throws Exception {
4076         final String html = DOCTYPE_HTML
4077             + "<html><head>\n"
4078             + "<script>\n"
4079             + LOG_TITLE_FUNCTION
4080             + "  function test() {\n"
4081             + "    var div = document.createElement('div');\n"
4082             + "    div.setAttribute('className', 't');\n"
4083             + "    log(div.className);\n"
4084             + "  }\n"
4085             + "</script>\n"
4086             + "</head>\n"
4087             + "<body onload='test()'></body></html>";
4088 
4089         loadPageVerifyTitle2(html);
4090     }
4091 
4092     /**
4093      * @throws Exception on test failure
4094      */
4095     @Test
4096     @Alerts("t")
4097     public void setAttribute_class() throws Exception {
4098         final String html = DOCTYPE_HTML
4099             + "<html><head>\n"
4100             + "<script>\n"
4101             + LOG_TITLE_FUNCTION
4102             + "  function test() {\n"
4103             + "    var div = document.createElement('div');\n"
4104             + "    div.setAttribute('class', 't');\n"
4105             + "    log(div.className);\n"
4106             + "  }\n"
4107             + "</script>\n"
4108             + "</head>\n"
4109             + "<body onload='test()'></body></html>";
4110 
4111         loadPageVerifyTitle2(html);
4112     }
4113 
4114     /**
4115      * @throws Exception on test failure
4116      */
4117     @Test
4118     @Alerts("")
4119     public void setAttribute_className_standards() throws Exception {
4120         final String html = DOCTYPE_HTML
4121             + "<html><head>\n"
4122             + "<script>\n"
4123             + LOG_TITLE_FUNCTION
4124             + "  function test() {\n"
4125             + "    var div = document.createElement('div');\n"
4126             + "    div.setAttribute('className', 't');\n"
4127             + "    log(div.className);\n"
4128             + "  }\n"
4129             + "</script>\n"
4130             + "</head>\n"
4131             + "<body onload='test()'></body></html>";
4132 
4133         loadPageVerifyTitle2(html);
4134     }
4135 
4136     /**
4137      * @throws Exception on test failure
4138      */
4139     @Test
4140     @Alerts("t")
4141     public void setAttribute_class_standards() throws Exception {
4142         final String html = DOCTYPE_HTML
4143             + "<html><head>\n"
4144             + "<script>\n"
4145             + LOG_TITLE_FUNCTION
4146             + "  function test() {\n"
4147             + "    var div = document.createElement('div');\n"
4148             + "    div.setAttribute('class', 't');\n"
4149             + "    log(div.className);\n"
4150             + "  }\n"
4151             + "</script>\n"
4152             + "</head>\n"
4153             + "<body onload='test()'></body></html>";
4154 
4155         loadPageVerifyTitle2(html);
4156     }
4157 
4158     /**
4159      * @throws Exception on test failure
4160      */
4161     @Test
4162     @Alerts({"null", "", "null", "undefined"})
4163     public void getAttribute2() throws Exception {
4164         final String html = DOCTYPE_HTML
4165                 + "<html>\n"
4166                 + "<head>\n"
4167                 + "  <script>\n"
4168                 + LOG_TITLE_FUNCTION
4169                 + "  function doTest() {\n"
4170                 + "    var form = document.getElementById('testForm');\n"
4171                 + "    log(form.getAttribute('target'));\n"
4172                 + "    log(form.target);\n"
4173                 + "    log(form.getAttribute('target222'));\n"
4174                 + "    log(form.target222);\n"
4175                 + "  }\n"
4176                 + "  </script>\n"
4177                 + "</head>\n"
4178                 + "<body onload='doTest()'>\n"
4179                 + "<form id='testForm' action='#' method='get'>\n"
4180                 + "</form>\n"
4181                 + "</body>\n"
4182                 + "</html>";
4183 
4184         loadPageVerifyTitle2(html);
4185     }
4186 
4187     /**
4188      * @throws Exception on test failure
4189      */
4190     @Test
4191     @Alerts({"null", "", "null", "undefined"})
4192     public void getAttribute2_standards() throws Exception {
4193         final String html = DOCTYPE_HTML
4194                 + "<html>\n"
4195                 + "<head>\n"
4196                 + "  <script>\n"
4197                 + LOG_TITLE_FUNCTION
4198                 + "  function doTest() {\n"
4199                 + "    var form = document.getElementById('testForm');\n"
4200                 + "    log(form.getAttribute('target'));\n"
4201                 + "    log(form.target);\n"
4202                 + "    log(form.getAttribute('target222'));\n"
4203                 + "    log(form.target222);\n"
4204                 + "  }\n"
4205                 + "  </script>\n"
4206                 + "</head>\n"
4207                 + "<body onload='doTest()'>\n"
4208                 + "<form id='testForm' action='#' method='get'>\n"
4209                 + "</form>\n"
4210                 + "</body>\n"
4211                 + "</html>";
4212 
4213         loadPageVerifyTitle2(html);
4214     }
4215 
4216     /**
4217      * @throws Exception if the test fails
4218      */
4219     @Test
4220     @Alerts({"DIV", "SECTION", "<div></div>", "<section></section>"})
4221     public void nodeNameVsOuterElement() throws Exception {
4222         final String html = DOCTYPE_HTML
4223             + "<html>\n"
4224             + "<head>\n"
4225             + "  <script>\n"
4226             + LOG_TITLE_FUNCTION
4227             + "    function test() {\n"
4228             + "      log(document.createElement('div').tagName);\n"
4229             + "      log(document.createElement('section').tagName);\n"
4230             + "      log(document.createElement('div').cloneNode( true ).outerHTML);\n"
4231             + "      log(document.createElement('section').cloneNode( true ).outerHTML);\n"
4232             + "    }\n"
4233             + "  </script>\n"
4234             + "</head><body onload='test()'>\n"
4235             + "</body></html>";
4236 
4237         loadPageVerifyTitle2(html);
4238     }
4239 
4240     /**
4241      * @throws Exception if the test fails
4242      */
4243     @Test
4244     @Alerts({"null", "ho"})
4245     public void getSetAttribute_in_xml() throws Exception {
4246         final String html = DOCTYPE_HTML
4247             + "<html><head><script>\n"
4248             + LOG_TITLE_FUNCTION
4249             + "  function test() {\n"
4250             + "    var text='<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\\n';\n"
4251             + "    text += '<xsl:stylesheet version=\"1.0\" xmlns:xsl=\"http://myNS\">\\n';\n"
4252             + "    text += '  <xsl:template match=\"/\">\\n';\n"
4253             + "    text += \"  <html xmlns='http://www.w3.org/1999/xhtml'>\\n\";\n"
4254             + "    text += '    <body>\\n';\n"
4255             + "    text += '    </body>\\n';\n"
4256             + "    text += '  </html>\\n';\n"
4257             + "    text += '  </xsl:template>\\n';\n"
4258             + "    text += '</xsl:stylesheet>';\n"
4259 
4260             + "    var parser=new DOMParser();\n"
4261             + "    var doc=parser.parseFromString(text,'text/xml');\n"
4262 
4263             + "    var elem = doc.documentElement.getElementsByTagName('html').item(0);\n"
4264             + "    log(elem.getAttribute('hi'));\n"
4265             + "    elem.setAttribute('hi', 'ho');\n"
4266             + "    log(elem.getAttribute('hi'));\n"
4267             + "  }\n"
4268             + "</script></head><body onload='test()'>\n"
4269             + "</body></html>";
4270 
4271         loadPageVerifyTitle2(html);
4272     }
4273 
4274     /**
4275      * @throws Exception if the test fails
4276      */
4277     @Test
4278     @Alerts({"[object Text]", "[object Text]"})
4279     public void textContentShouldNotDetachNestedNode() throws Exception {
4280         final String html = DOCTYPE_HTML
4281             + "<html><body><div><div id='it'>foo</div></div><script>\n"
4282             + LOG_TITLE_FUNCTION
4283             + "  var elt = document.getElementById('it');\n"
4284             + "  log(elt.firstChild);\n"
4285             + "  elt.parentNode.textContent = '';\n"
4286             + "  log(elt.firstChild);\n"
4287             + "</script></body></html>";
4288 
4289         loadPageVerifyTitle2(html);
4290     }
4291 
4292     /**
4293      * @throws Exception if the test fails
4294      */
4295     @Test
4296     @Alerts("<svg id=\"svgElem2\"></svg>")
4297     public void innerHTML_svg() throws Exception {
4298         final String html = DOCTYPE_HTML
4299                 + "<html>\n"
4300                 + "<head>\n"
4301                 + "  <script>\n"
4302                 + LOG_TITLE_FUNCTION
4303                 + "    function test() {\n"
4304                 + "      var div = document.createElement('div');\n"
4305                 + "      document.body.appendChild(div);\n"
4306                 + "      var svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');\n"
4307                 + "      svg.setAttribute('id', 'svgElem2');\n"
4308                 + "      div.appendChild(svg);\n"
4309                 + "      log(div.innerHTML);\n"
4310                 + "    }\n"
4311                 + "  </script>\n"
4312                 + "</head><body onload='test()'>\n"
4313                 + "</body></html>";
4314 
4315         loadPageVerifyTitle2(html);
4316     }
4317 
4318     /**
4319      * @throws Exception if the test fails
4320      */
4321     @Test
4322     @Alerts("executed")
4323     public void appendChildExecuteJavaScript() throws Exception {
4324         final String html = DOCTYPE_HTML
4325             + "<html><head><script>\n"
4326             + LOG_TITLE_FUNCTION
4327             + "  function test() {\n"
4328             + "    var newnode = document.createElement('script');\n"
4329             + "    try {\n"
4330             + "      newnode.appendChild(document.createTextNode('alerter();'));\n"
4331             + "      var outernode = document.getElementById('myNode');\n"
4332             + "      outernode.appendChild(newnode);\n"
4333             + "    } catch(e) { logEx(e); }\n"
4334             + "  }\n"
4335             + "  function alerter() {\n"
4336             + "    log('executed');\n"
4337             + "  }\n"
4338             + "</script></head><body onload='test()'>\n"
4339             + "  <div id='myNode'></div>\n"
4340             + "</body></html>";
4341 
4342         loadPageVerifyTitle2(html);
4343     }
4344 
4345     /**
4346      * @throws Exception if the test fails
4347      */
4348     @Test
4349     @Alerts({"appendChild start", "executed", "appendChild done"})
4350     public void appendChildExecuteNestedJavaScript() throws Exception {
4351         final String html = DOCTYPE_HTML
4352             + "<html><head><script>\n"
4353             + LOG_TITLE_FUNCTION
4354             + "  function test() {\n"
4355             + "    var newnode = document.createElement('div');\n"
4356             + "    var newscript = document.createElement('script');\n"
4357             + "    newnode.appendChild(newscript);\n"
4358             + "    try {\n"
4359             + "      newscript.appendChild(document.createTextNode('alerter();'));\n"
4360             + "      var outernode = document.getElementById('myNode');\n"
4361             + "      log('appendChild start');\n"
4362             + "      outernode.appendChild(newnode);\n"
4363             + "      log('appendChild done');\n"
4364             + "    } catch(e) { logEx(e); }\n"
4365             + "  }\n"
4366             + "  function alerter() {\n"
4367             + "    log('executed');\n"
4368             + "  }\n"
4369             + "</script></head><body onload='test()'>\n"
4370             + "  <div id='myNode'></div>\n"
4371             + "</body></html>";
4372 
4373         loadPageVerifyTitle2(html);
4374     }
4375 
4376     /**
4377      * @throws Exception if the test fails
4378      */
4379     @Test
4380     @Alerts({"appendChild start", "appendChild done", "executed"})
4381     public void appendChildExecuteNestedExternalJavaScript() throws Exception {
4382         getMockWebConnection().setDefaultResponse("alerter();", MimeType.TEXT_JAVASCRIPT);
4383 
4384         final String html = DOCTYPE_HTML
4385             + "<html><head><script>\n"
4386             + LOG_TITLE_FUNCTION
4387             + "  function test() {\n"
4388             + "    var newnode = document.createElement('div');\n"
4389             + "    var newscript = document.createElement('script');\n"
4390             + "    newscript.setAttribute('src', 'script.js');\n"
4391             + "    newnode.appendChild(newscript);\n"
4392             + "    try {\n"
4393             + "      var outernode = document.getElementById('myNode');\n"
4394             + "      log('appendChild start');\n"
4395             + "      outernode.appendChild(newnode);\n"
4396             + "      log('appendChild done');\n"
4397             + "    } catch(e) { logEx(e); }\n"
4398             + "  }\n"
4399             + "  function alerter() {\n"
4400             + "    log('executed');\n"
4401             + "  }\n"
4402             + "</script></head><body onload='test()'>\n"
4403             + "  <div id='myNode'></div>\n"
4404             + "</body></html>";
4405 
4406         loadPage2(html);
4407         verifyTitle2(DEFAULT_WAIT_TIME, getWebDriver(), getExpectedAlerts());
4408     }
4409 
4410     /**
4411      * @throws Exception if the test fails
4412      */
4413     @Test
4414     @Alerts(DEFAULT = {"parseFromString done", "appendChild start", "executed", "appendChild done"},
4415             FF = {"parseFromString done", "appendChild start", "appendChild done"},
4416             FF_ESR = {"parseFromString done", "appendChild start", "appendChild done"})
4417     public void appendChildExecuteTemplateChildJavaScript() throws Exception {
4418         final String html = DOCTYPE_HTML
4419             + "<html><head><script>\n"
4420             + LOG_TITLE_FUNCTION
4421             + "  function test() {\n"
4422             + "    var html = '<body><template><script>alerter();<' + '/script></template></body>';\n"
4423             + "    var parser = new DOMParser();\n"
4424             + "    var responseDoc = parser.parseFromString(html, 'text/html');\n"
4425             + "    log('parseFromString done');\n"
4426             + "    var responseBody = responseDoc.body;\n"
4427             + "    var template = responseBody.querySelector('template');\n"
4428             + "    var scriptElem = template.content.firstChild;\n"
4429             + "    try {\n"
4430             + "      var outernode = document.getElementById('myNode');\n"
4431             + "      log('appendChild start');\n"
4432             + "      outernode.appendChild(scriptElem);\n"
4433             + "      log('appendChild done');\n"
4434             + "    } catch(e) { logEx(e); }\n"
4435             + "  }\n"
4436             + "  function alerter() {\n"
4437             + "    log('executed');\n"
4438             + "  }\n"
4439             + "</script></head>\n"
4440             + "<body onload='test()'>\n"
4441             + "  <div id='myNode'></div>\n"
4442             + "</body></html>";
4443 
4444         loadPageVerifyTitle2(html);
4445     }
4446 
4447     /**
4448      * @throws Exception if the test fails
4449      */
4450     @Test
4451     @Alerts(DEFAULT = {"parseFromString done", "appendChild start", "appendChild done", "executed"},
4452             FF = {"parseFromString done", "appendChild start", "appendChild done"},
4453             FF_ESR = {"parseFromString done", "appendChild start", "appendChild done"})
4454     public void appendChildExecuteTemplateChildExternalJavaScript() throws Exception {
4455         getMockWebConnection().setDefaultResponse("alerter();", MimeType.TEXT_JAVASCRIPT);
4456 
4457         final String html = DOCTYPE_HTML
4458             + "<html><head><script>\n"
4459             + LOG_TITLE_FUNCTION
4460             + "  function test() {\n"
4461             + "    var html = '<body><template><script src=\"script.js\"><' + '/script></template></body>';\n"
4462             + "    var parser = new DOMParser();\n"
4463             + "    var responseDoc = parser.parseFromString(html, 'text/html');\n"
4464             + "    log('parseFromString done');\n"
4465             + "    var responseBody = responseDoc.body;\n"
4466             + "    var template = responseBody.querySelector('template');\n"
4467             + "    var scriptElem = template.content.firstChild;\n"
4468             + "    try {\n"
4469             + "      var outernode = document.getElementById('myNode');\n"
4470             + "      log('appendChild start');\n"
4471             + "      outernode.appendChild(scriptElem);\n"
4472             + "      log('appendChild done');\n"
4473             + "    } catch(e) { logEx(e); }\n"
4474             + "  }\n"
4475             + "  function alerter() {\n"
4476             + "    log('executed');\n"
4477             + "  }\n"
4478             + "</script></head>\n"
4479             + "<body onload='test()'>\n"
4480             + "  <div id='myNode'></div>\n"
4481             + "</body></html>";
4482 
4483         loadPageVerifyTitle2(html);
4484     }
4485 
4486     /**
4487      * @throws Exception if the test fails
4488      */
4489     @Test
4490     @Alerts(DEFAULT = {"parseFromString done", "appendChild start1", "executed",
4491                        "appendChild done1", "appendChild start2", "appendChild done2"},
4492             FF = {"parseFromString done", "appendChild start1", "appendChild done1",
4493                   "appendChild start2", "appendChild done2"},
4494             FF_ESR = {"parseFromString done", "appendChild start1", "appendChild done1",
4495                       "appendChild start2", "appendChild done2"})
4496     public void appendChildExecuteTemplateFragmentJavaScript() throws Exception {
4497         final String html = DOCTYPE_HTML
4498             + "<html><head><script>\n"
4499             + LOG_TITLE_FUNCTION
4500             + "  function test() {\n"
4501             + "    var html = '<body><template><script>alerter();<' + '/script></template></body>';\n"
4502             + "    var parser = new DOMParser();\n"
4503             + "    var responseDoc = parser.parseFromString(html, 'text/html');\n"
4504             + "    log('parseFromString done');\n"
4505             + "    var responseBody = responseDoc.body;\n"
4506             + "    var templateContent = responseBody.querySelector('template').content;\n"
4507             + "    var scriptElem = templateContent.firstChild;\n"
4508 
4509             + "    try {\n"
4510             + "      var outernode = document.getElementById('myNode');\n"
4511             + "      log('appendChild start1');\n"
4512             + "      outernode.appendChild(scriptElem);\n"
4513             + "      log('appendChild done1');\n"
4514             + "    } catch(e) { logEx(e); }\n"
4515 
4516             + "    try {\n"
4517             + "      var outernode = document.getElementById('secondNode');\n"
4518             + "      log('appendChild start2');\n"
4519             + "      outernode.appendChild(scriptElem);\n"
4520             + "      log('appendChild done2');\n"
4521             + "    } catch(e) { logEx(e); }\n"
4522             + "  }\n"
4523             + "  function alerter() {\n"
4524             + "    log('executed');\n"
4525             + "  }\n"
4526             + "</script></head>\n"
4527             + "<body onload='test()'>\n"
4528             + "  <div id='myNode'></div>\n"
4529             + "  <div id='secondNode'></div>\n"
4530             + "</body></html>";
4531 
4532         loadPageVerifyTitle2(html);
4533     }
4534 
4535     /**
4536      * @throws Exception if the test fails
4537      */
4538     @Test
4539     @Alerts(DEFAULT = {"parseFromString done", "appendChild start1",
4540                        "appendChild done1", "appendChild start2", "appendChild done2", "executed"},
4541             FF = {"parseFromString done", "appendChild start1", "appendChild done1",
4542                   "appendChild start2", "appendChild done2"},
4543             FF_ESR = {"parseFromString done", "appendChild start1", "appendChild done1",
4544                       "appendChild start2", "appendChild done2"})
4545     public void appendChildExecuteTemplateFragmentExternalJavaScript() throws Exception {
4546         getMockWebConnection().setDefaultResponse("alerter();", MimeType.TEXT_JAVASCRIPT);
4547 
4548         final String html = DOCTYPE_HTML
4549             + "<html><head><script>\n"
4550             + LOG_TITLE_FUNCTION
4551             + "  function test() {\n"
4552             + "    var html = '<body><template><script src=\"script.js\"><' + '/script></template></body>';\n"
4553             + "    var parser = new DOMParser();\n"
4554             + "    var responseDoc = parser.parseFromString(html, 'text/html');\n"
4555             + "    log('parseFromString done');\n"
4556             + "    var responseBody = responseDoc.body;\n"
4557             + "    var templateContent = responseBody.querySelector('template').content;\n"
4558             + "    var scriptElem = templateContent.firstChild;\n"
4559 
4560             + "    try {\n"
4561             + "      var outernode = document.getElementById('myNode');\n"
4562             + "      log('appendChild start1');\n"
4563             + "      outernode.appendChild(scriptElem);\n"
4564             + "      log('appendChild done1');\n"
4565             + "    } catch(e) { logEx(e); }\n"
4566 
4567             + "    try {\n"
4568             + "      var outernode = document.getElementById('secondNode');\n"
4569             + "      log('appendChild start2');\n"
4570             + "      outernode.appendChild(scriptElem);\n"
4571             + "      log('appendChild done2');\n"
4572             + "    } catch(e) { logEx(e); }\n"
4573             + "  }\n"
4574             + "  function alerter() {\n"
4575             + "    log('executed');\n"
4576             + "  }\n"
4577             + "</script></head>\n"
4578             + "<body onload='test()'>\n"
4579             + "  <div id='myNode'></div>\n"
4580             + "  <div id='secondNode'></div>\n"
4581             + "</body></html>";
4582 
4583         loadPageVerifyTitle2(html);
4584     }
4585 
4586     /**
4587      * @throws Exception if the test fails
4588      */
4589     @Test
4590     @Alerts("declared")
4591     public void appendChildDeclareJavaScript() throws Exception {
4592         final String html = DOCTYPE_HTML
4593             + "<html><head><script>\n"
4594             + LOG_TITLE_FUNCTION
4595             + "  function test() {\n"
4596             + "    var newnode = document.createElement('script');\n"
4597             + "    newnode.appendChild(document.createTextNode('function tester() { alerter(); }'));\n"
4598             + "    var outernode = document.getElementById('myNode');\n"
4599             + "    outernode.appendChild(newnode);\n"
4600             + "    tester();\n"
4601             + "  }\n"
4602             + "  function alerter() {\n"
4603             + "    log('declared');\n"
4604             + "  }\n"
4605             + "</script></head><body onload='test()'>\n"
4606             + "  <div id='myNode'></div>\n"
4607             + "</body></html>";
4608 
4609         loadPageVerifyTitle2(html);
4610     }
4611 
4612     /**
4613      * @throws Exception if the test fails
4614      */
4615     @Test
4616     @Alerts({"insertBefore start", "executed", "insertBefore done"})
4617     public void insertBeforeExecuteJavaScript() throws Exception {
4618         final String html = DOCTYPE_HTML
4619             + "<html><head><script>\n"
4620             + LOG_TITLE_FUNCTION
4621             + "  function test() {\n"
4622             + "    var newnode = document.createElement('script');\n"
4623             + "    try {\n"
4624             + "      newnode.appendChild(document.createTextNode('alerter();'));\n"
4625             + "      var outernode = document.getElementById('myNode');\n"
4626             + "      log('insertBefore start');\n"
4627             + "      outernode.insertBefore(newnode, null);\n"
4628             + "      log('insertBefore done');\n"
4629             + "    } catch(e) { logEx(e); }\n"
4630             + "  }\n"
4631             + "  function alerter() {\n"
4632             + "    log('executed');\n"
4633             + "  }\n"
4634             + "</script></head><body onload='test()'>\n"
4635             + "  <div id='myNode'></div>\n"
4636             + "</body></html>";
4637 
4638         loadPageVerifyTitle2(html);
4639     }
4640 
4641     /**
4642      * @throws Exception if the test fails
4643      */
4644     @Test
4645     @Alerts({"insertBefore start", "insertBefore done", "executed"})
4646     public void insertBeforeExecuteExternalJavaScript() throws Exception {
4647         getMockWebConnection().setDefaultResponse("alerter();", MimeType.TEXT_JAVASCRIPT);
4648 
4649         final String html = DOCTYPE_HTML
4650             + "<html><head><script>\n"
4651             + LOG_TITLE_FUNCTION
4652             + "  function test() {\n"
4653             + "    var newnode = document.createElement('script');\n"
4654             + "    try {\n"
4655             + "      newnode.setAttribute('src', 'script.js');\n"
4656             + "      var outernode = document.getElementById('myNode');\n"
4657             + "      log('insertBefore start');\n"
4658             + "      outernode.insertBefore(newnode, null);\n"
4659             + "      log('insertBefore done');\n"
4660             + "    } catch(e) { logEx(e); }\n"
4661             + "  }\n"
4662             + "  function alerter() {\n"
4663             + "    log('executed');\n"
4664             + "  }\n"
4665             + "</script></head><body onload='test()'>\n"
4666             + "  <div id='myNode'></div>\n"
4667             + "</body></html>";
4668 
4669         loadPage2(html);
4670         verifyTitle2(DEFAULT_WAIT_TIME, getWebDriver(), getExpectedAlerts());
4671     }
4672 
4673     /**
4674      * @throws Exception if the test fails
4675      */
4676     @Test
4677     @Alerts({"insertBefore start", "executed", "insertBefore done"})
4678     public void insertBeforeExecuteNestedJavaScript() throws Exception {
4679         final String html = DOCTYPE_HTML
4680             + "<html><head><script>\n"
4681             + LOG_TITLE_FUNCTION
4682             + "  function test() {\n"
4683             + "    var newnode = document.createElement('div');\n"
4684             + "    var newscript = document.createElement('script');\n"
4685             + "    newnode.appendChild(newscript);\n"
4686             + "    try {\n"
4687             + "      newscript.appendChild(document.createTextNode('alerter();'));\n"
4688             + "      var outernode = document.getElementById('myNode');\n"
4689             + "      log('insertBefore start');\n"
4690             + "      outernode.insertBefore(newnode, null);\n"
4691             + "      log('insertBefore done');\n"
4692             + "    } catch(e) { logEx(e); }\n"
4693             + "  }\n"
4694             + "  function alerter() {\n"
4695             + "    log('executed');\n"
4696             + "  }\n"
4697             + "</script></head><body onload='test()'>\n"
4698             + "  <div id='myNode'></div>\n"
4699             + "</body></html>";
4700 
4701         loadPageVerifyTitle2(html);
4702     }
4703 
4704     /**
4705      * @throws Exception if the test fails
4706      */
4707     @Test
4708     @Alerts({"insertBefore start", "insertBefore done", "executed"})
4709     public void insertBeforeExecuteNestedExternalJavaScript() throws Exception {
4710         getMockWebConnection().setDefaultResponse("alerter();", MimeType.TEXT_JAVASCRIPT);
4711 
4712         final String html = DOCTYPE_HTML
4713             + "<html><head><script>\n"
4714             + LOG_TITLE_FUNCTION
4715             + "  function test() {\n"
4716             + "    var newnode = document.createElement('div');\n"
4717             + "    var newscript = document.createElement('script');\n"
4718             + "    newnode.appendChild(newscript);\n"
4719             + "    try {\n"
4720             + "      newscript.setAttribute('src', 'script.js');\n"
4721             + "      var outernode = document.getElementById('myNode');\n"
4722             + "      log('insertBefore start');\n"
4723             + "      outernode.insertBefore(newnode, null);\n"
4724             + "      log('insertBefore done');\n"
4725             + "    } catch(e) { logEx(e); }\n"
4726             + "  }\n"
4727             + "  function alerter() {\n"
4728             + "    log('executed');\n"
4729             + "  }\n"
4730             + "</script></head><body onload='test()'>\n"
4731             + "  <div id='myNode'></div>\n"
4732             + "</body></html>";
4733 
4734         loadPage2(html);
4735         verifyTitle2(DEFAULT_WAIT_TIME, getWebDriver(), getExpectedAlerts());
4736     }
4737 
4738     /**
4739      * @throws Exception if the test fails
4740      */
4741     @Test
4742     @Alerts(DEFAULT = {"insertBefore start", "executed", "insertBefore done"},
4743             FF = {"insertBefore start", "insertBefore done"},
4744             FF_ESR = {"insertBefore start", "insertBefore done"})
4745     public void insertBeforeExecuteTemplateChildJavaScript() throws Exception {
4746         final String html = DOCTYPE_HTML
4747             + "<html><head><script>\n"
4748             + LOG_TITLE_FUNCTION
4749             + "  function test() {\n"
4750             + "    var html = '<body><template><script>alerter();<' + '/script></template></body>';\n"
4751             + "    var parser = new DOMParser();\n"
4752             + "    var responseDoc = parser.parseFromString(html, 'text/html');\n"
4753             + "    var responseBody = responseDoc.body;\n"
4754             + "    var template = responseBody.querySelector('template');\n"
4755             + "    var scriptElem = template.content.firstChild;\n"
4756             + "    try {\n"
4757             + "      var outernode = document.getElementById('myNode');\n"
4758             + "      log('insertBefore start');\n"
4759             + "      outernode.insertBefore(scriptElem, null);\n"
4760             + "      log('insertBefore done');\n"
4761             + "    } catch(e) { logEx(e); }\n"
4762             + "  }\n"
4763             + "  function alerter() {\n"
4764             + "    log('executed');\n"
4765             + "  }\n"
4766             + "</script></head>\n"
4767             + "<body onload='test()'>\n"
4768             + "  <div id='myNode'></div>\n"
4769             + "</body></html>";
4770         loadPageVerifyTitle2(html);
4771     }
4772 
4773     /**
4774      * @throws Exception if the test fails
4775      */
4776     @Test
4777     @Alerts(DEFAULT = {"insertBefore start", "insertBefore done", "executed"},
4778             FF = {"insertBefore start", "insertBefore done"},
4779             FF_ESR = {"insertBefore start", "insertBefore done"})
4780     public void insertBeforeExecuteTemplateChildExternalJavaScript() throws Exception {
4781         getMockWebConnection().setDefaultResponse("alerter();", MimeType.TEXT_JAVASCRIPT);
4782 
4783         final String html = DOCTYPE_HTML
4784             + "<html><head><script>\n"
4785             + LOG_TITLE_FUNCTION
4786             + "  function test() {\n"
4787             + "    var html = '<body><template><script src=\"script.js\"><' + '/script></template></body>';\n"
4788             + "    var parser = new DOMParser();\n"
4789             + "    var responseDoc = parser.parseFromString(html, 'text/html');\n"
4790             + "    var responseBody = responseDoc.body;\n"
4791             + "    var template = responseBody.querySelector('template');\n"
4792             + "    var scriptElem = template.content.firstChild;\n"
4793             + "    try {\n"
4794             + "      var outernode = document.getElementById('myNode');\n"
4795             + "      log('insertBefore start');\n"
4796             + "      outernode.insertBefore(scriptElem, null);\n"
4797             + "      log('insertBefore done');\n"
4798             + "    } catch(e) { logEx(e); }\n"
4799             + "  }\n"
4800             + "  function alerter() {\n"
4801             + "    log('executed');\n"
4802             + "  }\n"
4803             + "</script></head>\n"
4804             + "<body onload='test()'>\n"
4805             + "  <div id='myNode'></div>\n"
4806             + "</body></html>";
4807 
4808         loadPage2(html);
4809         verifyTitle2(DEFAULT_WAIT_TIME, getWebDriver(), getExpectedAlerts());
4810     }
4811 
4812     /**
4813      * @throws Exception if the test fails
4814      */
4815     @Test
4816     @Alerts(DEFAULT = {"insertBefore start1", "executed", "insertBefore done1",
4817                        "insertBefore start2", "insertBefore done2"},
4818             FF = {"insertBefore start1", "insertBefore done1", "insertBefore start2", "insertBefore done2"},
4819             FF_ESR = {"insertBefore start1", "insertBefore done1", "insertBefore start2", "insertBefore done2"})
4820     public void insertBeforeExecuteTemplateFragmentJavaScript() throws Exception {
4821         final String html = DOCTYPE_HTML
4822             + "<html><head><script>\n"
4823             + LOG_TITLE_FUNCTION
4824             + "  function test() {\n"
4825             + "    var html = '<body><template><script>alerter();<' + '/script></template></body>';\n"
4826             + "    var parser = new DOMParser();\n"
4827             + "    var responseDoc = parser.parseFromString(html, 'text/html');\n"
4828             + "    var responseBody = responseDoc.body;\n"
4829             + "    var templateContent = responseBody.querySelector('template').content;\n"
4830             + "    var scriptElem = templateContent.firstChild;\n"
4831 
4832             + "    try {\n"
4833             + "      var outernode = document.getElementById('myNode');\n"
4834             + "      log('insertBefore start1');\n"
4835             + "      outernode.insertBefore(scriptElem, null);\n"
4836             + "      log('insertBefore done1');\n"
4837             + "    } catch(e) { logEx(e); }\n"
4838 
4839             + "    try {\n"
4840             + "      var outernode = document.getElementById('secondNode');\n"
4841             + "      log('insertBefore start2');\n"
4842             + "      outernode.insertBefore(scriptElem, null);\n"
4843             + "      log('insertBefore done2');\n"
4844             + "    } catch(e) { logEx(e); }\n"
4845             + "  }\n"
4846             + "  function alerter() {\n"
4847             + "    log('executed');\n"
4848             + "  }\n"
4849             + "</script></head>\n"
4850             + "<body onload='test()'>\n"
4851             + "  <div id='myNode'></div>\n"
4852             + "  <div id='secondNode'></div>\n"
4853             + "</body></html>";
4854 
4855         loadPageVerifyTitle2(html);
4856     }
4857 
4858     /**
4859      * @throws Exception if the test fails
4860      */
4861     @Test
4862     @Alerts(DEFAULT = {"insertBefore start1", "insertBefore done1",
4863                        "insertBefore start2", "insertBefore done2", "executed"},
4864             FF = {"insertBefore start1", "insertBefore done1", "insertBefore start2", "insertBefore done2"},
4865             FF_ESR = {"insertBefore start1", "insertBefore done1", "insertBefore start2", "insertBefore done2"})
4866     public void insertBeforeExecuteTemplateFragmentExternalJavaScript() throws Exception {
4867         getMockWebConnection().setDefaultResponse("alerter();", MimeType.TEXT_JAVASCRIPT);
4868 
4869         final String html = DOCTYPE_HTML
4870             + "<html><head><script>\n"
4871             + LOG_TITLE_FUNCTION
4872             + "  function test() {\n"
4873             + "    var html = '<body><template><script src=\"script.js\"><' + '/script></template></body>';\n"
4874             + "    var parser = new DOMParser();\n"
4875             + "    var responseDoc = parser.parseFromString(html, 'text/html');\n"
4876             + "    var responseBody = responseDoc.body;\n"
4877             + "    var templateContent = responseBody.querySelector('template').content;\n"
4878             + "    var scriptElem = templateContent.firstChild;\n"
4879 
4880             + "    try {\n"
4881             + "      var outernode = document.getElementById('myNode');\n"
4882             + "      log('insertBefore start1');\n"
4883             + "      outernode.insertBefore(scriptElem, null);\n"
4884             + "      log('insertBefore done1');\n"
4885             + "    } catch(e) { logEx(e); }\n"
4886 
4887             + "    try {\n"
4888             + "      var outernode = document.getElementById('secondNode');\n"
4889             + "      log('insertBefore start2');\n"
4890             + "      outernode.insertBefore(scriptElem, null);\n"
4891             + "      log('insertBefore done2');\n"
4892             + "    } catch(e) { logEx(e); }\n"
4893             + "  }\n"
4894             + "  function alerter() {\n"
4895             + "    log('executed');\n"
4896             + "  }\n"
4897             + "</script></head>\n"
4898             + "<body onload='test()'>\n"
4899             + "  <div id='myNode'></div>\n"
4900             + "  <div id='secondNode'></div>\n"
4901             + "</body></html>";
4902 
4903         loadPage2(html);
4904         verifyTitle2(DEFAULT_WAIT_TIME, getWebDriver(), getExpectedAlerts());
4905     }
4906 
4907     /**
4908      * @throws Exception if the test fails
4909      */
4910     @Test
4911     @Alerts({"insertBefore start1", "executed", "insertBefore done1", "insertBefore start2", "insertBefore done2"})
4912     public void insertBeforeExecuteTemplateFragmentDom() throws Exception {
4913         final String html = DOCTYPE_HTML
4914             + "<html><head><script>\n"
4915             + LOG_TITLE_FUNCTION
4916             + "  function test() {\n"
4917             + "    var templateContent = document.getElementById('myTemplate').content;\n"
4918             + "    var scriptElem = templateContent.firstChild;\n"
4919 
4920             + "    try {\n"
4921             + "      var outernode = document.getElementById('myNode');\n"
4922             + "      log('insertBefore start1');\n"
4923             + "      outernode.insertBefore(scriptElem, null);\n"
4924             + "      log('insertBefore done1');\n"
4925             + "    } catch(e) { logEx(e); }\n"
4926 
4927             + "    try {\n"
4928             + "      var outernode = document.getElementById('secondNode');\n"
4929             + "      log('insertBefore start2');\n"
4930             + "      outernode.insertBefore(scriptElem, null);\n"
4931             + "      log('insertBefore done2');\n"
4932             + "    } catch(e) { logEx(e); }\n"
4933             + "  }\n"
4934             + "  function alerter() {\n"
4935             + "    log('executed');\n"
4936             + "  }\n"
4937             + "</script></head>\n"
4938             + "<body onload='test()'>\n"
4939             + "  <template id='myTemplate'><script>alerter();</script></template>\n"
4940             + "  <div id='myNode'></div>\n"
4941             + "  <div id='secondNode'></div>\n"
4942             + "</body></html>";
4943         loadPageVerifyTitle2(html);
4944     }
4945 
4946     /**
4947      * @throws Exception if the test fails
4948      */
4949     @Test
4950     @Alerts({"insertBefore start1", "insertBefore done1", "insertBefore start2", "insertBefore done2", "executed"})
4951     public void insertBeforeExecuteTemplateFragmentDomExternal() throws Exception {
4952         getMockWebConnection().setDefaultResponse("alerter();", MimeType.TEXT_JAVASCRIPT);
4953 
4954         final String html = DOCTYPE_HTML
4955             + "<html><head><script>\n"
4956             + LOG_TITLE_FUNCTION
4957             + "  function test() {\n"
4958             + "    var templateContent = document.getElementById('myTemplate').content;\n"
4959             + "    var scriptElem = templateContent.firstChild;\n"
4960 
4961             + "    try {\n"
4962             + "      var outernode = document.getElementById('myNode');\n"
4963             + "      log('insertBefore start1');\n"
4964             + "      outernode.insertBefore(scriptElem, null);\n"
4965             + "      log('insertBefore done1');\n"
4966             + "    } catch(e) { logEx(e); }\n"
4967 
4968             + "    try {\n"
4969             + "      var outernode = document.getElementById('secondNode');\n"
4970             + "      log('insertBefore start2');\n"
4971             + "      outernode.insertBefore(scriptElem, null);\n"
4972             + "      log('insertBefore done2');\n"
4973             + "    } catch(e) { logEx(e); }\n"
4974             + "  }\n"
4975             + "  function alerter() {\n"
4976             + "    log('executed');\n"
4977             + "  }\n"
4978             + "</script></head>\n"
4979             + "<body onload='test()'>\n"
4980             + "  <template id='myTemplate'><script src=\"script.js\"></script></template>\n"
4981             + "  <div id='myNode'></div>\n"
4982             + "  <div id='secondNode'></div>\n"
4983             + "</body></html>";
4984 
4985         loadPage2(html);
4986         verifyTitle2(DEFAULT_WAIT_TIME, getWebDriver(), getExpectedAlerts());
4987     }
4988 
4989     /**
4990      * @throws Exception if the test fails
4991      */
4992     @Test
4993     @Alerts({"insertBefore start", "executed", "insertBefore done"})
4994     public void insertBeforeDomFragmentJavaScript() throws Exception {
4995         final String html = DOCTYPE_HTML
4996             + "<html><head><script>\n"
4997             + LOG_TITLE_FUNCTION
4998             + "  function test() {\n"
4999             + "    let fragment = new DocumentFragment();\n"
5000             + "    var newscript = document.createElement('script');\n"
5001             + "    fragment.appendChild(newscript);\n"
5002 
5003             + "    try {\n"
5004             + "      newscript.appendChild(document.createTextNode('alerter();'));\n"
5005             + "      var outernode = document.getElementById('myNode');\n"
5006             + "      log('insertBefore start');\n"
5007             + "      outernode.insertBefore(fragment, null);\n"
5008             + "      log('insertBefore done');\n"
5009             + "    } catch(e) { logEx(e); }\n"
5010             + "  }\n"
5011             + "  function alerter() {\n"
5012             + "    log('executed');\n"
5013             + "  }\n"
5014             + "</script></head>\n"
5015             + "<body onload='test()'>\n"
5016             + "  <div id='myNode'></div>\n"
5017             + "</body></html>";
5018 
5019         loadPage2(html);
5020         verifyTitle2(DEFAULT_WAIT_TIME, getWebDriver(), getExpectedAlerts());
5021     }
5022 
5023     /**
5024      * @throws Exception if the test fails
5025      */
5026     @Test
5027     @Alerts({"insertBefore start", "insertBefore done", "executed"})
5028     public void insertBeforeDomFragmentExternalJavaScript() throws Exception {
5029         getMockWebConnection().setDefaultResponse("alerter();", MimeType.TEXT_JAVASCRIPT);
5030 
5031         final String html = DOCTYPE_HTML
5032             + "<html><head><script>\n"
5033             + LOG_TITLE_FUNCTION
5034             + "  function test() {\n"
5035             + "    let fragment = new DocumentFragment();\n"
5036             + "    var newscript = document.createElement('script');\n"
5037             + "    fragment.appendChild(newscript);\n"
5038 
5039             + "    try {\n"
5040             + "      newscript.setAttribute('src', 'script.js');\n"
5041             + "      var outernode = document.getElementById('myNode');\n"
5042             + "      log('insertBefore start');\n"
5043             + "      outernode.insertBefore(fragment, null);\n"
5044             + "      log('insertBefore done');\n"
5045             + "    } catch(e) { logEx(e); }\n"
5046             + "  }\n"
5047             + "  function alerter() {\n"
5048             + "    log('executed');\n"
5049             + "  }\n"
5050             + "</script></head>\n"
5051             + "<body onload='test()'>\n"
5052             + "  <div id='myNode'></div>\n"
5053             + "</body></html>";
5054 
5055         loadPage2(html);
5056         verifyTitle2(DEFAULT_WAIT_TIME, getWebDriver(), getExpectedAlerts());
5057     }
5058 
5059     /**
5060      * @throws Exception if the test fails
5061      */
5062     @Test
5063     @Alerts("declared")
5064     public void insertBeforeDeclareJavaScript() throws Exception {
5065         final String html = DOCTYPE_HTML
5066             + "<html><head><script>\n"
5067             + LOG_TITLE_FUNCTION
5068             + "  function test() {\n"
5069             + "    var newnode = document.createElement('script');\n"
5070             + "    newnode.appendChild(document.createTextNode('function tester() { alerter(); }'));\n"
5071             + "    var outernode = document.getElementById('myNode');\n"
5072             + "    outernode.insertBefore(newnode, null);\n"
5073             + "    tester();\n"
5074             + "  }\n"
5075             + "  function alerter() {\n"
5076             + "    log('declared');\n"
5077             + "  }\n"
5078             + "</script></head><body onload='test()'>\n"
5079             + "  <div id='myNode'></div>\n"
5080             + "</body></html>";
5081         loadPageVerifyTitle2(html);
5082     }
5083 
5084     /**
5085      * @throws Exception if the test fails
5086      */
5087     @Test
5088     @Alerts({"replaceChild start", "executed", "replaceChild done"})
5089     public void replaceChildExecuteJavaScript() throws Exception {
5090         final String html = DOCTYPE_HTML
5091             + "<html><head><script>\n"
5092             + LOG_TITLE_FUNCTION
5093             + "  function test() {\n"
5094             + "    var newnode = document.createElement('script');\n"
5095             + "    try {\n"
5096             + "      newnode.appendChild(document.createTextNode('alerter();'));\n"
5097             + "      var outernode = document.getElementById('myNode');\n"
5098             + "      log('replaceChild start');\n"
5099             + "      outernode.replaceChild(newnode, document.getElementById('inner'));\n"
5100             + "      log('replaceChild done');\n"
5101             + "    } catch(e) { logEx(e); }\n"
5102             + "  }\n"
5103             + "  function alerter() {\n"
5104             + "    log('executed');\n"
5105             + "  }\n"
5106             + "</script></head><body onload='test()'>\n"
5107             + "  <div id='myNode'><div id='inner'></div></div>\n"
5108             + "</body></html>";
5109 
5110         loadPageVerifyTitle2(html);
5111     }
5112 
5113     /**
5114      * @throws Exception if the test fails
5115      */
5116     @Test
5117     @Alerts({"replaceChild start", "replaceChild done", "executed"})
5118     public void replaceChildExecuteExternalJavaScript() throws Exception {
5119         getMockWebConnection().setDefaultResponse("alerter();", MimeType.TEXT_JAVASCRIPT);
5120 
5121         final String html = DOCTYPE_HTML
5122             + "<html><head><script>\n"
5123             + LOG_TITLE_FUNCTION
5124             + "  function test() {\n"
5125             + "    var newnode = document.createElement('script');\n"
5126             + "    try {\n"
5127             + "      newnode.setAttribute('src', 'script.js');\n"
5128             + "      var outernode = document.getElementById('myNode');\n"
5129             + "      log('replaceChild start');\n"
5130             + "      outernode.replaceChild(newnode, document.getElementById('inner'));\n"
5131             + "      log('replaceChild done');\n"
5132             + "    } catch(e) { logEx(e); }\n"
5133             + "  }\n"
5134             + "  function alerter() {\n"
5135             + "    log('executed');\n"
5136             + "  }\n"
5137             + "</script></head><body onload='test()'>\n"
5138             + "  <div id='myNode'><div id='inner'></div></div>\n"
5139             + "</body></html>";
5140 
5141         loadPage2(html);
5142         verifyTitle2(DEFAULT_WAIT_TIME, getWebDriver(), getExpectedAlerts());
5143     }
5144 
5145     /**
5146      * @throws Exception if the test fails
5147      */
5148     @Test
5149     @Alerts({"replaceChild start", "executed", "replaceChild done"})
5150     public void replaceChildExecuteNestedJavaScript() throws Exception {
5151         final String html = DOCTYPE_HTML
5152             + "<html><head><script>\n"
5153             + LOG_TITLE_FUNCTION
5154             + "  function test() {\n"
5155             + "    var newnode = document.createElement('div');\n"
5156             + "    var newscript = document.createElement('script');\n"
5157             + "    newnode.appendChild(newscript);\n"
5158             + "    try {\n"
5159             + "      newscript.appendChild(document.createTextNode('alerter();'));\n"
5160             + "      var outernode = document.getElementById('myNode');\n"
5161             + "      log('replaceChild start');\n"
5162             + "      outernode.replaceChild(newnode, document.getElementById('inner'));\n"
5163             + "      log('replaceChild done');\n"
5164             + "    } catch(e) { logEx(e); }\n"
5165             + "  }\n"
5166             + "  function alerter() {\n"
5167             + "    log('executed');\n"
5168             + "  }\n"
5169             + "</script></head><body onload='test()'>\n"
5170             + "  <div id='myNode'><div id='inner'></div></div>\n"
5171             + "</body></html>";
5172 
5173         loadPageVerifyTitle2(html);
5174     }
5175 
5176     /**
5177      * @throws Exception if the test fails
5178      */
5179     @Test
5180     @Alerts({"replaceChild start", "replaceChild done", "executed"})
5181     public void replaceChildExecuteNestedExternalJavaScript() throws Exception {
5182         getMockWebConnection().setDefaultResponse("alerter();", MimeType.TEXT_JAVASCRIPT);
5183 
5184         final String html = DOCTYPE_HTML
5185             + "<html><head><script>\n"
5186             + LOG_TITLE_FUNCTION
5187             + "  function test() {\n"
5188             + "    var newnode = document.createElement('div');\n"
5189             + "    var newscript = document.createElement('script');\n"
5190             + "    newnode.appendChild(newscript);\n"
5191             + "    try {\n"
5192             + "      newscript.setAttribute('src', 'script.js');\n"
5193             + "      var outernode = document.getElementById('myNode');\n"
5194             + "      log('replaceChild start');\n"
5195             + "      outernode.replaceChild(newnode, document.getElementById('inner'));\n"
5196             + "      log('replaceChild done');\n"
5197             + "    } catch(e) { logEx(e); }\n"
5198             + "  }\n"
5199             + "  function alerter() {\n"
5200             + "    log('executed');\n"
5201             + "  }\n"
5202             + "</script></head><body onload='test()'>\n"
5203             + "  <div id='myNode'><div id='inner'></div></div>\n"
5204             + "</body></html>";
5205 
5206         loadPage2(html);
5207         verifyTitle2(DEFAULT_WAIT_TIME, getWebDriver(), getExpectedAlerts());
5208     }
5209 
5210     /**
5211      * @throws Exception if the test fails
5212      */
5213     @Test
5214     @Alerts(DEFAULT = {"replaceChild start", "executed", "replaceChild done"},
5215             FF = {"replaceChild start", "replaceChild done"},
5216             FF_ESR = {"replaceChild start", "replaceChild done"})
5217     public void replaceChildExecuteTemplateChildJavaScript() throws Exception {
5218         final String html = DOCTYPE_HTML
5219             + "<html><head><script>\n"
5220             + LOG_TITLE_FUNCTION
5221             + "  function test() {\n"
5222             + "    var html = '<body><template><script>alerter();<' + '/script></template></body>';\n"
5223             + "    var parser = new DOMParser();\n"
5224             + "    var responseDoc = parser.parseFromString(html, 'text/html');\n"
5225             + "    var responseBody = responseDoc.body;\n"
5226             + "    var template = responseBody.querySelector('template');\n"
5227             + "    var scriptElem = template.content.firstChild;\n"
5228             + "    try {\n"
5229             + "      var outernode = document.getElementById('myNode');\n"
5230             + "      log('replaceChild start');\n"
5231             + "      outernode.replaceChild(scriptElem, document.getElementById('inner'));\n"
5232             + "      log('replaceChild done');\n"
5233             + "    } catch(e) { logEx(e); }\n"
5234             + "  }\n"
5235             + "  function alerter() {\n"
5236             + "    log('executed');\n"
5237             + "  }\n"
5238             + "</script></head>\n"
5239             + "<body onload='test()'>\n"
5240             + "  <div id='myNode'><div id='inner'></div></div>\n"
5241             + "</body></html>";
5242 
5243         loadPageVerifyTitle2(html);
5244     }
5245 
5246     /**
5247      * @throws Exception if the test fails
5248      */
5249     @Test
5250     @Alerts(DEFAULT = {"replaceChild start", "replaceChild done", "executed"},
5251             FF = {"replaceChild start", "replaceChild done"},
5252             FF_ESR = {"replaceChild start", "replaceChild done"})
5253     public void replaceChildExecuteTemplateChildExternalJavaScript() throws Exception {
5254         getMockWebConnection().setDefaultResponse("alerter();", MimeType.TEXT_JAVASCRIPT);
5255 
5256         final String html = DOCTYPE_HTML
5257             + "<html><head><script>\n"
5258             + LOG_TITLE_FUNCTION
5259             + "  function test() {\n"
5260             + "    var html = '<body><template><script src=\"script.js\"><' + '/script></template></body>';\n"
5261             + "    var parser = new DOMParser();\n"
5262             + "    var responseDoc = parser.parseFromString(html, 'text/html');\n"
5263             + "    var responseBody = responseDoc.body;\n"
5264             + "    var template = responseBody.querySelector('template');\n"
5265             + "    var scriptElem = template.content.firstChild;\n"
5266             + "    try {\n"
5267             + "      var outernode = document.getElementById('myNode');\n"
5268             + "      log('replaceChild start');\n"
5269             + "      outernode.replaceChild(scriptElem, document.getElementById('inner'));\n"
5270             + "      log('replaceChild done');\n"
5271             + "    } catch(e) { logEx(e); }\n"
5272             + "  }\n"
5273             + "  function alerter() {\n"
5274             + "    log('executed');\n"
5275             + "  }\n"
5276             + "</script></head>\n"
5277             + "<body onload='test()'>\n"
5278             + "  <div id='myNode'><div id='inner'></div></div>\n"
5279             + "</body></html>";
5280 
5281         loadPage2(html);
5282         verifyTitle2(DEFAULT_WAIT_TIME, getWebDriver(), getExpectedAlerts());
5283     }
5284 
5285     /**
5286      * @throws Exception if the test fails
5287      */
5288     @Test
5289     @Alerts(DEFAULT = {"replaceChild start1", "executed", "replaceChild done1",
5290                        "replaceChild start2", "replaceChild done2"},
5291             FF = {"replaceChild start1", "replaceChild done1", "replaceChild start2", "replaceChild done2"},
5292             FF_ESR = {"replaceChild start1", "replaceChild done1", "replaceChild start2", "replaceChild done2"})
5293     public void replaceChildExecuteTemplateFragmentJavaScript() throws Exception {
5294         final String html = DOCTYPE_HTML
5295             + "<html><head><script>\n"
5296             + LOG_TITLE_FUNCTION
5297             + "  function test() {\n"
5298             + "    var html = '<body><template><script>alerter();<' + '/script></template></body>';\n"
5299             + "    var parser = new DOMParser();\n"
5300             + "    var responseDoc = parser.parseFromString(html, 'text/html');\n"
5301             + "    var responseBody = responseDoc.body;\n"
5302             + "    var templateContent = responseBody.querySelector('template').content;\n"
5303             + "    var scriptElem = templateContent.firstChild;\n"
5304 
5305             + "    try {\n"
5306             + "      var outernode = document.getElementById('myNode');\n"
5307             + "      log('replaceChild start1');\n"
5308             + "      outernode.replaceChild(scriptElem, document.getElementById('inner'));\n"
5309             + "      log('replaceChild done1');\n"
5310             + "    } catch(e) { logEx(e); }\n"
5311 
5312             + "    try {\n"
5313             + "      var outernode = document.getElementById('secondNode');\n"
5314             + "      log('replaceChild start2');\n"
5315             + "      outernode.replaceChild(scriptElem, document.getElementById('inner2'));\n"
5316             + "      log('replaceChild done2');\n"
5317             + "    } catch(e) { logEx(e); }\n"
5318             + "  }\n"
5319             + "  function alerter() {\n"
5320             + "    log('executed');\n"
5321             + "  }\n"
5322             + "</script></head>\n"
5323             + "<body onload='test()'>\n"
5324             + "  <div id='myNode'><div id='inner'></div></div>\n"
5325             + "  <div id='secondNode'><div id='inner2'></div></div>\n"
5326             + "</body></html>";
5327         loadPageVerifyTitle2(html);
5328     }
5329 
5330     /**
5331      * @throws Exception if the test fails
5332      */
5333     @Test
5334     @Alerts(DEFAULT = {"replaceChild start1", "replaceChild done1",
5335                        "replaceChild start2", "replaceChild done2", "executed"},
5336             FF = {"replaceChild start1", "replaceChild done1", "replaceChild start2", "replaceChild done2"},
5337             FF_ESR = {"replaceChild start1", "replaceChild done1", "replaceChild start2", "replaceChild done2"})
5338     public void replaceChildExecuteTemplateFragmentExternalJavaScript() throws Exception {
5339         getMockWebConnection().setDefaultResponse("alerter();", MimeType.TEXT_JAVASCRIPT);
5340 
5341         final String html = DOCTYPE_HTML
5342             + "<html><head><script>\n"
5343             + LOG_TITLE_FUNCTION
5344             + "  function test() {\n"
5345             + "    var html = '<body><template><script src=\"script.js\"><' + '/script></template></body>';\n"
5346             + "    var parser = new DOMParser();\n"
5347             + "    var responseDoc = parser.parseFromString(html, 'text/html');\n"
5348             + "    var responseBody = responseDoc.body;\n"
5349             + "    var templateContent = responseBody.querySelector('template').content;\n"
5350             + "    var scriptElem = templateContent.firstChild;\n"
5351 
5352             + "    try {\n"
5353             + "      var outernode = document.getElementById('myNode');\n"
5354             + "      log('replaceChild start1');\n"
5355             + "      outernode.replaceChild(scriptElem, document.getElementById('inner'));\n"
5356             + "      log('replaceChild done1');\n"
5357             + "    } catch(e) { logEx(e); }\n"
5358 
5359             + "    try {\n"
5360             + "      var outernode = document.getElementById('secondNode');\n"
5361             + "      log('replaceChild start2');\n"
5362             + "      outernode.replaceChild(scriptElem, document.getElementById('inner2'));\n"
5363             + "      log('replaceChild done2');\n"
5364             + "    } catch(e) { logEx(e); }\n"
5365             + "  }\n"
5366             + "  function alerter() {\n"
5367             + "    log('executed');\n"
5368             + "  }\n"
5369             + "</script></head>\n"
5370             + "<body onload='test()'>\n"
5371             + "  <div id='myNode'><div id='inner'></div></div>\n"
5372             + "  <div id='secondNode'><div id='inner2'></div></div>\n"
5373             + "</body></html>";
5374 
5375         loadPage2(html);
5376         verifyTitle2(DEFAULT_WAIT_TIME, getWebDriver(), getExpectedAlerts());
5377     }
5378 
5379     /**
5380      * @throws Exception if the test fails
5381      */
5382     @Test
5383     @Alerts("declared")
5384     public void replaceChildDeclareJavaScript() throws Exception {
5385         final String html = DOCTYPE_HTML
5386             + "<html><head><script>\n"
5387             + LOG_TITLE_FUNCTION
5388             + "  function test() {\n"
5389             + "    var newnode = document.createElement('script');\n"
5390             + "    newnode.appendChild(document.createTextNode('function tester() { alerter(); }'));\n"
5391             + "    var outernode = document.getElementById('myNode');\n"
5392             + "    outernode.replaceChild(newnode, document.getElementById('inner'));\n"
5393             + "    tester();\n"
5394             + "  }\n"
5395             + "  function alerter() {\n"
5396             + "    log('declared');\n"
5397             + "  }\n"
5398             + "</script></head><body onload='test()'>\n"
5399             + "  <div id='myNode'><div id='inner'></div></div>\n"
5400             + "</body></html>";
5401         loadPageVerifyTitle2(html);
5402     }
5403 
5404     /**
5405      * @throws Exception if the test fails
5406      */
5407     @Test
5408     @Alerts({"false", "<!--some comment-->", "true", "false"})
5409     public void replaceChildAddNewChildToDocument() throws Exception {
5410         final String html = DOCTYPE_HTML
5411             + "<html><head><script>\n"
5412             + LOG_TITLE_FUNCTION
5413             + "  function test() {\n"
5414             + "    var newnode = document.createComment('some comment');\n"
5415             + "    log(document.contains ? document.contains(newnode) : '-');\n"
5416 
5417             + "    var outernode = document.getElementById('myNode');\n"
5418             + "    var oldnode = document.getElementById('inner');\n"
5419             + "    outernode.replaceChild(newnode, oldnode);\n"
5420             + "    log(outernode.innerHTML);\n"
5421             + "    log(document.contains ? document.contains(newnode) : '-');\n"
5422             + "    log(document.contains ? document.contains(oldnode) : '-');\n"
5423             + "  }\n"
5424             + "</script></head><body onload='test()'>\n"
5425             + "  <div id='myNode'><div id='inner'></div></div>\n"
5426             + "</body></html>";
5427         loadPageVerifyTitle2(html);
5428     }
5429 
5430     /**
5431      * @throws Exception if the test fails
5432      */
5433     @Test
5434     @Alerts({"outside", "1", "middle", "2", "3", "4",
5435         "before-begin after-begin inside before-end after-end"})
5436     public void insertAdjacentHTML() throws Exception {
5437         insertAdjacentHTML("beforeend", "afterend", "beforebegin", "afterbegin");
5438         insertAdjacentHTML("beforeEnd", "afterEnd", "beforeBegin", "afterBegin");
5439         insertAdjacentHTML("BeforeEnd", "AfterEnd", "BeFoReBeGiN", "afterbegin");
5440     }
5441 
5442     /**
5443      * @param beforeEnd data to insert
5444      * @param afterEnd data to insert
5445      * @param beforeBegin data to insert
5446      * @param afterBegin data to insert
5447      * @throws Exception if the test fails
5448      */
5449     private void insertAdjacentHTML(final String beforeEnd,
5450             final String afterEnd, final String beforeBegin, final String afterBegin) throws Exception {
5451         final String html = DOCTYPE_HTML
5452             + "<html><head>\n"
5453             + "<script>\n"
5454             + LOG_TITLE_FUNCTION
5455             + "function test() {\n"
5456             + "  var oNode = document.getElementById('middle');\n"
5457             + "  oNode.insertAdjacentHTML('" + beforeEnd + "', ' <span id=3>before-end</span> ');\n"
5458             + "  oNode.insertAdjacentHTML('" + afterEnd + "', ' <span id=4>after-end</span> ');\n"
5459             + "  oNode.insertAdjacentHTML('" + beforeBegin + "', ' <span id=1>before-begin</span> ');\n"
5460             + "  oNode.insertAdjacentHTML('" + afterBegin + "', ' <span id=2>after-begin</span> ');\n"
5461             + "  var coll = document.getElementsByTagName('SPAN');\n"
5462             + "  for (var i = 0; i < coll.length; i++) {\n"
5463             + "    log(coll[i].id);\n"
5464             + "  }\n"
5465             + "  var outside = document.getElementById('outside');\n"
5466             + "  var text = outside.textContent ? outside.textContent : outside.innerText;\n"
5467             + "  text = text.replace(/(\\r\\n|\\r|\\n)/gm, '');\n"
5468             + "  text = text.replace(/(\\s{2,})/g, ' ');\n"
5469             + "  text = text.replace(/^\\s+|\\s+$/g, '');\n"
5470             + "  log(text);\n"
5471             + "}\n"
5472             + "</script>\n"
5473             + "</head>\n"
5474             + "<body onload='test()'>\n"
5475             + "  <span id='outside' style='color: #00ff00'>\n"
5476             + "    <span id='middle' style='color: #ff0000'>\n"
5477             + "      inside\n"
5478             + "    </span>\n"
5479             + "  </span>\n"
5480             + "</body></html>";
5481         loadPageVerifyTitle2(html);
5482     }
5483 
5484     /**
5485      * @throws Exception if the test fails
5486      */
5487     @Test
5488     public void insertAdjacentHTMLExecuteJavaScript() throws Exception {
5489         final String html = DOCTYPE_HTML
5490             + "<html><head><script>\n"
5491             + LOG_TITLE_FUNCTION
5492             + "  function test() {\n"
5493             + "    var outernode = document.getElementById('myNode');\n"
5494             + "    outernode.insertAdjacentHTML('afterend', '<scr'+'ipt>alerter();</scr'+'ipt>');\n"
5495             + "  }\n"
5496             + "  function alerter() {\n"
5497             + "    log('executed');\n"
5498             + "  }\n"
5499             + "</script></head><body onload='test()'>\n"
5500             + "  <div id='myNode'></div>\n"
5501             + "</body></html>";
5502         loadPageVerifyTitle2(html);
5503     }
5504 
5505     /**
5506      * @throws Exception if the test fails
5507      */
5508     @Test
5509     public void insertAdjacentHTMLExecuteNestedJavaScript() throws Exception {
5510         final String html = DOCTYPE_HTML
5511             + "<html><head><script>\n"
5512             + LOG_TITLE_FUNCTION
5513             + "  function test() {\n"
5514             + "    var outernode = document.getElementById('myNode');\n"
5515             + "    outernode.insertAdjacentHTML('afterend', '<div><scr'+'ipt>alerter();</scr'+'ipt></div>');\n"
5516             + "  }\n"
5517             + "  function alerter() {\n"
5518             + "    log('executed');\n"
5519             + "  }\n"
5520             + "</script></head><body onload='test()'>\n"
5521             + "  <div id='myNode'></div>\n"
5522             + "</body></html>";
5523         loadPageVerifyTitle2(html);
5524     }
5525 
5526     /**
5527      * @throws Exception if the test fails
5528      */
5529     @Test
5530     @Alerts("ReferenceError")
5531     public void insertAdjacentHTMLDeclareJavaScript() throws Exception {
5532         final String html = DOCTYPE_HTML
5533             + "<html><head><script>\n"
5534             + LOG_TITLE_FUNCTION
5535             + "  function test() {\n"
5536             + "    var outernode = document.getElementById('myNode');\n"
5537             + "    outernode.insertAdjacentHTML('afterend', "
5538             + "'<scr'+'ipt>function tester() { alerter(); }</scr'+'ipt>');\n"
5539             + "    try {\n"
5540             + "      tester();\n"
5541             + "    } catch(e) { logEx(e); }\n"
5542             + "  }\n"
5543             + "  function alerter() {\n"
5544             + "    log('declared');\n"
5545             + "  }\n"
5546             + "</script></head><body onload='test()'>\n"
5547             + "  <div id='myNode'></div>\n"
5548             + "</body></html>";
5549         loadPageVerifyTitle2(html);
5550     }
5551 
5552     /**
5553      * @throws Exception if the test fails
5554      */
5555     @Test
5556     @Alerts({"outside", "1", "middle", "2", "3", "4",
5557                 "before-begin after-begin inside before-end after-end"})
5558     public void insertAdjacentElement() throws Exception {
5559         insertAdjacentElement("beforeend", "afterend", "beforebegin", "afterbegin");
5560         insertAdjacentElement("beforeEnd", "afterEnd", "beforeBegin", "afterBegin");
5561         insertAdjacentElement("BeforeEnd", "AfterEnd", "BeFoReBeGiN", "afterbegin");
5562     }
5563 
5564     private void insertAdjacentElement(final String beforeEnd,
5565             final String afterEnd, final String beforeBegin, final String afterBegin) throws Exception {
5566         final String html = DOCTYPE_HTML
5567             + "<html><head>\n"
5568             + "<script>\n"
5569             + LOG_TITLE_FUNCTION
5570             + "function test() {\n"
5571             + "  var oNode = document.getElementById('middle');\n"
5572             + "  if (!oNode.insertAdjacentElement) { log('insertAdjacentElement not available'); return }\n"
5573 
5574             + "  oNode.insertAdjacentElement('" + beforeEnd + "', makeElement(3, 'before-end'));\n"
5575             + "  oNode.insertAdjacentElement('" + afterEnd + "', makeElement(4, ' after-end'));\n"
5576             + "  oNode.insertAdjacentElement('" + beforeBegin + "', makeElement(1, 'before-begin '));\n"
5577             + "  oNode.insertAdjacentElement('" + afterBegin + "', makeElement(2, ' after-begin'));\n"
5578             + "  var coll = document.getElementsByTagName('SPAN');\n"
5579             + "  for (var i = 0; i < coll.length; i++) {\n"
5580             + "    log(coll[i].id);\n"
5581             + "  }\n"
5582             + "  var outside = document.getElementById('outside');\n"
5583             + "  var text = outside.textContent ? outside.textContent : outside.innerText;\n"
5584             + "  text = text.replace(/(\\r\\n|\\r|\\n)/gm, '');\n"
5585             + "  text = text.replace(/(\\s{2,})/g, ' ');\n"
5586             + "  text = text.replace(/^\\s+|\\s+$/g, '');\n"
5587             + "  log(text);\n"
5588             + "}\n"
5589             + "function makeElement(id, value) {\n"
5590             + "  var span = document.createElement('span');\n"
5591             + "  span.appendChild(document.createTextNode(value));\n"
5592             + "  span.id = id;\n"
5593             + "  return span;\n"
5594             + "}\n"
5595             + "</script>\n"
5596             + "</head>\n"
5597             + "<body onload='test()'>\n"
5598             + "  <span id='outside' style='color: #00ff00'>\n"
5599             + "    <span id='middle' style='color: #ff0000'>\n"
5600             + "      inside\n"
5601             + "    </span>\n"
5602             + "  </span>\n"
5603             + "</body></html>";
5604         loadPageVerifyTitle2(html);
5605     }
5606 
5607     /**
5608      * @throws Exception if the test fails
5609      */
5610     @Test
5611     @Alerts("executed")
5612     public void insertAdjacentElementExecuteJavaScript() throws Exception {
5613         final String html = DOCTYPE_HTML
5614             + "<html><head><script>\n"
5615             + LOG_TITLE_FUNCTION
5616             + "  function test() {\n"
5617             + "    var newnode = document.createElement('script');\n"
5618             + "    newnode.appendChild(document.createTextNode('alerter();'));\n"
5619 
5620             + "    var outernode = document.getElementById('myNode');\n"
5621             + "    if (!outernode.insertAdjacentElement) { log('insertAdjacentElement not available'); return }\n"
5622             + "    outernode.insertAdjacentElement('afterend', newnode);\n"
5623             + "  }\n"
5624             + "  function alerter() {\n"
5625             + "    log('executed');\n"
5626             + "  }\n"
5627             + "</script></head><body onload='test()'>\n"
5628             + "  <div id='myNode'></div>\n"
5629             + "</body></html>";
5630         loadPageVerifyTitle2(html);
5631     }
5632 
5633     /**
5634      * @throws Exception if the test fails
5635      */
5636     @Test
5637     @Alerts("executed")
5638     public void insertAdjacentElementExecuteNestedJavaScript() throws Exception {
5639         final String html = DOCTYPE_HTML
5640             + "<html><head><script>\n"
5641             + LOG_TITLE_FUNCTION
5642             + "  function test() {\n"
5643             + "    var newnode = document.createElement('div');\n"
5644             + "    var newscript = document.createElement('script');\n"
5645             + "    newnode.appendChild(newscript);\n"
5646             + "    newscript.appendChild(document.createTextNode('alerter();'));\n"
5647 
5648             + "    var outernode = document.getElementById('myNode');\n"
5649             + "    if (!outernode.insertAdjacentElement) { log('insertAdjacentElement not available'); return }\n"
5650             + "    outernode.insertAdjacentElement('afterend', newnode);\n"
5651             + "  }\n"
5652             + "  function alerter() {\n"
5653             + "    log('executed');\n"
5654             + "  }\n"
5655             + "</script></head><body onload='test()'>\n"
5656             + "  <div id='myNode'></div>\n"
5657             + "</body></html>";
5658         loadPageVerifyTitle2(html);
5659     }
5660 
5661     /**
5662      * @throws Exception if the test fails
5663      */
5664     @Test
5665     @Alerts(DEFAULT = {"executed", "insertAdjacentElement done"},
5666             FF = "insertAdjacentElement done",
5667             FF_ESR = "insertAdjacentElement done")
5668     public void insertAdjacentElementExecuteTemplateChildJavaScript() throws Exception {
5669         final String html = DOCTYPE_HTML
5670             + "<html><head><script>\n"
5671             + LOG_TITLE_FUNCTION
5672             + "  function test() {\n"
5673             + "    var html = '<body><template><script>alerter();<' + '/script></template></body>';\n"
5674             + "    var parser = new DOMParser();\n"
5675             + "    var responseDoc = parser.parseFromString(html, 'text/html');\n"
5676             + "    var responseBody = responseDoc.body;\n"
5677             + "    var template = responseBody.querySelector('template');\n"
5678             + "    var scriptElem = template.content.firstChild;\n"
5679             + "    try {\n"
5680             + "      var outernode = document.getElementById('myNode');\n"
5681             + "      outernode.insertAdjacentElement('afterend', scriptElem);\n"
5682             + "      log('insertAdjacentElement done');\n"
5683             + "    } catch(e) { logEx(e); }\n"
5684             + "  }\n"
5685             + "  function alerter() {\n"
5686             + "    log('executed');\n"
5687             + "  }\n"
5688             + "</script></head>\n"
5689             + "<body onload='test()'>\n"
5690             + "  <div id='myNode'></div>\n"
5691             + "</body></html>";
5692         loadPageVerifyTitle2(html);
5693     }
5694 
5695     /**
5696      * @throws Exception if the test fails
5697      */
5698     @Test
5699     @Alerts(DEFAULT = {"executed", "insertAdjacentElement done1", "insertAdjacentElement done2"},
5700             FF = {"insertAdjacentElement done1", "insertAdjacentElement done2"},
5701             FF_ESR = {"insertAdjacentElement done1", "insertAdjacentElement done2"})
5702     public void insertAdjacentElementExecuteTemplateFragmentJavaScript() throws Exception {
5703         final String html = DOCTYPE_HTML
5704             + "<html><head><script>\n"
5705             + LOG_TITLE_FUNCTION
5706             + "  function test() {\n"
5707             + "    var html = '<body><template><script>alerter();<' + '/script></template></body>';\n"
5708             + "    var parser = new DOMParser();\n"
5709             + "    var responseDoc = parser.parseFromString(html, 'text/html');\n"
5710             + "    var responseBody = responseDoc.body;\n"
5711             + "    var templateContent = responseBody.querySelector('template').content;\n"
5712             + "    var scriptElem = templateContent.firstChild;\n"
5713 
5714             + "    try {\n"
5715             + "      var outernode = document.getElementById('myNode');\n"
5716             + "      outernode.insertAdjacentElement('afterend', scriptElem);\n"
5717             + "      log('insertAdjacentElement done1');\n"
5718             + "    } catch(e) { logEx(e); }\n"
5719 
5720             + "    try {\n"
5721             + "      var outernode = document.getElementById('secondNode');\n"
5722             + "      outernode.insertAdjacentElement('afterend', scriptElem);\n"
5723             + "      log('insertAdjacentElement done2');\n"
5724             + "    } catch(e) { logEx(e); }\n"
5725             + "  }\n"
5726             + "  function alerter() {\n"
5727             + "    log('executed');\n"
5728             + "  }\n"
5729             + "</script></head>\n"
5730             + "<body onload='test()'>\n"
5731             + "  <div id='myNode'></div>\n"
5732             + "  <div id='secondNode'></div>\n"
5733             + "</body></html>";
5734         loadPageVerifyTitle2(html);
5735     }
5736 
5737     /**
5738      * @throws Exception if the test fails
5739      */
5740     @Test
5741     @Alerts("declared")
5742     public void insertAdjacentElementDeclareJavaScript() throws Exception {
5743         final String html = DOCTYPE_HTML
5744             + "<html><head><script>\n"
5745             + LOG_TITLE_FUNCTION
5746             + "  function test() {\n"
5747             + "    var newnode = document.createElement('script');\n"
5748             + "    newnode.appendChild(document.createTextNode('function tester() { alerter(); }'));\n"
5749             + "    var outernode = document.getElementById('myNode');\n"
5750             + "    if (!outernode.insertAdjacentElement) { log('insertAdjacentElement not available'); return }\n"
5751             + "    outernode.insertAdjacentElement('afterend', newnode);\n"
5752             + "    tester();\n"
5753             + "  }\n"
5754             + "  function alerter() {\n"
5755             + "    log('declared');\n"
5756             + "  }\n"
5757             + "</script></head><body onload='test()'>\n"
5758             + "  <div id='myNode'></div>\n"
5759             + "</body></html>";
5760         loadPageVerifyTitle2(html);
5761     }
5762 
5763     /**
5764      * @throws Exception if the test fails
5765      */
5766     @Test
5767     @Alerts({"outside", "middle",
5768                 "before-begin after-begin inside before-end after-end"})
5769     public void insertAdjacentText() throws Exception {
5770         insertAdjacentText("beforeend", "afterend", "beforebegin", "afterbegin");
5771         insertAdjacentText("beforeEnd", "afterEnd", "beforeBegin", "afterBegin");
5772         insertAdjacentText("BeforeEnd", "AfterEnd", "BeFoReBeGiN", "afterbegin");
5773     }
5774 
5775     private void insertAdjacentText(final String beforeEnd,
5776             final String afterEnd, final String beforeBegin, final String afterBegin) throws Exception {
5777         final String html = DOCTYPE_HTML
5778             + "<html><head><script>\n"
5779             + LOG_TITLE_FUNCTION
5780             + "function test() {\n"
5781             + "  var oNode = document.getElementById('middle');\n"
5782             + "  if (!oNode.insertAdjacentText) { log('insertAdjacentText not available'); return }\n"
5783             + "  oNode.insertAdjacentText('" + beforeEnd + "', 'before-end');\n"
5784             + "  oNode.insertAdjacentText('" + afterEnd + "', ' after-end');\n"
5785             + "  oNode.insertAdjacentText('" + beforeBegin + "', 'before-begin ');\n"
5786             + "  oNode.insertAdjacentText('" + afterBegin + "', ' after-begin');\n"
5787             + "  var coll = document.getElementsByTagName('SPAN');\n"
5788             + "  for (var i = 0; i < coll.length; i++) {\n"
5789             + "    log(coll[i].id);\n"
5790             + "  }\n"
5791             + "  var outside = document.getElementById('outside');\n"
5792             + "  var text = outside.textContent ? outside.textContent : outside.innerText;\n"
5793             + "  text = text.replace(/(\\r\\n|\\r|\\n)/gm, '');\n"
5794             + "  text = text.replace(/(\\s{2,})/g, ' ');\n"
5795             + "  text = text.replace(/^\\s+|\\s+$/g, '');\n"
5796             + "  log(text);\n"
5797             + "}\n"
5798             + "</script></head><body onload='test()'>\n"
5799             + "  <span id='outside' style='color: #00ff00'>\n"
5800             + "    <span id='middle' style='color: #ff0000'>\n"
5801             + "      inside\n"
5802             + "    </span>\n"
5803             + "  </span>\n"
5804             + "</body></html>";
5805         loadPageVerifyTitle2(html);
5806     }
5807 
5808     /**
5809      * Simple test that calls setCapture.
5810      * @throws Exception if the test fails
5811      */
5812     @Test
5813     @Alerts(DEFAULT = {"undefined", "undefined", "undefined", "setCapture available"},
5814             CHROME = "TypeError",
5815             EDGE = "TypeError")
5816     public void setCapture() throws Exception {
5817         final String html = DOCTYPE_HTML
5818             + "<html><head>\n"
5819             + "<script>\n"
5820             + LOG_TITLE_FUNCTION
5821             + "  function test() {\n"
5822             + "    var div = document.getElementById('myDiv');\n"
5823             + "    try {\n"
5824             + "      log(div.setCapture());\n"
5825             + "      log(div.setCapture(true));\n"
5826             + "      log(div.setCapture(false));\n"
5827             + "      log('setCapture available');\n"
5828             + "    } catch(e) { logEx(e); }\n"
5829             + "  }\n"
5830             + "</script>\n"
5831             + "</head>\n"
5832             + "<body onload='test()'>\n"
5833             + "  <div id='myDiv'></div>\n"
5834             + "</body></html>";
5835         loadPageVerifyTitle2(html);
5836     }
5837 
5838     /**
5839      * Simple test that calls setCapture.
5840      * @throws Exception if the test fails
5841      */
5842     @Test
5843     @Alerts(DEFAULT = {"undefined", "releaseCapture available"},
5844             CHROME = "TypeError",
5845             EDGE = "TypeError")
5846     public void releaseCapture() throws Exception {
5847         final String html = DOCTYPE_HTML
5848             + "<html><head>\n"
5849             + "<script>\n"
5850             + LOG_TITLE_FUNCTION
5851             + "  function test() {\n"
5852             + "    var div = document.getElementById('myDiv');\n"
5853             + "    try {\n"
5854             + "      log(div.releaseCapture());\n"
5855             + "      log('releaseCapture available');\n"
5856             + "    } catch(e) { logEx(e); }\n"
5857             + "  }\n"
5858             + "</script>\n"
5859             + "</head>\n"
5860             + "<body onload='test()'>\n"
5861             + "  <div id='myDiv'></div>\n"
5862             + "</body></html>";
5863         loadPageVerifyTitle2(html);
5864     }
5865 
5866     /**
5867      * @throws Exception if the test fails
5868      */
5869     @Test
5870     @Alerts({"inherit", "false", "string", "boolean"})
5871     public void contentEditable() throws Exception {
5872         final String html = DOCTYPE_HTML
5873             + "<html><head>\n"
5874             + "<script>\n"
5875             + LOG_TITLE_FUNCTION
5876             + "  function test() {\n"
5877             + "    var div = document.getElementById('myDiv');\n"
5878             + "    log(div.contentEditable);\n"
5879             + "    log(div.isContentEditable);\n"
5880             + "    log(typeof div.contentEditable);\n"
5881             + "    log(typeof div.isContentEditable);\n"
5882             + "  }\n"
5883             + "</script>\n"
5884             + "</head>\n"
5885             + "<body onload='test()'>\n"
5886             + "  <div id='myDiv'></div>\n"
5887             + "</body></html>";
5888         loadPageVerifyTitle2(html);
5889     }
5890 
5891     /**
5892      * See issue #1702.
5893      * @throws Exception if the test fails
5894      */
5895     @Test
5896     @Alerts("true")
5897     public void oninput() throws Exception {
5898         final String html = DOCTYPE_HTML
5899             + "<html>\n"
5900             + "<head>\n"
5901             + "  <script>\n"
5902             + LOG_TITLE_FUNCTION
5903             + "    function test() {\n"
5904             + "      var testNode = document.createElement('div');\n"
5905             + "      log('oninput' in testNode);\n"
5906             + "    }\n"
5907             + "  </script>\n"
5908             + "</head>\n"
5909             + "<body onload='test()'>"
5910             + "</body>\n"
5911             + "</html>";
5912 
5913         loadPageVerifyTitle2(html);
5914     }
5915 
5916     /**
5917      * @throws Exception if the test fails
5918      */
5919     @Test
5920     @Alerts({"[object HTMLBodyElement]", "[object HTMLButtonElement]",
5921              "http://srv/htmlunit.org", "http://srv/htmlunit.org"})
5922     public void focus() throws Exception {
5923         final String html = DOCTYPE_HTML
5924             + "<html>\n"
5925             + "<head>\n"
5926             + "  <script>\n"
5927             + LOG_TITLE_FUNCTION
5928             + "    function test() {\n"
5929             + "      log(document.activeElement);\n"
5930 
5931             + "      var testNode = document.getElementById('myButton');\n"
5932             + "      testNode.focus();\n"
5933             + "      log(document.activeElement);\n"
5934 
5935             + "      testNode = document.getElementById('myA');\n"
5936             + "      testNode.focus();\n"
5937             + "      log(document.activeElement);\n"
5938 
5939             + "      testNode = document.getElementById('myDiv');\n"
5940             + "      testNode.focus();\n"
5941             + "      log(document.activeElement);\n"
5942             + "    }\n"
5943             + "  </script>\n"
5944             + "</head>\n"
5945             + "<body onload='test()'>\n"
5946             + "  <div id='myDiv'>blah</div>\n"
5947             + "  <a id='myA' href='http://srv/htmlunit.org'>anchor</a>\n"
5948             + "  <button id='myButton'>Press</button>\n"
5949             + "</body>\n"
5950             + "</html>";
5951 
5952         loadPageVerifyTitle2(html);
5953     }
5954 
5955     /**
5956      * @throws Exception if the test fails
5957      */
5958     @Test
5959     public void blur() throws Exception {
5960         final String html = DOCTYPE_HTML
5961             + "<html><head>\n"
5962             + "<body>\n"
5963             + "  <div id='div1' onblur='alert(\"blurred\")'>the first div</div>\n"
5964             + "  <div id='div2'>the second div</div>\n"
5965             + "</body></html>";
5966 
5967         final WebDriver webDriver = loadPage2(html);
5968 
5969         webDriver.findElement(By.id("div1")).click();
5970         webDriver.findElement(By.id("div2")).click();
5971 
5972         verifyAlerts(webDriver, getExpectedAlerts());
5973     }
5974 
5975     /**
5976      * @throws Exception if the test fails
5977      */
5978     @Test
5979     @Alerts("blurred")
5980     public void blur2() throws Exception {
5981         final String html = DOCTYPE_HTML
5982             + "<html><head>\n"
5983             + "<body>\n"
5984             + "  <div id='div1' onblur='alert(\"blurred\")' tabindex='0'>the first div</div>\n"
5985             + "  <div id='div2'>the second div</div>\n"
5986             + "</body></html>";
5987 
5988         final WebDriver webDriver = loadPage2(html);
5989 
5990         webDriver.findElement(By.id("div1")).click();
5991         webDriver.findElement(By.id("div2")).click();
5992 
5993         verifyAlerts(webDriver, getExpectedAlerts());
5994     }
5995 
5996     /**
5997      * @throws Exception if the test fails
5998      */
5999     @Test
6000     @Alerts({"[object HTMLDivElement]", "[object HTMLBodyElement]", "[object Window]"})
6001     public void currentTarget() throws Exception {
6002         final String html = DOCTYPE_HTML
6003             + "<html>\n"
6004             + "<head>\n"
6005             + "<script>\n"
6006             + LOG_TITLE_FUNCTION
6007             + "  function handler(ev) {\n"
6008             + "    log(ev.currentTarget);\n"
6009             + "  }\n"
6010 
6011             + "  function test() {\n"
6012             + "    var byId = document.getElementById.bind(document);\n"
6013 
6014             + "    var under = byId('under');\n"
6015             + "    var over = byId('over');\n"
6016             + "    var body = document.body;\n"
6017 
6018             + "    var types = ['click'];\n"
6019             + "    for (var i = 0, type; (type = types[i]); ++i) {\n"
6020             + "      under.addEventListener(type, handler);\n"
6021             + "      over.addEventListener(type, handler);\n"
6022             + "      body.addEventListener(type, handler);\n"
6023             + "      window.addEventListener(type, handler);\n"
6024             + "    }\n"
6025             + "  }\n"
6026             + "</script>\n"
6027             + "</head>\n"
6028             + "<body onload='test()'>\n"
6029             + "  <div id='under'>\n"
6030             + "    <p id='contents'>Hello</p>"
6031             + "  </div>\n"
6032             + "  <div id='over'>abc</div>\n"
6033             + "</body>\n"
6034             + "</html>";
6035 
6036         final WebDriver webDriver = loadPage2(html);
6037         webDriver.findElement(By.id("over")).click();
6038         verifyTitle2(webDriver, getExpectedAlerts());
6039     }
6040 
6041     /**
6042      * @throws Exception if the test fails
6043      */
6044     @Test
6045     @Alerts({"[object HTMLDivElement]", "[object HTMLBodyElement]"})
6046     public void currentTargetBody() throws Exception {
6047         final String html = DOCTYPE_HTML
6048             + "<html>\n"
6049             + "<head>\n"
6050             + "<script>\n"
6051             + LOG_TITLE_FUNCTION
6052             + "  function handler(ev) {\n"
6053             + "    log(ev.currentTarget);\n"
6054             + "  }\n"
6055 
6056             + "  function test() {\n"
6057             + "    var byId = document.getElementById.bind(document);\n"
6058 
6059             + "    var under = byId('under');\n"
6060             + "    var over = byId('over');\n"
6061             + "    var body = document.body;\n"
6062 
6063             + "    var types = ['click'];\n"
6064             + "    for (var i = 0, type; (type = types[i]); ++i) {\n"
6065             + "      over.addEventListener(type, handler);\n"
6066             + "      body.addEventListener(type, handler);\n"
6067             + "    }\n"
6068             + "  }\n"
6069             + "</script>\n"
6070             + "</head>\n"
6071             + "<body onload='test()'>\n"
6072             + "  <div id='over'>abc</div>\n"
6073             + "</body>\n"
6074             + "</html>";
6075 
6076         final WebDriver webDriver = loadPage2(html);
6077         webDriver.findElement(By.id("over")).click();
6078         verifyTitle2(webDriver, getExpectedAlerts());
6079     }
6080 
6081     /**
6082      * @throws Exception if the test fails
6083      */
6084     @Test
6085     @Alerts({"[object HTMLDivElement]", "[object Window]"})
6086     public void currentTargetWindow() throws Exception {
6087         final String html = DOCTYPE_HTML
6088             + "<html>\n"
6089             + "<head>\n"
6090             + "<script>\n"
6091             + LOG_TITLE_FUNCTION
6092             + "  function handler(ev) {\n"
6093             + "    log(ev.currentTarget);\n"
6094             + "  }\n"
6095 
6096             + "  function test() {\n"
6097             + "    var byId = document.getElementById.bind(document);\n"
6098 
6099             + "    var under = byId('under');\n"
6100             + "    var over = byId('over');\n"
6101             + "    var body = document.body;\n"
6102 
6103             + "    var types = ['click'];\n"
6104             + "    for (var i = 0, type; (type = types[i]); ++i) {\n"
6105             + "      over.addEventListener(type, handler);\n"
6106             + "      window.addEventListener(type, handler);\n"
6107             + "    }\n"
6108             + "  }\n"
6109             + "</script>\n"
6110             + "</head>\n"
6111             + "<body onload='test()'>\n"
6112             + "  <div id='over'>abc</div>\n"
6113             + "</body>\n"
6114             + "</html>";
6115 
6116         final WebDriver webDriver = loadPage2(html);
6117         webDriver.findElement(By.id("over")).click();
6118         verifyTitle2(webDriver, getExpectedAlerts());
6119     }
6120 
6121     /**
6122      * @throws Exception if the test fails
6123      */
6124     @Test
6125     @Alerts({"added", "removed", "[object HTMLDivElement]", "[object Window]"})
6126     public void addRemoveEventListenerFromBody() throws Exception {
6127         final String html = DOCTYPE_HTML
6128             + "<html>\n"
6129             + "<head>\n"
6130             + "<script>\n"
6131             + LOG_TITLE_FUNCTION
6132             + "  function handler(ev) {\n"
6133             + "    log(ev.currentTarget);\n"
6134             + "  }\n"
6135 
6136             + "  function test() {\n"
6137             + "    var under = document.getElementById('under');\n"
6138             + "    var over = document.getElementById('over');\n"
6139             + "    var body = document.body;\n"
6140 
6141             + "    over.addEventListener('click', handler);\n"
6142             + "    body.addEventListener('click', handler);\n"
6143             + "    window.addEventListener('click', handler);\n"
6144             + "    log('added');\n"
6145 
6146             + "    body.removeEventListener('click', handler);\n"
6147             + "    log('removed');\n"
6148             + "  }\n"
6149             + "</script>\n"
6150             + "</head>\n"
6151             + "<body onload='test()'>\n"
6152             + "  <div id='over'>abc</div>\n"
6153             + "</body>\n"
6154             + "</html>";
6155 
6156         final WebDriver webDriver = loadPageVerifyTitle2(html,
6157                 getExpectedAlerts()[0], getExpectedAlerts()[1]);
6158 
6159         webDriver.findElement(By.id("over")).click();
6160         verifyTitle2(webDriver, getExpectedAlerts());
6161     }
6162 
6163     /**
6164      * @throws Exception if the test fails
6165      */
6166     @Test
6167     @Alerts({"added", "removed", "[object HTMLDivElement]", "[object Window]"})
6168     public void addRemoveEventListenerFromBody2() throws Exception {
6169         final String html = DOCTYPE_HTML
6170             + "<html>\n"
6171             + "<head>\n"
6172             + "<script>\n"
6173             + LOG_TITLE_FUNCTION
6174             + "  function handler(ev) {\n"
6175             + "    log(ev.currentTarget);\n"
6176             + "  }\n"
6177 
6178             + "  function test() {\n"
6179             + "    var under = document.getElementById('under');\n"
6180             + "    var over = document.getElementById('over');\n"
6181             + "    var body = document.body;\n"
6182 
6183             + "    over.addEventListener('click', handler);\n"
6184             + "    window.addEventListener('click', handler);\n"
6185 //            + "    body.addEventListener('click', handler);\n"
6186             + "    log('added');\n"
6187 
6188             + "    body.removeEventListener('click', handler);\n"
6189             + "    log('removed');\n"
6190             + "  }\n"
6191             + "</script>\n"
6192             + "</head>\n"
6193             + "<body onload='test()'>\n"
6194             + "  <div id='over'>abc</div>\n"
6195             + "</body>\n"
6196             + "</html>";
6197 
6198         final WebDriver webDriver = loadPageVerifyTitle2(html,
6199                 getExpectedAlerts()[0], getExpectedAlerts()[1]);
6200 
6201         webDriver.findElement(By.id("over")).click();
6202         verifyTitle2(webDriver, getExpectedAlerts());
6203     }
6204 
6205     /**
6206      * @throws Exception if the test fails
6207      */
6208     @Test
6209     @Alerts({"added", "removed", "[object HTMLDivElement]", "[object HTMLBodyElement]"})
6210     public void addRemoveEventListenerFromWindow() throws Exception {
6211         final String html = DOCTYPE_HTML
6212             + "<html>\n"
6213             + "<head>\n"
6214             + "<script>\n"
6215             + LOG_TITLE_FUNCTION
6216             + "  function handler(ev) {\n"
6217             + "    log(ev.currentTarget);\n"
6218             + "  }\n"
6219 
6220             + "  function test() {\n"
6221             + "    var under = document.getElementById('under');\n"
6222             + "    var over = document.getElementById('over');\n"
6223             + "    var body = document.body;\n"
6224 
6225             + "    over.addEventListener('click', handler);\n"
6226             + "    body.addEventListener('click', handler);\n"
6227             + "    window.addEventListener('click', handler);\n"
6228             + "    log('added');\n"
6229 
6230             + "    window.removeEventListener('click', handler);\n"
6231             + "    log('removed');\n"
6232             + "  }\n"
6233             + "</script>\n"
6234             + "</head>\n"
6235             + "<body onload='test()'>\n"
6236             + "  <div id='over'>abc</div>\n"
6237             + "</body>\n"
6238             + "</html>";
6239 
6240         final WebDriver webDriver = loadPageVerifyTitle2(html, getExpectedAlerts()[0], getExpectedAlerts()[1]);
6241 
6242         webDriver.findElement(By.id("over")).click();
6243         verifyTitle2(webDriver, getExpectedAlerts());
6244     }
6245 
6246     /**
6247      * @throws Exception if the test fails
6248      */
6249     @Test
6250     @Alerts({"added", "removed", "[object HTMLDivElement]", "[object HTMLBodyElement]"})
6251     public void addRemoveEventListenerFromWindow1() throws Exception {
6252         final String html = DOCTYPE_HTML
6253             + "<html>\n"
6254             + "<head>\n"
6255             + "<script>\n"
6256             + LOG_TITLE_FUNCTION
6257             + "  function handler(ev) {\n"
6258             + "    log(ev.currentTarget);\n"
6259             + "  }\n"
6260 
6261             + "  function test() {\n"
6262             + "    var under = document.getElementById('under');\n"
6263             + "    var over = document.getElementById('over');\n"
6264             + "    var body = document.body;\n"
6265 
6266             + "    over.addEventListener('click', handler);\n"
6267             + "    window.addEventListener('click', handler);\n"
6268             + "    body.addEventListener('click', handler);\n"
6269             + "    log('added');\n"
6270 
6271             + "    window.removeEventListener('click', handler);\n"
6272             + "    log('removed');\n"
6273             + "  }\n"
6274             + "</script>\n"
6275             + "</head>\n"
6276             + "<body onload='test()'>\n"
6277             + "  <div id='over'>abc</div>\n"
6278             + "</body>\n"
6279             + "</html>";
6280 
6281         final WebDriver webDriver = loadPageVerifyTitle2(html, getExpectedAlerts()[0], getExpectedAlerts()[1]);
6282 
6283         webDriver.findElement(By.id("over")).click();
6284         verifyTitle2(webDriver, getExpectedAlerts());
6285     }
6286 
6287     /**
6288      * @throws Exception if the test fails
6289      */
6290     @Test
6291     @Alerts(DEFAULT = "mousedown-over-over\nmousedown-over-body\nmousedown-over-undefined\n"
6292                     + "mouseup--body\nmouseup--undefined",
6293             FF = "mousedown-over-over\nmousedown-over-body\nmousedown-over-undefined\n"
6294                     + "mouseup--body\nmouseup--undefined\nclick-body-body\nclick-body-undefined",
6295             FF_ESR = "mousedown-over-over\nmousedown-over-body\nmousedown-over-undefined\n"
6296                     + "mouseup--body\nmouseup--undefined\nclick-body-body\nclick-body-undefined")
6297     @HtmlUnitNYI(CHROME = "mousedown-over-over\nmousedown-over-body\nmousedown-over-undefined\n"
6298                     + "mouseup-over-over\nmouseup-over-body\nmouseup-over-undefined",
6299             EDGE = "mousedown-over-over\nmousedown-over-body\nmousedown-over-undefined\n"
6300                     + "mouseup-over-over\nmouseup-over-body\nmouseup-over-undefined",
6301             FF = "mousedown-over-over\nmousedown-over-body\nmousedown-over-undefined\n"
6302                     + "mouseup-over-over\nmouseup-over-body\nmouseup-over-undefined",
6303             FF_ESR = "mousedown-over-over\nmousedown-over-body\nmousedown-over-undefined\n"
6304                     + "mouseup-over-over\nmouseup-over-body\nmouseup-over-undefined")
6305     public void clickAnElementThatDisappears() throws Exception {
6306         final String html = DOCTYPE_HTML
6307             + "<html>\n"
6308             + "<head>\n"
6309             + "<title>Test</title>\n"
6310             + "<script>\n"
6311             + "  function handler(e) {\n"
6312             + "    var log = document.getElementById('log');\n"
6313             + "    log.innerHTML += '<p></p>';\n"
6314             + "    log.lastElementChild.textContent = e.type + '-' + e.target.id + '-' + e.currentTarget.id;\n"
6315             + "  }\n"
6316 
6317             + "  function test() {\n"
6318             + "    var over = document.getElementById('over');\n"
6319             + "    var body = document.body;\n"
6320 
6321             + "    var types = ['click', 'mousedown', 'mouseup'];\n"
6322             + "    for (var i = 0, type; (type = types[i]); ++i) {\n"
6323             + "      over.addEventListener(type, handler);\n"
6324             + "      body.addEventListener(type, handler);\n"
6325             + "      window.addEventListener(type, handler);\n"
6326             + "    }\n"
6327 
6328             + "    over.addEventListener('mousedown', function () {\n"
6329             + "      over.style.display = 'none';\n"
6330             + "    });\n"
6331             + "  }\n"
6332             + "</script>\n"
6333             + "</head>\n"
6334             + "<body id='body' onload='test()'>\n"
6335             + "  <div id='over'>abc</div>\n"
6336             + "  <div id='log'></div>\n"
6337             + "  </div>\n"
6338             + "</body>\n"
6339             + "</html>";
6340 
6341         final WebDriver webDriver = loadPage2(html);
6342         webDriver.findElement(By.id("over")).click();
6343         assertEquals(getExpectedAlerts()[0], webDriver.findElement(By.id("log")).getText());
6344     }
6345 
6346     /**
6347      * @throws Exception if the test fails
6348      */
6349     @Test
6350     @Alerts("<select id=\"myId\"><option>Two</option></select>")
6351     public void innerHTML() throws Exception {
6352         final String html = DOCTYPE_HTML
6353             + "<html>\n"
6354             + "<head>\n"
6355             + "  <script>\n"
6356             + LOG_TITLE_FUNCTION
6357             + "    function test() {\n"
6358             + "      var select = document.getElementById('myId');\n"
6359             + "      select.innerHTML = \"<select id='myId2'><option>Two</option></select>\";\n"
6360             + "      log(document.body.innerHTML.trim());\n"
6361             + "    }\n"
6362             + "  </script>\n"
6363             + "</head>\n"
6364             + "<body onload='test()'>\n"
6365             + "  <select id='myId'><option>One</option></select>\n"
6366             + "</body>\n"
6367             + "</html>";
6368 
6369         loadPageVerifyTitle2(html);
6370     }
6371 
6372     /**
6373      * @throws Exception if the test fails
6374      */
6375     @Test
6376     @Alerts("1")
6377     public void innerHTMLGetElementsByTagName() throws Exception {
6378         final String html = DOCTYPE_HTML
6379             + "<html>\n"
6380             + "<head>\n"
6381             + "  <script>\n"
6382             + LOG_TITLE_FUNCTION
6383             + "    function test() {\n"
6384             + "      var div = document.createElement('div');\n"
6385             + "      div.innerHTML = \"<table></table><a href='/a'>a</a>\";\n"
6386             + "      log(div.getElementsByTagName('a').length);\n"
6387             + "    }\n"
6388             + "  </script>\n"
6389             + "</head>\n"
6390             + "<body onload='test()'>\n"
6391             + "</body>\n"
6392             + "</html>";
6393 
6394         loadPageVerifyTitle2(html);
6395     }
6396 
6397     /**
6398      * @throws Exception if the test fails
6399      */
6400     @Test
6401     @Alerts({"false", "false"})
6402     public void hidden() throws Exception {
6403         final String html = DOCTYPE_HTML
6404             + "<html><head><script>\n"
6405             + LOG_TITLE_FUNCTION
6406             + "  function test() {\n"
6407             + "    var d1 = document.getElementById('div1');\n"
6408             + "    log(d1.hidden);\n"
6409             + "    var d2 = document.getElementById('div2');\n"
6410             + "    log(d2.hidden);\n"
6411             + "  }\n"
6412             + "</script></head>\n"
6413             + "<body onload='test()'>\n"
6414             + "  <div id='div1' style='display: none'>\n"
6415             + "  </div>\n"
6416             + "  <div id='div2' />\n"
6417             + "</body></html>";
6418 
6419         loadPageVerifyTitle2(html);
6420     }
6421 
6422     /**
6423      * @throws Exception if an error occurs
6424      */
6425     @Test
6426     @Alerts({"1 null/false", "2 /true", "3 /true", "4 hidden/true", "5 true/true", "6 false/true",
6427              "7 until-found/until-found", "8 show/true", "9 Until-Found/until-found", "10 HIDDEN/true"})
6428     public void hiddenGet() throws Exception {
6429         final String html = DOCTYPE_HTML
6430             + "<html><body>\n"
6431             + "<p id='p1'>p1</p>\n"
6432             + "<p id='p2' hidden>p2</p>\n"
6433             + "<p id='p3' hidden=''>p3</p>\n"
6434             + "<p id='p4' hidden='hidden'>p4</p>\n"
6435             + "<p id='p5' hidden='true'>p5</p>\n"
6436             + "<p id='p6' hidden='false'>p6</p>\n"
6437             + "<p id='p7' hidden='until-found'>p7</p>\n"
6438             + "<p id='p8' hidden='show'>p8</p>\n"
6439 
6440             + "<p id='p9' hidden='Until-Found'>p9</p>\n"
6441             + "<p id='p10' hidden='HIDDEN'>p10</p>\n"
6442 
6443             + "<script>\n"
6444             + LOG_TITLE_FUNCTION
6445             + "var p1 = document.getElementById('p1');\n"
6446             + "var p2 = document.getElementById('p2');\n"
6447             + "var p3 = document.getElementById('p3');\n"
6448             + "var p4 = document.getElementById('p4');\n"
6449             + "var p5 = document.getElementById('p5');\n"
6450             + "var p6 = document.getElementById('p6');\n"
6451             + "var p7 = document.getElementById('p7');\n"
6452             + "var p8 = document.getElementById('p8');\n"
6453             + "var p9 = document.getElementById('p9');\n"
6454             + "var p10 = document.getElementById('p10');\n"
6455 
6456             + "log('1 ' + p1.getAttribute('hidden') + '/' + p1.hidden);\n"
6457             + "log('2 ' + p2.getAttribute('hidden') + '/' + p2.hidden);\n"
6458             + "log('3 ' + p3.getAttribute('hidden') + '/' + p3.hidden);\n"
6459             + "log('4 ' + p4.getAttribute('hidden') + '/' + p4.hidden);\n"
6460             + "log('5 ' + p5.getAttribute('hidden') + '/' + p5.hidden);\n"
6461             + "log('6 ' + p6.getAttribute('hidden') + '/' + p6.hidden);\n"
6462             + "log('7 ' + p7.getAttribute('hidden') + '/' + p7.hidden);\n"
6463             + "log('8 ' + p8.getAttribute('hidden') + '/' + p8.hidden);\n"
6464             + "log('9 ' + p9.getAttribute('hidden') + '/' + p9.hidden);\n"
6465             + "log('10 ' + p10.getAttribute('hidden') + '/' + p10.hidden);\n"
6466             + "</script>\n"
6467             + "</body></html>";
6468 
6469         loadPageVerifyTitle2(html);
6470     }
6471 
6472     /**
6473      * @throws Exception if an error occurs
6474      */
6475     @Test
6476     @Alerts({"1 null/false", "2 null/false", "3 /true", "4 /true", "5 null/false",
6477              "6 null/false", "7 /true", "8 /true",
6478              "9 null/false", "10 /true", "11 /true",
6479              "12 null/false", "13 until-found/until-found", "14 null/false",
6480              "15 null/false", "16 until-found/until-found",
6481              "17 null/false", "18 /true"})
6482     public void hiddenSet() throws Exception {
6483         final String html = DOCTYPE_HTML
6484             + "<html><body>\n"
6485             + "<p id='p1'>p1</p>\n"
6486             + "<p id='p2'>p2</p>\n"
6487             + "<p id='p3'>p3</p>\n"
6488             + "<p id='p4'>p4</p>\n"
6489             + "<p id='p5'>p5</p>\n"
6490             + "<p id='p6'>p6</p>\n"
6491 
6492             + "<script>\n"
6493             + LOG_TITLE_FUNCTION
6494             + "function set(p, value) {\n"
6495             + "  try {\n"
6496             + "    p.hidden = value;\n"
6497             + "  } catch(e) {\n"
6498             + "    log('!');\n"
6499             + "  }\n"
6500             + "}\n"
6501             + "var p1 = document.getElementById('p1');\n"
6502             + "var p2 = document.getElementById('p2');\n"
6503             + "var p3 = document.getElementById('p3');\n"
6504             + "var p4 = document.getElementById('p4');\n"
6505             + "var p5 = document.getElementById('p5');\n"
6506             + "var p6 = document.getElementById('p6');\n"
6507 
6508             + "log('1 ' + p1.getAttribute('hidden') + '/' + p1.hidden);\n"
6509 
6510             + "set(p1, '');\n"
6511             + "log('2 ' + p1.getAttribute('hidden') + '/' + p1.hidden);\n"
6512 
6513             + "set(p1, 'hidden');\n"
6514             + "log('3 ' + p1.getAttribute('hidden') + '/' + p1.hidden);\n"
6515 
6516             + "set(p1, 'false');\n"
6517             + "log('4 ' + p1.getAttribute('hidden') + '/' + p1.hidden);\n"
6518 
6519             + "set(p1, false);\n"
6520             + "log('5 ' + p1.getAttribute('hidden') + '/' + p1.hidden);\n"
6521 
6522             // p2
6523             + "log('6 ' + p2.getAttribute('hidden') + '/' + p2.hidden);\n"
6524             + "set(p2, 'true');\n"
6525             + "log('7 ' + p2.getAttribute('hidden') + '/' + p2.hidden);\n"
6526 
6527             + "set(p2, 'show');\n"
6528             + "log('8 ' + p2.getAttribute('hidden') + '/' + p2.hidden);\n"
6529 
6530             // p3
6531             + "log('9 ' + p3.getAttribute('hidden') + '/' + p3.hidden);\n"
6532             + "set(p3, true);\n"
6533             + "log('10 ' + p3.getAttribute('hidden') + '/' + p3.hidden);\n"
6534 
6535             + "set(p3, 'show');\n"
6536             + "log('11 ' + p3.getAttribute('hidden') + '/' + p3.hidden);\n"
6537 
6538             // p4
6539             + "log('12 ' + p4.getAttribute('hidden') + '/' + p4.hidden);\n"
6540             + "set(p4, 'until-found');\n"
6541             + "log('13 ' + p4.getAttribute('hidden') + '/' + p4.hidden);\n"
6542 
6543             + "set(p4, '');\n"
6544             + "log('14 ' + p4.getAttribute('hidden') + '/' + p4.hidden);\n"
6545 
6546             // p5
6547             + "log('15 ' + p5.getAttribute('hidden') + '/' + p5.hidden);\n"
6548             + "set(p5, 'Until-Found');\n"
6549             + "log('16 ' + p5.getAttribute('hidden') + '/' + p5.hidden);\n"
6550 
6551             // p6
6552             + "log('17 ' + p6.getAttribute('hidden') + '/' + p6.hidden);\n"
6553             + "set(p6, 'HIDDEN');\n"
6554             + "log('18 ' + p6.getAttribute('hidden') + '/' + p6.hidden);\n"
6555 
6556             + "</script>\n"
6557             + "</body></html>";
6558 
6559         loadPageVerifyTitle2(html);
6560     }
6561 
6562     /**
6563      * @throws Exception if the test fails
6564      */
6565     @Test
6566     public void isDisplayed() throws Exception {
6567         final String html = DOCTYPE_HTML
6568             + "<html>\n"
6569             + "<body>\n"
6570             + "  <div id='div1' hidden>\n"
6571             + "    <div id='child' />\n"
6572             + "  </div>\n"
6573             + "</body></html>";
6574 
6575         final WebDriver driver = loadPage2(html);
6576         final WebElement element = driver.findElement(By.id("child"));
6577         assertFalse(element.isDisplayed());
6578     }
6579 
6580     /**
6581      * @throws Exception if the test fails
6582      */
6583     @Test
6584     @Alerts({"", "go", "", "enter", "done",  "go", "next", "previous", "search", "send"})
6585     public void enterKeyHint() throws Exception {
6586         final String html = DOCTYPE_HTML
6587             + "<html><head><script>\n"
6588             + LOG_TITLE_FUNCTION
6589             + "  function test() {\n"
6590             + "    var d1 = document.getElementById('div1');\n"
6591             + "    log(d1.enterKeyHint);\n"
6592 
6593             + "    d1.enterKeyHint = 'GO';\n"
6594             + "    log(d1.enterKeyHint);\n"
6595 
6596             + "    d1.enterKeyHint = 'run';\n"
6597             + "    log(d1.enterKeyHint);\n"
6598 
6599             + "    d1.enterKeyHint = 'enter';\n"
6600             + "    log(d1.enterKeyHint);\n"
6601 
6602             + "    d1.enterKeyHint = 'done';\n"
6603             + "    log(d1.enterKeyHint);\n"
6604 
6605             + "    d1.enterKeyHint = 'go';\n"
6606             + "    log(d1.enterKeyHint);\n"
6607 
6608             + "    d1.enterKeyHint = 'next';\n"
6609             + "    log(d1.enterKeyHint);\n"
6610 
6611             + "    d1.enterKeyHint = 'previous';\n"
6612             + "    log(d1.enterKeyHint);\n"
6613 
6614             + "    d1.enterKeyHint = 'search';\n"
6615             + "    log(d1.enterKeyHint);\n"
6616 
6617             + "    d1.enterKeyHint = 'send';\n"
6618             + "    log(d1.enterKeyHint);\n"
6619             + "  }\n"
6620             + "</script></head>\n"
6621             + "<body onload='test()'>\n"
6622             + "  <div id='div1' style='display: none'>\n"
6623             + "  </div>\n"
6624             + "</body></html>";
6625 
6626         loadPageVerifyTitle2(html);
6627     }
6628 
6629 
6630     /**
6631      * @throws Exception if the test fails
6632      */
6633     @Test
6634     @Alerts({"", "go", "", "", ""})
6635     public void enterKeyHint2() throws Exception {
6636         final String html = DOCTYPE_HTML
6637             + "<html><head><script>\n"
6638             + LOG_TITLE_FUNCTION
6639             + "  function test() {\n"
6640             + "    var d1 = document.getElementById('div1');\n"
6641             + "    log(d1.enterKeyHint);\n"
6642 
6643             + "    d1.enterKeyHint = 'GO';\n"
6644             + "    log(d1.enterKeyHint);\n"
6645 
6646             + "    d1.enterKeyHint = 'run';\n"
6647             + "    log(d1.enterKeyHint);\n"
6648 
6649             + "    d1.enterKeyHint = undefined;\n"
6650             + "    log(d1.enterKeyHint);\n"
6651 
6652             + "    d1.enterKeyHint = null;\n"
6653             + "    log(d1.enterKeyHint);\n"
6654             + "  }\n"
6655             + "</script></head>\n"
6656             + "<body onload='test()'>\n"
6657             + "  <div id='div1' style='display: none'>\n"
6658             + "  </div>\n"
6659             + "</body></html>";
6660 
6661         loadPageVerifyTitle2(html);
6662     }
6663 
6664     /**
6665      * @throws Exception if the test fails
6666      */
6667     @Test
6668     @Alerts({"go", "go", "", "", ""})
6669     public void enterKeyHintDefaults() throws Exception {
6670         final String html = DOCTYPE_HTML
6671             + "<html><head><script>\n"
6672             + LOG_TITLE_FUNCTION
6673             + "  function test() {\n"
6674             + "    var input1 = document.getElementById('input1');\n"
6675             + "    log(input1.enterKeyHint);\n"
6676 
6677             + "    var input2 = document.getElementById('input2');\n"
6678             + "    log(input2.enterKeyHint);\n"
6679 
6680             + "    var input3 = document.getElementById('input3');\n"
6681             + "    log(input3.enterKeyHint);\n"
6682 
6683             + "    var input4 = document.getElementById('input4');\n"
6684             + "    log(input4.enterKeyHint);\n"
6685 
6686             + "    var input5 = document.getElementById('input5');\n"
6687             + "    log(input5.enterKeyHint);\n"
6688             + "  }\n"
6689             + "</script></head>\n"
6690             + "<body onload='test()'>\n"
6691             + "  <input id='input1' enterkeyhint='go'>\n"
6692             + "  <input id='input2' enterkeyhint='gO'>\n"
6693             + "  <input id='input3' enterkeyhint='run'>\n"
6694             + "  <input id='input4' enterkeyhint=undefined>\n"
6695             + "  <input id='input5' enterkeyhint=null>\n"
6696             + "</body></html>";
6697 
6698         loadPageVerifyTitle2(html);
6699     }
6700 
6701     /**
6702      * @throws Exception on test failure
6703      */
6704     @Test
6705     @Alerts({"true", "", "true", "7", "true", "seven", "false", "null"})
6706     public void autofocus() throws Exception {
6707         final String html = DOCTYPE_HTML
6708                 + "<html>\n"
6709                 + "<head>\n"
6710                 + "  <title>test</title>\n"
6711                 + "  <script>\n"
6712                 + LOG_TEXTAREA_FUNCTION
6713                 + "  function doTest() {\n"
6714                 + "    var myNode1 = document.getElementById('myNode1');\n"
6715                 + "    log(myNode1.autofocus);\n"
6716                 + "    log(myNode1.getAttribute('autofocus'));\n"
6717 
6718                 + "    var myNode2 = document.getElementById('myNode2');\n"
6719                 + "    log(myNode2.autofocus);\n"
6720                 + "    log(myNode2.getAttribute('autofocus'));\n"
6721 
6722                 + "    var myNode3 = document.getElementById('myNode3');\n"
6723                 + "    log(myNode3.autofocus);\n"
6724                 + "    log(myNode3.getAttribute('autofoCuS'));\n"
6725 
6726                 + "    var myNode4 = document.getElementById('myNode4');\n"
6727                 + "    log(myNode4.autofocus);\n"
6728                 + "    log(myNode4.getAttribute('autofocus'));\n"
6729                 + "  }\n"
6730                 + "  </script>\n"
6731                 + "</head>\n"
6732                 + "<body onload='doTest()'>\n"
6733                 + "<p id='myNode1' autofocus></p>\n"
6734                 + "<p id='myNode2' autofocus=7></p>\n"
6735                 + "<p id='myNode3' autOFocus='seven'></p>\n"
6736                 + "<p id='myNode4'></p>\n"
6737                 + LOG_TEXTAREA
6738                 + "</body>\n"
6739                 + "</html>";
6740 
6741         loadPageVerifyTextArea2(html);
6742     }
6743 
6744     /**
6745      * @throws Exception on test failure
6746      */
6747     @Test
6748     @Alerts({"true", "", "true", "", "false", "null", "true", "7",
6749              "true", "", "false", "null", "true", "", "false", "null",
6750              "true", "", "false", "null", "false", "null"})
6751     public void editAutofocus() throws Exception {
6752         final String html = DOCTYPE_HTML
6753                 + "<html>\n"
6754                 + "<head>\n"
6755                 + "  <title>test</title>\n"
6756                 + "  <script>\n"
6757                 + LOG_TEXTAREA_FUNCTION
6758                 + "  function doTest() {\n"
6759                 + "    var myNode1 = document.getElementById('myNode1');\n"
6760                 + "    log(myNode1.autofocus);\n"
6761                 + "    log(myNode1.getAttribute('autofocus'));\n"
6762 
6763                 + "    myNode1.setAttribute('autofocus', '');\n"
6764                 + "    log(myNode1.autofocus);\n"
6765                 + "    log(myNode1.getAttribute('autofocus'));\n"
6766 
6767                 + "    myNode1.removeAttribute('autofocus');\n"
6768                 + "    log(myNode1.autofocus);\n"
6769                 + "    log(myNode1.getAttribute('autofocus'));\n"
6770 
6771                 + "    var myNode2 = document.getElementById('myNode2');\n"
6772                 + "    log(myNode2.autofocus);\n"
6773                 + "    log(myNode2.getAttribute('autofocus'));\n"
6774 
6775                 + "    myNode2.autofocus = true;\n"
6776                 + "    log(myNode2.autofocus);\n"
6777                 + "    log(myNode2.getAttribute('autofocus'));\n"
6778 
6779                 + "    myNode2.autofocus = false;\n"
6780                 + "    log(myNode2.autofocus);\n"
6781                 + "    log(myNode2.getAttribute('autofocus'));\n"
6782 
6783                 + "    myNode2.autofocus = true;\n"
6784                 + "    log(myNode2.autofocus);\n"
6785                 + "    log(myNode2.getAttribute('autofocus'));\n"
6786 
6787                 + "    myNode2.autofocus = false;\n"
6788                 + "    log(myNode2.autofocus);\n"
6789                 + "    log(myNode2.getAttribute('autofocus'));\n"
6790 
6791                 + "    myNode2.autofocus = 'no';\n"
6792                 + "    log(myNode2.autofocus);\n"
6793                 + "    log(myNode2.getAttribute('autofocus'));\n"
6794 
6795                 + "    myNode2.autofocus = null;\n"
6796                 + "    log(myNode2.autofocus);\n"
6797                 + "    log(myNode2.getAttribute('autofocus'));\n"
6798 
6799                 + "    myNode2.autofocus = undefined;\n"
6800                 + "    log(myNode2.autofocus);\n"
6801                 + "    log(myNode2.getAttribute('autofocus'));\n"
6802                 + "  }\n"
6803                 + "  </script>\n"
6804                 + "</head>\n"
6805                 + "<body onload='doTest()'>\n"
6806                 + "<p id='myNode1' autofocus></p>\n"
6807                 + "<p id='myNode2' autofocus=7></p>\n"
6808                 + LOG_TEXTAREA
6809                 + "</body>\n"
6810                 + "</html>";
6811 
6812         loadPageVerifyTextArea2(html);
6813     }
6814 
6815     /**
6816      * @throws Exception if the test fails
6817      */
6818     @Test
6819     @Alerts(DEFAULT = {"DIV", "SPAN", "P", "DIV", "P", "SPAN"},
6820             FF_ESR = {"DIV", "SPAN", "P", "no moveBefore()"})
6821     public void moveBefore_basic() throws Exception {
6822         final String html = DOCTYPE_HTML
6823             + "<html><head><script>\n"
6824             + LOG_TITLE_FUNCTION
6825             + "  function test() {\n"
6826             + "    var parent = document.getElementById('parent');\n"
6827             + "    var div = document.getElementById('div1');\n"
6828             + "    var span = document.getElementById('span1');\n"
6829             + "    var p = document.getElementById('p1');\n"
6830 
6831             + "    log(parent.children[0].tagName);\n"
6832             + "    log(parent.children[1].tagName);\n"
6833             + "    log(parent.children[2].tagName);\n"
6834 
6835             + "    if (!parent.moveBefore) { log('no moveBefore()'); return; }\n"
6836 
6837             + "    parent.moveBefore(p, span);\n"
6838             + "    log(parent.children[0].tagName);\n"
6839             + "    log(parent.children[1].tagName);\n"
6840             + "    log(parent.children[2].tagName);\n"
6841             + "  }\n"
6842             + "</script></head>\n"
6843             + "<body onload='test()'>\n"
6844             + "  <div id='parent'>\n"
6845             + "    <div id='div1'>1</div>\n"
6846             + "    <span id='span1'>2</span>\n"
6847             + "    <p id='p1'>3</p>\n"
6848             + "  </div>\n"
6849             + "</body></html>";
6850         loadPageVerifyTitle2(html);
6851     }
6852 
6853     /**
6854      * @throws Exception if the test fails
6855      */
6856     @Test
6857     @Alerts(DEFAULT = {"DIV", "SPAN", "P", "P", "DIV", "SPAN"},
6858             FF_ESR = {"DIV", "SPAN", "P", "no moveBefore()"})
6859     public void moveBefore_moveToFirst() throws Exception {
6860         final String html = DOCTYPE_HTML
6861             + "<html><head><script>\n"
6862             + LOG_TITLE_FUNCTION
6863             + "  function test() {\n"
6864             + "    var parent = document.getElementById('parent');\n"
6865             + "    var div = document.getElementById('div1');\n"
6866             + "    var span = document.getElementById('span1');\n"
6867             + "    var p = document.getElementById('p1');\n"
6868 
6869             + "    log(parent.children[0].tagName);\n"
6870             + "    log(parent.children[1].tagName);\n"
6871             + "    log(parent.children[2].tagName);\n"
6872 
6873             + "    if (!parent.moveBefore) { log('no moveBefore()'); return; }\n"
6874 
6875             + "    parent.moveBefore(p, div);\n"
6876             + "    log(parent.children[0].tagName);\n"
6877             + "    log(parent.children[1].tagName);\n"
6878             + "    log(parent.children[2].tagName);\n"
6879             + "  }\n"
6880             + "</script></head>\n"
6881             + "<body onload='test()'>\n"
6882             + "  <div id='parent'>\n"
6883             + "    <div id='div1'>1</div>\n"
6884             + "    <span id='span1'>2</span>\n"
6885             + "    <p id='p1'>3</p>\n"
6886             + "  </div>\n"
6887             + "</body></html>";
6888         loadPageVerifyTitle2(html);
6889     }
6890 
6891     /**
6892      * @throws Exception if the test fails
6893      */
6894     @Test
6895     @Alerts(DEFAULT = {"DIV", "SPAN", "P", "DIV", "SPAN", "P"},
6896             FF_ESR = {"DIV", "SPAN", "P", "no moveBefore()"})
6897     public void moveBefore_samePosition() throws Exception {
6898         final String html = DOCTYPE_HTML
6899             + "<html><head><script>\n"
6900             + LOG_TITLE_FUNCTION
6901             + "  function test() {\n"
6902             + "    var parent = document.getElementById('parent');\n"
6903             + "    var div = document.getElementById('div1');\n"
6904             + "    var span = document.getElementById('span1');\n"
6905             + "    var p = document.getElementById('p1');\n"
6906 
6907             + "    log(parent.children[0].tagName);\n"
6908             + "    log(parent.children[1].tagName);\n"
6909             + "    log(parent.children[2].tagName);\n"
6910 
6911             + "    if (!parent.moveBefore) { log('no moveBefore()'); return; }\n"
6912 
6913             + "    parent.moveBefore(span, p);\n"
6914             + "    log(parent.children[0].tagName);\n"
6915             + "    log(parent.children[1].tagName);\n"
6916             + "    log(parent.children[2].tagName);\n"
6917             + "  }\n"
6918             + "</script></head>\n"
6919             + "<body onload='test()'>\n"
6920             + "  <div id='parent'>\n"
6921             + "    <div id='div1'>1</div>\n"
6922             + "    <span id='span1'>2</span>\n"
6923             + "    <p id='p1'>3</p>\n"
6924             + "  </div>\n"
6925             + "</body></html>";
6926         loadPageVerifyTitle2(html);
6927     }
6928 
6929     /**
6930      * @throws Exception if the test fails
6931      */
6932     @Test
6933     @Alerts(DEFAULT = {"DIV", "SPAN", "P", "DIV", "SPAN", "P"},
6934             FF_ESR = {"DIV", "SPAN", "P", "no moveBefore()"})
6935     public void moveBefore_samePositionFirst() throws Exception {
6936         final String html = DOCTYPE_HTML
6937             + "<html><head><script>\n"
6938             + LOG_TITLE_FUNCTION
6939             + "  function test() {\n"
6940             + "    var parent = document.getElementById('parent');\n"
6941             + "    var div = document.getElementById('div1');\n"
6942             + "    var span = document.getElementById('span1');\n"
6943             + "    var p = document.getElementById('p1');\n"
6944 
6945             + "    log(parent.children[0].tagName);\n"
6946             + "    log(parent.children[1].tagName);\n"
6947             + "    log(parent.children[2].tagName);\n"
6948 
6949             + "    if (!parent.moveBefore) { log('no moveBefore()'); return; }\n"
6950 
6951             + "    parent.moveBefore(div, span);\n"
6952             + "    log(parent.children[0].tagName);\n"
6953             + "    log(parent.children[1].tagName);\n"
6954             + "    log(parent.children[2].tagName);\n"
6955             + "  }\n"
6956             + "</script></head>\n"
6957             + "<body onload='test()'>\n"
6958             + "  <div id='parent'>\n"
6959             + "    <div id='div1'>1</div>\n"
6960             + "    <span id='span1'>2</span>\n"
6961             + "    <p id='p1'>3</p>\n"
6962             + "  </div>\n"
6963             + "</body></html>";
6964         loadPageVerifyTitle2(html);
6965     }
6966 
6967     /**
6968      * @throws Exception if the test fails
6969      */
6970     @Test
6971     @Alerts(DEFAULT = {"DIV", "SPAN", "P", "DIV", "SPAN", "P"},
6972             FF_ESR = {"DIV", "SPAN", "P", "no moveBefore()"})
6973     public void moveBefore_itself() throws Exception {
6974         final String html = DOCTYPE_HTML
6975             + "<html><head><script>\n"
6976             + LOG_TITLE_FUNCTION
6977             + "  function test() {\n"
6978             + "    var parent = document.getElementById('parent');\n"
6979             + "    var div = document.getElementById('div1');\n"
6980             + "    var span = document.getElementById('span1');\n"
6981             + "    var p = document.getElementById('p1');\n"
6982 
6983             + "    log(parent.children[0].tagName);\n"
6984             + "    log(parent.children[1].tagName);\n"
6985             + "    log(parent.children[2].tagName);\n"
6986 
6987             + "    if (!parent.moveBefore) { log('no moveBefore()'); return; }\n"
6988 
6989             + "    parent.moveBefore(span, span);\n"
6990             + "    log(parent.children[0].tagName);\n"
6991             + "    log(parent.children[1].tagName);\n"
6992             + "    log(parent.children[2].tagName);\n"
6993             + "  }\n"
6994             + "</script></head>\n"
6995             + "<body onload='test()'>\n"
6996             + "  <div id='parent'>\n"
6997             + "    <div id='div1'>1</div>\n"
6998             + "    <span id='span1'>2</span>\n"
6999             + "    <p id='p1'>3</p>\n"
7000             + "  </div>\n"
7001             + "</body></html>";
7002         loadPageVerifyTitle2(html);
7003     }
7004 
7005     /**
7006      * @throws Exception if the test fails
7007      */
7008     @Test
7009     @Alerts(DEFAULT = "HierarchyRequestError/DOMException",
7010             FF_ESR = "no moveBefore()")
7011     public void moveBefore_ancestor() throws Exception {
7012         final String html = DOCTYPE_HTML
7013             + "<html><head><script>\n"
7014             + LOG_TITLE_FUNCTION
7015             + "  function test() {\n"
7016             + "    var parent = document.getElementById('parent');\n"
7017             + "    var div = document.getElementById('div1');\n"
7018             + "    var span = document.getElementById('span1');\n"
7019             + "    var p = document.getElementById('p1');\n"
7020 
7021             + "    if (!parent.moveBefore) { log('no moveBefore()'); return; }\n"
7022 
7023             + "    try {\n"
7024             + "      span.moveBefore(div, null);\n"
7025             + "      log('success');\n"
7026             + "    } catch(e) {\n"
7027             + "      logEx(e);\n"
7028             + "    }\n"
7029             + "  }\n"
7030             + "</script></head>\n"
7031             + "<body onload='test()'>\n"
7032             + "  <div id='parent'>\n"
7033             + "    <div id='div1'>1\n"
7034             + "      <span id='span1'>2</span>\n"
7035             + "    </div>\n"
7036             + "    <p id='p1'>3</p>\n"
7037             + "  </div>\n"
7038             + "</body></html>";
7039         loadPageVerifyTitle2(html);
7040     }
7041 
7042     /**
7043      * @throws Exception if the test fails
7044      */
7045     @Test
7046     @Alerts(DEFAULT = "NotFoundError/DOMException",
7047             FF_ESR = "no moveBefore()")
7048     public void moveBefore_differentParents() throws Exception {
7049         final String html = DOCTYPE_HTML
7050             + "<html><head><script>\n"
7051             + LOG_TITLE_FUNCTION
7052             + "  function test() {\n"
7053             + "    var parent = document.getElementById('parent');\n"
7054             + "    var div = document.getElementById('div1');\n"
7055             + "    var p = document.getElementById('p1');\n"
7056 
7057             + "    if (!parent.moveBefore) { log('no moveBefore()'); return; }\n"
7058 
7059             + "    try {\n"
7060             + "      parent.moveBefore(div, p);\n"
7061             + "      log('success');\n"
7062             + "    } catch(e) {\n"
7063             + "      logEx(e);\n"
7064             + "    }\n"
7065             + "  }\n"
7066             + "</script></head>\n"
7067             + "<body onload='test()'>\n"
7068             + "  <div id='parent'>\n"
7069             + "    <div id='div1'>1</div>\n"
7070             + "  </div>\n"
7071             + "  <div id='parent2'>\n"
7072             + "    <p id='p1'>2</p>\n"
7073             + "  </div>\n"
7074             + "</body></html>";
7075         loadPageVerifyTitle2(html);
7076     }
7077 
7078     /**
7079      * @throws Exception if the test fails
7080      */
7081     @Test
7082     @Alerts(DEFAULT = "NotFoundError/DOMException",
7083             FF_ESR = "no moveBefore()")
7084     public void moveBefore_descendant() throws Exception {
7085         final String html = DOCTYPE_HTML
7086             + "<html><head><script>\n"
7087             + LOG_TITLE_FUNCTION
7088             + "  function test() {\n"
7089             + "    var parent = document.getElementById('parent');\n"
7090             + "    var child = document.getElementById('child');\n"
7091             + "    var span = document.getElementById('span1');\n"
7092 
7093             + "    if (!parent.moveBefore) { log('no moveBefore()'); return; }\n"
7094 
7095             + "    try {\n"
7096             + "      child.moveBefore(span, parent);\n"
7097             + "      log('success');\n"
7098             + "    } catch(e) {\n"
7099             + "      logEx(e);\n"
7100             + "    }\n"
7101             + "  }\n"
7102             + "</script></head>\n"
7103             + "<body onload='test()'>\n"
7104             + "  <div id='parent'>\n"
7105             + "    <div id='child'>\n"
7106             + "      <span id='span1'>text</span>\n"
7107             + "    </div>\n"
7108             + "    <p id='p1'>2</p>\n"
7109             + "  </div>\n"
7110             + "</body></html>";
7111         loadPageVerifyTitle2(html);
7112     }
7113 
7114     /**
7115      * @throws Exception if the test fails
7116      */
7117     @Test
7118     @Alerts(DEFAULT = {"2", "P", "SPAN", "0"},
7119             FF_ESR = "no moveBefore()")
7120     public void moveBefore_movedNotChild() throws Exception {
7121         final String html = DOCTYPE_HTML
7122             + "<html><head><script>\n"
7123             + LOG_TITLE_FUNCTION
7124             + "  function test() {\n"
7125             + "    var parent = document.getElementById('parent');\n"
7126             + "    var span = document.getElementById('span1');\n"
7127             + "    var p = document.getElementById('p1');\n"
7128 
7129             + "    if (!parent.moveBefore) { log('no moveBefore()'); return; }\n"
7130 
7131             + "    parent.moveBefore(p, span);\n"
7132             + "    log(parent.children.length);\n"
7133             + "    log(parent.children[0].tagName);\n"
7134             + "    log(parent.children[1].tagName);\n"
7135 
7136             + "    var parent2 = document.getElementById('parent2');\n"
7137             + "    log(parent2.children.length);\n"
7138             + "  }\n"
7139             + "</script></head>\n"
7140             + "<body onload='test()'>\n"
7141             + "  <div id='parent'>\n"
7142             + "    <span id='span1'>1</span>\n"
7143             + "  </div>\n"
7144             + "  <div id='parent2'>\n"
7145             + "    <p id='p1'>2</p>\n"
7146             + "  </div>\n"
7147             + "</body></html>";
7148         loadPageVerifyTitle2(html);
7149     }
7150 
7151     /**
7152      * @throws Exception if the test fails
7153      */
7154     @Test
7155     @Alerts(DEFAULT = "NotFoundError/DOMException",
7156             FF_ESR = "no moveBefore()")
7157     public void moveBefore_referenceNotChild() throws Exception {
7158         final String html = DOCTYPE_HTML
7159             + "<html><head><script>\n"
7160             + LOG_TITLE_FUNCTION
7161             + "  function test() {\n"
7162             + "    var parent = document.getElementById('parent');\n"
7163             + "    var span = document.getElementById('span1');\n"
7164             + "    var p = document.getElementById('p1');\n"
7165 
7166             + "    if (!parent.moveBefore) { log('no moveBefore()'); return; }\n"
7167 
7168             + "    try {\n"
7169             + "      parent.moveBefore(span, p);\n"
7170             + "      log('success');\n"
7171             + "    } catch(e) {\n"
7172             + "      logEx(e);\n"
7173             + "    }\n"
7174             + "  }\n"
7175             + "</script></head>\n"
7176             + "<body onload='test()'>\n"
7177             + "  <div id='parent'>\n"
7178             + "    <span id='span1'>1</span>\n"
7179             + "  </div>\n"
7180             + "  <div id='parent2'>\n"
7181             + "    <p id='p1'>2</p>\n"
7182             + "  </div>\n"
7183             + "</body></html>";
7184         loadPageVerifyTitle2(html);
7185     }
7186 
7187     /**
7188      * @throws Exception if the test fails
7189      */
7190     @Test
7191     @Alerts(DEFAULT = {"SPAN", "DIV", "P", "3", "A"},
7192             FF_ESR = "no moveBefore()")
7193     public void moveBefore_preservesChildren() throws Exception {
7194         final String html = DOCTYPE_HTML
7195             + "<html><head><script>\n"
7196             + LOG_TITLE_FUNCTION
7197             + "  function test() {\n"
7198             + "    var parent = document.getElementById('parent');\n"
7199             + "    var div = document.getElementById('div1');\n"
7200             + "    var span = document.getElementById('span1');\n"
7201             + "    var p = document.getElementById('p1');\n"
7202 
7203             + "    if (!parent.moveBefore) { log('no moveBefore()'); return; }\n"
7204 
7205             + "    parent.moveBefore(div, p);\n"
7206             + "    log(parent.children[0].tagName);\n"
7207             + "    log(parent.children[1].tagName);\n"
7208             + "    log(parent.children[2].tagName);\n"
7209             + "    log(div.children.length);\n"
7210             + "    log(div.children[0].textContent);\n"
7211             + "  }\n"
7212             + "</script></head>\n"
7213             + "<body onload='test()'>\n"
7214             + "  <div id='parent'>\n"
7215             + "    <span id='span1'>1</span>\n"
7216             + "    <p id='p1'>2</p>\n"
7217             + "    <div id='div1'>\n"
7218             + "      <span>A</span>\n"
7219             + "      <span>B</span>\n"
7220             + "      <span>C</span>\n"
7221             + "    </div>\n"
7222             + "  </div>\n"
7223             + "</body></html>";
7224         loadPageVerifyTitle2(html);
7225     }
7226 
7227     /**
7228      * @throws Exception if the test fails
7229      */
7230     @Test
7231     @Alerts(DEFAULT = {"text1", "myClass"},
7232             FF_ESR = "no moveBefore()")
7233     public void moveBefore_preservesAttributes() throws Exception {
7234         final String html = DOCTYPE_HTML
7235             + "<html><head><script>\n"
7236             + LOG_TITLE_FUNCTION
7237             + "  function test() {\n"
7238             + "    var parent = document.getElementById('parent');\n"
7239             + "    var div = document.getElementById('div1');\n"
7240             + "    var span = document.getElementById('span1');\n"
7241 
7242             + "    if (!parent.moveBefore) { log('no moveBefore()'); return; }\n"
7243 
7244             + "    parent.moveBefore(div, span);\n"
7245             + "    log(div.getAttribute('data-test'));\n"
7246             + "    log(div.className);\n"
7247             + "  }\n"
7248             + "</script></head>\n"
7249             + "<body onload='test()'>\n"
7250             + "  <div id='parent'>\n"
7251             + "    <span id='span1'>1</span>\n"
7252             + "    <div id='div1' data-test='text1' class='myClass'>2</div>\n"
7253             + "  </div>\n"
7254             + "</body></html>";
7255         loadPageVerifyTitle2(html);
7256     }
7257 
7258     /**
7259      * @throws Exception if the test fails
7260      */
7261     @Test
7262     @Alerts(DEFAULT = "true",
7263             FF_ESR = "no moveBefore()")
7264     public void moveBefore_returnValue() throws Exception {
7265         final String html = DOCTYPE_HTML
7266             + "<html><head><script>\n"
7267             + LOG_TITLE_FUNCTION
7268             + "  function test() {\n"
7269             + "    var parent = document.getElementById('parent');\n"
7270             + "    var div = document.getElementById('div1');\n"
7271             + "    var span = document.getElementById('span1');\n"
7272 
7273             + "    if (!parent.moveBefore) { log('no moveBefore()'); return; }\n"
7274 
7275             + "    var result = parent.moveBefore(div, span);\n"
7276             + "    log(result === undefined);\n"
7277             + "  }\n"
7278             + "</script></head>\n"
7279             + "<body onload='test()'>\n"
7280             + "  <div id='parent'>\n"
7281             + "    <span id='span1'>1</span>\n"
7282             + "    <div id='div1'>2</div>\n"
7283             + "  </div>\n"
7284             + "</body></html>";
7285         loadPageVerifyTitle2(html);
7286     }
7287 
7288     /**
7289      * @throws Exception if the test fails
7290      */
7291     @Test
7292     @Alerts(DEFAULT = {"DIV", "P", "SPAN", "SECTION"},
7293             FF_ESR = "no moveBefore()")
7294     public void moveBefore_multipleOperations() throws Exception {
7295         final String html = DOCTYPE_HTML
7296             + "<html><head><script>\n"
7297             + LOG_TITLE_FUNCTION
7298             + "  function test() {\n"
7299             + "    var parent = document.getElementById('parent');\n"
7300             + "    var div = document.getElementById('div1');\n"
7301             + "    var span = document.getElementById('span1');\n"
7302             + "    var p = document.getElementById('p1');\n"
7303             + "    var section = document.getElementById('section1');\n"
7304 
7305             + "    if (!parent.moveBefore) { log('no moveBefore()'); return; }\n"
7306 
7307             + "    parent.moveBefore(section, span);\n"
7308             + "    parent.moveBefore(p, section);\n"
7309             + "    parent.moveBefore(span, section);\n"
7310 
7311             + "    log(parent.children[0].tagName);\n"
7312             + "    log(parent.children[1].tagName);\n"
7313             + "    log(parent.children[2].tagName);\n"
7314             + "    log(parent.children[3].tagName);\n"
7315             + "  }\n"
7316             + "</script></head>\n"
7317             + "<body onload='test()'>\n"
7318             + "  <div id='parent'>\n"
7319             + "    <div id='div1'>1</div>\n"
7320             + "    <span id='span1'>2</span>\n"
7321             + "    <p id='p1'>3</p>\n"
7322             + "    <section id='section1'>4</section>\n"
7323             + "  </div>\n"
7324             + "</body></html>";
7325         loadPageVerifyTitle2(html);
7326     }
7327 
7328     /**
7329      * @throws Exception if the test fails
7330      */
7331     @Test
7332     @Alerts(DEFAULT = "true",
7333             FF_ESR = "no moveBefore()")
7334     public void moveBefore_staysInDocument() throws Exception {
7335         final String html = DOCTYPE_HTML
7336             + "<html><head><script>\n"
7337             + LOG_TITLE_FUNCTION
7338             + "  function test() {\n"
7339             + "    var parent = document.getElementById('parent');\n"
7340             + "    var div = document.getElementById('div1');\n"
7341             + "    var span = document.getElementById('span1');\n"
7342 
7343             + "    if (!parent.moveBefore) { log('no moveBefore()'); return; }\n"
7344 
7345             + "    parent.moveBefore(div, span);\n"
7346             + "    log(document.contains(div));\n"
7347             + "  }\n"
7348             + "</script></head>\n"
7349             + "<body onload='test()'>\n"
7350             + "  <div id='parent'>\n"
7351             + "    <span id='span1'>1</span>\n"
7352             + "    <div id='div1'>2</div>\n"
7353             + "  </div>\n"
7354             + "</body></html>";
7355         loadPageVerifyTitle2(html);
7356     }
7357 
7358     /**
7359      * @throws Exception if the test fails
7360      */
7361     @Test
7362     @Alerts(DEFAULT = {"2", "DIV", "SPAN"},
7363             FF_ESR = "no moveBefore()")
7364     public void moveBefore_nullReferenceNode() throws Exception {
7365         final String html = DOCTYPE_HTML
7366             + "<html><head><script>\n"
7367             + LOG_TITLE_FUNCTION
7368             + "  function test() {\n"
7369             + "    var parent = document.getElementById('parent');\n"
7370             + "    var div = document.getElementById('div1');\n"
7371             + "    var span = document.getElementById('span1');\n"
7372 
7373             + "    if (!parent.moveBefore) { log('no moveBefore()'); return; }\n"
7374 
7375             + "    parent.moveBefore(span, null);\n"
7376 
7377             + "    log(parent.children.length);\n"
7378             + "    log(parent.children[0].tagName);\n"
7379             + "    log(parent.children[1].tagName);\n"
7380             + "  }\n"
7381             + "</script></head>\n"
7382             + "<body onload='test()'>\n"
7383             + "  <div id='parent'>\n"
7384             + "    <span id='span1'>1</span>\n"
7385             + "    <div id='div1'>2</div>\n"
7386             + "  </div>\n"
7387             + "</body></html>";
7388         loadPageVerifyTitle2(html);
7389     }
7390 
7391     /**
7392      * @throws Exception if the test fails
7393      */
7394     @Test
7395     @Alerts(DEFAULT = {"SPAN", "DIV", "DIV", "0", "1", "A"},
7396             FF_ESR = "no moveBefore()")
7397     public void moveBefore_nullLevelUp() throws Exception {
7398         final String html = DOCTYPE_HTML
7399             + "<html><head><script>\n"
7400             + LOG_TITLE_FUNCTION
7401             + "  function test() {\n"
7402             + "    var parent = document.getElementById('parent');\n"
7403             + "    var div1 = document.getElementById('div1');\n"
7404             + "    var div2 = document.getElementById('div2');\n"
7405 
7406             + "    if (!parent.moveBefore) { log('no moveBefore()'); return; }\n"
7407 
7408             + "    parent.moveBefore(div2, null);\n"
7409 
7410             + "    log(parent.children[0].tagName);\n"
7411             + "    log(parent.children[1].tagName);\n"
7412             + "    log(parent.children[2].tagName);\n"
7413 
7414             + "    log(div1.children.length);\n"
7415             + "    log(div2.children.length);\n"
7416             + "    log(div2.children[0].textContent);\n"
7417             + "  }\n"
7418             + "</script></head>\n"
7419             + "<body onload='test()'>\n"
7420             + "  <div id='parent'>\n"
7421             + "    <span id='span1'>1</span>\n"
7422             + "    <div id='div1'>\n"
7423             + "      <div id='div2'>\n"
7424             + "        <span>A</span>\n"
7425             + "      </div>\n"
7426             + "    </div>\n"
7427             + "  </div>\n"
7428             + "</body></html>";
7429         loadPageVerifyTitle2(html);
7430     }
7431 
7432     /**
7433      * @throws Exception if the test fails
7434      */
7435     @Test
7436     @Alerts(DEFAULT = "NotFoundError/DOMException",
7437             FF_ESR = "no moveBefore()")
7438     public void moveBefore_detachedReferenceNode() throws Exception {
7439         final String html = DOCTYPE_HTML
7440             + "<html><head><script>\n"
7441             + LOG_TITLE_FUNCTION
7442             + "  function test() {\n"
7443             + "    var parent = document.getElementById('parent');\n"
7444             + "    var div = document.getElementById('div');\n"
7445             + "    var divDetached = document.createElement('div');\n"
7446 
7447             + "    if (!parent.moveBefore) { log('no moveBefore()'); return; }\n"
7448 
7449             + "    try {\n"
7450             + "      parent.moveBefore(div, divDetached);\n"
7451             + "      log('success');\n"
7452             + "    } catch(e) {\n"
7453             + "      logEx(e);\n"
7454             + "    }\n"
7455             + "  }\n"
7456             + "</script></head>\n"
7457             + "<body onload='test()'>\n"
7458             + "  <div id='parent'>\n"
7459             + "    <span id='span1'>1</span>\n"
7460             + "    <div id='div'>x</div>\n"
7461             + "  </div>\n"
7462             + "</body></html>";
7463         loadPageVerifyTitle2(html);
7464     }
7465 
7466     /**
7467      * @throws Exception if the test fails
7468      */
7469     @Test
7470     @Alerts(DEFAULT = "HierarchyRequestError/DOMException",
7471             FF_ESR = "no moveBefore()")
7472     public void moveBefore_detachedMovedNode() throws Exception {
7473         final String html = DOCTYPE_HTML
7474             + "<html><head><script>\n"
7475             + LOG_TITLE_FUNCTION
7476             + "  function test() {\n"
7477             + "    var parent = document.getElementById('parent');\n"
7478             + "    var div = document.getElementById('div');\n"
7479             + "    var divDetached = document.createElement('div');\n"
7480 
7481             + "    if (!parent.moveBefore) { log('no moveBefore()'); return; }\n"
7482 
7483             + "    try {\n"
7484             + "      parent.moveBefore(divDetached, div);\n"
7485             + "      log('success');\n"
7486             + "    } catch(e) {\n"
7487             + "      logEx(e);\n"
7488             + "    }\n"
7489             + "  }\n"
7490             + "</script></head>\n"
7491             + "<body onload='test()'>\n"
7492             + "  <div id='parent'>\n"
7493             + "    <span id='span1'>1</span>\n"
7494             + "    <div id='div'>x</div>\n"
7495             + "  </div>\n"
7496             + "</body></html>";
7497         loadPageVerifyTitle2(html);
7498     }
7499 
7500     /**
7501      * @throws Exception if the test fails
7502      */
7503     @Test
7504     @Alerts(DEFAULT = "TypeError",
7505             FF_ESR = "no moveBefore()")
7506     public void moveBefore_missingArgs() throws Exception {
7507         final String html = DOCTYPE_HTML
7508             + "<html><head><script>\n"
7509             + LOG_TITLE_FUNCTION
7510             + "  function test() {\n"
7511             + "    var parent = document.getElementById('parent');\n"
7512             + "    var div = document.getElementById('div');\n"
7513             + "    var divDetached = document.createElement('div');\n"
7514 
7515             + "    if (!parent.moveBefore) { log('no moveBefore()'); return; }\n"
7516 
7517             + "    try {\n"
7518             + "      parent.moveBefore();\n"
7519             + "      log('success');\n"
7520             + "    } catch(e) {\n"
7521             + "      logEx(e);\n"
7522             + "    }\n"
7523             + "  }\n"
7524             + "</script></head>\n"
7525             + "<body onload='test()'>\n"
7526             + "  <div id='parent'>\n"
7527             + "    <span id='span1'>1</span>\n"
7528             + "    <div id='div'>x</div>\n"
7529             + "  </div>\n"
7530             + "</body></html>";
7531         loadPageVerifyTitle2(html);
7532     }
7533 
7534     /**
7535      * @throws Exception if the test fails
7536      */
7537     @Test
7538     @Alerts(DEFAULT = "TypeError",
7539             FF_ESR = "no moveBefore()")
7540     public void moveBefore_missingReferenceNode() throws Exception {
7541         final String html = DOCTYPE_HTML
7542             + "<html><head><script>\n"
7543             + LOG_TITLE_FUNCTION
7544             + "  function test() {\n"
7545             + "    var parent = document.getElementById('parent');\n"
7546             + "    var div = document.getElementById('div');\n"
7547             + "    var divDetached = document.createElement('div');\n"
7548 
7549             + "    if (!parent.moveBefore) { log('no moveBefore()'); return; }\n"
7550 
7551             + "    try {\n"
7552             + "      parent.moveBefore();\n"
7553             + "      log('success');\n"
7554             + "    } catch(e) {\n"
7555             + "      logEx(e);\n"
7556             + "    }\n"
7557             + "  }\n"
7558             + "</script></head>\n"
7559             + "<body onload='test()'>\n"
7560             + "  <div id='parent'>\n"
7561             + "    <span id='span1'>1</span>\n"
7562             + "    <div id='div'>x</div>\n"
7563             + "  </div>\n"
7564             + "</body></html>";
7565         loadPageVerifyTitle2(html);
7566     }
7567 
7568     /**
7569      * @throws Exception if the test fails
7570      */
7571     @Test
7572     @Alerts(DEFAULT = "TypeError",
7573             FF_ESR = "no moveBefore()")
7574     public void moveBefore_wrongMovedNode() throws Exception {
7575         final String html = DOCTYPE_HTML
7576             + "<html><head><script>\n"
7577             + LOG_TITLE_FUNCTION
7578             + "  function test() {\n"
7579             + "    var parent = document.getElementById('parent');\n"
7580             + "    var div = document.getElementById('div');\n"
7581             + "    var divDetached = document.createElement('div');\n"
7582 
7583             + "    if (!parent.moveBefore) { log('no moveBefore()'); return; }\n"
7584 
7585             + "    try {\n"
7586             + "      parent.moveBefore('HtmlUnit', null);\n"
7587             + "      log('success');\n"
7588             + "    } catch(e) {\n"
7589             + "      logEx(e);\n"
7590             + "    }\n"
7591             + "  }\n"
7592             + "</script></head>\n"
7593             + "<body onload='test()'>\n"
7594             + "  <div id='parent'>\n"
7595             + "    <span id='span1'>1</span>\n"
7596             + "    <div id='div'>x</div>\n"
7597             + "  </div>\n"
7598             + "</body></html>";
7599         loadPageVerifyTitle2(html);
7600     }
7601 
7602     /**
7603      * @throws Exception if the test fails
7604      */
7605     @Test
7606     @Alerts(DEFAULT = "TypeError",
7607             FF_ESR = "no moveBefore()")
7608     public void moveBefore_wrongReferenceNodeNode() throws Exception {
7609         final String html = DOCTYPE_HTML
7610             + "<html><head><script>\n"
7611             + LOG_TITLE_FUNCTION
7612             + "  function test() {\n"
7613             + "    var parent = document.getElementById('parent');\n"
7614             + "    var div = document.getElementById('div');\n"
7615             + "    var divDetached = document.createElement('div');\n"
7616 
7617             + "    if (!parent.moveBefore) { log('no moveBefore()'); return; }\n"
7618 
7619             + "    try {\n"
7620             + "      parent.moveBefore(div, 'HtmlUnit');\n"
7621             + "      log('success');\n"
7622             + "    } catch(e) {\n"
7623             + "      logEx(e);\n"
7624             + "    }\n"
7625             + "  }\n"
7626             + "</script></head>\n"
7627             + "<body onload='test()'>\n"
7628             + "  <div id='parent'>\n"
7629             + "    <span id='span1'>1</span>\n"
7630             + "    <div id='div'>x</div>\n"
7631             + "  </div>\n"
7632             + "</body></html>";
7633         loadPageVerifyTitle2(html);
7634     }
7635 
7636     /**
7637      * @throws Exception if the test fails
7638      */
7639     @Test
7640     @Alerts({"1", "true"})
7641     public void getAttributeNames_noAttributes() throws Exception {
7642         final String html = DOCTYPE_HTML
7643             + "<html><head><script>\n"
7644             + LOG_TITLE_FUNCTION
7645             + "  function test() {\n"
7646             + "    var elem = document.getElementById('testDiv');\n"
7647             + "    var names = elem.getAttributeNames();\n"
7648             + "    log(names.length);\n"
7649             + "    log(Array.isArray(names));\n"
7650             + "  }\n"
7651             + "</script></head>\n"
7652             + "<body onload='test()'>\n"
7653             + "  <div id='testDiv'></div>\n"
7654             + "</body></html>";
7655         loadPageVerifyTitle2(html);
7656     }
7657 
7658     /**
7659      * @throws Exception if the test fails
7660      */
7661     @Test
7662     @Alerts({"3", "id", "class", "title"})
7663     public void getAttributeNames_multipleAttributes() throws Exception {
7664         final String html = DOCTYPE_HTML
7665             + "<html><head><script>\n"
7666             + LOG_TITLE_FUNCTION
7667             + "  function test() {\n"
7668             + "    var elem = document.getElementById('testDiv');\n"
7669             + "    var names = elem.getAttributeNames();\n"
7670             + "    log(names.length);\n"
7671             + "    for (var i = 0; i < names.length; i++) {\n"
7672             + "      log(names[i]);\n"
7673             + "    }\n"
7674             + "  }\n"
7675             + "</script></head>\n"
7676             + "<body onload='test()'>\n"
7677             + "  <div id='testDiv' class='myClass' title='Test Title'></div>\n"
7678             + "</body></html>";
7679         loadPageVerifyTitle2(html);
7680     }
7681 
7682     /**
7683      * @throws Exception if the test fails
7684      */
7685     @Test
7686     @Alerts({"3", "id", "data-foo", "data-bar"})
7687     public void getAttributeNames_dataAttributes() throws Exception {
7688         final String html = DOCTYPE_HTML
7689             + "<html><head><script>\n"
7690             + LOG_TITLE_FUNCTION
7691             + "  function test() {\n"
7692             + "    var elem = document.getElementById('testDiv');\n"
7693             + "    var names = elem.getAttributeNames();\n"
7694             + "    log(names.length);\n"
7695             + "    for (var i = 0; i < names.length; i++) {\n"
7696             + "      log(names[i]);\n"
7697             + "    }\n"
7698             + "  }\n"
7699             + "</script></head>\n"
7700             + "<body onload='test()'>\n"
7701             + "  <div id='testDiv' data-foo='value1' data-bar='value2'></div>\n"
7702             + "</body></html>";
7703         loadPageVerifyTitle2(html);
7704     }
7705 
7706     /**
7707      * @throws Exception if the test fails
7708      */
7709     @Test
7710     @Alerts({"2", "id", "custom-attr"})
7711     public void getAttributeNames_customAttribute() throws Exception {
7712         final String html = DOCTYPE_HTML
7713             + "<html><head><script>\n"
7714             + LOG_TITLE_FUNCTION
7715             + "  function test() {\n"
7716             + "    var elem = document.getElementById('testDiv');\n"
7717             + "    var names = elem.getAttributeNames();\n"
7718             + "    log(names.length);\n"
7719             + "    for (var i = 0; i < names.length; i++) {\n"
7720             + "      log(names[i]);\n"
7721             + "    }\n"
7722             + "  }\n"
7723             + "</script></head>\n"
7724             + "<body onload='test()'>\n"
7725             + "  <div id='testDiv' custom-attr='customValue'></div>\n"
7726             + "</body></html>";
7727         loadPageVerifyTitle2(html);
7728     }
7729 
7730     /**
7731      * @throws Exception if the test fails
7732      */
7733     @Test
7734     @Alerts({"1", "id", "2", "id", "new-attr"})
7735     public void getAttributeNames_afterSetAttribute() throws Exception {
7736         final String html = DOCTYPE_HTML
7737             + "<html><head><script>\n"
7738             + LOG_TITLE_FUNCTION
7739             + "  function test() {\n"
7740             + "    var elem = document.getElementById('testDiv');\n"
7741             + "    var names = elem.getAttributeNames();\n"
7742             + "    log(names.length);\n"
7743             + "    for (var i = 0; i < names.length; i++) {\n"
7744             + "      log(names[i]);\n"
7745             + "    }\n"
7746             + "    elem.setAttribute('new-attr', 'newValue');\n"
7747             + "    names = elem.getAttributeNames();\n"
7748             + "    log(names.length);\n"
7749             + "    for (var i = 0; i < names.length; i++) {\n"
7750             + "      log(names[i]);\n"
7751             + "    }\n"
7752             + "  }\n"
7753             + "</script></head>\n"
7754             + "<body onload='test()'>\n"
7755             + "  <div id='testDiv'></div>\n"
7756             + "</body></html>";
7757         loadPageVerifyTitle2(html);
7758     }
7759 
7760     /**
7761      * @throws Exception if the test fails
7762      */
7763     @Test
7764     @Alerts({"2", "id", "title", "1", "id"})
7765     public void getAttributeNames_afterRemoveAttribute() throws Exception {
7766         final String html = DOCTYPE_HTML
7767             + "<html><head><script>\n"
7768             + LOG_TITLE_FUNCTION
7769             + "  function test() {\n"
7770             + "    var elem = document.getElementById('testDiv');\n"
7771             + "    var names = elem.getAttributeNames();\n"
7772             + "    log(names.length);\n"
7773             + "    for (var i = 0; i < names.length; i++) {\n"
7774             + "      log(names[i]);\n"
7775             + "    }\n"
7776             + "    elem.removeAttribute('title');\n"
7777             + "    names = elem.getAttributeNames();\n"
7778             + "    log(names.length);\n"
7779             + "    for (var i = 0; i < names.length; i++) {\n"
7780             + "      log(names[i]);\n"
7781             + "    }\n"
7782             + "  }\n"
7783             + "</script></head>\n"
7784             + "<body onload='test()'>\n"
7785             + "  <div id='testDiv' title='Test'></div>\n"
7786             + "</body></html>";
7787         loadPageVerifyTitle2(html);
7788     }
7789 
7790     /**
7791      * @throws Exception if the test fails
7792      */
7793     @Test
7794     @Alerts({"2", "id", "class"})
7795     public void getAttributeNames_caseInsensitive() throws Exception {
7796         final String html = DOCTYPE_HTML
7797             + "<html><head><script>\n"
7798             + LOG_TITLE_FUNCTION
7799             + "  function test() {\n"
7800             + "    var elem = document.getElementById('testDiv');\n"
7801             + "    var names = elem.getAttributeNames();\n"
7802             + "    log(names.length);\n"
7803             + "    for (var i = 0; i < names.length; i++) {\n"
7804             + "      log(names[i]);\n"
7805             + "    }\n"
7806             + "  }\n"
7807             + "</script></head>\n"
7808             + "<body onload='test()'>\n"
7809             + "  <div id='testDiv' CLASS='myClass'></div>\n"
7810             + "</body></html>";
7811         loadPageVerifyTitle2(html);
7812     }
7813 
7814     /**
7815      * @throws Exception if the test fails
7816      */
7817     @Test
7818     @Alerts({"4", "id", "type", "name", "value"})
7819     public void getAttributeNames_inputElement() throws Exception {
7820         final String html = DOCTYPE_HTML
7821             + "<html><head><script>\n"
7822             + LOG_TITLE_FUNCTION
7823             + "  function test() {\n"
7824             + "    var elem = document.getElementById('myInput');\n"
7825             + "    var names = elem.getAttributeNames();\n"
7826             + "    log(names.length);\n"
7827             + "    for (var i = 0; i < names.length; i++) {\n"
7828             + "      log(names[i]);\n"
7829             + "    }\n"
7830             + "  }\n"
7831             + "</script></head>\n"
7832             + "<body onload='test()'>\n"
7833             + "  <input id='myInput' type='text' name='username' value='test'>\n"
7834             + "</body></html>";
7835         loadPageVerifyTitle2(html);
7836     }
7837 
7838     /**
7839      * @throws Exception if the test fails
7840      */
7841     @Test
7842     @Alerts("0")
7843     public void getAttributeNames_createdElement() throws Exception {
7844         final String html = DOCTYPE_HTML
7845             + "<html><head><script>\n"
7846             + LOG_TITLE_FUNCTION
7847             + "  function test() {\n"
7848             + "    var elem = document.createElement('div');\n"
7849             + "    var names = elem.getAttributeNames();\n"
7850             + "    log(names.length);\n"
7851             + "  }\n"
7852             + "</script></head>\n"
7853             + "<body onload='test()'>\n"
7854             + "</body></html>";
7855         loadPageVerifyTitle2(html);
7856     }
7857 
7858     /**
7859      * @throws Exception if the test fails
7860      */
7861     @Test
7862     @Alerts({"2", "xmlns", "id"})
7863     public void getAttributeNames_svgElement() throws Exception {
7864         final String html = DOCTYPE_HTML
7865             + "<html><head><script>\n"
7866             + LOG_TITLE_FUNCTION
7867             + "  function test() {\n"
7868             + "    var elem = document.getElementById('mySvg');\n"
7869             + "    var names = elem.getAttributeNames();\n"
7870             + "    log(names.length);\n"
7871             + "    for (var i = 0; i < names.length; i++) {\n"
7872             + "      log(names[i]);\n"
7873             + "    }\n"
7874             + "  }\n"
7875             + "</script></head>\n"
7876             + "<body onload='test()'>\n"
7877             + "  <svg xmlns='http://www.w3.org/2000/svg' id='mySvg'></svg>\n"
7878             + "</body></html>";
7879         loadPageVerifyTitle2(html);
7880     }
7881 
7882     /**
7883      * @throws Exception if the test fails
7884      */
7885     @Test
7886     @Alerts({"3", "id", "foo", "bar"})
7887     public void getAttributeNames_attributeOrder() throws Exception {
7888         final String html = DOCTYPE_HTML
7889             + "<html><head><script>\n"
7890             + LOG_TITLE_FUNCTION
7891             + "  function test() {\n"
7892             + "    var elem = document.getElementById('testDiv');\n"
7893             + "    var names = elem.getAttributeNames();\n"
7894             + "    log(names.length);\n"
7895             + "    for (var i = 0; i < names.length; i++) {\n"
7896             + "      log(names[i]);\n"
7897             + "    }\n"
7898             + "  }\n"
7899             + "</script></head>\n"
7900             + "<body onload='test()'>\n"
7901             + "  <div id='testDiv' foo='1' bar='2'></div>\n"
7902             + "</body></html>";
7903         loadPageVerifyTitle2(html);
7904     }
7905 
7906     /**
7907      * @throws Exception if the test fails
7908      */
7909     @Test
7910     @Alerts({"2", "id", "onclick"})
7911     public void getAttributeNames_eventAttribute() throws Exception {
7912         final String html = DOCTYPE_HTML
7913             + "<html><head><script>\n"
7914             + LOG_TITLE_FUNCTION
7915             + "  function test() {\n"
7916             + "    var elem = document.getElementById('testDiv');\n"
7917             + "    var names = elem.getAttributeNames();\n"
7918             + "    log(names.length);\n"
7919             + "    for (var i = 0; i < names.length; i++) {\n"
7920             + "      log(names[i]);\n"
7921             + "    }\n"
7922             + "  }\n"
7923             + "</script></head>\n"
7924             + "<body onload='test()'>\n"
7925             + "  <div id='testDiv' onclick='alert(\"clicked\")'></div>\n"
7926             + "</body></html>";
7927         loadPageVerifyTitle2(html);
7928     }
7929 
7930     /**
7931      * @throws Exception if the test fails
7932      */
7933     @Test
7934     @Alerts({"2", "id", "style"})
7935     public void getAttributeNames_styleAttribute() throws Exception {
7936         final String html = DOCTYPE_HTML
7937             + "<html><head><script>\n"
7938             + LOG_TITLE_FUNCTION
7939             + "  function test() {\n"
7940             + "    var elem = document.getElementById('testDiv');\n"
7941             + "    var names = elem.getAttributeNames();\n"
7942             + "    log(names.length);\n"
7943             + "    for (var i = 0; i < names.length; i++) {\n"
7944             + "      log(names[i]);\n"
7945             + "    }\n"
7946             + "  }\n"
7947             + "</script></head>\n"
7948             + "<body onload='test()'>\n"
7949             + "  <div id='testDiv' style='color: red;'></div>\n"
7950             + "</body></html>";
7951         loadPageVerifyTitle2(html);
7952     }
7953 
7954     /**
7955      * @throws Exception if the test fails
7956      */
7957     @Test
7958     @Alerts({"2", "id", "disabled"})
7959     public void getAttributeNames_booleanAttribute() throws Exception {
7960         final String html = DOCTYPE_HTML
7961             + "<html><head><script>\n"
7962             + LOG_TITLE_FUNCTION
7963             + "  function test() {\n"
7964             + "    var elem = document.getElementById('testBtn');\n"
7965             + "    var names = elem.getAttributeNames();\n"
7966             + "    log(names.length);\n"
7967             + "    for (var i = 0; i < names.length; i++) {\n"
7968             + "      log(names[i]);\n"
7969             + "    }\n"
7970             + "  }\n"
7971             + "</script></head>\n"
7972             + "<body onload='test()'>\n"
7973             + "  <button id='testBtn' disabled></button>\n"
7974             + "</body></html>";
7975         loadPageVerifyTitle2(html);
7976     }
7977 
7978     /**
7979      * @throws Exception if the test fails
7980      */
7981     @Test
7982     @Alerts({"3", "href", "xlink:href", "show"})
7983     public void getAttributeNames_namespace() throws Exception {
7984         final String html = DOCTYPE_HTML
7985             + "<html><head><script>\n"
7986             + LOG_TITLE_FUNCTION
7987             + "  function test() {\n"
7988             + "    var elem = document.createElement('a');\n"
7989             + "    elem.setAttribute('href', 'https://example.com');\n"
7990             + "    elem.setAttributeNS('http://www.w3.org/1999/xlink',"
7991             + "                         'xlink:href', 'https://example.com');\n"
7992             + "    elem.setAttributeNS('http://www.w3.org/1999/xlink', 'show', 'new');\n"
7993             + "    var names = elem.getAttributeNames();\n"
7994             + "    log(names.length);\n"
7995             + "    for (var i = 0; i < names.length; i++) {\n"
7996             + "      log(names[i]);\n"
7997             + "    }\n"
7998             + "  }\n"
7999             + "</script></head>\n"
8000             + "<body onload='test()'>\n"
8001             + "  <button id='testBtn' disabled></button>\n"
8002             + "</body></html>";
8003         loadPageVerifyTitle2(html);
8004     }
8005 }