4 https://bugzilla.mozilla.org/show_bug.cgi?id=369814
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" />
14 <a target=
"_blank" href=
"https://bugzilla.mozilla.org/show_bug.cgi?id=384014">Mozilla Bug
369814</a>
18 <iframe id=
"testFrame"></iframe>
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
30 const gLoadTimeout =
3000;
32 var Ci = Components.interfaces;
39 var gTestFrame = document.getElementById('testFrame');
42 * Called by documents loaded from jar files to indicate that they can access
45 function poke(description) {
46 ok(false, gCurrentTest['name'] +
": got unexpected poke: " + description);
50 function loadEvent(window, callback)
53 window.removeEventListener(
"load", fn, false);
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();
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
81 var item = gTestFrame.contentDocument.getElementById(gCurrentTest['data-iframe']);
86 ok(errorPage, gCurrentTest[
"name"] +
": should block a suspicious JAR load.");
92 function iframeTest(test) {
93 gTestFrame.src = test['url'];
94 loadEvent(gTestFrame, function() {
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
105 setTimeout(function() {
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() {
128 {
"name" :
"iframes.html loaded from non-jar type, pref disabled",
129 "url" :
"jar:http://localhost:8888/tests/docshell/test/bug369814.zip!/iframes.html",
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",
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",
146 {
"name" :
"anchors.html loaded from non-jar type, pref enabled",
147 "url" :
"jar:http://localhost:8888/tests/docshell/test/bug369814.zip!/anchors.html",
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++];
166 prefs.setBoolPref(
"network.jar.open-unsafe-types", gCurrentTest['pref']);
168 gCurrentTest['func'](gCurrentTest);
170 // Put back the pref value we had at test start
171 prefs.setBoolPref(
"network.jar.open-unsafe-types", gPrefValue);
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");
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);