Source code

Revision control

Copy as Markdown

Other Tools

Test Info:

<title>Bug 1450965: Skip Cors Check for Early WebExtention Redirects </title>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<script src="/tests/SimpleTest/ExtensionTestUtils.js"></script>
<script type="text/javascript" src="head.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
<script type="text/javascript">
"use strict";
/* Description of the test:
* We try to Check if a WebExtention can redirect a request and bypass CORS
* We're redirecting a fetch request in onBeforeRequest
* which should not be blocked, even though we do not have
* the CORS information yet.
const WIN_URL =
add_task(async function test_webRequest_redirect_cors_bypass() {
// disable third-party storage isolation so the test works as expected
await SpecialPowers.pushPrefEnv({
set: [["privacy.partition.always_partition_third_party_non_cookie_storage", false]],
let extension = ExtensionTestUtils.loadExtension({
manifest: {
permissions: [
background() {
browser.webRequest.onBeforeRequest.addListener((details) => {
if (details.url.includes("file_cors_blocked.txt")) {
// File_cors_blocked does not need to exist, because we're redirecting anyway.
const testPath = "";
let redirectUrl = `https://${testPath}/file_sample.txt`;
// If the WebExtion cant bypass CORS, the fetch will throw a CORS-Exception
// because we do not have the CORS header yet for 'file-cors-blocked.txt'
return {redirectUrl};
}, {urls: ["<all_urls>"]}, ["blocking"]);
await extension.startup();
let win =;
// Creating a message channel to the new tab.
const channel = new BroadcastChannel("test_bus");
await new Promise((resolve) => {
channel.onmessage = async function(fetch_result) {
// Fetch result data will either be the text content of file_sample.txt -> 'Sample'
// or a network-Error.
// In case it's 'Sample' the redirect did happen correctly.
ok( == "Sample", "Cors was Bypassed");
await extension.unload();