gecko/content/xbl/test/test_bug379959.html

98 lines
2.5 KiB
HTML

<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=379959
-->
<head>
<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="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
previous url in the iframe which will result in an extra unexpected
message.
</p>
<div id="content" style="display: none"></div>
<iframe id="f"></iframe>
<pre id="test">
<script class="testbody" type="application/javascript;version=1.7">
SimpleTest.waitForExplicitFinish();
var messages = 0;
function receiveMessage(e) {
is(e.origin, "http://mochi.test:8888", "wrong sender!");
messages++;
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);
var iframe = document.getElementById('f');
function runTest() {
// Test with data-urls off
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
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";
}
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");
SimpleTest.finish();
}
</script>
</pre>
</body>
</html>