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