Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
1 <!DOCTYPE HTML>
2 <html>
3 <!--
4 https://bugzilla.mozilla.org/show_bug.cgi?id=666604
5 -->
6 <head>
7 <title>Test for Bug 666604</title>
8 <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
9 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
10 </head>
11 <body>
12 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=666604">Mozilla Bug 666604</a>
13 <p id="display"></p>
14 <div id="content" style="display: none">
16 </div>
17 <a href="javascript:activationListener()" id="testlink">test</a>
18 <pre id="test">
19 <script type="application/javascript">
21 /** Test for Bug 666604 **/
23 SimpleTest.waitForExplicitFinish();
25 function hitEventLoop(times, next)
26 {
27 if (times == 0) {
28 next();
29 return;
30 }
32 SimpleTest.executeSoon(function() {
33 hitEventLoop(times - 1, next);
34 });
35 }
37 var activationListener;
39 function dispatchClick(target, ctrl) {
40 var e = document.createEvent("MouseEvent");
41 e.initMouseEvent("click", true, true, window, 0, 0, 0, 0, 0,
42 ctrl, false, false, false, 0, null);
43 target.dispatchEvent(e);
44 }
46 function dispatchReturn(target, ctrl) {
47 var e = document.createEvent("KeyboardEvent");
48 e.initKeyEvent("keypress", true, true, window, ctrl, false,
49 false, false, 13, 0);
50 target.dispatchEvent(e);
51 }
53 function dispatchDOMActivate(target) {
54 var e = document.createEvent("UIEvent");
55 e.initUIEvent("DOMActivate", true, true, window, 0);
56 target.dispatchEvent(e);
57 }
59 var testlink = document.getElementById("testlink");
60 function test1() {
61 activationListener =
62 function() {
63 ok(true, "Untrusted click should activate a link");
64 test2();
65 }
66 dispatchClick(testlink, false);
67 }
69 function test2() {
70 activationListener =
71 function() {
72 ok(true, "Untrusted return keypress should activate a link");
73 test3();
74 }
75 dispatchReturn(testlink, false);
76 }
78 function test3() {
79 activationListener =
80 function() {
81 ok(false, "Untrusted click+ctrl should not activate a link");
82 test4();
83 }
84 dispatchClick(testlink, true);
85 hitEventLoop(10, test4);
86 }
88 function test4() {
89 activationListener =
90 function() {
91 ok(false, "Untrusted return keypress+ctrl should not activate a link");
92 test5();
93 }
94 dispatchReturn(testlink, true);
95 hitEventLoop(10, test5);
96 }
98 function test5() {
99 activationListener =
100 function() {
101 ok(true, "click() should activate a link");
102 test6();
103 }
104 testlink.click();
105 }
107 function test6() {
108 activationListener =
109 function() {
110 ok(true, "Untrusted DOMActivate should activate a link");
111 test7();
112 }
113 dispatchDOMActivate(testlink);
114 }
116 var oldPref;
117 function test7() {
118 oldPref = SpecialPowers.getBoolPref("dom.disable_open_during_load");
119 SpecialPowers.setBoolPref("dom.disable_open_during_load", false);
120 testlink.href = "javascript:opener.activationListener(); window.close();";
121 testlink.target = "_blank";
122 activationListener =
123 function() {
124 ok(true, "Click() should activate a link");
125 setTimeout(test8, 0);
126 }
127 testlink.click();
128 }
130 function test8() {
131 SpecialPowers.setBoolPref("dom.disable_open_during_load", true);
132 testlink.href = "javascript:opener.activationListener(); window.close();";
133 testlink.target = "_blank";
134 activationListener =
135 function() {
136 ok(false, "Click() should not activate a link");
137 setTimeout(test9, 0);
138 }
139 testlink.click();
140 hitEventLoop(10, test9);
141 }
144 function test9() {
145 SpecialPowers.setBoolPref("dom.disable_open_during_load", oldPref);
146 SimpleTest.finish();
147 }
149 addLoadEvent(test1);
151 </script>
152 </pre>
153 </body>
154 </html>