Bug 478956. Merge pseudo-frame handling for outer tables and non-table frames. ...
[mozilla-central.git] / docshell / test / test_bug369814.html
blob85a7b3bdb7a386a60e020a9d25f01a7f87ff39d9
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="/MochiKit/MochiKit.js"></script>
9 <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
10 <script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
11 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
12 </head>
13 <body>
14 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=384014">Mozilla Bug 369814</a>
16 <p>
18 <iframe id="testFrame"></iframe>
20 <pre id="test">
21 <script class="testbody" type="text/javascript">
23 /** Tests for Bug 369814 **/
25 SimpleTest.waitForExplicitFinish();
27 // Because child scripts won't be able to run to tell us they're done,
28 // we need to just wait for them. Wait this amount of time before checking
29 // the results.
30 const gLoadTimeout = 3000;
32 var Ci = Components.interfaces;
34 var gCurrentTest;
35 var gTargetWindow;
36 var gNumPokes;
37 var gPrefValue;
39 var gTestFrame = document.getElementById('testFrame');
41 /**
42 * Called by documents loaded from jar files to indicate that they can access
43 * this document.
45 function poke(description) {
46 ok(false, gCurrentTest['name'] + ": got unexpected poke: " + description);
47 gNumPokes++;
50 function loadEvent(window, callback)
52 var fn = function() {
53 window.removeEventListener("load", fn, false);
54 callback();
56 window.addEventListener("load", fn, false);
59 function loadTestTarget(callback)
61 gTargetWindow = window.open("http://localhost:8888", "bug369814target");
62 loadEvent(gTargetWindow, callback);
65 function closeTestTarget()
67 gTargetWindow.close();
68 gTargetWindow = null;
71 function loadErrorTest(test)
73 gTestFrame.src = test['url'];
75 // Give the frame a chance to fail at loading
76 setTimeout(function() {
77 // XXX: There doesn't seem to be a reliable check for "got an error,"
78 // but reaching in to an error document will throw an exception
79 var errorPage;
80 try {
81 var item = gTestFrame.contentDocument.getElementById(gCurrentTest['data-iframe']);
82 errorPage = false;
83 } catch (e) {
84 errorPage = true;
86 ok(errorPage, gCurrentTest["name"] + ": should block a suspicious JAR load.");
88 finishTest();
89 }, gLoadTimeout);
92 function iframeTest(test) {
93 gTestFrame.src = test['url'];
94 loadEvent(gTestFrame, function() {
95 finishTest();
96 });
99 function refreshTest(test) {
100 gTestFrame.src = test['url'];
101 loadEvent(gTestFrame, function() {
102 // Wait for the frame to try and refresh
103 // XXX: a "blocked redirect" signal would be needed to get rid of
104 // this timeout.
105 setTimeout(function() {
106 finishTest();
107 }, gLoadTimeout);
111 function anchorTest(test) {
112 loadTestTarget(function() {
113 gTestFrame.src = test['url'];
114 loadEvent(gTestFrame, function() {
115 sendMouseEvent({type:'click'}, 'target', gTestFrame.contentWindow);
116 sendMouseEvent({type:'click'}, 'notarget', gTestFrame.contentWindow);
118 // Give the clicks a chance to load
119 setTimeout(function() {
120 closeTestTarget();
121 finishTest();
122 }, gLoadTimeout);
127 var gTests = [
128 { "name" : "iframes.html loaded from non-jar type, pref disabled",
129 "url" : "jar:http://localhost:8888/tests/docshell/test/bug369814.zip!/iframes.html",
130 "pref" : false,
131 "pokes" : { },
132 "func" : loadErrorTest,
134 { "name" : "refresh.html loaded from non-jar type, pref enabled",
135 "url" : "jar:http://localhost:8888/tests/docshell/test/bug369814.zip!/refresh.html",
136 "pref" : true,
137 "pokes" : { },
138 "func" : refreshTest,
140 { "name" : "iframes.html loaded from non-jar type, pref enabled",
141 "url" : "jar:http://localhost:8888/tests/docshell/test/bug369814.zip!/iframes.html",
142 "pref" : true,
143 "pokes" : { },
144 "func" : iframeTest,
146 { "name" : "anchors.html loaded from non-jar type, pref enabled",
147 "url" : "jar:http://localhost:8888/tests/docshell/test/bug369814.zip!/anchors.html",
148 "pref" : true,
149 "pokes" : { },
150 "func" : anchorTest,
154 var gNextTest = 0;
156 function runNextTest()
158 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
159 var prefs = Components.classes["@mozilla.org/preferences-service;1"].
160 getService(Components.interfaces.nsIPrefBranch);
162 if (gNextTest < gTests.length) {
163 gCurrentTest = gTests[gNextTest++];
164 gNumPokes = 0;
166 prefs.setBoolPref("network.jar.open-unsafe-types", gCurrentTest['pref']);
168 gCurrentTest['func'](gCurrentTest);
169 } else {
170 // Put back the pref value we had at test start
171 prefs.setBoolPref("network.jar.open-unsafe-types", gPrefValue);
172 SimpleTest.finish();
176 function finishTest()
178 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
179 var prefs = Components.classes["@mozilla.org/preferences-service;1"].
180 getService(Components.interfaces.nsIPrefBranch);
181 prefs.setBoolPref("network.jar.open-unsafe-types", false);
183 if (gNumPokes == 0) {
184 ok(true, gCurrentTest["name"] + ": no unexpected pokes");
187 runNextTest();
190 function startTests()
192 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
193 var prefs = Components.classes["@mozilla.org/preferences-service;1"].
194 getService(Components.interfaces.nsIPrefBranch);
195 gPrefValue = prefs.getBoolPref("network.jar.open-unsafe-types");
198 addLoadEvent(runNextTest);
200 </script>
201 </pre>
202 </body>
203 </html>