5 https://bugzilla.mozilla.org/show_bug.cgi?id=1267075
7 <title>Test for Bug
1267075</title>
8 <script src=
"chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
9 <script src=
"chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script>
10 <link rel=
"stylesheet" type=
"text/css" href=
"chrome://mochikit/content/tests/SimpleTest/test.css"/>
12 <body onload=
"onLoad()">
13 <a target=
"_blank" href=
"https://bugzilla.mozilla.org/show_bug.cgi?id=1267075">Mozilla Bug
1267075</a>
15 <script class=
"testbody" type=
"text/javascript">
16 SimpleTest.waitForExplicitFinish();
19 var iframe = document.createElement(
"iframe");
20 iframe.onload = function () {
21 info(
"iframe loaded");
22 function imgListener(img) {
23 return new Promise((resolve, reject) =
> {
24 img.addEventListener(
"load", () =
> reject());
25 img.addEventListener(
"error", () =
> resolve());
29 var doc = iframe.contentDocument;
30 var img = doc.createElement(
"img");
31 var img2 = doc.createElement(
"img");
32 var img3 = doc.createElement(
"img");
34 // image from HTTP should be blocked.
35 img.src =
"http://example.com/tests/image/test/mochitest/shaver.png";
36 doc.body.appendChild(img);
38 imgListener(img).then(() =
> {
39 ok(true,
"img shouldn't be loaded");
41 // `iframe` is a content iframe, and thus not in the same docgroup with
42 // us, which are a chrome-privileged test.
44 // Ensure the frame is laid out so that this cross-origin
45 // getComputedStyle call is guaranteed to work after bug
1440537.
46 iframe.getBoundingClientRect();
48 img2.src =
"https://test.invalid";
49 doc.body.appendChild(img2);
50 return imgListener(img2);
52 ok(true,
"img2 shouldn't be loaded");
54 // Now prepare for the next test, deny image.
55 return new Promise(resolve =
> {
56 SpecialPowers.pushPrefEnv({
"set": [[
"permissions.default.image",
2]]}, resolve)
59 // Now image is denied, loading image will be rejected with REJECT_TYPE.
60 img3.src =
"https://example.com/tests/image/test/mochitest/shaver.png";
61 doc.body.appendChild(img3);
62 return imgListener(img3);
64 ok(true,
"img3 shouldn't be loaded");
67 // Expected early return
72 ok(false,
"throwing " + e);
76 // file_blocking_image.html contains meta tag for CSP, which will block images from
78 iframe.src =
"http://mochi.test:8888/chrome/dom/base/test/file_blocking_image.html";
79 document.getElementById(
"content").appendChild(iframe);