1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package org.htmlunit.javascript.host;
16
17 import java.io.ByteArrayOutputStream;
18 import java.io.File;
19 import java.io.OutputStreamWriter;
20 import java.net.URL;
21 import java.nio.charset.StandardCharsets;
22
23 import org.apache.commons.io.FileUtils;
24 import org.htmlunit.CookieManager4Test;
25 import org.htmlunit.WebDriverTestCase;
26 import org.htmlunit.junit.annotation.Alerts;
27 import org.htmlunit.junit.annotation.HtmlUnitNYI;
28 import org.htmlunit.util.MimeType;
29 import org.junit.jupiter.api.Test;
30 import org.openqa.selenium.By;
31 import org.openqa.selenium.JavascriptExecutor;
32 import org.openqa.selenium.WebDriver;
33 import org.openqa.selenium.htmlunit.HtmlUnitDriver;
34
35
36
37
38
39
40
41
42
43
44
45
46
47 public class Window2Test extends WebDriverTestCase {
48
49
50
51
52 @Test
53 @Alerts({"[object Window]", "ReferenceError", "undefined", "undefined", "hello", "hello", "world", "world"})
54 public void thisIsWindow() throws Exception {
55 final String html = DOCTYPE_HTML
56 + "<html><head></head><body>\n"
57 + "<script>\n"
58 + LOG_TITLE_FUNCTION
59 + " log(this);\n"
60 + " try {\n"
61 + " log(abc);\n"
62 + " } catch(e) { logEx(e) }\n"
63 + " log(this.abc);\n"
64 + " log(this.def);\n"
65 + " this.abc = 'hello';\n"
66 + " def = 'world';\n"
67 + " log(abc);\n"
68 + " log(this.abc);\n"
69 + " log(def);\n"
70 + " log(this.def);\n"
71 + "</script>\n"
72 + "</body></html>";
73 loadPageVerifyTitle2(html);
74 }
75
76
77
78
79 @Test
80 @Alerts({"function", "function"})
81 public void thisIsWindow2() throws Exception {
82 final String html = DOCTYPE_HTML
83 + "<html><head></head><body>\n"
84 + "<script>\n"
85 + LOG_TITLE_FUNCTION
86 + " function hello() {\n"
87 + " var x = 1;\n"
88 + " } \n"
89 + " log(typeof hello);\n"
90 + " log(typeof window.hello);\n"
91 + "</script>\n"
92 + "</body></html>";
93 loadPageVerifyTitle2(html);
94 }
95
96
97
98
99
100 @Test
101 @Alerts(DEFAULT = {"not found", "true"},
102 FF = {"found", "true"},
103 FF_ESR = {"found", "true"})
104 public void FF_controllers() throws Exception {
105 final String html = DOCTYPE_HTML
106 + "<html><head></head><body>\n"
107 + "<script>\n"
108 + LOG_TITLE_FUNCTION
109 + "if (window.controllers)\n"
110 + " log('found');\n"
111 + "else\n"
112 + " log('not found');\n"
113 + "window.controllers = 'hello';\n"
114 + "log(window.controllers == 'hello');\n"
115 + "</script>\n"
116 + "</body></html>";
117 loadPageVerifyTitle2(html);
118 }
119
120
121
122
123 @Test
124 @Alerts("true")
125 public void FF_controllers_set() throws Exception {
126 final String html = DOCTYPE_HTML
127 + "<html><head></head><body>\n"
128 + "<script>\n"
129 + LOG_TITLE_FUNCTION
130 + " window.controllers = 'hello';\n"
131 + " log(window.controllers == 'hello');\n"
132 + "</script>\n"
133 + "</body></html>";
134 loadPageVerifyTitle2(html);
135 }
136
137
138
139
140
141 @Test
142 @Alerts({"a", "1"})
143 public void onload_prototype() throws Exception {
144 final String html = DOCTYPE_HTML
145 + "<html>\n"
146 + "<head>\n"
147 + "<script>\n"
148 + LOG_WINDOW_NAME_FUNCTION
149 + "</script>\n"
150 + "</head>"
151 + "<body onload='log(1)'>\n"
152 + "<script>Function.prototype.x='a'; log(window.onload.x);</script>\n"
153 + "</body></html>";
154
155 loadPage2(html);
156 verifyWindowName2(getWebDriver(), getExpectedAlerts());
157 }
158
159
160
161
162 @Test
163 @Alerts({"SGVsbG8gV29ybGQh", "Hello World!"})
164 public void atob() throws Exception {
165 final String html = DOCTYPE_HTML
166 + "<html><head></head><body>\n"
167 + "<script>\n"
168 + LOG_TITLE_FUNCTION
169 + " var data = window.btoa('Hello World!');\n"
170 + " log(data);\n"
171 + " log(window.atob(data));\n"
172 + "</script>\n"
173 + "</body></html>";
174 loadPageVerifyTitle2(html);
175 }
176
177
178
179
180 @Test
181 @Alerts({"SGVsbG8gV29ybGQh", "Hello World!"})
182 public void atobTrailingWhitespace() throws Exception {
183 final String html = DOCTYPE_HTML
184 + "<html><head></head><body>\n"
185 + "<script>\n"
186 + LOG_TITLE_FUNCTION
187 + " var data = window.btoa('Hello World!');\n"
188 + " log(data);\n"
189 + " try {\n"
190 + " log(window.atob(data + ' \\t\\r\\n\\x0C'));\n"
191 + " } catch(e) { logEx(e) }\n"
192 + "</script>\n"
193 + "</body></html>";
194 loadPageVerifyTitle2(html);
195 }
196
197
198
199
200 @Test
201 @Alerts({"SGVsbG8gV29ybGQh", "Hello World!"})
202 public void atobLeadingWhitespace() throws Exception {
203 final String html = DOCTYPE_HTML
204 + "<html><head></head><body>\n"
205 + "<script>\n"
206 + LOG_TITLE_FUNCTION
207 + " var data = window.btoa('Hello World!');\n"
208 + " log(data);\n"
209 + " try {\n"
210 + " log(window.atob(' \\t\\r\\n\\x0C' + data));\n"
211 + " } catch(e) { logEx(e) }\n"
212 + "</script>\n"
213 + "</body></html>";
214 loadPageVerifyTitle2(html);
215 }
216
217
218
219
220 @Test
221 @Alerts({"SGVsbG8gV29ybGQh", "Hello World!"})
222 public void atobWhitespace() throws Exception {
223 final String html = DOCTYPE_HTML
224 + "<html><head></head><body>\n"
225 + "<script>\n"
226 + LOG_TITLE_FUNCTION
227 + " var data = window.btoa('Hello World!');\n"
228 + " log(data);\n"
229 + " try {\n"
230 + " log(window.atob(data.substr(0, 2) + ' ' + data.substr(2)));\n"
231 + " } catch(e) { logEx(e) }\n"
232 + "</script>\n"
233 + "</body></html>";
234 loadPageVerifyTitle2(html);
235 }
236
237
238
239
240 @Test
241 @Alerts({"SGVsbG8gV29ybGQh", "InvalidCharacterError/DOMException",
242 "InvalidCharacterError/DOMException", "InvalidCharacterError/DOMException"})
243 public void atobNbsp() throws Exception {
244 final String html = DOCTYPE_HTML
245 + "<html><head></head><body>\n"
246 + "<script>\n"
247 + LOG_TITLE_FUNCTION
248 + " var data = window.btoa('Hello World!');\n"
249 + " log(data);\n"
250 + " try {\n"
251 + " log(window.atob('\\xA0' + data));\n"
252 + " } catch(e) { logEx(e) }\n"
253 + " try {\n"
254 + " log(window.atob(data + '\\xA0'));\n"
255 + " } catch(e) { logEx(e) }\n"
256 + " try {\n"
257 + " log(window.atob(data.substr(0, 2) + '\\xA0' + data.substr(2)));\n"
258 + " } catch(e) { logEx(e) }\n"
259 + "</script>\n"
260 + "</body></html>";
261 loadPageVerifyTitle2(html);
262 }
263
264
265
266
267 @Test
268 @Alerts({"SGVsbG8gV29ybGQh", "InvalidCharacterError/DOMException"})
269 public void atobInvalid() throws Exception {
270 final String html = DOCTYPE_HTML
271 + "<html><head></head><body>\n"
272 + "<script>\n"
273 + LOG_TITLE_FUNCTION
274 + " var data = window.btoa('Hello World!');\n"
275 + " log(data);\n"
276 + " try {\n"
277 + " log(window.atob(data.substr(0, 2) + '!' + data.substr(2)));\n"
278 + " } catch(e) { logEx(e) }\n"
279 + "</script>\n"
280 + "</body></html>";
281 loadPageVerifyTitle2(html);
282 }
283
284
285
286
287 @Test
288 @Alerts("InvalidCharacterError/DOMException")
289 public void atobMalformedInput() throws Exception {
290 final String html = DOCTYPE_HTML
291 + "<html><head></head><body>\n"
292 + "<script>\n"
293 + LOG_TITLE_FUNCTION
294 + " try {\n"
295 + " window.atob('b');\n"
296 + " } catch(e) { logEx(e) }\n"
297 + "</script>\n"
298 + "</body></html>";
299 loadPageVerifyTitle2(html);
300 }
301
302
303
304
305 @Test
306 @Alerts("InvalidCharacterError/DOMException")
307 public void atobEmptyInput() throws Exception {
308 final String html = DOCTYPE_HTML
309 + "<html><head></head><body>\n"
310 + "<script>\n"
311 + LOG_TITLE_FUNCTION
312 + " try {\n"
313 + " window.atob('b');\n"
314 + " } catch(e) { logEx(e) }\n"
315 + "</script>\n"
316 + "</body></html>";
317 loadPageVerifyTitle2(html);
318 }
319
320
321
322
323 @Test
324 @Alerts({"InvalidCharacterError/DOMException", "InvalidCharacterError/DOMException"})
325 public void atobUnicode() throws Exception {
326 final String html = DOCTYPE_HTML
327 + "<html><head></head><body>\n"
328 + "<script>\n"
329 + LOG_TITLE_FUNCTION
330 + " try {\n"
331 + " window.btoa('I \\u2661 Unicode!');\n"
332 + " } catch(e) { logEx(e) }\n"
333 + " try {\n"
334 + " window.atob('I \\u2661 Unicode!');\n"
335 + " } catch(e) { logEx(e) }\n"
336 + "</script>\n"
337 + "</body></html>";
338 loadPageVerifyTitle2(html);
339 }
340
341
342
343
344 @Test
345 @Alerts({"M8OuwqY=", "3\u00C3\u00AE\u00C2\u00A6"})
346 public void atobUnicodeOutput() throws Exception {
347 final String html = DOCTYPE_HTML
348 + "<html><head></head><body>\n"
349 + "<script>\n"
350 + " var data = window.btoa('3\u00C3\u00AE\u00C2\u00A6');\n"
351 + " var dataAtob = window.atob(data);\n"
352 + "</script>\n"
353 + "</body></html>";
354
355 final WebDriver driver = loadPage2(html);
356
357 verifyJsVariable(driver, "data", getExpectedAlerts()[0]);
358 verifyJsVariable(driver, "dataAtob", getExpectedAlerts()[1]);
359 }
360
361
362
363
364 @Test
365 @Alerts({"CSAe", "\t \u001e"})
366 public void atobControlChar() throws Exception {
367 final String html = DOCTYPE_HTML
368 + "<html><head></head><body>\n"
369 + "<script>\n"
370 + " var data = window.btoa('\\t \\u001e');\n"
371 + " var dataAtob = window.atob(data);\n"
372 + "</script>\n"
373 + "</body></html>";
374
375 final WebDriver driver = loadPage2(html);
376
377 verifyJsVariable(driver, "data", getExpectedAlerts()[0]);
378 verifyJsVariable(driver, "dataAtob", getExpectedAlerts()[1]);
379 }
380
381
382
383
384 @Test
385 @Alerts({"bnVsbA==", "null"})
386 public void atobNull() throws Exception {
387 final String html = DOCTYPE_HTML
388 + "<html><head></head><body>\n"
389 + "<script>\n"
390 + LOG_TITLE_FUNCTION
391 + " var data = window.btoa(null);\n"
392 + " log(data);\n"
393 + " log(window.atob(data));\n"
394 + "</script>\n"
395 + "</body></html>";
396 loadPageVerifyTitle2(html);
397 }
398
399
400
401
402 @Test
403 @Alerts({"dW5kZWZpbmVk", "undefined"})
404 public void atobUndefined() throws Exception {
405 final String html = DOCTYPE_HTML
406 + "<html><head></head><body>\n"
407 + "<script>\n"
408 + LOG_TITLE_FUNCTION
409 + " var data = window.btoa(undefined);\n"
410 + " log(data);\n"
411 + " log(window.atob(data));\n"
412 + "</script>\n"
413 + "</body></html>";
414 loadPageVerifyTitle2(html);
415 }
416
417
418
419
420
421
422
423 @Test
424 @Alerts({"getClass: undefined,undefined", "java: undefined,undefined", "javax: undefined,undefined",
425 "javafx: undefined,undefined", "org: undefined,undefined", "com: undefined,undefined",
426 "edu: undefined,undefined", "net: undefined,undefined", "JavaAdapter: undefined,undefined",
427 "JavaImporter: undefined,undefined", "Continuation: undefined,undefined", "Packages: undefined,undefined",
428 "XML: undefined,undefined", "XMLList: undefined,undefined", "Namespace: undefined,undefined",
429 "QName: undefined,undefined", "arguments: undefined,undefined", "load: undefined,undefined",
430 "loadWithNewGlobal: undefined,undefined", "exit: undefined,undefined", "quit: undefined,undefined",
431 "__FILE__: undefined,undefined", "__DIR__: undefined,undefined", "__LINE__: undefined,undefined",
432 "context: undefined,undefined", "engine: undefined,undefined", "__noSuchProperty__: undefined,undefined",
433 "Java: undefined,undefined", "JSAdapter: undefined,undefined",
434 "NaN: number,number", "Infinity: number,number", "eval: function,function", "print: function,function",
435 "parseInt: function,function", "parseFloat: function,function",
436 "isNaN: function,function", "isFinite: function,function", "encodeURI: function,function",
437 "encodeURIComponent: function,function", "decodeURI: function,function",
438 "decodeURIComponent: function,function", "escape: function,function", "unescape: function,function"})
439 public void topLevelProperties() throws Exception {
440 final String[] properties = {
441 "getClass", "java", "javax", "javafx", "org", "com", "edu", "net", "JavaAdapter",
442 "JavaImporter", "Continuation", "Packages", "XML", "XMLList", "Namespace", "QName", "arguments", "load",
443 "loadWithNewGlobal", "exit", "quit", "__FILE__", "__DIR__", "__LINE__", "context", "engine",
444 "__noSuchProperty__", "Java", "JSAdapter",
445 "NaN", "Infinity", "eval", "print", "parseInt", "parseFloat", "isNaN", "isFinite", "encodeURI",
446 "encodeURIComponent", "decodeURI", "decodeURIComponent", "escape", "unescape"};
447
448 final String html = DOCTYPE_HTML
449 + "<html><head></head><body>\n"
450 + "<script>\n"
451 + LOG_TITLE_FUNCTION
452 + " var props = ['" + String.join("', '", properties) + "'];\n"
453 + " for (var i = 0; i < props.length; i++)\n"
454 + " log(props[i] + ': ' + typeof(window[props[i]]) + ',' + typeof(eval('this.' + props[i])));\n"
455 + "</script>\n"
456 + "</body></html>";
457 loadPageVerifyTitle2(html);
458 }
459
460
461
462
463 @Test
464 @Alerts("javax.script.filename: undefined")
465 public void topLevelPropertiesWithDot() throws Exception {
466 final String[] properties = {"javax.script.filename"};
467
468 final String html = DOCTYPE_HTML
469 + "<html><head></head><body>\n"
470 + "<script>\n"
471 + LOG_TITLE_FUNCTION
472 + " var props = ['" + String.join("', '", properties) + "'];\n"
473 + " for (var i = 0; i < props.length; i++)\n"
474 + " log(props[i] + ': ' + typeof(window[props[i]]));\n"
475 + "</script>\n"
476 + "</body></html>";
477
478 loadPageVerifyTitle2(html);
479 }
480
481
482
483
484 @Test
485 @Alerts("TypeError")
486 public void execScript2() throws Exception {
487 final String html = DOCTYPE_HTML
488 + "<html><head><script>\n"
489 + LOG_TITLE_FUNCTION
490 + " function test() {\n"
491 + " try {\n"
492 + " window.execScript('log(1);');\n"
493 + " }\n"
494 + " catch(e) { logEx(e) }\n"
495 + " }\n"
496 + "</script></head><body onload='test()'>\n"
497 + "</body></html>";
498
499 loadPageVerifyTitle2(html);
500 }
501
502
503
504
505 @Test
506 @Alerts("TypeError")
507 public void execScript_returnValue() throws Exception {
508 final String html = DOCTYPE_HTML
509 + "<html><head><script>\n"
510 + LOG_TITLE_FUNCTION
511 + "try {\n"
512 + " log(window.execScript('1') === undefined);\n"
513 + "}\n"
514 + "catch(e) { logEx(e) }\n"
515 + "</script></head><body>\n"
516 + "</body></html>";
517
518 loadPageVerifyTitle2(html);
519 }
520
521
522
523
524 @Test
525 @Alerts("undefined")
526 public void collectGarbage() throws Exception {
527 final String html = DOCTYPE_HTML
528 + "<html><head><script>\n"
529 + LOG_TITLE_FUNCTION
530 + " function test() {\n"
531 + " log(typeof CollectGarbage);\n"
532 + " }\n"
533 + "</script></head><body onload='test()'>\n"
534 + "</body></html>";
535
536 loadPageVerifyTitle2(html);
537 }
538
539
540
541
542 @Test
543 @Alerts({"original", "changed"})
544 public void eval_localVariable() throws Exception {
545 final String html = DOCTYPE_HTML
546 + "<html><head><script>\n"
547 + LOG_TITLE_FUNCTION
548 + " function test() {\n"
549 + " var f = document.getElementById('testForm1');\n"
550 + " log(f.text1.value);\n"
551 + " eval('f.text_' + 1).value = 'changed';\n"
552 + " log(f.text1.value);\n"
553 + " }\n"
554 + "</script></head><body onload='test()'>\n"
555 + " <form id='testForm1'>\n"
556 + " <input id='text1' type='text' name='text_1' value='original'>\n"
557 + " </form>\n"
558 + "</body></html>";
559
560 loadPageVerifyTitle2(html);
561 }
562
563
564
565
566
567
568 @Test
569 @Alerts({"function Node() { [native code] }", "function Element() { [native code] }"})
570 public void windowProperties() throws Exception {
571 final String html = DOCTYPE_HTML
572 + "<html><head><script>\n"
573 + LOG_TITLE_FUNCTION
574 + " function test() {\n"
575 + " log(window.Node);\n"
576 + " log(window.Element);\n"
577 + " }\n"
578 + "</script></head><body onload='test()'>\n"
579 + "<form name='myForm'></form>\n"
580 + "</body></html>";
581
582 loadPageVerifyTitle2(html);
583 }
584
585
586
587
588
589 @Test
590 @Alerts({"0", "0"})
591 public void framesLengthZero() throws Exception {
592 final String html = DOCTYPE_HTML
593 + "<html><head><script>\n"
594 + LOG_TITLE_FUNCTION
595 + "log(window.length);\n"
596 + "log(window.frames.length);\n"
597 + "</script></head><body>\n"
598 + "</body></html>";
599 loadPageVerifyTitle2(html);
600 }
601
602
603
604
605
606 @Test
607 @Alerts({"2", "2", "frame1", "frame2"})
608 public void framesLengthAndFrameAccess() throws Exception {
609 final String html = DOCTYPE_HTML
610 + "<html>\n"
611 + "<script>\n"
612 + LOG_TITLE_FUNCTION
613 + "function test() {\n"
614 + " log(window.length);\n"
615 + " log(window.frames.length);\n"
616 + " log(window.frames[0].name);\n"
617 + " log(window.frames.frame2.name);\n"
618 + "}\n"
619 + "</script>\n"
620 + "<frameset rows='50,*' onload='test()'>\n"
621 + "<frame name='frame1' src='about:blank'/>\n"
622 + "<frame name='frame2' src='about:blank'/>\n"
623 + "</frameset>\n"
624 + "</html>";
625
626 loadPageVerifyTitle2(html);
627 }
628
629
630
631
632 @Test
633 @Alerts({"0", "0", "2", "2", "2", "true"})
634 public void windowFramesLive() throws Exception {
635 final String html = DOCTYPE_HTML
636 + "<html>\n"
637 + "<script>\n"
638 + LOG_TITLE_FUNCTION
639 + "log(window.length);\n"
640 + "var oFrames = window.frames;\n"
641 + "log(oFrames.length);\n"
642 + "function test() {\n"
643 + " log(oFrames.length);\n"
644 + " log(window.length);\n"
645 + " log(window.frames.length);\n"
646 + " log(oFrames == window.frames);\n"
647 + "}\n"
648 + "</script>\n"
649 + "<frameset rows='50,*' onload='test()'>\n"
650 + "<frame src='about:blank'/>\n"
651 + "<frame src='about:blank'/>\n"
652 + "</frameset>\n"
653 + "</html>";
654
655 loadPageVerifyTitle2(html);
656 }
657
658
659
660
661
662
663 @Test
664 @Alerts("hello")
665 public void overwriteFunctions_navigator() throws Exception {
666 final String html = DOCTYPE_HTML
667 + "<html><head><script>\n"
668 + LOG_TITLE_FUNCTION
669 + " function test() {\n"
670 + " function navigator() {\n"
671 + " log('hello');\n"
672 + " }\n"
673 + " navigator();\n"
674 + " }\n"
675 + "</script></head><body onload='test()'></body></html>";
676
677 loadPageVerifyTitle2(html);
678 }
679
680
681
682
683
684 @Test
685 public void onbeforeunload_setToString() throws Exception {
686 final String html = DOCTYPE_HTML
687 + "<html>\n"
688 + "<head>\n"
689 + "<script>\n"
690 + LOG_WINDOW_NAME_FUNCTION
691 + "</script>\n"
692 + "</head>"
693 + "<body><script>\n"
694 + " window.onbeforeunload = \"log('x')\";\n"
695 + " window.location = 'about:blank';\n"
696 + "</script></body></html>";
697
698 loadPage2(html);
699 verifyWindowName2(getWebDriver(), getExpectedAlerts());
700 }
701
702
703
704
705
706 @Test
707 @Alerts({"true", "true", "function"})
708 public void onbeforeunload_defined() throws Exception {
709 onbeforeunload("onbeforeunload", "var x;");
710 }
711
712
713
714
715
716 @Test
717 @Alerts({"true", "true", "object"})
718 public void onbeforeunload_notDefined() throws Exception {
719 onbeforeunload("onbeforeunload", null);
720 }
721
722 private void onbeforeunload(final String name, final String js) throws Exception {
723 final String html = DOCTYPE_HTML
724 + "<html><body" + (js != null ? " " + name + "='" + js + "'" : "") + "><script>\n"
725 + LOG_TITLE_FUNCTION
726 + " log('" + name + "' in window);\n"
727 + " var x = false;\n"
728 + " for(var p in window) { if(p == '" + name + "') { x = true; break; } }\n"
729 + " log(x);\n"
730 + " log(typeof window." + name + ");\n"
731 + "</script></body></html>";
732 loadPageVerifyTitle2(html);
733 }
734
735
736
737
738
739
740 @Test
741 @Alerts({"[object Window]", "[object Window]", "[object Window]", "1", "true", "true",
742 "[object Window]", "true", "true", "no function", "undefined", "true", "true",
743 "[object History]", "true", "true", "[object Window]", "true", "true"})
744 public void framesAreWindows() throws Exception {
745 final String html = DOCTYPE_HTML
746 + "<html><body><iframe name='f'></iframe><script>\n"
747 + LOG_TITLE_FUNCTION
748 + "log(window.frames);\n"
749 + "log(window.f);\n"
750 + "log(window.frames.f);\n"
751 + "log(window.length);\n"
752 + "log(window.length == window.frames.length);\n"
753 + "log(window.length == window.frames.frames.length);\n"
754 + "log(window[0]);\n"
755 + "log(window[0] == window.frames[0]);\n"
756 + "log(window[0] == window.frames.frames[0]);\n"
757 + "try {\n"
758 + " log(window(0));\n"
759 + " log(window(0) == window.frames(0));\n"
760 + " log(window(0) == window.frames.frames(0));\n"
761 + "} catch(e) {\n"
762 + " log('no function');\n"
763 + "}\n"
764 + "log(window[1]);\n"
765 + "log(window[1] == window.frames[1]);\n"
766 + "log(window[1] == window.frames.frames[1]);\n"
767 + "log(window.history);\n"
768 + "log(window.history == window.frames.history);\n"
769 + "log(window.history == window.frames.frames.history);\n"
770 + "log(window.self);\n"
771 + "log(window.self == window.frames.self);\n"
772 + "log(window.self == window.frames.frames.self);\n"
773 + "</script></body></html>";
774 loadPageVerifyTitle2(html);
775 }
776
777
778
779
780
781 @Test
782 @Alerts({"Hello window", ""})
783 public void open() throws Exception {
784 final String html = DOCTYPE_HTML
785 + "<html><head>\n"
786 + "<script>\n"
787 + LOG_TITLE_FUNCTION
788 + "</script>\n"
789 + "</head>\n"
790 + "<body>\n"
791 + "<script>\n"
792 + " window.open('" + URL_SECOND + "');\n"
793 + "</script>\n"
794 + "</body></html>";
795 final String windowContent = DOCTYPE_HTML
796 + "<html><head></head>\n"
797 + "<body>\n"
798 + "<script>\n"
799 + " window.opener.log('Hello window');\n"
800 + " window.opener.log(window.name);\n"
801 + "</script>\n"
802 + "</body></html>";
803 getMockWebConnection().setDefaultResponse(windowContent);
804 loadPageVerifyTitle2(html);
805
806
807 releaseResources();
808 shutDownAll();
809 }
810
811
812
813
814
815 @Test
816 @Alerts({"Hello window", "New window"})
817 public void openWindowParams() throws Exception {
818 final String html = DOCTYPE_HTML
819 + "<html><head>\n"
820 + "<script>\n"
821 + LOG_TITLE_FUNCTION
822 + "</script>\n"
823 + "</head>\n"
824 + "<body>\n"
825 + "<script>\n"
826 + " window.open('" + URL_SECOND + "', 'New window', 'width=200,height=100');\n"
827 + "</script>\n"
828 + "</body></html>";
829 final String windowContent = DOCTYPE_HTML
830 + "<html><head></head>\n"
831 + "<body>\n"
832 + "<script>\n"
833 + " window.opener.log('Hello window');\n"
834 + " window.opener.log(window.name);\n"
835 + "</script>\n"
836 + "</body></html>";
837 getMockWebConnection().setDefaultResponse(windowContent);
838 loadPageVerifyTitle2(html);
839
840
841 releaseResources();
842 shutDownAll();
843 }
844
845
846
847
848
849 @Test
850 @Alerts("window1window2")
851 public void openWindowParamReplace() throws Exception {
852 final String html = DOCTYPE_HTML
853 + "<html><head>\n"
854 + "<script>\n"
855 + " function info(msg) {\n"
856 + " document.title += msg;\n"
857 + " }\n"
858 + "</script>\n"
859 + "</head>\n"
860 + "<body>\n"
861 + "<script>\n"
862 + " window.open('" + URL_SECOND + "', 'window1', 'width=200,height=100', true);\n"
863 + " window.open('" + URL_SECOND + "', 'window2', 'width=200,height=100', 'true');\n"
864 + "</script>\n"
865 + "</body></html>";
866 final String windowContent = DOCTYPE_HTML
867 + "<html><head></head>\n"
868 + "<body>\n"
869 + "<script>\n"
870 + " window.opener.info(window.name);\n"
871 + "</script>\n"
872 + "</body></html>";
873 getMockWebConnection().setDefaultResponse(windowContent);
874 final WebDriver driver = loadPage2(html);
875
876 Thread.sleep(400);
877 assertEquals(getExpectedAlerts()[0], driver.getTitle());
878
879
880 releaseResources();
881 shutDownAll();
882 }
883
884
885
886
887
888 @Test
889 @Alerts({"[object Window]", "[object Window] (true)", "1234 (true)", "null (true)", "undefined (true)",
890 "[object Window] (true)", "[object Window] (true)", "[object Window] (true)"})
891 public void set_opener() throws Exception {
892 final String html = DOCTYPE_HTML
893 + "<html><head><script>\n"
894 + LOG_TITLE_FUNCTION
895 + "var otherWindow = window.open('about:blank');\n"
896 + "function trySetOpener1(_win, value) {\n"
897 + " try {\n"
898 + " _win.opener = value;\n"
899 + " log(_win.opener + ' (' + (_win.opener === value) + ')');\n"
900 + " }\n"
901 + " catch(e) { logEx(e) }\n"
902 + "}\n"
903 + "function trySetOpener(_win) {\n"
904 + " var originalValue = _win.opener;\n"
905 + " log(originalValue);\n"
906 + " trySetOpener1(_win, _win.opener);\n"
907 + " trySetOpener1(_win, 1234);\n"
908 + " trySetOpener1(_win, null);\n"
909 + " trySetOpener1(_win, undefined);\n"
910 + " trySetOpener1(_win, _win);\n"
911 + " trySetOpener1(_win, otherWindow);\n"
912 + " trySetOpener1(_win, originalValue);\n"
913 + "}\n"
914 + "function doTest() {\n"
915 + " trySetOpener(window.open('about:blank'));\n"
916 + "}\n"
917 + "</script></head>\n"
918 + "<body onload='doTest()'>\n"
919 + "</body></html>";
920
921 loadPageVerifyTitle2(html);
922
923 releaseResources();
924 shutDownAll();
925 }
926
927
928
929
930 @Test
931 @Alerts({"ReferenceError", "ReferenceError", "ReferenceError", "ReferenceError"})
932 public void IEScriptEngineXxx() throws Exception {
933 final String html = DOCTYPE_HTML
934 + "<html><head><script>\n"
935 + LOG_TITLE_FUNCTION
936 + "try { log(ScriptEngine()); } catch(e) { logEx(e) }\n"
937 + "try { log(ScriptEngineMajorVersion()); } catch(e) { logEx(e) }\n"
938 + "try { log(ScriptEngineMinorVersion()); } catch(e) { logEx(e) }\n"
939 + "try { log(typeof ScriptEngineBuildVersion()); } catch(e) { logEx(e) }\n"
940 + "</script></head>\n"
941 + "<body>\n"
942 + "</body></html>";
943 loadPageVerifyTitle2(html);
944 }
945
946
947
948
949
950 @Test
951 @Alerts(CHROME = {"true", "621", "147", "true", "16", "16"},
952 EDGE = {"true", "630", "138", "true", "16", "24"},
953 FF = {"true", "675", "93", "true", "16", "16"},
954 FF_ESR = {"true", "677", "91", "true", "16", "12"})
955 @HtmlUnitNYI(CHROME = {"true", "605", "147", "true", "0", "16"},
956 EDGE = {"true", "605", "138", "true", "0", "24"},
957 FF = {"true", "605", "93", "true", "0", "16"},
958 FF_ESR = {"true", "605", "91", "true", "0", "12"})
959 public void heightsAndWidths() throws Exception {
960 final String html = DOCTYPE_HTML
961 + "<html><body onload='test()'><script>\n"
962 + LOG_TITLE_FUNCTION
963 + "function test() {\n"
964 + " log(window.innerHeight > 0);\n"
965 + " log(window.innerHeight - document.body.clientHeight);\n"
966 + " log(window.outerHeight - window.innerHeight);\n"
967 + " log(window.innerWidth > 0);\n"
968 + " log(window.innerWidth - document.body.clientWidth);\n"
969 + " log(window.outerWidth - window.innerWidth);\n"
970 + "}\n"
971 + "</script>\n"
972 + "</body></html>";
973 loadPageVerifyTitle2(html);
974 }
975
976
977
978
979
980 @Test
981 @Alerts(CHROME = {"true", "0", "147", "true", "true", "16"},
982 EDGE = {"true", "0", "138", "true", "true", "24"},
983 FF = {"true", "0", "93", "true", "true", "16"},
984 FF_ESR = {"true", "0", "91", "true", "true", "12"})
985 public void heightsAndWidthsQuirks() throws Exception {
986 final String html =
987 "<html><body onload='test()'><script>\n"
988 + LOG_TITLE_FUNCTION
989 + "function test() {\n"
990 + " log(window.innerHeight > 0);\n"
991 + " log(window.innerHeight - document.body.clientHeight);\n"
992 + " log(window.outerHeight - window.innerHeight);\n"
993 + " log(window.innerWidth > 0);\n"
994 + " log(window.innerWidth == document.body.clientWidth);\n"
995 + " log(window.outerWidth - window.innerWidth);\n"
996 + "}\n"
997 + "</script>\n"
998 + "</body></html>";
999 loadPageVerifyTitle2(html);
1000 }
1001
1002
1003
1004
1005 @Test
1006 @Alerts({"true", "1234"})
1007 public void setInnerWidth() throws Exception {
1008 final String html = DOCTYPE_HTML
1009 + "<html><body onload='test()'><script>\n"
1010 + LOG_TITLE_FUNCTION
1011 + "function test() {\n"
1012 + " log(window.innerWidth > 0);\n"
1013 + " window.innerWidth = 1234;\n"
1014 + " log(window.innerWidth);\n"
1015 + "}\n"
1016 + "</script>\n"
1017 + "</body></html>";
1018 loadPageVerifyTitle2(html);
1019 }
1020
1021
1022
1023
1024 @Test
1025 @Alerts({"true", "1234"})
1026 public void setInnerHeight() throws Exception {
1027 final String html = DOCTYPE_HTML
1028 + "<html><body onload='test()'><script>\n"
1029 + LOG_TITLE_FUNCTION
1030 + "function test() {\n"
1031 + " log(window.innerHeight > 0);\n"
1032 + " window.innerHeight = 1234;\n"
1033 + " log(window.innerHeight);\n"
1034 + "}\n"
1035 + "</script>\n"
1036 + "</body></html>";
1037 loadPageVerifyTitle2(html);
1038 }
1039
1040
1041
1042
1043 @Test
1044 @Alerts({"true", "1234"})
1045 public void setOuterWidth() throws Exception {
1046 final String html = DOCTYPE_HTML
1047 + "<html><body onload='test()'><script>\n"
1048 + LOG_TITLE_FUNCTION
1049 + "function test() {\n"
1050 + " log(window.outerWidth > 0);\n"
1051 + " window.outerWidth = 1234;\n"
1052 + " log(window.outerWidth);\n"
1053 + "}\n"
1054 + "</script>\n"
1055 + "</body></html>";
1056 loadPageVerifyTitle2(html);
1057 }
1058
1059
1060
1061
1062 @Test
1063 @Alerts({"true", "1234"})
1064 public void setOuterHeight() throws Exception {
1065 final String html = DOCTYPE_HTML
1066 + "<html><body onload='test()'><script>\n"
1067 + LOG_TITLE_FUNCTION
1068 + "function test() {\n"
1069 + " log(window.outerHeight > 0);\n"
1070 + " window.outerHeight = 1234;\n"
1071 + " log(window.outerHeight);\n"
1072 + "}\n"
1073 + "</script>\n"
1074 + "</body></html>";
1075 loadPageVerifyTitle2(html);
1076 }
1077
1078
1079
1080
1081
1082 @Test
1083 @Alerts(CHROME = {"0", "1240", "100", "1240"},
1084 EDGE = {"0", "1232", "100", "1232"},
1085 FF = {"0", "1240", "100", "1240"},
1086 FF_ESR = {"0", "1244", "100", "1244"})
1087 @HtmlUnitNYI(CHROME = {"0", "1256", "100", "1256"},
1088 EDGE = {"0", "1256", "100", "1256"},
1089 FF = {"0", "1256", "100", "1256"},
1090 FF_ESR = {"0", "1256", "100", "1256"})
1091
1092
1093 public void changeHeightsAndWidths() throws Exception {
1094 final String html = DOCTYPE_HTML
1095 + "<html><head>\n"
1096 + "<script language='javascript'>\n"
1097 + LOG_TITLE_FUNCTION
1098 + " function test() {\n"
1099 + " var oldHeight = document.body.clientHeight;\n"
1100 + " var oldWidth = document.body.clientWidth;\n"
1101 + " log(document.body.clientHeight);\n"
1102 + " log(document.body.clientWidth);\n"
1103 + " newDiv = document.createElement('div');\n"
1104 + " document.body.appendChild(newDiv);\n"
1105 + " newDiv.style['height'] = oldHeight + 100 + 'px';\n"
1106 + " newDiv.style['width'] = oldWidth + 100 + 'px';\n"
1107 + " log(document.body.clientHeight);\n"
1108 + " log(document.body.clientWidth);\n"
1109 + " }\n"
1110 + "</script>\n"
1111 + "</head>\n"
1112 + "<body onload='test()'></body>\n"
1113 + "</html>";
1114 loadPageVerifyTitle2(html);
1115 }
1116
1117
1118
1119
1120
1121 @Test
1122 @Alerts(CHROME = {"621", "1256", "606", "1241"},
1123 EDGE = {"630", "1248", "615", "1233"},
1124 FF = {"675", "1256", "658", "1239"},
1125 FF_ESR = {"677", "1260", "660", "1243"})
1126
1127
1128 @HtmlUnitNYI(CHROME = {"605", "1256", "705", "1256"},
1129 EDGE = {"605", "1256", "705", "1256"},
1130 FF = {"605", "1256", "705", "1256"},
1131 FF_ESR = {"605", "1256", "705", "1256"})
1132 public void changeHeightsAndWidthsQuirks() throws Exception {
1133 final String html =
1134 "<html><head>\n"
1135 + "<script language='javascript'>\n"
1136 + LOG_TITLE_FUNCTION
1137 + " function test() {\n"
1138 + " var oldHeight = document.body.clientHeight;\n"
1139 + " var oldWidth = document.body.clientWidth;\n"
1140 + " log(document.body.clientHeight);\n"
1141 + " log(document.body.clientWidth);\n"
1142 + " newDiv = document.createElement('div');\n"
1143 + " document.body.appendChild(newDiv);\n"
1144 + " newDiv.style['height'] = oldHeight + 100 + 'px';\n"
1145 + " newDiv.style['width'] = oldWidth + 100 + 'px';\n"
1146 + " log(document.body.clientHeight);\n"
1147 + " log(document.body.clientWidth);\n"
1148 + " }\n"
1149 + "</script>\n"
1150 + "</head>\n"
1151 + "<body onload='test()'></body>\n"
1152 + "</html>";
1153 loadPageVerifyTitle2(html);
1154 }
1155
1156
1157
1158
1159
1160 @Test
1161 @Alerts(DEFAULT = {"0,0", "0,0", "0,0", "0,0", "no scrollByLines()", "0,0", "no scrollByPages()"},
1162 FF = {"0,0", "0,0", "0,0", "0,0", "0,0", "0,0", "0,0"},
1163 FF_ESR = {"0,0", "0,0", "0,0", "0,0", "0,0", "0,0", "0,0"})
1164 @HtmlUnitNYI(CHROME = {"0,0", "100,200", "110,230", "0,0", "no scrollByLines()", "0,0", "no scrollByPages()"},
1165 EDGE = {"0,0", "100,200", "110,230", "0,0", "no scrollByLines()", "0,0", "no scrollByPages()"},
1166 FF = {"0,0", "100,200", "110,230", "0,0", "0,95", "0,0", "0,1210"},
1167 FF_ESR = {"0,0", "100,200", "110,230", "0,0", "0,95", "0,0", "0,1210"})
1168 public void scrolling1() throws Exception {
1169 scrolling(true);
1170 }
1171
1172
1173
1174
1175
1176 @Test
1177 @Alerts(DEFAULT = {"0,0", "0,0", "0,0", "0,0", "no scrollByLines()", "0,0", "no scrollByPages()"},
1178 FF = {"0,0", "0,0", "0,0", "0,0", "0,0", "0,0", "0,0"},
1179 FF_ESR = {"0,0", "0,0", "0,0", "0,0", "0,0", "0,0", "0,0"})
1180 public void scrolling2() throws Exception {
1181 scrolling(false);
1182 }
1183
1184 private void scrolling(final boolean addHugeDiv) throws Exception {
1185 final String html = DOCTYPE_HTML
1186 + "<html><body onload='test()'>\n"
1187 + (addHugeDiv ? "<div id='d' style='width:10000px;height:10000px;background-color:blue;'></div>\n" : "")
1188 + "<script>\n"
1189 + LOG_TITLE_FUNCTION
1190 + "function test() {\n"
1191 + " var b = document.body;\n"
1192 + " log(b.scrollLeft + ',' + b.scrollTop);\n"
1193 + " window.scrollTo(100, 200);\n"
1194 + " log(b.scrollLeft + ',' + b.scrollTop);\n"
1195 + " window.scrollBy(10, 30);\n"
1196 + " log(b.scrollLeft + ',' + b.scrollTop);\n"
1197 + " window.scrollTo(-5, -20);\n"
1198 + " log(b.scrollLeft + ',' + b.scrollTop);\n"
1199 + " if(window.scrollByLines) {\n"
1200 + " window.scrollByLines(5);\n"
1201 + " log(b.scrollLeft + ',' + b.scrollTop);\n"
1202 + " } else {\n"
1203 + " log('no scrollByLines()');\n"
1204 + " }\n"
1205 + " window.scroll(0, 0);\n"
1206 + " log(b.scrollLeft + ',' + b.scrollTop);\n"
1207 + " if(window.scrollByPages) {\n"
1208 + " window.scrollByPages(2);\n"
1209 + " log(b.scrollLeft + ',' + b.scrollTop);\n"
1210 + " } else {\n"
1211 + " log('no scrollByPages()');\n"
1212 + " }\n"
1213 + "}\n"
1214 + "</script></body></html>";
1215 loadPageVerifyTitle2(html);
1216 }
1217
1218
1219
1220
1221
1222 @Test
1223 @Alerts(DEFAULT = {"0,0", "0,0", "0,0", "0,0", "no scrollByLines()", "0,0", "no scrollByPages()"},
1224 FF = {"0,0", "0,0", "0,0", "0,0", "0,0", "0,0", "0,0"},
1225 FF_ESR = {"0,0", "0,0", "0,0", "0,0", "0,0", "0,0", "0,0"})
1226 @HtmlUnitNYI(CHROME = {"0,0", "100,200", "110,230", "0,0", "no scrollByLines()", "0,0", "no scrollByPages()"},
1227 EDGE = {"0,0", "100,200", "110,230", "0,0", "no scrollByLines()", "0,0", "no scrollByPages()"},
1228 FF = {"0,0", "100,200", "110,230", "0,0", "0,95", "0,0", "0,1210"},
1229 FF_ESR = {"0,0", "100,200", "110,230", "0,0", "0,95", "0,0", "0,1210"})
1230 public void scrollingOptions1() throws Exception {
1231 scrollingOptions(true);
1232 }
1233
1234
1235
1236
1237
1238 @Test
1239 @Alerts(DEFAULT = {"0,0", "0,0", "0,0", "0,0", "no scrollByLines()", "0,0", "no scrollByPages()"},
1240 FF = {"0,0", "0,0", "0,0", "0,0", "0,0", "0,0", "0,0"},
1241 FF_ESR = {"0,0", "0,0", "0,0", "0,0", "0,0", "0,0", "0,0"})
1242 public void scrollingOptions2() throws Exception {
1243 scrollingOptions(false);
1244 }
1245
1246 private void scrollingOptions(final boolean addHugeDiv) throws Exception {
1247 final String html = DOCTYPE_HTML
1248 + "<html><body onload='test()'>\n"
1249 + (addHugeDiv ? "<div id='d' style='width:10000px;height:10000px;background-color:blue;'></div>\n" : "")
1250 + "<script>\n"
1251 + LOG_TITLE_FUNCTION
1252 + "function test() {\n"
1253 + " var b = document.body;\n"
1254 + " log(b.scrollLeft + ',' + b.scrollTop);\n"
1255 + " window.scrollTo({left: 100, top: 200});\n"
1256 + " log(b.scrollLeft + ',' + b.scrollTop);\n"
1257 + " window.scrollBy({left: 10, top: 30});\n"
1258 + " log(b.scrollLeft + ',' + b.scrollTop);\n"
1259 + " window.scrollTo({left: -5, top: -20});\n"
1260 + " log(b.scrollLeft + ',' + b.scrollTop);\n"
1261 + " if(window.scrollByLines) {\n"
1262 + " window.scrollByLines(5);\n"
1263 + " log(b.scrollLeft + ',' + b.scrollTop);\n"
1264 + " } else {\n"
1265 + " log('no scrollByLines()');\n"
1266 + " }\n"
1267 + " window.scroll({left: 0, top: 0});\n"
1268 + " log(b.scrollLeft + ',' + b.scrollTop);\n"
1269 + " if(window.scrollByPages) {\n"
1270 + " window.scrollByPages(2);\n"
1271 + " log(b.scrollLeft + ',' + b.scrollTop);\n"
1272 + " } else {\n"
1273 + " log('no scrollByPages()');\n"
1274 + " }\n"
1275 + "}\n"
1276 + "</script></body></html>";
1277 loadPageVerifyTitle2(html);
1278 }
1279
1280
1281
1282
1283 @Test
1284 @Alerts({"0", "0", "0", "0"})
1285 public void pageXOffset() throws Exception {
1286 final String html = DOCTYPE_HTML
1287 + "<html><body onload='test()'><script>\n"
1288 + LOG_TITLE_FUNCTION
1289 + "function test() {\n"
1290 + " window.scrollBy(5, 10);\n"
1291 + " log(window.pageXOffset);\n"
1292 + " log(window.pageYOffset);\n"
1293 + " log(window.scrollX);\n"
1294 + " log(window.scrollY);\n"
1295 + "}\n"
1296 + "</script>\n"
1297 + "</body></html>";
1298 loadPageVerifyTitle2(html);
1299 }
1300
1301
1302
1303
1304 @Test
1305 @Alerts("object")
1306 public void typeof() throws Exception {
1307 final String html = DOCTYPE_HTML
1308 + "<html><body><script>\n"
1309 + LOG_TITLE_FUNCTION
1310 + " log(typeof window);\n"
1311 + "</script></body></html>";
1312 loadPageVerifyTitle2(html);
1313 }
1314
1315
1316
1317
1318 @Test
1319 @Alerts(DEFAULT = {"undefined", "undefined"},
1320 FF = {"12", "89"},
1321 FF_ESR = {"10", "89"})
1322 public void mozInnerScreen() throws Exception {
1323 final String html = DOCTYPE_HTML
1324 + "<html><body onload='test()'><script>\n"
1325 + LOG_TITLE_FUNCTION
1326 + "function test() {\n"
1327 + " log(window.mozInnerScreenX);\n"
1328 + " log(window.mozInnerScreenY);\n"
1329 + "}\n"
1330 + "</script>\n"
1331 + "</body></html>";
1332 loadPageVerifyTitle2(html);
1333 }
1334
1335
1336
1337
1338 @Test
1339 @Alerts("undefined")
1340 public void mozPaintCount() throws Exception {
1341 final String html = DOCTYPE_HTML
1342 + "<html><body onload='test()'><script>\n"
1343 + LOG_TITLE_FUNCTION
1344 + "function test() {\n"
1345 + " log(typeof window.mozPaintCount);\n"
1346 + "}\n"
1347 + "</script>\n"
1348 + "</body></html>";
1349 loadPageVerifyTitle2(html);
1350 }
1351
1352
1353
1354
1355 @Test
1356 @Alerts({"ReferenceError", "ReferenceError", "Success"})
1357 public void eval() throws Exception {
1358 final String html = DOCTYPE_HTML
1359 + "<html><body onload='test()'><script>\n"
1360 + LOG_TITLE_FUNCTION
1361 + "function test() {\n"
1362 + " var x = new Object();\n"
1363 + " x.a = 'Success';\n"
1364 + " try {\n"
1365 + " log(window['eval']('x.a'));\n"
1366 + " } catch(e) { logEx(e) }\n"
1367 + " try {\n"
1368 + " log(window.eval('x.a'));\n"
1369 + " } catch(e) { logEx(e) }\n"
1370 + " try {\n"
1371 + " log(eval('x.a'));\n"
1372 + " } catch(e) { logEx(e) }\n"
1373 + "}\n"
1374 + "</script>\n"
1375 + "</body></html>";
1376 loadPageVerifyTitle2(html);
1377 }
1378
1379
1380
1381
1382
1383 @Test
1384 @Alerts({"true", "I was here"})
1385 public void firedEvent_equals_original_event() throws Exception {
1386 final String html = DOCTYPE_HTML
1387 + "<html><head>\n"
1388 + "<script>\n"
1389 + LOG_TITLE_FUNCTION
1390 + "function test() {\n"
1391 + " var myEvent;\n"
1392 + " var listener = function(x) {\n"
1393 + " log(x == myEvent);\n"
1394 + " x.foo = 'I was here';\n"
1395 + " }\n"
1396 + " window.addEventListener('click', listener, false);\n"
1397 + " myEvent = document.createEvent('HTMLEvents');\n"
1398 + " myEvent.initEvent('click', true, true);\n"
1399 + " window.dispatchEvent(myEvent);\n"
1400 + " log(myEvent.foo);\n"
1401 + "}\n"
1402 + "</script>\n"
1403 + "</head><body onload='test()'>\n"
1404 + "</body></html>";
1405
1406 loadPageVerifyTitle2(html);
1407 }
1408
1409
1410
1411
1412 @Test
1413 @Alerts({"true", "true", "true", "true"})
1414 public void thisEquals() throws Exception {
1415 final String html = DOCTYPE_HTML
1416 + "<html><head>\n"
1417 + "<script>\n"
1418 + LOG_TITLE_FUNCTION
1419 + "function test() {\n"
1420 + " log(this === window);\n"
1421 + " log(window === this);\n"
1422 + " log(this == window);\n"
1423 + " log(window == this);\n"
1424 + "}\n"
1425 + "</script>\n"
1426 + "</head><body onload='test()'>\n"
1427 + "</body></html>";
1428
1429 loadPageVerifyTitle2(html);
1430 }
1431
1432
1433
1434
1435 @Test
1436 @Alerts({"null", "function", "null", "null"})
1437 public void onbeforeunload() throws Exception {
1438 final String html = DOCTYPE_HTML
1439 + "<html><head>\n"
1440 + "<script>\n"
1441 + LOG_TITLE_FUNCTION
1442 + "function test() {\n"
1443 + " log(window.onbeforeunload);\n"
1444 + " var handle = function() {};\n"
1445 + " window.onbeforeunload = handle;\n"
1446 + " log(typeof window.onbeforeunload);\n"
1447 + " window.onbeforeunload = null;\n"
1448 + " log(window.onbeforeunload);\n"
1449 + " window.onbeforeunload = undefined;\n"
1450 + " log(window.onbeforeunload);\n"
1451 + " \n"
1452 + "}\n"
1453 + "</script>\n"
1454 + "</head><body onload='test()'>\n"
1455 + "</body></html>";
1456
1457 loadPageVerifyTitle2(html);
1458 }
1459
1460
1461
1462
1463
1464
1465
1466
1467 @Test
1468 @Alerts({"true", "0", "2", "2", "null"})
1469 public void functionPrototypeArguments() throws Exception {
1470 final String html = DOCTYPE_HTML
1471 + "<html>\n"
1472 + "<body onload='test()'>\n"
1473 + "<script>\n"
1474 + LOG_TITLE_FUNCTION
1475 + " function test() {\n"
1476 + " \n"
1477 + " Function.prototype.doAlerts = function() {\n"
1478 + " log(this == o.f);\n"
1479 + " log(arguments ? arguments.length : 'null');\n"
1480 + " log(this.arguments ? this.arguments.length : 'null');\n"
1481 + " }\n"
1482 + " \n"
1483 + " var o = function() {};\n"
1484 + " o.f = function(x, y, z) {\n"
1485 + " this.f.doAlerts();\n"
1486 + " log(arguments ? arguments.length : 'null');\n"
1487 + " log(this.arguments ? this.arguments.length : 'null');\n"
1488 + " }\n"
1489 + " o.f('a', 'b');\n"
1490 + " }\n"
1491 + "</script>\n"
1492 + "</body>\n"
1493 + "</html>";
1494
1495 loadPageVerifyTitle2(html);
1496 }
1497
1498
1499
1500
1501 @Test
1502 @Alerts({"true", "[object Arguments]", "null", "true", "[object Arguments]", "[object Arguments]"})
1503 public void functionPrototypeArguments2() throws Exception {
1504 final String html = DOCTYPE_HTML
1505 + "<html>\n"
1506 + "<body onload='test()'>\n"
1507 + "<script>\n"
1508 + LOG_TITLE_FUNCTION
1509 + " function test() {\n"
1510 + " \n"
1511 + " Function.prototype.doAlerts = function() {\n"
1512 + " log(this == o.f);\n"
1513 + " log(arguments);\n"
1514 + " log(this.arguments);\n"
1515 + " }\n"
1516 + " \n"
1517 + " var o = function() {};\n"
1518 + " o.f = function(x, y, z) {\n"
1519 + " log(this == o);\n"
1520 + " log(arguments);\n"
1521 + " log(this.arguments);\n"
1522 + " this.f.doAlerts();\n"
1523 + " }\n"
1524 + " o.f('a', 'b');\n"
1525 + " }\n"
1526 + "</script>\n"
1527 + "</body>\n"
1528 + "</html>";
1529
1530 loadPageVerifyTitle2(html);
1531 }
1532
1533
1534
1535
1536 @Test
1537 @Alerts({"true", "[object Arguments]", "null", "true", "[object Arguments]", "null"})
1538 public void functionPrototypeArguments3() throws Exception {
1539 final String html = DOCTYPE_HTML
1540 + "<html>\n"
1541 + "<body onload='test()'>\n"
1542 + "<script>\n"
1543 + LOG_TITLE_FUNCTION
1544 + " function test() {\n"
1545 + " var o = function() {};\n"
1546 + " o.x = function() {\n"
1547 + " log(this == o);\n"
1548 + " log(arguments);\n"
1549 + " log(this.arguments);\n"
1550 + " }\n"
1551 + " o.f = function(x, y, z) {\n"
1552 + " log(this == o);\n"
1553 + " log(arguments);\n"
1554 + " log(this.arguments);\n"
1555 + " this.x();\n"
1556 + " }\n"
1557 + " o.f('a', 'b');\n"
1558 + " }\n"
1559 + "</script>\n"
1560 + "</body>\n"
1561 + "</html>";
1562
1563 loadPageVerifyTitle2(html);
1564 }
1565
1566
1567
1568
1569 @Test
1570 @Alerts({"null", "function", "5"})
1571 public void onError() throws Exception {
1572 final String html
1573 = "<script>\n"
1574 + LOG_TITLE_FUNCTION
1575 + " log(window.onerror);\n"
1576 + " window.onerror = function() { log(arguments.length); };\n"
1577 + " log(typeof window.onerror);\n"
1578 + " try { log(undef); } catch(e) { /* caught, so won't trigger onerror */ }\n"
1579 + " log(undef);\n"
1580 + "</script>";
1581
1582 if (getWebDriver() instanceof HtmlUnitDriver) {
1583 getWebClient().getOptions().setThrowExceptionOnScriptError(false);
1584 }
1585 loadPageVerifyTitle2(html);
1586 }
1587
1588
1589
1590
1591 @Test
1592 @Alerts({"string string 26 number string",
1593 "string string 27 number object"})
1594 public void onErrorExceptionInstance() throws Exception {
1595 final String html = DOCTYPE_HTML
1596 + "<html>\n"
1597 + "<script>\n"
1598 + LOG_TITLE_FUNCTION
1599 + " window.onerror = function(messageOrEvent, source, lineno, colno, error) {\n"
1600 + " log(typeof messageOrEvent + ' ' + typeof source + ' '"
1601 + " + lineno + ' ' + typeof colno + ' ' + typeof error);\n"
1602 + " };\n"
1603 + "</script>\n"
1604 + "<script>throw 'string';</script>\n"
1605 + "<script>throw {'object':'property'};</script>\n"
1606 + "</html>";
1607
1608 if (getWebDriver() instanceof HtmlUnitDriver) {
1609 getWebClient().getOptions().setThrowExceptionOnScriptError(false);
1610 }
1611 loadPageVerifyTitle2(html);
1612 }
1613
1614
1615
1616
1617 @Test
1618 @Alerts({"string string 26 number object", "string string 1 number object"})
1619 public void onErrorExceptionInstance2() throws Exception {
1620 final String html = DOCTYPE_HTML
1621 + "<html>\n"
1622 + "<script>\n"
1623 + LOG_TITLE_FUNCTION
1624 + " window.onerror = function(messageOrEvent, source, lineno, colno, error) {\n"
1625 + " log(typeof messageOrEvent + ' ' + typeof source + ' '"
1626 + " + lineno + ' ' + typeof colno + ' ' + typeof error);\n"
1627 + " };\n"
1628 + "</script>\n"
1629 + "<script>does.not.exist();</script>\n"
1630 + "<script>eval('syntax[error');</script>\n"
1631 + "</html>";
1632
1633 if (getWebDriver() instanceof HtmlUnitDriver) {
1634 getWebClient().getOptions().setThrowExceptionOnScriptError(false);
1635 }
1636 loadPageVerifyTitle2(html);
1637 }
1638
1639
1640
1641
1642 @Test
1643 @Alerts("success")
1644 public void onErrorModifyObject() throws Exception {
1645 final String html = DOCTYPE_HTML
1646 + "<html>\n"
1647 + "<script>\n"
1648 + LOG_TITLE_FUNCTION
1649 + " window.onerror = function(messageOrEvent, source, lineno, colno, error) {\n"
1650 + " error.property = 'success'\n"
1651 + " log(error.property);\n"
1652 + " };\n"
1653 + "</script>\n"
1654 + "<script>throw {};</script>\n"
1655 + "</html>";
1656
1657 if (getWebDriver() instanceof HtmlUnitDriver) {
1658 getWebClient().getOptions().setThrowExceptionOnScriptError(false);
1659 }
1660 loadPageVerifyTitle2(html);
1661 }
1662
1663
1664
1665
1666 @Test
1667 @Alerts("rgb(0, 0, 0)")
1668 public void getComputedStyle() throws Exception {
1669 final String html = DOCTYPE_HTML
1670 + "<html><body>\n"
1671 + "<div id='myDiv'></div>\n"
1672 + "<script>\n"
1673 + LOG_TITLE_FUNCTION
1674 + " var e = document.getElementById('myDiv');\n"
1675 + " log(window.getComputedStyle(e, null).color);\n"
1676 + "</script>\n"
1677 + "</body></html>";
1678
1679 loadPageVerifyTitle2(html);
1680 }
1681
1682
1683
1684
1685 @Test
1686 @Alerts("rgb(255, 0, 0)")
1687 public void getComputedStyle_WithComputedColor() throws Exception {
1688 final String html = DOCTYPE_HTML
1689 + "<html>\n"
1690 + " <head>\n"
1691 + " <style>div.x { color: red; }</style>\n"
1692 + "<script>\n"
1693 + LOG_TITLE_FUNCTION
1694 + " function test() {\n"
1695 + " var e = document.getElementById('d');\n"
1696 + " log(window.getComputedStyle(e, '').color);\n"
1697 + " }\n"
1698 + "</script>\n"
1699 + "</head>\n"
1700 + "<body onload='test()'>\n"
1701 + " <div id='d' class='x'>foo bar</div>\n"
1702 + "</body>\n"
1703 + "</html>";
1704
1705 loadPageVerifyTitle2(html);
1706 }
1707
1708
1709
1710
1711
1712 @Test
1713 @Alerts("rgb(0, 0, 0)")
1714 public void getComputedStyle_svg() throws Exception {
1715 final String html = DOCTYPE_HTML
1716 + "<html><body>\n"
1717 + " <svg xmlns='http://www.w3.org/2000/svg' id='myId' version='1.1'></svg>\n"
1718 + "<script>\n"
1719 + LOG_TITLE_FUNCTION
1720 + " var e = document.getElementById('myId');\n"
1721 + " log(window.getComputedStyle(e, null).color);\n"
1722 + "</script>\n"
1723 + "</body></html>";
1724
1725 loadPageVerifyTitle2(html);
1726 }
1727
1728
1729
1730
1731 @Test
1732 @Alerts("false")
1733 public void getComputedStyleCached() throws Exception {
1734 final String html = DOCTYPE_HTML
1735 + "<html><body>\n"
1736 + "<div id='myDiv'></div>\n"
1737 + "<script>\n"
1738 + LOG_TITLE_FUNCTION
1739 + " var e = document.getElementById('myDiv');\n"
1740 + " var cs1 = window.getComputedStyle(e, null);\n"
1741 + " var cs2 = window.getComputedStyle(e, null);\n"
1742 + " log(cs1 === cs2);\n"
1743 + "</script>\n"
1744 + "</body></html>";
1745
1746 loadPageVerifyTitle2(html);
1747 }
1748
1749
1750
1751
1752
1753
1754 @Test
1755 @Alerts("undefined")
1756 public void hangingObjectCallOnWindowProxy() throws Exception {
1757 final String html = DOCTYPE_HTML
1758 + "<html><body>\n"
1759 + "<iframe id='it'></iframe>;\n"
1760 + "<script>\n"
1761 + LOG_TITLE_FUNCTION
1762 + " Object(top);\n"
1763 + " log(window.foo);\n"
1764 + "</script>\n"
1765 + "</body></html>";
1766
1767 loadPageVerifyTitle2(html);
1768 }
1769
1770
1771
1772
1773
1774
1775 @Test
1776 @Alerts("false")
1777 public void equalsString() throws Exception {
1778 final String html = DOCTYPE_HTML
1779 + "<html><body>\n"
1780 + "<script>\n"
1781 + LOG_TITLE_FUNCTION
1782 + " log('foo' == window);\n"
1783 + "</script>\n"
1784 + "</body></html>";
1785
1786 loadPageVerifyTitle2(html);
1787 }
1788
1789
1790
1791
1792
1793
1794 @Test
1795 @Alerts("false")
1796 public void equalsInt() throws Exception {
1797 final String html = DOCTYPE_HTML
1798 + "<html><body>\n"
1799 + "<script>\n"
1800 + LOG_TITLE_FUNCTION
1801 + " var i = 0;\n"
1802 + " log(i == window);\n"
1803 + "</script>\n"
1804 + "</body></html>";
1805
1806 loadPageVerifyTitle2(html);
1807 }
1808
1809
1810
1811
1812 @Test
1813 @Alerts({"number", "done", "result"})
1814 public void setTimeout() throws Exception {
1815 final String html = DOCTYPE_HTML
1816 + "<html>\n"
1817 + "<head>\n"
1818 + " <script>\n"
1819 + LOG_TEXTAREA_FUNCTION
1820 + " function test() {\n"
1821 + " var id = window.setTimeout( function() { log('result'); }, 20);\n"
1822 + " log(typeof id);\n"
1823 + " log('done');\n"
1824 + " }\n"
1825 + "</script></head>\n"
1826 + "<body onload='test()'>\n"
1827 + LOG_TEXTAREA
1828 + "</body>\n"
1829 + "</html>\n";
1830
1831 loadPageVerifyTextArea2(html);
1832 }
1833
1834
1835
1836
1837 @Test
1838 @Alerts({"number", "done", "42"})
1839 public void setTimeoutWithParams() throws Exception {
1840 final String html = DOCTYPE_HTML
1841 + "<html>\n"
1842 + "<head>\n"
1843 + " <script>\n"
1844 + LOG_TEXTAREA_FUNCTION
1845 + " function test() {\n"
1846 + " var id = window.setTimeout( function(p1) { log(p1); }, 20, 42);\n"
1847 + " log(typeof id);\n"
1848 + " log('done');\n"
1849 + " }\n"
1850 + "</script></head>\n"
1851 + "<body onload='test()'>\n"
1852 + LOG_TEXTAREA
1853 + "</body>\n"
1854 + "</html>\n";
1855
1856 loadPageVerifyTextArea2(html);
1857 }
1858
1859
1860
1861
1862 @Test
1863 @Alerts({"done 2", "7"})
1864 public void setTimeoutCode() throws Exception {
1865 final String html = DOCTYPE_HTML
1866 + "<html>\n"
1867 + "<head>\n"
1868 + " <script>\n"
1869 + LOG_TEXTAREA_FUNCTION
1870 + " function test() {\n"
1871 + " try{\n"
1872 + " var id = window.setTimeout('log(7)');\n"
1873 + " log('done 2');\n"
1874 + " } catch(e) { log(e); }\n"
1875 + " }\n"
1876 + "</script></head>\n"
1877 + "<body onload='test()'>\n"
1878 + LOG_TEXTAREA
1879 + "</body>\n"
1880 + "</html>\n";
1881
1882 loadPageVerifyTextArea2(html);
1883 }
1884
1885
1886
1887
1888 @Test
1889 @Alerts("true")
1890 public void setTimeoutWrongParams() throws Exception {
1891 final String html = DOCTYPE_HTML
1892 + "<html>\n"
1893 + "<head>\n"
1894 + " <script>\n"
1895 + LOG_TEXTAREA_FUNCTION
1896 + " function test() {\n"
1897 + " try{\n"
1898 + " window.setTimeout();\n"
1899 + " log('done');\n"
1900 + " } catch(e) { log(e instanceof TypeError); }\n"
1901 + " }\n"
1902 + "</script></head>\n"
1903 + "<body onload='test()'>\n"
1904 + LOG_TEXTAREA
1905 + "</body>\n"
1906 + "</html>\n";
1907
1908 loadPageVerifyTextArea2(html);
1909 }
1910
1911
1912
1913
1914
1915
1916 @Test
1917 public void setTimeoutShouldNotBeExecutedBeforeHandlers() throws Exception {
1918 final String html = DOCTYPE_HTML
1919 + "<html><body><script>\n"
1920 + "function stop() {\n"
1921 + " window.stopIt = true;\n"
1922 + "}\n"
1923 + "for (var i = 0; i < 1000; i++) {\n"
1924 + " var handler = function(e) {\n"
1925 + " if (window.stopIt) {\n"
1926 + " e.preventDefault ? e.preventDefault() : e.returnValue = false;\n"
1927 + " }\n"
1928 + " }\n"
1929 + " window.addEventListener('click', handler, false);\n"
1930 + "}\n"
1931 + "</script>\n"
1932 + "<form action='page2' method='post'>\n"
1933 + "<input id='it' type='submit' onclick='setTimeout(stop, 0)'>\n"
1934 + "</form>\n"
1935 + "</body></html>";
1936 getMockWebConnection().setDefaultResponse("Error: not found", 404, "Not Found", MimeType.TEXT_HTML);
1937
1938 final WebDriver driver = loadPage2(html);
1939 driver.findElement(By.id("it")).click();
1940
1941 assertEquals(URL_FIRST + "page2", driver.getCurrentUrl());
1942 }
1943
1944
1945
1946
1947 @Test
1948 @Alerts({"number", "done", "result"})
1949 public void setInterval() throws Exception {
1950 final String html = DOCTYPE_HTML
1951 + "<html>\n"
1952 + "<head>\n"
1953 + " <script>\n"
1954 + LOG_TEXTAREA_FUNCTION
1955 + " var id;\n"
1956 + " function test() {\n"
1957 + " id = window.setInterval( function() { log('result'); clearInterval(id); }, 20);\n"
1958 + " log(typeof id);\n"
1959 + " log('done');\n"
1960 + " }\n"
1961 + "</script></head>\n"
1962 + "<body onload='test()'>\n"
1963 + LOG_TEXTAREA
1964 + "</body>\n"
1965 + "</html>\n";
1966
1967 loadPageVerifyTextArea2(html);
1968 }
1969
1970
1971
1972
1973 @Test
1974 @Alerts({"number", "done", "42"})
1975 public void setIntervalWithParams() throws Exception {
1976 final String html = DOCTYPE_HTML
1977 + "<html>\n"
1978 + "<head>\n"
1979 + " <script>\n"
1980 + LOG_TEXTAREA_FUNCTION
1981 + " var id;\n"
1982 + " function test() {\n"
1983 + " id = window.setInterval( function(p1) { log(p1); clearInterval(id); }, 20, 42);\n"
1984 + " log(typeof id);\n"
1985 + " log('done');\n"
1986 + " }\n"
1987 + "</script></head>\n"
1988 + "<body onload='test()'>\n"
1989 + LOG_TEXTAREA
1990 + "</body>\n"
1991 + "</html>\n";
1992
1993 loadPageVerifyTextArea2(html);
1994 }
1995
1996
1997
1998
1999 @Test
2000 @Alerts({"done 2", "7"})
2001 public void setIntervalCode() throws Exception {
2002 final String html = DOCTYPE_HTML
2003 + "<html>\n"
2004 + "<head>\n"
2005 + " <script>\n"
2006 + LOG_TEXTAREA_FUNCTION
2007 + " var id;\n"
2008 + " function test() {\n"
2009 + " try{\n"
2010 + " id = window.setInterval('log(7); clearInterval(id);' );\n"
2011 + " log('done 2');\n"
2012 + " } catch(e) { log(e); }\n"
2013 + " }\n"
2014 + "</script></head>\n"
2015 + "<body onload='test()'>\n"
2016 + LOG_TEXTAREA
2017 + "</body>\n"
2018 + "</html>\n";
2019
2020 loadPageVerifyTextArea2(html);
2021 }
2022
2023
2024
2025
2026 @Test
2027 @Alerts("true")
2028 public void setIntervalWrongParams() throws Exception {
2029 final String html = DOCTYPE_HTML
2030 + "<html>\n"
2031 + "<head>\n"
2032 + " <script>\n"
2033 + LOG_TEXTAREA_FUNCTION
2034 + " function test() {\n"
2035 + " try{\n"
2036 + " window.setInterval();\n"
2037 + " log('done');\n"
2038 + " } catch(e) { log(e instanceof TypeError); }\n"
2039 + " }\n"
2040 + "</script></head>\n"
2041 + "<body onload='test()'>\n"
2042 + LOG_TEXTAREA
2043 + "</body>\n"
2044 + "</html>\n";
2045
2046 loadPageVerifyTextArea2(html);
2047 }
2048
2049
2050
2051
2052
2053
2054 @Test
2055 public void setIntervalShouldNotBeExecutedBeforeHandlers() throws Exception {
2056 final String html = DOCTYPE_HTML
2057 + "<html><body>\n"
2058 + "<script>\n"
2059 + " var id;\n"
2060
2061 + " function stop() {\n"
2062 + " window.stopIt = true;\n"
2063 + " clearInterval(id);\n"
2064 + " }\n"
2065
2066 + " for (var i = 0; i < 1000; i++) {\n"
2067 + " var handler = function(e) {\n"
2068 + " if (window.stopIt) {\n"
2069 + " e.preventDefault ? e.preventDefault() : e.returnValue = false;\n"
2070 + " }\n"
2071 + " }\n"
2072 + " window.addEventListener('click', handler, false);\n"
2073 + " }\n"
2074 + "</script>\n"
2075 + "<form action='page2' method='post'>\n"
2076 + " <input id='it' type='submit' onclick='id = setInterval(stop, 0)'>\n"
2077 + "</form>\n"
2078 + "</body></html>";
2079 getMockWebConnection().setDefaultResponse("Error: not found", 404, "Not Found", MimeType.TEXT_HTML);
2080
2081 final WebDriver driver = loadPage2(html);
2082 driver.findElement(By.id("it")).click();
2083
2084 assertEquals(URL_FIRST + "page2", driver.getCurrentUrl());
2085 }
2086
2087
2088
2089
2090 @Test
2091 @Alerts({"true", "null"})
2092 public void onchange_noHandler() throws Exception {
2093 final String html = DOCTYPE_HTML
2094 + "<html><body><script>\n"
2095 + LOG_TITLE_FUNCTION
2096 + " log('onchange' in window);\n"
2097 + " log(window.onchange);\n"
2098 + "</script></body></html>";
2099 loadPageVerifyTitle2(html);
2100 }
2101
2102
2103
2104
2105 @Test
2106 @Alerts("changed")
2107 public void onchange_withHandler() throws Exception {
2108 final String html = DOCTYPE_HTML
2109 + "<html>\n"
2110 + "<head>\n"
2111 + "<script>\n"
2112 + LOG_WINDOW_NAME_FUNCTION
2113 + "</script>\n"
2114 + "</head>"
2115 + "<body>\n"
2116 + "<input id='it'/>\n"
2117 + "<div id='tester'>Tester</div>\n"
2118 + "<script>\n"
2119 + " window.onchange = function() {\n"
2120 + " log('changed');\n"
2121 + " }\n"
2122 + "</script></body></html>";
2123
2124 final WebDriver driver = loadPage2(html);
2125 driver.findElement(By.id("it")).sendKeys("X");
2126 driver.findElement(By.id("tester")).click();
2127
2128 verifyWindowName2(driver, getExpectedAlerts());
2129 }
2130
2131
2132
2133
2134 @Test
2135 @Alerts({"true", "null"})
2136 public void onsubmit_noHandler() throws Exception {
2137 final String html = DOCTYPE_HTML
2138 + "<html>\n"
2139 + "<body>\n"
2140 + "<script>\n"
2141 + LOG_TITLE_FUNCTION
2142 + " log('onsubmit' in window);\n"
2143 + " log(window.onsubmit);\n"
2144 + "</script>\n"
2145 + "</body></html>";
2146 loadPageVerifyTitle2(html);
2147 }
2148
2149
2150
2151
2152 @Test
2153 @Alerts("-onsubmit-")
2154 public void onsubmit_withHandler() throws Exception {
2155 final String html = DOCTYPE_HTML
2156 + "<html>\n"
2157 + "<head>\n"
2158 + " <title>Title</title>\n"
2159 + "</head>\n"
2160 + "<body>\n"
2161 + "<form>\n"
2162 + " <input type='submit' id='it' value='submit' />\n"
2163 + "</form>\n"
2164 + "<script>\n"
2165 + " window.onsubmit = function() {\n"
2166 + " window.name = window.name + '-onsubmit-' + '\\u00a7';\n"
2167 + " }\n"
2168 + "</script>\n"
2169 + "</body></html>";
2170
2171 final WebDriver driver = loadPage2(html);
2172 driver.findElement(By.id("it")).click();
2173
2174 verifyWindowName2(driver, getExpectedAlerts()[0]);
2175 }
2176
2177
2178
2179
2180
2181 @Test
2182 @Alerts("about:blank")
2183 public void openWindow_emptyUrl() throws Exception {
2184 final String html = DOCTYPE_HTML
2185 + "<html><head>\n"
2186 + "<script>\n"
2187 + LOG_TITLE_FUNCTION
2188 + "var w = window.open('');\n"
2189 + "log(w ? w.document.location : w);\n"
2190 + "</script>\n"
2191 + "</head>\n"
2192 + "<body>\n"
2193 + "</body>\n"
2194 + "</html>";
2195
2196 loadPageVerifyTitle2(html);
2197 }
2198
2199
2200
2201
2202 @Test
2203 @Alerts({"true", "true", "true"})
2204 public void location() throws Exception {
2205 final String html = DOCTYPE_HTML
2206 + "<html><head>\n"
2207 + "<script>\n"
2208 + LOG_TITLE_FUNCTION
2209 + " log(location === window.location);\n"
2210 + " log(location === document.location);\n"
2211 + " log(window.location === document.location);\n"
2212 + "</script></head>\n"
2213 + "<body></body></html>";
2214
2215 loadPageVerifyTitle2(html);
2216 }
2217
2218
2219
2220
2221 @Test
2222 public void setLocation() throws Exception {
2223 final String firstContent = DOCTYPE_HTML
2224 + "<html>\n"
2225 + "<head><title>First</title></head>\n"
2226 + "<body>\n"
2227 + "<form name='form1'>\n"
2228 + " <a id='link' onClick='location=\"" + URL_SECOND + "\";'>Click me</a>\n"
2229 + "</form>\n"
2230 + "</body></html>";
2231 final String secondContent = DOCTYPE_HTML
2232 + "<html><head><title>Second</title></head><body></body></html>";
2233
2234 getMockWebConnection().setResponse(URL_SECOND, secondContent);
2235
2236 final WebDriver driver = loadPage2(firstContent);
2237 assertTitle(driver, "First");
2238 assertEquals(1, driver.getWindowHandles().size());
2239
2240 driver.findElement(By.id("link")).click();
2241 assertTitle(driver, "Second");
2242
2243 assertEquals(1, driver.getWindowHandles().size());
2244 assertEquals(new String[] {"", "second/"}, getMockWebConnection().getRequestedUrls(URL_FIRST));
2245 assertEquals(URL_SECOND.toString(), driver.getCurrentUrl());
2246 }
2247
2248
2249
2250
2251 @Test
2252 public void setWindowLocation() throws Exception {
2253 final String firstContent = DOCTYPE_HTML
2254 + "<html>\n"
2255 + "<head><title>First</title></head>\n"
2256 + "<body>\n"
2257 + "<form name='form1'>\n"
2258 + " <a id='link' onClick='window.location=\"" + URL_SECOND + "\";'>Click me</a>\n"
2259 + "</form>\n"
2260 + "</body></html>";
2261 final String secondContent = DOCTYPE_HTML
2262 + "<html><head><title>Second</title></head><body></body></html>";
2263
2264 getMockWebConnection().setResponse(URL_SECOND, secondContent);
2265
2266 final WebDriver driver = loadPage2(firstContent);
2267 assertTitle(driver, "First");
2268 assertEquals(1, driver.getWindowHandles().size());
2269
2270 driver.findElement(By.id("link")).click();
2271 assertTitle(driver, "Second");
2272
2273 assertEquals(1, driver.getWindowHandles().size());
2274 assertEquals(new String[] {"", "second/"}, getMockWebConnection().getRequestedUrls(URL_FIRST));
2275 assertEquals(URL_SECOND.toString(), driver.getCurrentUrl());
2276 }
2277
2278
2279
2280
2281 @Test
2282 public void setDocumentLocation() throws Exception {
2283 final String firstContent = DOCTYPE_HTML
2284 + "<html>\n"
2285 + "<head><title>First</title></head>\n"
2286 + "<body>\n"
2287 + "<form name='form1'>\n"
2288 + " <a id='link' onClick='document.location=\"" + URL_SECOND + "\";'>Click me</a>\n"
2289 + "</form>\n"
2290 + "</body></html>";
2291 final String secondContent = DOCTYPE_HTML
2292 + "<html><head><title>Second</title></head><body></body></html>";
2293
2294 getMockWebConnection().setResponse(URL_SECOND, secondContent);
2295
2296 final WebDriver driver = loadPage2(firstContent);
2297 assertTitle(driver, "First");
2298 assertEquals(1, driver.getWindowHandles().size());
2299
2300 driver.findElement(By.id("link")).click();
2301 assertTitle(driver, "Second");
2302
2303 assertEquals(1, driver.getWindowHandles().size());
2304 assertEquals(new String[] {"", "second/"}, getMockWebConnection().getRequestedUrls(URL_FIRST));
2305 assertEquals(URL_SECOND.toString(), driver.getCurrentUrl());
2306 }
2307
2308
2309
2310
2311 @Test
2312 @Alerts(DEFAULT = {"[object Window]", "function Window() { [native code] }",
2313 "TEMPORARY, PERSISTENT, "},
2314 FF = {"[object Window]", "function Window() { [native code] }", ""},
2315 FF_ESR = {"[object Window]", "function Window() { [native code] }", ""})
2316 public void enumeratedProperties() throws Exception {
2317 final String html = DOCTYPE_HTML
2318 + "<html><head>\n"
2319 + "<script>\n"
2320 + LOG_TITLE_FUNCTION
2321 + " function test() {\n"
2322 + " var str = '';\n"
2323 + " log(window);\n"
2324 + " log(Window);\n"
2325 + " var str = '';\n"
2326 + " for (var i in Window) {\n"
2327 + " str += i + ', ';\n"
2328 + " }\n"
2329 + " log(str);\n"
2330 + " }\n"
2331 + "</script>\n"
2332 + "</head>\n"
2333 + "<body onload='test()'>\n"
2334 + "</body></html>";
2335
2336 loadPageVerifyTitle2(html);
2337 }
2338
2339
2340
2341
2342 @Test
2343 @Alerts(DEFAULT = "undefined",
2344 FF = "function",
2345 FF_ESR = "function")
2346 public void dump() throws Exception {
2347 final String html = DOCTYPE_HTML
2348 + "<html>\n"
2349 + "<body>\n"
2350 + "<script>\n"
2351 + LOG_TITLE_FUNCTION
2352 + " log(typeof window.dump);\n"
2353 + "</script>\n"
2354 + "</body></html>";
2355
2356 loadPageVerifyTitle2(html);
2357 }
2358
2359
2360
2361
2362 @Test
2363 @Alerts({"function", "function"})
2364 public void requestAnimationFrame() throws Exception {
2365 final String html = DOCTYPE_HTML
2366 + "<html><body><script>\n"
2367 + LOG_TITLE_FUNCTION
2368 + " log(typeof window.requestAnimationFrame);\n"
2369 + " log(typeof window.cancelAnimationFrame);\n"
2370 + "</script></body></html>";
2371
2372 loadPageVerifyTitle2(html);
2373 }
2374
2375
2376
2377
2378 @Test
2379 @Alerts("undefined")
2380 public void showModalDialog() throws Exception {
2381 final String html = DOCTYPE_HTML
2382 + "<html><body><script>\n"
2383 + LOG_TITLE_FUNCTION
2384 + " log(typeof window.showModalDialog);\n"
2385 + "</script></body></html>";
2386
2387 loadPageVerifyTitle2(html);
2388 }
2389
2390
2391
2392
2393 @Test
2394 @Alerts("undefined")
2395 public void showModelessDialog() throws Exception {
2396 final String html = DOCTYPE_HTML
2397 + "<html><body><script>\n"
2398 + LOG_TITLE_FUNCTION
2399 + " log(typeof window.showModelessDialog);\n"
2400 + "</script></body></html>";
2401
2402 loadPageVerifyTitle2(html);
2403 }
2404
2405
2406
2407
2408
2409 @Test
2410 @Alerts("function")
2411 public void find() throws Exception {
2412 final String html = DOCTYPE_HTML
2413 + "<html><body><script>\n"
2414 + LOG_TITLE_FUNCTION
2415 + " log(typeof window.find);\n"
2416 + "</script></body></html>";
2417
2418 loadPageVerifyTitle2(html);
2419 }
2420
2421
2422
2423
2424
2425
2426 @Test
2427 @Alerts("\"0.33\"")
2428 public void getComputedStylePseudo() throws Exception {
2429 final String html = DOCTYPE_HTML
2430 + "<html>\n"
2431 + "<head>\n"
2432 + " <style>\n"
2433 + " #mydiv:before {\n"
2434 + " content: '0.33';\n"
2435 + " }\n"
2436 + " </style>\n"
2437 + " <script>\n"
2438 + LOG_TITLE_FUNCTION
2439 + " function test() {\n"
2440 + " var div = document.getElementById('mydiv');\n"
2441 + " log(window.getComputedStyle(div, ':before').getPropertyValue('content'));\n"
2442 + " }\n"
2443 + " </script>\n"
2444 + "</head>\n"
2445 + "<body onload='test()'>\n"
2446 + " <div id='mydiv'></div>\n"
2447 + "</body>\n"
2448 + "</html>";
2449
2450 loadPageVerifyTitle2(html);
2451 }
2452
2453
2454
2455
2456
2457
2458 @Test
2459 @Alerts("\"0.33\"")
2460 public void getComputedStylePseudoCache() throws Exception {
2461 final String html = DOCTYPE_HTML
2462 + "<html>\n"
2463 + "<head>\n"
2464 + " <style>\n"
2465 + " #mydiv:before {\n"
2466 + " content: '0.33';\n"
2467 + " }\n"
2468 + " </style>\n"
2469 + " <script>\n"
2470 + LOG_TITLE_FUNCTION
2471 + " function test() {\n"
2472 + " var div = document.getElementById('mydiv');\n"
2473 + " div.getBoundingClientRect();\n"
2474 + " log(window.getComputedStyle(div, ':before').getPropertyValue('content'));\n"
2475 + " }\n"
2476 + " </script>\n"
2477 + "</head>\n"
2478 + "<body onload='test()'>\n"
2479 + " <div id='mydiv'></div>\n"
2480 + "</body>\n"
2481 + "</html>";
2482
2483 loadPageVerifyTitle2(html);
2484 }
2485
2486
2487
2488
2489 @Test
2490 @Alerts("inline")
2491 public void getComputedStyleElementDocument() throws Exception {
2492 final String html = DOCTYPE_HTML
2493 + "<html><head>\n"
2494 + "<style>\n"
2495 + " tt { display: none; }\n"
2496 + "</style>\n"
2497 + "<script>\n"
2498 + LOG_TITLE_FUNCTION
2499 + " function test() {\n"
2500 + " var iframe = document.createElement('iframe');\n"
2501 + " document.body.appendChild(iframe);\n"
2502 + "\n"
2503 + " var doc = iframe.contentWindow.document;\n"
2504 + " var tt = doc.createElement('tt');\n"
2505 + " doc.body.appendChild(tt);\n"
2506 + " log(window.getComputedStyle(tt, null).display);\n"
2507 + " }\n"
2508 + "</script></head>\n"
2509 + "<body onload='test()'>\n"
2510 + "</body></html>\n";
2511 loadPageVerifyTitle2(html);
2512 }
2513
2514
2515
2516
2517 @Test
2518 @Alerts({"1", "false", "true", "false", "false"})
2519 public void in() throws Exception {
2520 final String html = DOCTYPE_HTML
2521 + "<html>\n"
2522 + "<script>\n"
2523 + LOG_TITLE_FUNCTION
2524 + "function test() {\n"
2525 + " log(window.length);\n"
2526 + " log(-1 in window);\n"
2527 + " log(0 in window);\n"
2528 + " log(1 in window);\n"
2529 + " log(42 in window);\n"
2530 + "}\n"
2531 + "</script>\n"
2532 + "<frameset rows='50,*' onload='test()'>\n"
2533 + "<frame name='frame1' src='about:blank'/>\n"
2534 + "</frameset>\n"
2535 + "</html>";
2536
2537 loadPageVerifyTitle2(html);
2538 }
2539
2540
2541
2542
2543 @Test
2544 @Alerts({"a", "b"})
2545 public void calledTwice() throws Exception {
2546 final String html = DOCTYPE_HTML
2547 + "<html><head>\n"
2548 + "<script>\n"
2549 + LOG_TITLE_FUNCTION
2550 + "</script>\n"
2551 + "</head>\n"
2552 + "<body>\n"
2553 + "<script>\n"
2554 + " log('a');\n"
2555 + " log('b');\n"
2556 + "</script>\n"
2557 + "</body></html>";
2558 loadPageVerifyTitle2(html);
2559 }
2560
2561
2562
2563
2564 @Test
2565 @Alerts("TypeError")
2566 public void constructor() throws Exception {
2567 final String html = DOCTYPE_HTML
2568 + "<html><head>\n"
2569 + "<script>\n"
2570 + LOG_TITLE_FUNCTION
2571 + " function test() {\n"
2572 + " try {\n"
2573 + " log(new Window());\n"
2574 + " } catch(e) { logEx(e); }\n"
2575 + " }\n"
2576 + "</script>\n"
2577 + "</head>\n"
2578 + "<body onload='test()'>\n"
2579 + "</body></html>";
2580 loadPageVerifyTitle2(html);
2581 }
2582
2583
2584
2585
2586
2587
2588
2589 @Test
2590 @Alerts("0")
2591 public void constructorError() throws Exception {
2592 final String html = DOCTYPE_HTML
2593 + "<html><head>\n"
2594 + "<script>\n"
2595 + LOG_TITLE_FUNCTION
2596 + " function test() {\n"
2597 + " try {\n"
2598 + " var divs = document.querySelectorAll('div');\n"
2599 + " var a = Array.from.call(window, divs);\n"
2600 + " log(a.length);\n"
2601 + " } catch(e) { logEx(e) }\n"
2602 + " }\n"
2603 + "</script>\n"
2604 + "</head>\n"
2605 + "<body onload='test()'>\n"
2606 + "</body></html>";
2607 loadPageVerifyTitle2(html);
2608 }
2609
2610
2611
2612
2613 @Test
2614 @Alerts({"false", "false", "test2 alert"})
2615 public void objectCallOnFrameWindow() throws Exception {
2616 final String firstContent = DOCTYPE_HTML
2617 + "<html><head>\n"
2618 + "<script>\n"
2619 + LOG_WINDOW_NAME_FUNCTION
2620 + " function test1() {\n"
2621 + " log(window.frames[0].test2 === undefined);\n"
2622 + " Object(window.frames[0]);\n"
2623 + " }\n"
2624 + "</script>\n"
2625 + "</head>\n"
2626 + "<body>\n"
2627 + " <iframe src='" + URL_SECOND + "'></iframe>\n"
2628 + "</body></html>\n";
2629 final String secondContent = DOCTYPE_HTML
2630 + "<html><head>\n"
2631 + "<script>\n"
2632 + LOG_WINDOW_NAME_FUNCTION
2633 + " function test2() {\n"
2634 + " log('test2 alert');\n"
2635 + " }\n"
2636 + " window.top.test1();\n"
2637 + " log(test2 === undefined);\n"
2638 + "</script>\n"
2639 + "</head>\n"
2640 + "<body onload='test2()'>\n"
2641 + "</body></html>\n";
2642
2643 getMockWebConnection().setResponse(URL_SECOND, secondContent);
2644
2645 loadPage2(firstContent);
2646 verifyWindowName2(getWebDriver(), getExpectedAlerts());
2647 }
2648
2649
2650
2651
2652 @Test
2653 @Alerts({"[object Window]", "[object WindowProperties]", "[object EventTarget]", "[object Object]"})
2654 @HtmlUnitNYI(CHROME = {"[object Window]", "[object EventTarget]", "[object Object]"},
2655 EDGE = {"[object Window]", "[object EventTarget]", "[object Object]"},
2656 FF = {"[object Window]", "[object EventTarget]", "[object Object]"},
2657 FF_ESR = {"[object Window]", "[object EventTarget]", "[object Object]"})
2658 public void test__proto__() throws Exception {
2659 final String html = DOCTYPE_HTML
2660 + "<html><head>\n"
2661 + "<script>\n"
2662 + LOG_TITLE_FUNCTION
2663 + " function test() {\n"
2664 + " try {\n"
2665 + " for (var p = this.__proto__; p != null; p = p.__proto__) {\n"
2666 + " log(p);\n"
2667 + " }\n"
2668 + " } catch(e) { logEx(e) }\n"
2669 + " }\n"
2670 + "</script>\n"
2671 + "</head>\n"
2672 + "<body onload='test()'>\n"
2673 + "</body></html>";
2674 loadPageVerifyTitle2(html);
2675 }
2676
2677
2678
2679
2680 @Test
2681 @Alerts({"false", "false", "false", "false"})
2682 public void xmlNotInWindow() throws Exception {
2683 final String html
2684 = "<html xmlns='http://www.w3.org/1999/xhtml' xmlns:me='http://mysite'>\n"
2685 + "<script>\n"
2686 + LOG_TITLE_FUNCTION
2687 + " function test() {\n"
2688 + " log('XML' in window);\n"
2689 + " log('XMLList' in window);\n"
2690 + " log('Namespace' in window);\n"
2691 + " log('QName' in window);\n"
2692 + " }\n"
2693 + "</script>\n"
2694 + "</head>\n"
2695 + "<body onload='test()'>\n"
2696 + " <app:dIv xmlns='http://anotherURL'></app:dIv>\n"
2697 + "</body></html>";
2698
2699 loadPageVerifyTitle2(html);
2700 }
2701
2702
2703
2704
2705 @Test
2706 @Alerts({"[object Window]", "true", "true"})
2707 public void globalThis() throws Exception {
2708 final String html = DOCTYPE_HTML
2709 + "<html><head></head><body>\n"
2710 + "<script>\n"
2711 + LOG_TITLE_FUNCTION
2712 + " try {\n"
2713 + " log(globalThis);\n"
2714 + " log(window === globalThis);\n"
2715 + " log(self === globalThis);\n"
2716 + " } catch(e) { log('globalThis is undefined'); }"
2717 + "</script>\n"
2718 + "</body></html>";
2719 loadPageVerifyTitle2(html);
2720 }
2721
2722
2723
2724
2725 @Test
2726 @Alerts({"function", "function"})
2727 public void defineGetterSetter() throws Exception {
2728 final String html = DOCTYPE_HTML
2729 + "<html><head>\n"
2730 + "<script>\n"
2731 + LOG_TITLE_FUNCTION
2732 + " function test() {\n"
2733 + " log(typeof window.__defineGetter__);\n"
2734 + " log(typeof window.__lookupGetter__);\n"
2735 + " }\n"
2736 + "</script></head>\n"
2737 + "<body onload='test()'></body>\n"
2738 + "</html>";
2739
2740 loadPageVerifyTitle2(html);
2741 }
2742
2743
2744
2745
2746 @Test
2747 @Alerts({"function", "function"})
2748 public void defineGetterSetter_standards() throws Exception {
2749 final String html = DOCTYPE_HTML
2750 + "<html><head>\n"
2751 + "<script>\n"
2752 + LOG_TITLE_FUNCTION
2753 + " function test() {\n"
2754 + " log(typeof window.__defineGetter__);\n"
2755 + " log(typeof window.__lookupGetter__);\n"
2756 + " }\n"
2757 + "</script></head>\n"
2758 + "<body onload='test()'></body>\n"
2759 + "</html>";
2760
2761 loadPageVerifyTitle2(html);
2762 }
2763
2764
2765
2766
2767 @Test
2768 @Alerts("hello")
2769 public void delegatorAnd__defineGetter__() throws Exception {
2770 final String html = DOCTYPE_HTML
2771 + "<html><head>\n"
2772 + "<script>\n"
2773 + LOG_TITLE_FUNCTION
2774 + " function test() {\n"
2775 + " window.__defineGetter__('foo', function() { return 'hello' });\n"
2776 + " log(window.foo);\n"
2777 + " }\n"
2778 + "</script></head>\n"
2779 + "<body onload='test()'></body>\n"
2780 + "</html>";
2781
2782 loadPageVerifyTitle2(html);
2783 }
2784
2785
2786
2787
2788 @Test
2789 @Alerts("worldworld")
2790 public void delegatorAnd__defineSetter__() throws Exception {
2791 final String html = DOCTYPE_HTML
2792 + "<html><head>\n"
2793 + "<script>\n"
2794 + LOG_TITLE_FUNCTION
2795 + " function test() {\n"
2796 + " window.__defineSetter__('foo', function(a) { document.title = a; });\n"
2797 + " window.foo = 'world';\n"
2798 + " log(document.title);\n"
2799 + " }\n"
2800 + "</script></head>\n"
2801 + "<body onload='test()'></body>\n"
2802 + "</html>";
2803
2804 loadPageVerifyTitle2(html);
2805 }
2806
2807
2808
2809
2810 @Test
2811 @Alerts("1")
2812 public void userDefinedProperty() throws Exception {
2813 final String html = DOCTYPE_HTML
2814 + "<html><head>\n"
2815 + "<script>\n"
2816 + LOG_TITLE_FUNCTION
2817 + " function test() {\n"
2818 + " window.count = 0;\n"
2819 + " window.count++;\n"
2820 + " log(window.count);\n"
2821 + " }\n"
2822 + "</script></head>\n"
2823 + "<body onload='test()'></body>\n"
2824 + "</html>";
2825
2826 loadPageVerifyTitle2(html);
2827 }
2828
2829
2830
2831
2832 @Test
2833 @Alerts({"undefined", "{\"enumerable\":true,\"configurable\":true}",
2834 "[object Event]", "{\"enumerable\":true,\"configurable\":true}"})
2835 public void eventProperty() throws Exception {
2836 final String html = DOCTYPE_HTML
2837 + "<html><head>\n"
2838 + "<script>\n"
2839 + LOG_TITLE_FUNCTION
2840 + " function test() {\n"
2841 + " log(window.event);\n"
2842 + " log(JSON.stringify(Object.getOwnPropertyDescriptor(window, 'event')));\n"
2843 + " }\n"
2844 + "</script></head>\n"
2845 + "<body onload='test()'></body>\n"
2846 + "<script>\n"
2847 + " log(window.event);\n"
2848 + " log(JSON.stringify(Object.getOwnPropertyDescriptor(window, 'event')));\n"
2849 + "</script>\n"
2850 + "</html>";
2851
2852 loadPageVerifyTitle2(html);
2853 }
2854
2855
2856
2857
2858 @Test
2859 @Alerts("{\"value\":7,\"writable\":true,\"enumerable\":true,\"configurable\":true}")
2860 public void eventPropertyReplaced() throws Exception {
2861 final String html = DOCTYPE_HTML
2862 + "<html><head>\n"
2863 + "<script>\n"
2864 + LOG_TITLE_FUNCTION
2865 + " function test() {\n"
2866 + " log(JSON.stringify(Object.getOwnPropertyDescriptor(window, 'event')));\n"
2867 + " }\n"
2868 + "</script></head>\n"
2869 + "<body onload='test()'></body>\n"
2870 + "<script>\n"
2871 + " event = 7;\n"
2872 + "</script>\n"
2873 + "</html>";
2874
2875 loadPageVerifyTitle2(html);
2876 }
2877
2878
2879
2880
2881 @Test
2882 @Alerts("true")
2883 public void isSecureContextLocalhost() throws Exception {
2884 final String html = DOCTYPE_HTML
2885 + "<html><body><script>\n"
2886 + LOG_TITLE_FUNCTION
2887 + " log(window.hasOwnProperty('isSecureContext') ? isSecureContext : 'not available');\n"
2888 + "</script></body></html>";
2889
2890 loadPageVerifyTitle2(html);
2891 }
2892
2893
2894
2895
2896 @Test
2897 @Alerts("false")
2898 public void isSecureContextHttp() throws Exception {
2899 final String html = DOCTYPE_HTML
2900 + "<html><body><script>\n"
2901 + LOG_TITLE_FUNCTION
2902 + " log(window.hasOwnProperty('isSecureContext') ? isSecureContext : 'not available');\n"
2903 + "</script></body></html>";
2904
2905 final WebDriver driver = loadPage2(html, new URL(CookieManager4Test.URL_HOST1));
2906 verifyTitle2(driver, getExpectedAlerts());
2907 }
2908
2909
2910
2911
2912 @Test
2913 @Alerts("true")
2914 public void isSecureContextHttpS() throws Exception {
2915 final WebDriver driver = loadPage2(new URL("https://www.wetator.org/HtmlUnit"), StandardCharsets.UTF_8);
2916
2917 final String script = "return window.isSecureContext";
2918 final Object result = ((JavascriptExecutor) driver).executeScript(script);
2919 assertEquals(getExpectedAlerts()[0], "" + result);
2920 }
2921
2922
2923
2924
2925 @Test
2926 @Alerts("true")
2927 public void isSecureContextFile() throws Exception {
2928 final String html = DOCTYPE_HTML
2929 + "<html><body><script>\n"
2930 + LOG_TITLE_FUNCTION
2931 + " log(window.hasOwnProperty('isSecureContext') ? isSecureContext : 'not available');\n"
2932 + "</script></body></html>";
2933
2934 final File currentDirectory = new File((new File("")).getAbsolutePath());
2935 final File tmpFile = File.createTempFile("isSecureContext", ".html", currentDirectory);
2936 tmpFile.deleteOnExit();
2937 final String encoding = (new OutputStreamWriter(new ByteArrayOutputStream())).getEncoding();
2938 FileUtils.writeStringToFile(tmpFile, html, encoding);
2939
2940 final WebDriver driver = getWebDriver();
2941 driver.get("file://" + tmpFile.getCanonicalPath());
2942
2943 final String script = "return window.isSecureContext";
2944 final Object result = ((JavascriptExecutor) driver).executeScript(script);
2945 assertEquals(getExpectedAlerts()[0], "" + result);
2946
2947 shutDownAll();
2948 }
2949
2950
2951
2952
2953 @Test
2954 @Alerts("false")
2955 public void isSecureContextAboutBlank() throws Exception {
2956 final WebDriver driver = getWebDriver();
2957 driver.get("about:blank");
2958
2959 final String script = "return window.isSecureContext";
2960 final Object result = ((JavascriptExecutor) driver).executeScript(script);
2961 assertEquals(getExpectedAlerts()[0], "" + result);
2962
2963 shutDownAll();
2964 }
2965
2966
2967
2968
2969 @Test
2970 @Alerts("inline")
2971 public void getComputedStyleShouldLoadOnlyStylesheets() throws Exception {
2972 final String html = DOCTYPE_HTML
2973 + "<html><head>\n"
2974
2975 + "<link rel='stylesheet' href='imp.css'>\n"
2976 + "<link rel='alternate' href='alternate.css'>\n"
2977
2978 + "<script>\n"
2979 + LOG_TITLE_FUNCTION
2980 + " function test() {\n"
2981 + " var tt = document.getElementById('tt');\n"
2982 + " log(window.getComputedStyle(tt, null).display);\n"
2983 + " }\n"
2984 + "</script></head>\n"
2985 + "<body onload='test()'>\n"
2986 + " <p id='tt'>abcd</p>\n"
2987 + "</body></html>\n";
2988
2989 String css = "p { display: inline };";
2990 getMockWebConnection().setResponse(new URL(URL_FIRST, "imp.css"), css, MimeType.TEXT_CSS);
2991
2992 css = "p { display: none };";
2993 getMockWebConnection().setResponse(new URL(URL_FIRST, "alternate.css"), css, MimeType.TEXT_CSS);
2994
2995 final int requestCount = getMockWebConnection().getRequestCount();
2996 loadPageVerifyTitle2(html);
2997
2998 assertEquals(2, getMockWebConnection().getRequestCount() - requestCount);
2999 }
3000
3001
3002
3003
3004 @Test
3005 @Alerts("length[GSCE]")
3006 public void lengthProperty() throws Exception {
3007 final String html = DOCTYPE_HTML
3008 + "<html>\n"
3009 + "<head></head>\n"
3010 + "<body>\n"
3011 + "<script>\n"
3012 + LOG_TITLE_FUNCTION
3013
3014 + " let property = 'length';\n"
3015 + " let desc = Object.getOwnPropertyDescriptor(window, property);\n"
3016 + " property += '[';\n"
3017 + " if (desc.get != undefined) property += 'G';\n"
3018 + " if (desc.set != undefined) property += 'S';\n"
3019 + " if (desc.writable) property += 'W';\n"
3020 + " if (desc.configurable) property += 'C';\n"
3021 + " if (desc.enumerable) property += 'E';\n"
3022 + " property += ']'\n"
3023 + " log(property);\n"
3024
3025 + "</script>\n"
3026 + "</body></html>\n";
3027
3028 loadPageVerifyTitle2(html);
3029 }
3030
3031
3032
3033
3034
3035 @Test
3036 @Alerts({"1", "two", "undefined"})
3037 public void lengthPropertyEdit() throws Exception {
3038 final String html = DOCTYPE_HTML
3039 + "<html>\n"
3040 + "<head></head>\n"
3041 + "<body>\n"
3042 + "<iframe></iframe>"
3043 + "<script>\n"
3044 + LOG_TITLE_FUNCTION
3045
3046 + " log(window.length);\n"
3047
3048 + " window.length = 'two';\n"
3049 + " log(window.length);\n"
3050
3051 + " delete window.length;\n"
3052 + " log(window.length);\n"
3053
3054 + "</script>\n"
3055 + "</body></html>\n";
3056
3057 loadPageVerifyTitle2(html);
3058 }
3059
3060
3061
3062
3063 @Test
3064 @Alerts("self[GSCE]")
3065 public void selfProperty() throws Exception {
3066 final String html = DOCTYPE_HTML
3067 + "<html>\n"
3068 + "<head></head>\n"
3069 + "<body>\n"
3070 + "<script>\n"
3071 + LOG_TITLE_FUNCTION
3072
3073 + " let property = 'self';\n"
3074 + " let desc = Object.getOwnPropertyDescriptor(window, property);\n"
3075 + " property += '[';\n"
3076 + " if (desc.get != undefined) property += 'G';\n"
3077 + " if (desc.set != undefined) property += 'S';\n"
3078 + " if (desc.writable) property += 'W';\n"
3079 + " if (desc.configurable) property += 'C';\n"
3080 + " if (desc.enumerable) property += 'E';\n"
3081 + " property += ']'\n"
3082 + " log(property);\n"
3083
3084 + "</script>\n"
3085 + "</body></html>\n";
3086
3087 loadPageVerifyTitle2(html);
3088 }
3089
3090
3091
3092
3093 @Test
3094 @Alerts({"[object Window]", "tester", "two", "undefined"})
3095 public void selfPropertyEdit() throws Exception {
3096 final String html = "<html><head>\n"
3097 + "<title>tester</title>"
3098 + "</head>\n"
3099 + "<body>\n"
3100 + LOG_TEXTAREA
3101 + "<script>\n"
3102 + LOG_TEXTAREA_FUNCTION
3103
3104 + " log(window.self);\n"
3105 + " log(window.self.document.title);\n"
3106
3107 + " window.self = 'two';\n"
3108 + " log(window.self);\n"
3109
3110 + " delete window.self;\n"
3111 + " log(window.self);\n"
3112
3113 + "</script>\n"
3114 + "</body></html>\n";
3115
3116 loadPageVerifyTextArea2(html);
3117 }
3118
3119
3120
3121
3122 @Test
3123 @Alerts("frames[GSCE]")
3124 public void framesProperty() throws Exception {
3125 final String html = DOCTYPE_HTML
3126 + "<html>\n"
3127 + "<head></head>\n"
3128 + "<body>\n"
3129 + "<script>\n"
3130 + LOG_TITLE_FUNCTION
3131
3132 + " let property = 'frames';\n"
3133 + " let desc = Object.getOwnPropertyDescriptor(window, property);\n"
3134 + " property += '[';\n"
3135 + " if (desc.get != undefined) property += 'G';\n"
3136 + " if (desc.set != undefined) property += 'S';\n"
3137 + " if (desc.writable) property += 'W';\n"
3138 + " if (desc.configurable) property += 'C';\n"
3139 + " if (desc.enumerable) property += 'E';\n"
3140 + " property += ']'\n"
3141 + " log(property);\n"
3142
3143 + "</script>\n"
3144 + "</body></html>\n";
3145
3146 loadPageVerifyTitle2(html);
3147 }
3148
3149
3150
3151
3152 @Test
3153 @Alerts({"[object Window]", "tester", "1", "two", "undefined"})
3154 public void framesPropertyEdit() throws Exception {
3155 final String html = DOCTYPE_HTML
3156 + "<html><head>\n"
3157 + "<title>tester</title>"
3158 + "</head>\n"
3159 + "<body>\n"
3160 + "<iframe></iframe>"
3161 + LOG_TEXTAREA
3162 + "<script>\n"
3163 + LOG_TEXTAREA_FUNCTION
3164
3165 + " log(window.frames);\n"
3166 + " log(window.frames.document.title);\n"
3167 + " log(window.frames.length);\n"
3168
3169 + " window.frames = 'two';\n"
3170 + " log(window.frames);\n"
3171
3172 + " delete window.frames;\n"
3173 + " log(window.frames);\n"
3174
3175 + "</script>\n"
3176 + "</body></html>\n";
3177
3178 loadPageVerifyTextArea2(html);
3179 }
3180
3181
3182
3183
3184 @Test
3185 @Alerts("parent[GSCE]")
3186 public void parentProperty() throws Exception {
3187 final String html = DOCTYPE_HTML
3188 + "<html><head>\n"
3189 + "<body>\n"
3190 + "<script>\n"
3191 + LOG_TITLE_FUNCTION
3192
3193 + " let property = 'parent';\n"
3194 + " let desc = Object.getOwnPropertyDescriptor(window, property);\n"
3195 + " property += '[';\n"
3196 + " if (desc.get != undefined) property += 'G';\n"
3197 + " if (desc.set != undefined) property += 'S';\n"
3198 + " if (desc.writable) property += 'W';\n"
3199 + " if (desc.configurable) property += 'C';\n"
3200 + " if (desc.enumerable) property += 'E';\n"
3201 + " property += ']'\n"
3202 + " log(property);\n"
3203
3204 + "</script>\n"
3205 + "</body></html>\n";
3206
3207 loadPageVerifyTitle2(html);
3208 }
3209
3210
3211
3212
3213 @Test
3214 @Alerts({"[object Window]", "two", "undefined"})
3215 public void parentPropertyEdit() throws Exception {
3216 final String html = DOCTYPE_HTML
3217 + "<html><head>\n"
3218 + "<body>\n"
3219 + "<script>\n"
3220 + LOG_TITLE_FUNCTION
3221
3222 + " log(window.parent);\n"
3223
3224 + " window.parent = 'two';\n"
3225 + " log(window.parent);\n"
3226
3227 + " delete window.parent;\n"
3228 + " log(window.parent);\n"
3229
3230 + "</script>\n"
3231 + "</body></html>\n";
3232
3233 loadPageVerifyTitle2(html);
3234 }
3235
3236
3237
3238
3239 @Test
3240 @Alerts(DEFAULT = {"clientInformation[GSCE]", "undefined"},
3241 FF_ESR = {"clientInformation[GCE]", "undefined"})
3242 public void clientInformationProperty() throws Exception {
3243 final String html = DOCTYPE_HTML
3244 + "<html><head>\n"
3245 + "<body>\n"
3246 + "<script>\n"
3247 + LOG_TITLE_FUNCTION
3248
3249 + " let property = 'clientInformation';\n"
3250
3251 + " let desc = Object.getOwnPropertyDescriptor(window, property);\n"
3252 + " property += '[';\n"
3253 + " if (desc.get != undefined) property += 'G';\n"
3254 + " if (desc.set != undefined) property += 'S';\n"
3255 + " if (desc.writable) property += 'W';\n"
3256 + " if (desc.configurable) property += 'C';\n"
3257 + " if (desc.enumerable) property += 'E';\n"
3258 + " property += ']'\n"
3259 + " log(property);\n"
3260
3261 + " delete window.clientInformation;\n"
3262
3263 + " desc = Object.getOwnPropertyDescriptor(window, property);\n"
3264 + " log(desc);\n"
3265
3266 + "</script>\n"
3267 + "</body></html>\n";
3268
3269 loadPageVerifyTitle2(html);
3270 }
3271
3272
3273
3274
3275 @Test
3276 @Alerts(DEFAULT = {"[object Navigator]", "two", "undefined"},
3277 FF_ESR = {"[object Navigator]", "[object Navigator]", "undefined"})
3278 @HtmlUnitNYI(CHROME = {"[object Navigator]", "two", "two"},
3279 EDGE = {"[object Navigator]", "two", "two"},
3280 FF = {"[object Navigator]", "two", "two"},
3281 FF_ESR = {"[object Navigator]", "[object Navigator]", "[object Navigator]"})
3282 public void clientInformationPropertyEdit() throws Exception {
3283 final String html = DOCTYPE_HTML
3284 + "<html><head>\n"
3285 + "<body>\n"
3286 + "<script>\n"
3287 + LOG_TITLE_FUNCTION
3288
3289 + " log(window.clientInformation);\n"
3290
3291 + " window.clientInformation = 'two';\n"
3292 + " log(window.clientInformation);\n"
3293
3294 + " delete window.clientInformation;\n"
3295 + " log(window.clientInformation);\n"
3296
3297 + "</script>\n"
3298 + "</body></html>\n";
3299
3300 loadPageVerifyTitle2(html);
3301 }
3302
3303
3304
3305
3306 @Test
3307 @Alerts({"performance[GSCE]", "undefined"})
3308 public void performanceProperty() throws Exception {
3309 final String html = DOCTYPE_HTML
3310 + "<html><head>\n"
3311 + "<body>\n"
3312 + "<script>\n"
3313 + LOG_TITLE_FUNCTION
3314
3315 + " let property = 'performance';\n"
3316
3317 + " let desc = Object.getOwnPropertyDescriptor(window, property);\n"
3318 + " property += '[';\n"
3319 + " if (desc.get != undefined) property += 'G';\n"
3320 + " if (desc.set != undefined) property += 'S';\n"
3321 + " if (desc.writable) property += 'W';\n"
3322 + " if (desc.configurable) property += 'C';\n"
3323 + " if (desc.enumerable) property += 'E';\n"
3324 + " property += ']'\n"
3325 + " log(property);\n"
3326
3327 + " delete window.performance;\n"
3328
3329 + " desc = Object.getOwnPropertyDescriptor(window, property);\n"
3330 + " log(desc);\n"
3331
3332 + "</script>\n"
3333 + "</body></html>\n";
3334
3335 loadPageVerifyTitle2(html);
3336 }
3337
3338
3339
3340
3341 @Test
3342 @Alerts({"[object Performance]", "two", "undefined"})
3343 @HtmlUnitNYI(CHROME = {"[object Performance]", "two", "two"},
3344 EDGE = {"[object Performance]", "two", "two"},
3345 FF = {"[object Performance]", "two", "two"},
3346 FF_ESR = {"[object Performance]", "two", "two"})
3347 public void performancePropertyEdit() throws Exception {
3348 final String html = DOCTYPE_HTML
3349 + "<html><head>\n"
3350 + "<body>\n"
3351 + "<script>\n"
3352 + LOG_TITLE_FUNCTION
3353
3354 + " log(window.performance);\n"
3355
3356 + " window.performance = 'two';\n"
3357 + " log(window.performance);\n"
3358
3359 + " delete window.performance;\n"
3360 + " log(window.performance);\n"
3361
3362 + "</script>\n"
3363 + "</body></html>\n";
3364
3365 loadPageVerifyTitle2(html);
3366 }
3367
3368
3369
3370
3371
3372
3373 @Test
3374 @Alerts({"c0", "c1", "c2", "c3", "c4", "cancelled"})
3375 public void setIntervallProceeds() throws Exception {
3376 final String content = DOCTYPE_HTML
3377 + "<html>\n"
3378 + "<head>\n"
3379 + "</head>\n"
3380 + "<body>\n"
3381 + "<script>\n"
3382 + LOG_TITLE_FUNCTION
3383 + "var intervalID = setInterval(myCallback, 50);\n"
3384 + "var count = 0;\n"
3385 + "function myCallback() {\n"
3386 + " log('c' + count);\n"
3387 + " if (count == 4) {\n"
3388 + " clearInterval(intervalID);\r\n"
3389 + " log('cancelled');\r\n"
3390 + " }\n"
3391 + " count++;\n"
3392 + " test.hide();\n"
3393 + "}\n"
3394 + "</script>\n"
3395 + "</body>\n"
3396 + "</html>";
3397
3398 loadPage2(content);
3399 verifyTitle2(DEFAULT_WAIT_TIME, getWebDriver(), getExpectedAlerts());
3400 }
3401 }