Source code

Revision control

Copy as Markdown

Other Tools

Test Info: Warnings

<!DOCTYPE HTML>
<html>
<head>
<!--
-->
<title>Test for Bug 1267075</title>
<link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"/>
</head>
<body onload="onLoad()">
<pre id="test">
<script class="testbody" type="text/javascript">
SimpleTest.waitForExplicitFinish();
function onLoad() {
var iframe = document.createElement("iframe");
iframe.onload = function () {
info("iframe loaded");
function imgListener(img) {
return new Promise((resolve, reject) => {
img.addEventListener("load", () => reject());
img.addEventListener("error", () => resolve());
});
}
var doc = iframe.contentDocument;
var img = doc.createElement("img");
var img2 = doc.createElement("img");
var img3 = doc.createElement("img");
// image from HTTP should be blocked.
doc.body.appendChild(img);
imgListener(img).then(() => {
ok(true, "img shouldn't be loaded");
// `iframe` is a content iframe, and thus not in the same docgroup with
// us, which are a chrome-privileged test.
//
// Ensure the frame is laid out so that this cross-origin
// getComputedStyle call is guaranteed to work after bug 1440537.
iframe.getBoundingClientRect();
img2.src = "https://test.invalid";
doc.body.appendChild(img2);
return imgListener(img2);
}).then(() => {
ok(true, "img2 shouldn't be loaded");
// Now prepare for the next test, deny image.
return new Promise(resolve => {
SpecialPowers.pushPrefEnv({"set": [["permissions.default.image", 2]]}, resolve)
});
}).then(() => {
// Now image is denied, loading image will be rejected with REJECT_TYPE.
doc.body.appendChild(img3);
return imgListener(img3);
}).then(() => {
ok(true, "img3 shouldn't be loaded");
SimpleTest.finish();
}).catch((e) => {
// Expected early return
if(e === true) {
SimpleTest.finish();
return;
}
ok(false, "throwing " + e);
});
};
// file_blocking_image.html contains meta tag for CSP, which will block images from
// http.
document.getElementById("content").appendChild(iframe);
}
</script>
</pre>
<p id="display"></p>
<div id="content">
</div>
</body> </html>