Bug 907648 - test_bug379959.html and test_bug369814.html should use SpecialPowers. r=jmaher

This commit is contained in:
Martijn Wargers 2013-08-21 18:11:26 +02:00
parent 7d8e4ddf8d
commit a9e9e27117
2 changed files with 65 additions and 72 deletions

View File

@ -1,15 +1,15 @@
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=366770
https://bugzilla.mozilla.org/show_bug.cgi?id=379959
-->
<head>
<title>Test for Bug 366770</title>
<title>Test for Bug 379959</title>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body onload="gen.next();">
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=366770">Mozilla Bug 366770</a>
<body onload="runTest();">
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=379959">Mozilla Bug 379959</a>
<p id="display">
Note: In order to re-run this test correctly you need to shift-reload
rather than simply reload. If you just reload we will restore the
@ -23,63 +23,74 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=366770
<script class="testbody" type="application/javascript;version=1.7">
SimpleTest.waitForExplicitFinish();
gen = runTest();
var messages = 0;
function receiveMessage(e)
{
function receiveMessage(e) {
is(e.origin, "http://mochi.test:8888", "wrong sender!");
messages++;
gen.send(e.data);
switch (messages) {
case 1:
receiveMessage1(e.data);
break;
case 2:
receiveMessage2(e.data);
break;
case 3:
receiveMessage3(e.data);
break;
case 4:
receiveMessage4(e.data);
break;
default:
ok(false, "should not be reached");
Simpletest.finish();
}
}
window.addEventListener("message", receiveMessage, false);
const prefName = "layout.debug.enable_data_xbl";
var iframe = document.getElementById('f');
function runTest() {
iframe = document.getElementById('f');
// Turn on loads of data-urls
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
var prefs = Components.classes["@mozilla.org/preferences-service;1"]
.getService(Components.interfaces.nsIPrefBranch);
var oldPrefVal = undefined;
if (prefs.prefHasUserValue(prefName)) {
oldPrefVal = prefs.getBoolPref(prefName);
}
// Test with data-urls off
prefs.setBoolPref(prefName, false);
iframe.src = "file_bug379959_data.html";
is((yield), 0, "data-url load should have failed");
SpecialPowers.pushPrefEnv({"set": [["layout.debug.enable_data_xbl", false]]}, runTest1);
}
function runTest1() {
iframe.src = "file_bug379959_data.html";
}
function receiveMessage1(aData) {
is(aData, 0, "data-url load should have failed");
// Test with data-urls on
prefs.setBoolPref(prefName, true);
iframe.src = "file_bug379959_data.html";
is((yield), 1, "data-url load should have been successful");
SpecialPowers.pushPrefEnv({"set": [["layout.debug.enable_data_xbl", true]]}, runTest2);
}
function runTest2() {
iframe.src = "file_bug379959_data.html";
}
function receiveMessage2(aData) {
is(aData, 1, "data-url load should have been successful");
// Try a cross-site load
iframe.src = "file_bug379959_cross.html";
is((yield), 1, "same site load should have succeeded");
is((yield), 0, "cross site load should have failed");
}
function receiveMessage3(aData) {
is(aData, 1, "same site load should have succeeded");
}
function receiveMessage4(aData) {
is(aData, 0, "cross site load should have failed");
// Check that we got the right number of messages to make sure that
// the right message has aligned with the right test
is(messages, 4, "wrong number of messages");
// We're done
if (oldPrefVal === undefined) {
prefs.clearUserPref(prefName);
}
else {
prefs.setBoolPref(prefName, oldPrefVal);
}
SimpleTest.finish();
yield undefined;
}
</script>
</pre>
</body>

View File

@ -26,13 +26,9 @@ SimpleTest.waitForExplicitFinish();
// checking the results.
const gLoadEventLoopCount = 100;
var Ci = SpecialPowers.Ci;
var gCurrentTest;
var gTargetWindow;
var gNumPokes;
var gPrefValue;
var gTestFrame;
/**
@ -186,49 +182,36 @@ var gNextTest = 0;
function runNextTest()
{
var prefs = SpecialPowers.Cc["@mozilla.org/preferences-service;1"]
.getService(SpecialPowers.Ci.nsIPrefBranch);
if (gNextTest < gTests.length) {
gCurrentTest = gTests[gNextTest++];
gNumPokes = 0;
prefs.setBoolPref("network.jar.open-unsafe-types", gCurrentTest['pref']);
SpecialPowers.pushPrefEnv({"set": [["network.jar.open-unsafe-types", gCurrentTest['pref']]]}, function() {
// 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"));
// 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"));
gCurrentTest['func'](gCurrentTest);
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()
{
var prefs = SpecialPowers.Cc["@mozilla.org/preferences-service;1"]
.getService(SpecialPowers.Ci.nsIPrefBranch);
prefs.setBoolPref("network.jar.open-unsafe-types", false);
SpecialPowers.pushPrefEnv({"set": [["network.jar.open-unsafe-types", false]]}, function() {
if (gNumPokes == 0) {
ok(true, gCurrentTest["name"] + ": no unexpected pokes");
}
if (gNumPokes == 0) {
ok(true, gCurrentTest["name"] + ": no unexpected pokes");
}
runNextTest();
}
function startTests()
{
var prefs = SpecialPowers.Cc["@mozilla.org/preferences-service;1"]
.getService(SpecialPowers.Ci.nsIPrefBranch);
gPrefValue = prefs.getBoolPref("network.jar.open-unsafe-types");
runNextTest();
});
}
addLoadEvent(runNextTest);
@ -237,4 +220,3 @@ addLoadEvent(runNextTest);
</pre>
</body>
</html>