Source code
Revision control
Copy as Markdown
Other Tools
Test Info: Warnings
-
CI results over the last 21 days32,234Runs100%Pass0Failures0Timeouts0Crashes1,898Skips
Scheduled runs skipped per day (up to 6.4%) Nov 12Dec 2 - This test gets skipped with pattern: http2 OR http3
- Manifest: toolkit/components/extensions/test/mochitest/mochitest-remote.toml includes toolkit/components/extensions/test/mochitest/mochitest-common.toml
- Manifest: toolkit/components/extensions/test/mochitest/mochitest.toml includes toolkit/components/extensions/test/mochitest/mochitest-common.toml
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>DNR with upgradeScheme action</title>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<script type="text/javascript" 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">
</head>
<body>
<script>
"use strict";
// This test is not a xpcshell test, because we want to test upgrades to https,
/* eslint-disable sdl/no-insecure-url */
const URLS = {
MATCHING_HTTP_URL: "http://example.com/tests/toolkit/components/extensions/test/mochitest/file_sample.txt",
UPGRADED_HTTPS_URL: "https://example.com/tests/toolkit/components/extensions/test/mochitest/file_sample.txt",
NON_MATCHING_HTTP_URL: "http://example.net/tests/toolkit/components/extensions/test/mochitest/file_sample.txt"
};
/* eslint-enable sdl/no-insecure-url */
add_setup(async () => {
await SpecialPowers.pushPrefEnv({
set: [
["extensions.dnr.enabled", true],
],
});
});
// Tests that the upgradeScheme action works as expected:
// - http should be upgraded to https
// - after the https upgrade the request should happen instead of being stuck
// in a upgrade redirect loop.
add_task(async function upgradeScheme_with_dnr() {
async function background({ MATCHING_HTTP_URL, UPGRADED_HTTPS_URL, NON_MATCHING_HTTP_URL }) {
await browser.declarativeNetRequest.updateSessionRules({
addRules: [{ id: 1, condition: { requestDomains: ["example.com"] }, action: { type: "upgradeScheme" } }],
});
let sanityCheckResponse = await fetch(NON_MATCHING_HTTP_URL);
browser.test.assertEq(
NON_MATCHING_HTTP_URL,
sanityCheckResponse.url,
"non-matching request should not be upgraded"
);
let res = await fetch(MATCHING_HTTP_URL);
browser.test.assertEq(
UPGRADED_HTTPS_URL,
res.url,
"upgradeScheme should have upgraded to https"
);
// Server adds "Access-Control-Allow-Origin: *" to file_sample.txt, so
// we should be able to read the response despite no host_permissions.
browser.test.assertEq("Sample", await res.text(), "read body with CORS");
browser.test.sendMessage("dnr_registered");
}
let extension = ExtensionTestUtils.loadExtension({
background: `(${background})(${JSON.stringify(URLS)})`,
manifest: {
manifest_version: 3,
// Note: host_permissions missing. upgradeScheme should not need it.
permissions: ["declarativeNetRequest"],
},
allowInsecureRequests: true,
});
await extension.startup();
await extension.awaitMessage("dnr_registered");
// Requests made from outside the extension should be upgraded by its DNR
// rule too.
const iframe = document.createElement("iframe");
const iframeLoaded = waitForLoad(iframe);
iframe.src = URLS.NON_MATCHING_HTTP_URL;
document.body.appendChild(iframe);
await iframeLoaded;
const { sanityCheckResult, result } = await SpecialPowers.spawn(
iframe,
[URLS],
async ({ MATCHING_HTTP_URL, NON_MATCHING_HTTP_URL }) => {
const sanityCheckResponse = await content.fetch(NON_MATCHING_HTTP_URL);
const sanityCheckResult = {
url: sanityCheckResponse.url,
status: sanityCheckResponse.status,
};
const response = await content.fetch(MATCHING_HTTP_URL);
const result = {
url: response.url,
status: response.status,
};
// Verify that the body can be read, just in case.
await Promise.all([sanityCheckResponse.text(), response.text()]);
return { sanityCheckResult, result };
}
);
is(result.status, 200, "Correct HTTP status");
is(
result.url,
URLS.UPGRADED_HTTPS_URL,
"upgradeScheme action upgraded HTTP to HTTPS"
);
is(sanityCheckResult.status, 200, "Correct HTTP status");
is(
sanityCheckResult.url,
URLS.NON_MATCHING_HTTP_URL,
"Non-matching request not upgraded to HTTPS"
);
await extension.unload();
});
</script>
</body>
</html>