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_bug1222633.html | |
parent | Initial commit. (diff) | |
download | firefox-2aa4a82499d4becd2284cdb482213d541b8804dd.tar.xz firefox-2aa4a82499d4becd2284cdb482213d541b8804dd.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_bug1222633.html')
-rw-r--r-- | dom/base/test/test_bug1222633.html | 112 |
1 files changed, 112 insertions, 0 deletions
diff --git a/dom/base/test/test_bug1222633.html b/dom/base/test/test_bug1222633.html new file mode 100644 index 0000000000..f2f83145de --- /dev/null +++ b/dom/base/test/test_bug1222633.html @@ -0,0 +1,112 @@ +<!DOCTYPE HTML> +<html> +<!-- +https://bugzilla.mozilla.org/show_bug.cgi?id=1222633 +--> +<head> + <title>Test for Bug 1222633</title> + <script 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=1222633">Mozilla Bug 1222633</a> +<p id="display"></p> +<div id="content" style="display: none"></div> +<script class="testbody" type="text/javascript"> + +/** Test for Bug 1222633 **/ + +function testPreloadEvent(url, crossorigin, expectLoad) { + return new Promise((resolve) => { + var link = document.createElement("LINK"); + link.setAttribute("rel", "preload"); + link.setAttribute("href", url); + link.setAttribute("as", "fetch"); + if (crossorigin) { + link.setAttribute("crossorigin", ""); + } + + link.addEventListener("load", () => { + ok(expectLoad, "not expecting load event for " + url); + link.remove(); + resolve(); + }); + link.addEventListener("error", () => { + ok(!expectLoad, "not expecting error event for " + url); + link.remove(); + resolve(); + }); + document.head.appendChild(link); + }); +} + +function testChangePrefetchToPreload(url) { + return new Promise((resolve) => { + var preloaded = false; + var link = document.createElement("LINK"); + link.setAttribute("rel", "prefetch"); + link.setAttribute("href", url); + link.setAttribute("as", "fetch"); + + link.addEventListener("load", () => { + ok(preloaded, "this will happen only on a preload"); + ok(true, "not expecting load event for " + url); + link.remove(); + resolve(); + }); + link.addEventListener("error", () => { + ok(false, "not expecting error event for " + url); + link.remove(); + resolve(); + }); + document.head.appendChild(link); + preloaded = true; + link.setAttribute("rel", "preload"); + }) +}; + +const SJS_PATH = window.location.pathname.replace(/[^/]+$/, "file_bug1268962.sjs"); +const SAME_ORIGIN = "http://mochi.test:8888" + SJS_PATH; +const CROSS_ORIGIN = "http://example.com" + SJS_PATH; + +SimpleTest.waitForExplicitFinish(); + +SpecialPowers.pushPrefEnv({"set": [["network.preload", true]]}) + +// test same origin +.then(() => testPreloadEvent(SAME_ORIGIN + "?statusCode=200&cacheControl=no-cache", false, true)) +.then(() => testPreloadEvent(SAME_ORIGIN + "?statusCode=404&cacheControl=no-cache", false, false)) +.then(() => testPreloadEvent(SAME_ORIGIN + "?statusCode=200&cacheControl=max-age%3D120", false, true)) +.then(() => testPreloadEvent(SAME_ORIGIN + "?statusCode=404&cacheControl=max-age%3D120", false, false)) + +// test cross origin without CORS +.then(() => testPreloadEvent(CROSS_ORIGIN + "?statusCode=200&cacheControl=no-cache", false, true)) +.then(() => testPreloadEvent(CROSS_ORIGIN + "?statusCode=404&cacheControl=no-cache", false, true)) +.then(() => testPreloadEvent(CROSS_ORIGIN + "?statusCode=200&cacheControl=max-age%3D120", false, true)) +.then(() => testPreloadEvent(CROSS_ORIGIN + "?statusCode=404&cacheControl=max-age%3D120", false, true)) + +// test cross origin by redirection without CORS +.then(() => testPreloadEvent(SAME_ORIGIN + "?redirect=crossorigin&statusCode=200&cacheControl=no-cache", false, true)) +.then(() => testPreloadEvent(SAME_ORIGIN + "?redirect=crossorigin&statusCode=404&cacheControl=no-cache", false, true)) +.then(() => testPreloadEvent(SAME_ORIGIN + "?redirect=crossorigin&statusCode=200&cacheControl=max-age%3D120", false, true)) +.then(() => testPreloadEvent(SAME_ORIGIN + "?redirect=crossorigin&statusCode=404&cacheControl=max-age%3D120", false, true)) + +// test cross origin with CORS request but no CORS response +.then(() => testPreloadEvent(CROSS_ORIGIN + "?statusCode=200&cacheControl=no-cache", true, true)) +.then(() => testPreloadEvent(CROSS_ORIGIN + "?statusCode=404&cacheControl=no-cache", true, true)) +.then(() => testPreloadEvent(CROSS_ORIGIN + "?statusCode=200&cacheControl=max-age%3D120", true, true)) +.then(() => testPreloadEvent(CROSS_ORIGIN + "?statusCode=404&cacheControl=max-age%3D120", true, true)) + +// test cross origin with CORS request and CORS response +.then(() => testPreloadEvent(CROSS_ORIGIN + "?statusCode=200&cacheControl=no-cache&allowOrigin=*", true, true)) +.then(() => testPreloadEvent(CROSS_ORIGIN + "?statusCode=404&cacheControl=no-cache&allowOrigin=*", true, false)) +.then(() => testPreloadEvent(CROSS_ORIGIN + "?statusCode=200&cacheControl=max-age%3D120&allowOrigin=*", true, true)) +.then(() => testPreloadEvent(CROSS_ORIGIN + "?statusCode=404&cacheControl=max-age%3D120&allowOrigin=*", true, false)) +.then(() => testChangePrefetchToPreload(SAME_ORIGIN + "?statusCode=200&cacheControl=max-age%3D120", false, true)) + +.catch((err) => ok(false, "promise rejected: " + err)) +.then(() => SimpleTest.finish()); + +</script> +</body> +</html> |