|
1 <!DOCTYPE HTML> |
|
2 <html> |
|
3 <!-- |
|
4 https://bugzilla.mozilla.org/show_bug.cgi?id=369814 |
|
5 --> |
|
6 <head> |
|
7 <title>Test for Bug 369814</title> |
|
8 <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> |
|
9 <script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script> |
|
10 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> |
|
11 </head> |
|
12 <body> |
|
13 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=384014">Mozilla Bug 369814</a> |
|
14 |
|
15 <p> |
|
16 |
|
17 <pre id="test"> |
|
18 <script class="testbody" type="text/javascript"> |
|
19 |
|
20 /** Tests for Bug 369814 **/ |
|
21 |
|
22 SimpleTest.waitForExplicitFinish(); |
|
23 |
|
24 // Because child scripts won't be able to run to tell us they're done, |
|
25 // we need to just wait for them. Wait this many event loop spins before |
|
26 // checking the results. |
|
27 const gLoadEventLoopCount = 100; |
|
28 |
|
29 var gCurrentTest; |
|
30 var gTargetWindow; |
|
31 var gNumPokes; |
|
32 var gTestFrame; |
|
33 |
|
34 /** |
|
35 * Called by documents loaded from jar files to indicate that they can access |
|
36 * this document. |
|
37 */ |
|
38 function poke(description) { |
|
39 ok(false, gCurrentTest['name'] + ": got unexpected poke: " + description); |
|
40 gNumPokes++; |
|
41 } |
|
42 |
|
43 function loadEvent(window, callback) |
|
44 { |
|
45 var fn = function() { |
|
46 window.removeEventListener("load", fn, false); |
|
47 callback(); |
|
48 }; |
|
49 window.addEventListener("load", fn, false); |
|
50 } |
|
51 |
|
52 function loadTestTarget(callback) |
|
53 { |
|
54 gTargetWindow = window.open("http://mochi.test:8888", "bug369814target"); |
|
55 loadEvent(gTargetWindow, callback); |
|
56 } |
|
57 |
|
58 function closeTestTarget() |
|
59 { |
|
60 gTargetWindow.close(); |
|
61 gTargetWindow = null; |
|
62 } |
|
63 |
|
64 function loadErrorTest(test) |
|
65 { |
|
66 // Give the frame a chance to fail at loading. |
|
67 // How do detect failure to load? Error pages don't fire load |
|
68 // events. But we can load another page before the error page and |
|
69 // then use its unload handler to know when the error page is just |
|
70 // about loaded; at that point a single trip through the event loop |
|
71 // should do the trick. |
|
72 loadEvent(gTestFrame, function() { |
|
73 gTestFrame.src = test['url']; |
|
74 }); |
|
75 gTestFrame.unloading = function() { |
|
76 gTestFrame.unloading = null; |
|
77 // Go out to the event loop once so that unload processing finishes and |
|
78 // the new document is set up. |
|
79 setTimeout(function() { |
|
80 // XXX: There doesn't seem to be a reliable check for "got an error," |
|
81 // but reaching in to an error document will throw an exception |
|
82 var errorPage; |
|
83 try { |
|
84 var item = gTestFrame.contentDocument.getElementById(gCurrentTest['data-iframe']); |
|
85 errorPage = false; |
|
86 } catch (e) { |
|
87 errorPage = true; |
|
88 } |
|
89 ok(errorPage, gCurrentTest["name"] + ": should block a suspicious JAR load."); |
|
90 |
|
91 finishTest(); |
|
92 }, 0); |
|
93 } |
|
94 var unloadDetector = "data:text/html,<script>window.onunload = function() { frameElement.unloading(); }</" + "script>"; |
|
95 gTestFrame.src = unloadDetector; |
|
96 } |
|
97 |
|
98 function iframeTest(test) { |
|
99 gTestFrame.src = test['url']; |
|
100 loadEvent(gTestFrame, function() { |
|
101 finishTest(); |
|
102 }); |
|
103 } |
|
104 |
|
105 |
|
106 function hitEventLoop(func, times) { |
|
107 if (times > 0) { |
|
108 SimpleTest.executeSoon(function() { hitEventLoop(func, times-1); }); |
|
109 } else { |
|
110 SimpleTest.executeSoon(func); |
|
111 } |
|
112 } |
|
113 |
|
114 function refreshTest(test) { |
|
115 gTestFrame.src = test['url']; |
|
116 loadEvent(gTestFrame, function() { |
|
117 // Wait for the frame to try and refresh |
|
118 // XXX: a "blocked redirect" signal would be needed to get rid of |
|
119 // this timeout. |
|
120 hitEventLoop(function() { |
|
121 finishTest(); |
|
122 }, gLoadEventLoopCount); |
|
123 }); |
|
124 } |
|
125 |
|
126 function anchorTest(test) { |
|
127 loadTestTarget(function() { |
|
128 gTestFrame.src = test['url']; |
|
129 loadEvent(gTestFrame, function() { |
|
130 sendMouseEvent({type:'click'}, 'target', gTestFrame.contentWindow); |
|
131 sendMouseEvent({type:'click'}, 'notarget', gTestFrame.contentWindow); |
|
132 |
|
133 // Give the clicks a chance to load |
|
134 hitEventLoop(function() { |
|
135 closeTestTarget(); |
|
136 finishTest(); |
|
137 }, gLoadEventLoopCount); |
|
138 }); |
|
139 }); |
|
140 } |
|
141 |
|
142 var gTests = [ |
|
143 { "name" : "iframes.html loaded from non-jar type, pref disabled", |
|
144 "url" : "jar:http://mochi.test:8888/tests/docshell/test/bug369814.zip!/iframes.html", |
|
145 "pref" : false, |
|
146 "pokes" : { }, |
|
147 "func" : loadErrorTest, |
|
148 }, |
|
149 { "name" : "refresh.html loaded from non-jar type, pref enabled", |
|
150 "url" : "jar:http://mochi.test:8888/tests/docshell/test/bug369814.zip!/refresh.html", |
|
151 "pref" : true, |
|
152 "pokes" : { }, |
|
153 "func" : refreshTest, |
|
154 }, |
|
155 { "name" : "iframes.html loaded from non-jar type, pref enabled", |
|
156 "url" : "jar:http://mochi.test:8888/tests/docshell/test/bug369814.zip!/iframes.html", |
|
157 "pref" : true, |
|
158 "pokes" : { }, |
|
159 "func" : iframeTest, |
|
160 }, |
|
161 { "name" : "anchors.html loaded from non-jar type, pref enabled", |
|
162 "url" : "jar:http://mochi.test:8888/tests/docshell/test/bug369814.zip!/anchors.html", |
|
163 "pref" : true, |
|
164 "pokes" : { }, |
|
165 "func" : anchorTest, |
|
166 }, |
|
167 { "name" : "iframes.html loaded from view-source jar type, pref disabled", |
|
168 "url" : "jar:view-source:http://mochi.test:8888/tests/docshell/test/bug369814.jar!/iframes.html", |
|
169 "pref" : false, |
|
170 "pokes" : { }, |
|
171 "func" : loadErrorTest |
|
172 }, |
|
173 { "name" : "iframes.html loaded from view-source jar type, pref enabled", |
|
174 "url" : "jar:view-source:http://mochi.test:8888/tests/docshell/test/bug369814.jar!/iframes.html", |
|
175 "pref" : true, |
|
176 "pokes" : { }, |
|
177 "func" : loadErrorTest |
|
178 }, |
|
179 ]; |
|
180 |
|
181 var gNextTest = 0; |
|
182 |
|
183 function runNextTest() |
|
184 { |
|
185 if (gNextTest < gTests.length) { |
|
186 gCurrentTest = gTests[gNextTest++]; |
|
187 gNumPokes = 0; |
|
188 |
|
189 SpecialPowers.pushPrefEnv({"set": [["network.jar.open-unsafe-types", gCurrentTest['pref']]]}, function() { |
|
190 |
|
191 // Create a new frame each time, so our restictions on loads in a |
|
192 // jar:-loaded iframe don't interfere with the test. |
|
193 if (gTestFrame) { |
|
194 document.body.removeChild(gTestFrame); |
|
195 } |
|
196 gTestFrame = document.createElement("iframe"); |
|
197 document.body.insertBefore(gTestFrame, $("test")); |
|
198 |
|
199 gCurrentTest['func'](gCurrentTest); |
|
200 }); |
|
201 } else { |
|
202 SimpleTest.finish(); |
|
203 } |
|
204 } |
|
205 |
|
206 function finishTest() |
|
207 { |
|
208 SpecialPowers.pushPrefEnv({"set": [["network.jar.open-unsafe-types", false]]}, function() { |
|
209 if (gNumPokes == 0) { |
|
210 ok(true, gCurrentTest["name"] + ": no unexpected pokes"); |
|
211 } |
|
212 |
|
213 runNextTest(); |
|
214 }); |
|
215 } |
|
216 |
|
217 addLoadEvent(runNextTest); |
|
218 |
|
219 </script> |
|
220 </pre> |
|
221 </body> |
|
222 </html> |