[Release] Webkit-EFL Ver. 2.0_beta_118996_0.6.22
[framework/web/webkit-efl.git] / LayoutTests / fast / events / popup-blocked-from-untrusted-mouse-click.html
1 <html>
2 <head>
3 <script>
4 if (window.layoutTestController) {
5     layoutTestController.dumpAsText();
6     layoutTestController.setCanOpenWindows();
7     layoutTestController.setCloseRemainingWindowsWhenComplete(true);
8     layoutTestController.waitUntilDone();
9 }
10
11 var TEST_STARTED = 0;
12 var TEST_WITH_ENABLING_POPUP_BLOCKER = 1;
13 var TEST_WITH_DISABLING_POPUP_BLOCKER = 2;
14 var TEST_COMPLETED = 3;
15
16 function nextTestStage() {
17     window.testStage++;
18     if (TEST_WITH_ENABLING_POPUP_BLOCKER == window.testStage) {
19         window.popupBlockerIsEnabled = true;
20         doClick();
21     } else if (TEST_WITH_DISABLING_POPUP_BLOCKER == window.testStage) {
22         window.popupBlockerIsEnabled = false;
23         doClick();
24     } else {
25         document.getElementById("console").innerHTML = "PASSED";
26         layoutTestController.notifyDone();
27     }
28 }
29
30 function dispatchEvent(obj, evt)  { 
31     return function() {
32         return obj.dispatchEvent(evt);
33     }
34 }
35
36 function simulateClick() {
37     var evt = document.createEvent("MouseEvents");
38     evt.initMouseEvent("click", true, true, window,
39         0, 0, 0, 0, 0, false, false, false, false, 0, null);
40     var cb = document.getElementById("anchor"); 
41     setTimeout(dispatchEvent(cb, evt), 100);
42 }
43
44 function openWindow(evt) {
45     window.open("data:text/html\, try to open new window", "_blank");
46     // If we enabled the popup blocker, the new window should be blocked.
47     // The windowCount should still be 1.
48     var expectedWindowCount = 1;
49     // If we disabled the popup blocker, the new window should be created.
50     // The windowCount should be 2.
51     if (!window.popupBlockerIsEnabled)
52         expectedWindowCount = 2;
53     // Encounter a failure, quit test.
54     if (layoutTestController.windowCount() != expectedWindowCount) {
55         layoutTestController.notifyDone();
56         return;
57     }
58     // Go to next test stage.
59     window.setTimeout(nextTestStage, 0);
60 }
61
62 function doClick() {
63     layoutTestController.setPopupBlockingEnabled(window.popupBlockerIsEnabled);
64     // Send a mouse-click event to click the button.
65     eventSender.mouseMoveTo(0, 0);
66     eventSender.mouseMoveTo(20, 20);
67     eventSender.mouseDown();
68     eventSender.mouseUp();
69 }
70
71 function test() {
72     if (!window.layoutTestController)
73         return;
74     window.testStage = TEST_STARTED;
75     nextTestStage();
76 }
77
78 </script>
79 <body onload="window.setTimeout(test, 0);">
80 <input type="button" onclick="simulateClick();" value="click me" id="btn"><br>
81 <a onclick="openWindow(event)" id="anchor"> open a new window </a><br>
82 The JavaScript created (untrusted) event inside a user-initiated (trusted) event should not cache the UserGesture status. This test is for bug https://bugs.webkit.org/show_bug.cgi?id=50508.
83 <div id="console">FAILED</div>