2010-06-04 14:03:50 -07:00
|
|
|
<!DOCTYPE HTML>
|
|
|
|
<html>
|
|
|
|
<!--
|
|
|
|
https://bugzilla.mozilla.org/show_bug.cgi?id=519928
|
|
|
|
-->
|
|
|
|
<head>
|
|
|
|
<title>Test for Bug 519928</title>
|
|
|
|
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.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=519928">Mozilla Bug 519928</a>
|
|
|
|
<p id="display"></p>
|
|
|
|
<div id="content">
|
|
|
|
<iframe id="load-frame"></iframe>
|
|
|
|
</div>
|
|
|
|
<pre id="test">
|
|
|
|
<script class="testbody" type="text/javascript">
|
|
|
|
|
|
|
|
var iframe = document.getElementById("load-frame");
|
|
|
|
|
2010-07-22 23:40:19 -07:00
|
|
|
function enableJS() allowJS(true, iframe);
|
|
|
|
function disableJS() allowJS(false, iframe);
|
|
|
|
function allowJS(allow, frame) {
|
2014-02-15 13:12:34 -08:00
|
|
|
SpecialPowers.wrap(frame.contentWindow)
|
|
|
|
.QueryInterface(SpecialPowers.Ci.nsIInterfaceRequestor)
|
2012-09-24 05:46:29 -07:00
|
|
|
.getInterface(SpecialPowers.Ci.nsIWebNavigation)
|
|
|
|
.QueryInterface(SpecialPowers.Ci.nsIDocShell)
|
2012-08-06 13:15:49 -07:00
|
|
|
.allowJavascript = allow;
|
2010-06-04 14:03:50 -07:00
|
|
|
}
|
|
|
|
function expectJSAllowed(allowed, testCondition, callback) {
|
|
|
|
window.ICanRunMyJS = false;
|
|
|
|
var self_ = window;
|
|
|
|
testCondition();
|
|
|
|
|
|
|
|
var doc = iframe.contentDocument;
|
|
|
|
doc.body.innerHTML = "<iframe></iframe>";
|
|
|
|
var innerFrame = doc.querySelector("iframe");
|
|
|
|
innerFrame.addEventListener("load", function() {
|
|
|
|
innerFrame.removeEventListener("load", arguments.callee, false);
|
|
|
|
|
|
|
|
var msg = "The inner iframe should" + (allowed ? "" : " not") + " be able to run Javascript";
|
|
|
|
is(self_.ICanRunMyJS, allowed, msg);
|
|
|
|
callback();
|
|
|
|
}, false);
|
|
|
|
var iframeSrc = "data:text/html,<script>parent.parent.ICanRunMyJS = true;</scr" + "ipt>";
|
|
|
|
innerFrame.src = iframeSrc;
|
|
|
|
}
|
|
|
|
|
|
|
|
SimpleTest.waitForExplicitFinish();
|
|
|
|
addLoadEvent(function() {
|
|
|
|
var enterDesignMode = function() document.designMode = "on";
|
|
|
|
var leaveDesignMode = function() document.designMode = "off";
|
|
|
|
expectJSAllowed(false, disableJS, function() {
|
|
|
|
expectJSAllowed(true, enableJS, function() {
|
|
|
|
expectJSAllowed(true, enterDesignMode, function() {
|
|
|
|
expectJSAllowed(true, leaveDesignMode, function() {
|
|
|
|
expectJSAllowed(false, disableJS, function() {
|
|
|
|
expectJSAllowed(false, enterDesignMode, function() {
|
|
|
|
expectJSAllowed(false, leaveDesignMode, function() {
|
|
|
|
expectJSAllowed(true, enableJS, function() {
|
|
|
|
enterDesignMode = function() iframe.contentDocument.designMode = "on";
|
|
|
|
leaveDesignMode = function() iframe.contentDocument.designMode = "off";
|
|
|
|
expectJSAllowed(false, disableJS, function() {
|
|
|
|
expectJSAllowed(true, enableJS, function() {
|
|
|
|
expectJSAllowed(true, enterDesignMode, function() {
|
|
|
|
expectJSAllowed(true, leaveDesignMode, function() {
|
|
|
|
expectJSAllowed(false, disableJS, function() {
|
2013-04-08 14:04:20 -07:00
|
|
|
expectJSAllowed(false, enterDesignMode, function() {
|
2010-06-04 14:03:50 -07:00
|
|
|
expectJSAllowed(false, leaveDesignMode, function() {
|
|
|
|
expectJSAllowed(true, enableJS, function() {
|
2010-07-22 23:40:19 -07:00
|
|
|
testDocumentDisabledJS();
|
2010-06-04 14:03:50 -07:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2010-07-22 23:40:19 -07:00
|
|
|
function testDocumentDisabledJS() {
|
|
|
|
window.ICanRunMyJS = false;
|
|
|
|
var self_ = window;
|
|
|
|
// Ensure design modes are disabled
|
|
|
|
document.designMode = "off";
|
|
|
|
iframe.contentDocument.designMode = "off";
|
|
|
|
|
2013-04-08 14:04:20 -07:00
|
|
|
// Javascript enabled on the main iframe
|
2010-07-22 23:40:19 -07:00
|
|
|
enableJS();
|
|
|
|
|
|
|
|
var doc = iframe.contentDocument;
|
|
|
|
doc.body.innerHTML = "<iframe></iframe>";
|
|
|
|
var innerFrame = doc.querySelector("iframe");
|
|
|
|
|
|
|
|
// Javascript disabled on the innerFrame.
|
|
|
|
allowJS(false, innerFrame);
|
|
|
|
|
|
|
|
innerFrame.addEventListener("load", function() {
|
|
|
|
innerFrame.removeEventListener("load", arguments.callee, false);
|
|
|
|
|
|
|
|
var msg = "The inner iframe should not be able to run Javascript";
|
|
|
|
is(self_.ICanRunMyJS, false, msg);
|
|
|
|
SimpleTest.finish();
|
|
|
|
}, false);
|
|
|
|
var iframeSrc = "data:text/html,<script>parent.parent.ICanRunMyJS = true;</scr" + "ipt>";
|
|
|
|
innerFrame.src = iframeSrc;
|
|
|
|
}
|
|
|
|
|
2010-06-04 14:03:50 -07:00
|
|
|
</script>
|
|
|
|
</pre>
|
|
|
|
</body>
|
|
|
|
</html>
|
|
|
|
|