Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / fast / events / popup-blocked-from-untrusted-mouse-click.html
blob19a8ddd9906f5772b3729a746572cceaf5ed1cf1
1 <html>
2 <head>
3 <script>
4 if (window.testRunner) {
5 testRunner.dumpAsText();
6 testRunner.setCanOpenWindows();
7 testRunner.setCloseRemainingWindowsWhenComplete(true);
8 testRunner.waitUntilDone();
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;
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 testRunner.notifyDone();
30 function dispatchEvent(obj, evt) {
31 return function() {
32 return obj.dispatchEvent(evt);
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);
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 (testRunner.windowCount() != expectedWindowCount) {
55 testRunner.notifyDone();
56 return;
58 // Go to next test stage.
59 window.setTimeout(nextTestStage, 0);
62 function doClick() {
63 testRunner.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();
71 function test() {
72 if (!window.testRunner)
73 return;
74 window.testStage = TEST_STARTED;
75 nextTestStage();
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>