diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /toolkit/components/extensions/test/mochitest/test_ext_streamfilter_processswitch.html | |
parent | Initial commit. (diff) | |
download | firefox-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 'toolkit/components/extensions/test/mochitest/test_ext_streamfilter_processswitch.html')
-rw-r--r-- | toolkit/components/extensions/test/mochitest/test_ext_streamfilter_processswitch.html | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/toolkit/components/extensions/test/mochitest/test_ext_streamfilter_processswitch.html b/toolkit/components/extensions/test/mochitest/test_ext_streamfilter_processswitch.html new file mode 100644 index 0000000000..049178cad0 --- /dev/null +++ b/toolkit/components/extensions/test/mochitest/test_ext_streamfilter_processswitch.html @@ -0,0 +1,76 @@ +<!DOCTYPE html> +<html> +<head> + <title>Test for using filterResponseData to intercept a cross-origin navigation that will involve a process switch with fission</title> + <script src="/tests/SimpleTest/SimpleTest.js"></script> + <script src="/tests/SimpleTest/EventUtils.js"></script> + <script src="/tests/SimpleTest/ExtensionTestUtils.js"></script> + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> +</head> +<body> + +<script type="text/javascript"> +"use strict"; + +const TEST_HOST = "http://example.com/"; +const CROSS_ORIGIN_HOST = "http://example.org/"; +const TEST_PATH = + "tests/toolkit/components/extensions/test/mochitest/file_streamfilter.txt"; + +const TEST_URL = TEST_HOST + TEST_PATH; +const CROSS_ORIGIN_URL = CROSS_ORIGIN_HOST + TEST_PATH; + +add_task(async () => { + const extension = ExtensionTestUtils.loadExtension({ + manifest: { + permissions: ["webRequest", "webRequestBlocking", "<all_urls>"], + }, + + background() { + browser.webRequest.onBeforeRequest.addListener( + ({ requestId }) => { + const filter = browser.webRequest.filterResponseData(requestId); + filter.onerror = () => browser.test.fail( + `Unexpected filterResponseData error: ${filter.error}` + ); + filter.ondata = event => { + filter.write(event.data); + }; + filter.onstop = event => { + filter.write(new TextEncoder().encode(" End")); + filter.close(); + }; + }, + { + urls: [ + "http://example.org/*/file_streamfilter.txt", + ], + }, + ["blocking"] + ); + }, + }); + + await extension.startup(); + + let iframe = document.createElement("iframe"); + iframe.src = TEST_URL; + document.body.appendChild(iframe); + await new Promise(resolve => iframe.addEventListener("load", () => resolve(), {once: true})); + + + iframe.src = CROSS_ORIGIN_URL; + await new Promise(resolve => iframe.addEventListener("load", () => resolve(), {once: true})); + + let content = await SpecialPowers.spawn(iframe, [], async () => { + return this.content.document.body.textContent; + }); + SimpleTest.is(content, "Middle\n End", "Correctly intercepted page content"); + + await extension.unload(); +}); + +</script> + +</body> +</html> |