JS Test Harness: Insert the stylesheet dynamically
[WebKit-https.git] / LayoutTests / fast / events / popup-blocking-timers.html
1 <head>
2     <script src="../js/resources/js-test-pre.js"></script>
3     <script>
4         var newWindow;
5         var intervalId;
6         var firstIntervalExecution = true;
7         
8         if (window.layoutTestController) {
9             layoutTestController.dumpAsText();
10             layoutTestController.setCanOpenWindows();
11             layoutTestController.waitUntilDone();
12             layoutTestController.setPopupBlockingEnabled(true);
13         }
14     
15         function clickHandler() {
16             newWindow = window.open("about:blank");
17             self.focus();
18             debug("Test calling window.open() directly. A popup should be allowed.");
19             shouldBeNonNull("newWindow");
20                         
21             setTimeout(function() {
22                 newWindow = window.open("about:blank");
23                 self.focus();
24                 debug("Test calling window.open() with a 0 ms delay. A popup should be allowed.")
25                 shouldBeNonNull("newWindow");
26             }, 0);
27             
28             setTimeout(function() {
29                 newWindow = window.open("about:blank");
30                 self.focus();
31                 debug("Test calling window.open() with a 1000 ms delay. A popup should be allowed.")
32                 shouldBeNonNull("newWindow");
33             }, 1000);
34             
35             setTimeout(function() {
36                 newWindow = window.open("about:blank");
37                 self.focus();
38                 debug("Test calling window.open() with a 1001 ms delay. A popup should not be allowed.")
39                 shouldBeUndefined("newWindow");
40                 
41                 if (window.layoutTestController)
42                     layoutTestController.notifyDone();
43             }, 1001);
44             
45             intervalId = setInterval(function() {
46                 debug("Test calling window.open() in a 100 ms interval. A popup should only be allowed on the first execution of the interval.");
47                 newWindow = window.open("about:blank");
48                 self.focus();
49                 if (firstIntervalExecution) {
50                     shouldBeNonNull("newWindow");
51                     firstIntervalExecution = false;
52                 } else {
53                     shouldBeUndefined("newWindow");
54                     clearInterval(intervalId);
55                 }
56             }, 100);
57             
58             setTimeout(function() {
59                 setTimeout(function() {
60                     newWindow = window.open("about:blank");
61                     self.focus();
62                     debug("Test calling window.open() in a nested call to setTimeout(). A popup should not be allowed.")
63                     shouldBeUndefined("newWindow");
64                 }, 0);
65             }, 300);
66             
67             if (window.eventSender)
68                 eventSender.leapForward(1001);
69         }
70         
71         function clickButton() {
72             var button = document.getElementById("test");
73             var buttonX = button.offsetLeft + button.offsetWidth / 2;
74             var buttonY = button.offsetTop + button.offsetHeight / 2;
75             if (window.eventSender) {
76                 eventSender.mouseMoveTo(buttonX, buttonY);
77                 eventSender.mouseDown();
78                 eventSender.mouseUp();
79             }
80         }        
81     </script>
82 </head>
83 <body onload="clickButton()">
84     <button id="test" onclick="clickHandler()">Click Here</button>
85     <div id="console"></div>
86 </body>