diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
commit | 2aa4a82499d4becd2284cdb482213d541b8804dd (patch) | |
tree | b80bf8bf13c3766139fbacc530efd0dd9d54394c /dom/base/test/test_blocking_image.html | |
parent | Initial commit. (diff) | |
download | firefox-upstream.tar.xz firefox-upstream.zip |
Adding upstream version 86.0.1.upstream/86.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'dom/base/test/test_blocking_image.html')
-rw-r--r-- | dom/base/test/test_blocking_image.html | 94 |
1 files changed, 94 insertions, 0 deletions
diff --git a/dom/base/test/test_blocking_image.html b/dom/base/test/test_blocking_image.html new file mode 100644 index 0000000000..64924b0dab --- /dev/null +++ b/dom/base/test/test_blocking_image.html @@ -0,0 +1,94 @@ +<!DOCTYPE HTML> +<html> +<head> +<!-- +https://bugzilla.mozilla.org/show_bug.cgi?id=1267075 +--> + <title>Test for Bug 1267075</title> + <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> + <script src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script> + <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"/> +</head> +<body onload="onLoad()"> +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1267075">Mozilla Bug 1267075</a> +<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. + img.src = "http://example.com/tests/image/test/mochitest/shaver.png"; + 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(); + + ok(img2.matches(":-moz-broken"), "should match ':-moz-broken' selector"); + + img2.src = "https://test.invalid"; + doc.body.appendChild(img2); + return imgListener(img2); + }).then(() => { + ok(true, "img2 shouldn't be loaded"); + ok(img2.matches(":-moz-broken"), "should match ':-moz-broken' selector"); + + // 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, + // which will be mapped to :-moz-broken too. + img3.src = "https://example.com/tests/image/test/mochitest/shaver.png"; + doc.body.appendChild(img3); + return imgListener(img3); + }).then(() => { + ok(true, "img3 shouldn't be loaded"); + + ok(img3.matches(":-moz-broken"), "should match ':-moz-broken' selector"); + + 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. + iframe.src = "http://mochi.test:8888/chrome/dom/base/test/file_blocking_image.html"; + document.getElementById("content").appendChild(iframe); +} +</script> +</pre> +<p id="display"></p> +<div id="content"> +</div> + +</body> </html> |