summaryrefslogtreecommitdiffstats
path: root/dom/base/test/test_bug1667316.html
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
commit36d22d82aa202bb199967e9512281e9a53db42c9 (patch)
tree105e8c98ddea1c1e4784a60a5a6410fa416be2de /dom/base/test/test_bug1667316.html
parentInitial commit. (diff)
downloadfirefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz
firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip
Adding upstream version 115.7.0esr.upstream/115.7.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'dom/base/test/test_bug1667316.html')
-rw-r--r--dom/base/test/test_bug1667316.html153
1 files changed, 153 insertions, 0 deletions
diff --git a/dom/base/test/test_bug1667316.html b/dom/base/test/test_bug1667316.html
new file mode 100644
index 0000000000..2770d58dd4
--- /dev/null
+++ b/dom/base/test/test_bug1667316.html
@@ -0,0 +1,153 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=1667316
+-->
+<head>
+ <title>Test for Bug 1667316</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=1667316">Mozilla Bug 1667316</a>
+<p id="display"></p>
+<div id="content" style="display: none"></div>
+<script class="testbody" type="text/javascript">
+
+/** Test for Bug 1667316 **/
+
+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");
+// eslint-disable-next-line @microsoft/sdl/no-insecure-url
+const SAME_ORIGIN = "http://mochi.test:8888" + SJS_PATH;
+// eslint-disable-next-line @microsoft/sdl/no-insecure-url
+const CROSS_ORIGIN = "http://example.com" + SJS_PATH;
+
+SimpleTest.waitForExplicitFinish();
+
+SpecialPowers.pushPrefEnv({"set": [["network.preload", true]]})
+
+
+.then(async () => {
+ await SpecialPowers.spawnChrome([], () => {
+
+let window = this.browsingContext.currentWindowGlobal;
+window.ChannelEventSink = {
+ _classDescription: "WebRequest channel event sink",
+ _classID: Components.ID("115062f8-92f1-11e5-8b7f-08001110f7ec"),
+ _contractID: "@mozilla.org/webrequest/channel-event-sink;1",
+
+ QueryInterface: ChromeUtils.generateQI(["nsIChannelEventSink", "nsIFactory"]),
+
+ init() {
+ Components.manager
+ .QueryInterface(Ci.nsIComponentRegistrar)
+ .registerFactory(
+ this._classID,
+ this._classDescription,
+ this._contractID,
+ this
+ );
+ },
+
+ register() {
+ Services.catMan.addCategoryEntry(
+ "net-channel-event-sinks",
+ this._contractID,
+ this._contractID,
+ false,
+ true
+ );
+ },
+
+ unregister() {
+ Components.manager
+ .QueryInterface(Ci.nsIComponentRegistrar)
+ .unregisterFactory(this._classID, window.ChannelEventSink);
+ Services.catMan.deleteCategoryEntry(
+ "net-channel-event-sinks",
+ this._contractID,
+ false
+ );
+ },
+
+ // nsIChannelEventSink implementation
+ asyncOnChannelRedirect(oldChannel, newChannel, flags, redirectCallback) {
+ // Abort the redirection.
+ redirectCallback.onRedirectVerifyCallback(Cr.NS_ERROR_NO_INTERFACE);
+ },
+
+ // nsIFactory implementation
+ createInstance(iid) {
+ return this.QueryInterface(iid);
+ },
+};
+
+window.ChannelEventSink.init();
+window.ChannelEventSink.register();
+})})
+
+// test cross origin by redirection without CORS
+.then(() => testPreloadEvent(SAME_ORIGIN + "?redirect=crossorigin&statusCode=200&cacheControl=no-cache", false, false))
+
+.catch((err) => ok(false, "promise rejected: " + err))
+.then(async () => {
+ await SpecialPowers.spawnChrome([], () => {
+ let window = this.browsingContext.currentWindowGlobal;
+ window.ChannelEventSink.unregister();
+ delete window.ChannelEventSink;
+ })
+})
+.then(() => SimpleTest.finish());
+
+</script>
+</body>
+</html>