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