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