Backed out changeset 2450366cf7ca (bug 1891629) for causing win msix mochitest failures
[gecko.git] / dom / base / test / test_blocking_image.html
blobe579d9f0255b7c3401856e37e699c09574108aa8
1 <!DOCTYPE HTML>
2 <html>
3 <head>
4 <!--
5 https://bugzilla.mozilla.org/show_bug.cgi?id=1267075
6 -->
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"/>
11 </head>
12 <body onload="onLoad()">
13 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1267075">Mozilla Bug 1267075</a>
14 <pre id="test">
15 <script class="testbody" type="text/javascript">
16 SimpleTest.waitForExplicitFinish();
18 function onLoad() {
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());
26 });
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);
51 }).then(() => {
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)
57 });
58 }).then(() => {
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);
63 }).then(() => {
64 ok(true, "img3 shouldn't be loaded");
65 SimpleTest.finish();
66 }).catch((e) => {
67 // Expected early return
68 if(e === true) {
69 SimpleTest.finish();
70 return;
72 ok(false, "throwing " + e);
73 });
76 // file_blocking_image.html contains meta tag for CSP, which will block images from
77 // http.
78 iframe.src = "http://mochi.test:8888/chrome/dom/base/test/file_blocking_image.html";
79 document.getElementById("content").appendChild(iframe);
81 </script>
82 </pre>
83 <p id="display"></p>
84 <div id="content">
85 </div>
87 </body> </html>