2007-11-27 08:32:23 +03:00
|
|
|
<!DOCTYPE HTML>
|
|
|
|
<html>
|
|
|
|
<!--
|
|
|
|
https://bugzilla.mozilla.org/show_bug.cgi?id=369814
|
|
|
|
-->
|
|
|
|
<head>
|
|
|
|
<title>Test for Bug 369814</title>
|
|
|
|
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
|
|
|
<script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
|
|
|
|
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
|
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=384014">Mozilla Bug 369814</a>
|
|
|
|
|
|
|
|
<p>
|
|
|
|
|
|
|
|
<pre id="test">
|
|
|
|
<script class="testbody" type="text/javascript">
|
|
|
|
|
|
|
|
/** Tests for Bug 369814 **/
|
|
|
|
|
|
|
|
SimpleTest.waitForExplicitFinish();
|
|
|
|
|
|
|
|
// Because child scripts won't be able to run to tell us they're done,
|
2011-05-11 19:28:53 +04:00
|
|
|
// we need to just wait for them. Wait this many event loop spins before
|
|
|
|
// checking the results.
|
|
|
|
const gLoadEventLoopCount = 100;
|
2007-11-27 08:32:23 +03:00
|
|
|
|
2012-09-24 16:46:29 +04:00
|
|
|
var Ci = SpecialPowers.Ci;
|
2007-11-27 08:32:23 +03:00
|
|
|
|
|
|
|
var gCurrentTest;
|
|
|
|
var gTargetWindow;
|
|
|
|
var gNumPokes;
|
|
|
|
var gPrefValue;
|
|
|
|
|
2011-05-11 19:28:53 +04:00
|
|
|
var gTestFrame;
|
2007-11-27 08:32:23 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Called by documents loaded from jar files to indicate that they can access
|
|
|
|
* this document.
|
|
|
|
*/
|
|
|
|
function poke(description) {
|
|
|
|
ok(false, gCurrentTest['name'] + ": got unexpected poke: " + description);
|
|
|
|
gNumPokes++;
|
|
|
|
}
|
|
|
|
|
|
|
|
function loadEvent(window, callback)
|
|
|
|
{
|
|
|
|
var fn = function() {
|
|
|
|
window.removeEventListener("load", fn, false);
|
|
|
|
callback();
|
|
|
|
};
|
|
|
|
window.addEventListener("load", fn, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
function loadTestTarget(callback)
|
|
|
|
{
|
2010-03-13 00:53:36 +03:00
|
|
|
gTargetWindow = window.open("http://mochi.test:8888", "bug369814target");
|
2007-11-27 08:32:23 +03:00
|
|
|
loadEvent(gTargetWindow, callback);
|
|
|
|
}
|
|
|
|
|
|
|
|
function closeTestTarget()
|
|
|
|
{
|
|
|
|
gTargetWindow.close();
|
|
|
|
gTargetWindow = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
function loadErrorTest(test)
|
|
|
|
{
|
2011-05-11 19:28:53 +04:00
|
|
|
// Give the frame a chance to fail at loading.
|
|
|
|
// How do detect failure to load? Error pages don't fire load
|
|
|
|
// events. But we can load another page before the error page and
|
|
|
|
// then use its unload handler to know when the error page is just
|
|
|
|
// about loaded; at that point a single trip through the event loop
|
|
|
|
// should do the trick.
|
|
|
|
loadEvent(gTestFrame, function() {
|
|
|
|
gTestFrame.src = test['url'];
|
|
|
|
});
|
|
|
|
gTestFrame.unloading = function() {
|
|
|
|
gTestFrame.unloading = null;
|
|
|
|
// Go out to the event loop once so that unload processing finishes and
|
|
|
|
// the new document is set up.
|
|
|
|
setTimeout(function() {
|
2007-11-27 08:32:23 +03:00
|
|
|
// XXX: There doesn't seem to be a reliable check for "got an error,"
|
|
|
|
// but reaching in to an error document will throw an exception
|
|
|
|
var errorPage;
|
|
|
|
try {
|
|
|
|
var item = gTestFrame.contentDocument.getElementById(gCurrentTest['data-iframe']);
|
|
|
|
errorPage = false;
|
|
|
|
} catch (e) {
|
|
|
|
errorPage = true;
|
|
|
|
}
|
|
|
|
ok(errorPage, gCurrentTest["name"] + ": should block a suspicious JAR load.");
|
|
|
|
|
|
|
|
finishTest();
|
2011-05-11 19:28:53 +04:00
|
|
|
}, 0);
|
|
|
|
}
|
|
|
|
var unloadDetector = "data:text/html,<script>window.onunload = function() { frameElement.unloading(); }</" + "script>";
|
|
|
|
gTestFrame.src = unloadDetector;
|
2007-11-27 08:32:23 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function iframeTest(test) {
|
|
|
|
gTestFrame.src = test['url'];
|
|
|
|
loadEvent(gTestFrame, function() {
|
|
|
|
finishTest();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2011-05-11 19:28:53 +04:00
|
|
|
|
|
|
|
function hitEventLoop(func, times) {
|
|
|
|
if (times > 0) {
|
|
|
|
SimpleTest.executeSoon(function() { hitEventLoop(func, times-1); });
|
|
|
|
} else {
|
|
|
|
SimpleTest.executeSoon(func);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-11-27 08:32:23 +03:00
|
|
|
function refreshTest(test) {
|
|
|
|
gTestFrame.src = test['url'];
|
|
|
|
loadEvent(gTestFrame, function() {
|
|
|
|
// Wait for the frame to try and refresh
|
|
|
|
// XXX: a "blocked redirect" signal would be needed to get rid of
|
|
|
|
// this timeout.
|
2011-05-11 19:28:53 +04:00
|
|
|
hitEventLoop(function() {
|
2007-11-27 08:32:23 +03:00
|
|
|
finishTest();
|
2011-05-11 19:28:53 +04:00
|
|
|
}, gLoadEventLoopCount);
|
2007-11-27 08:32:23 +03:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function anchorTest(test) {
|
|
|
|
loadTestTarget(function() {
|
|
|
|
gTestFrame.src = test['url'];
|
|
|
|
loadEvent(gTestFrame, function() {
|
|
|
|
sendMouseEvent({type:'click'}, 'target', gTestFrame.contentWindow);
|
|
|
|
sendMouseEvent({type:'click'}, 'notarget', gTestFrame.contentWindow);
|
|
|
|
|
|
|
|
// Give the clicks a chance to load
|
2011-05-11 19:28:53 +04:00
|
|
|
hitEventLoop(function() {
|
2007-11-27 08:32:23 +03:00
|
|
|
closeTestTarget();
|
|
|
|
finishTest();
|
2011-05-11 19:28:53 +04:00
|
|
|
}, gLoadEventLoopCount);
|
2007-11-27 08:32:23 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
var gTests = [
|
|
|
|
{ "name" : "iframes.html loaded from non-jar type, pref disabled",
|
2010-03-13 00:53:36 +03:00
|
|
|
"url" : "jar:http://mochi.test:8888/tests/docshell/test/bug369814.zip!/iframes.html",
|
2007-11-27 08:32:23 +03:00
|
|
|
"pref" : false,
|
|
|
|
"pokes" : { },
|
|
|
|
"func" : loadErrorTest,
|
|
|
|
},
|
|
|
|
{ "name" : "refresh.html loaded from non-jar type, pref enabled",
|
2010-03-13 00:53:36 +03:00
|
|
|
"url" : "jar:http://mochi.test:8888/tests/docshell/test/bug369814.zip!/refresh.html",
|
2007-11-27 08:32:23 +03:00
|
|
|
"pref" : true,
|
|
|
|
"pokes" : { },
|
|
|
|
"func" : refreshTest,
|
|
|
|
},
|
|
|
|
{ "name" : "iframes.html loaded from non-jar type, pref enabled",
|
2010-03-13 00:53:36 +03:00
|
|
|
"url" : "jar:http://mochi.test:8888/tests/docshell/test/bug369814.zip!/iframes.html",
|
2007-11-27 08:32:23 +03:00
|
|
|
"pref" : true,
|
|
|
|
"pokes" : { },
|
|
|
|
"func" : iframeTest,
|
|
|
|
},
|
|
|
|
{ "name" : "anchors.html loaded from non-jar type, pref enabled",
|
2010-03-13 00:53:36 +03:00
|
|
|
"url" : "jar:http://mochi.test:8888/tests/docshell/test/bug369814.zip!/anchors.html",
|
2007-11-27 08:32:23 +03:00
|
|
|
"pref" : true,
|
|
|
|
"pokes" : { },
|
|
|
|
"func" : anchorTest,
|
|
|
|
},
|
2009-03-11 00:58:00 +03:00
|
|
|
{ "name" : "iframes.html loaded from view-source jar type, pref disabled",
|
2010-03-13 00:53:36 +03:00
|
|
|
"url" : "jar:view-source:http://mochi.test:8888/tests/docshell/test/bug369814.jar!/iframes.html",
|
2010-01-07 04:14:38 +03:00
|
|
|
"pref" : false,
|
2009-03-11 00:58:00 +03:00
|
|
|
"pokes" : { },
|
|
|
|
"func" : loadErrorTest
|
|
|
|
},
|
|
|
|
{ "name" : "iframes.html loaded from view-source jar type, pref enabled",
|
2010-03-13 00:53:36 +03:00
|
|
|
"url" : "jar:view-source:http://mochi.test:8888/tests/docshell/test/bug369814.jar!/iframes.html",
|
2009-03-11 00:58:00 +03:00
|
|
|
"pref" : true,
|
|
|
|
"pokes" : { },
|
|
|
|
"func" : loadErrorTest
|
|
|
|
},
|
2007-11-27 08:32:23 +03:00
|
|
|
];
|
|
|
|
|
|
|
|
var gNextTest = 0;
|
|
|
|
|
|
|
|
function runNextTest()
|
|
|
|
{
|
2012-09-24 16:46:29 +04:00
|
|
|
var prefs = SpecialPowers.Cc["@mozilla.org/preferences-service;1"]
|
|
|
|
.getService(SpecialPowers.Ci.nsIPrefBranch);
|
2007-11-27 08:32:23 +03:00
|
|
|
|
|
|
|
if (gNextTest < gTests.length) {
|
|
|
|
gCurrentTest = gTests[gNextTest++];
|
|
|
|
gNumPokes = 0;
|
|
|
|
|
|
|
|
prefs.setBoolPref("network.jar.open-unsafe-types", gCurrentTest['pref']);
|
|
|
|
|
2011-05-11 19:28:53 +04:00
|
|
|
// Create a new frame each time, so our restictions on loads in a
|
|
|
|
// jar:-loaded iframe don't interfere with the test.
|
|
|
|
if (gTestFrame) {
|
|
|
|
document.body.removeChild(gTestFrame);
|
|
|
|
}
|
|
|
|
gTestFrame = document.createElement("iframe");
|
|
|
|
document.body.insertBefore(gTestFrame, $("test"));
|
|
|
|
|
2007-11-27 08:32:23 +03:00
|
|
|
gCurrentTest['func'](gCurrentTest);
|
|
|
|
} else {
|
|
|
|
// Put back the pref value we had at test start
|
|
|
|
prefs.setBoolPref("network.jar.open-unsafe-types", gPrefValue);
|
|
|
|
SimpleTest.finish();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function finishTest()
|
|
|
|
{
|
2012-09-24 16:46:29 +04:00
|
|
|
var prefs = SpecialPowers.Cc["@mozilla.org/preferences-service;1"]
|
|
|
|
.getService(SpecialPowers.Ci.nsIPrefBranch);
|
2007-11-27 08:32:23 +03:00
|
|
|
prefs.setBoolPref("network.jar.open-unsafe-types", false);
|
|
|
|
|
|
|
|
if (gNumPokes == 0) {
|
|
|
|
ok(true, gCurrentTest["name"] + ": no unexpected pokes");
|
|
|
|
}
|
|
|
|
|
|
|
|
runNextTest();
|
|
|
|
}
|
|
|
|
|
|
|
|
function startTests()
|
|
|
|
{
|
2012-09-24 16:46:29 +04:00
|
|
|
var prefs = SpecialPowers.Cc["@mozilla.org/preferences-service;1"]
|
|
|
|
.getService(SpecialPowers.Ci.nsIPrefBranch);
|
2007-11-27 08:32:23 +03:00
|
|
|
gPrefValue = prefs.getBoolPref("network.jar.open-unsafe-types");
|
|
|
|
}
|
|
|
|
|
|
|
|
addLoadEvent(runNextTest);
|
|
|
|
|
|
|
|
</script>
|
|
|
|
</pre>
|
|
|
|
</body>
|
|
|
|
</html>
|
|
|
|
|