Source code
Revision control
Copy as Markdown
Other Tools
Test Info: Errors
- This test gets skipped with pattern: os == 'win' && (debug || asan)
- This test failed 9 times in the preceding 30 days. quicksearch this test
- 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">
<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"/>
</head>
<body>
<script>
"use strict";
function getExtension() {
return ExtensionTestUtils.loadExtension({
manifest: {
"browser_specific_settings": {
"gecko": {
"id": "redirect-to-jar@mochi.test",
},
},
"permissions": [
"webRequest",
"webRequestBlocking",
"<all_urls>",
],
"web_accessible_resources": [
"finished.html",
],
},
useAddonManager: "temporary",
files: {
"finished.html": `
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
</head>
<body>
<h1>redirected!</h1>
</body>
</html>
`,
},
background: async () => {
let redirectUrl = browser.runtime.getURL("finished.html");
browser.webRequest.onBeforeRequest.addListener(() => {
return {redirectUrl};
}, {urls: ["*://*/intercept*"]}, ["blocking"]);
let code = `new Promise(resolve => {
var s = document.createElement('iframe');
s.src = "/intercept?r=" + Math.random();
s.onload = async () => {
let url = await window.wrappedJSObject.SpecialPowers.spawn(s, [], () => content.location.href );
resolve(['loaded', url]);
}
s.onerror = () => resolve(['error']);
document.documentElement.appendChild(s);
});`;
async function testSubFrameResource(tabId, code) {
let [result] = await browser.tabs.executeScript(tabId, { code });
return result;
}
let tab = await browser.tabs.create({url: "http://mochi.test:8888/tests/toolkit/components/extensions/test/mochitest/file_sample.html"});
let result = await testSubFrameResource(tab.id, code);
browser.test.assertEq("loaded", result[0], "frame 1 loaded");
browser.test.assertEq(redirectUrl, result[1], "frame 1 redirected");
result = await testSubFrameResource(tab.id, code);
browser.test.assertEq("loaded", result[0], "frame 2 loaded");
browser.test.assertEq(redirectUrl, result[1], "frame 2 redirected");
await browser.tabs.remove(tab.id);
browser.test.sendMessage("requestsCompleted");
},
});
}
add_task(async function test_redirect_to_jar() {
let extension = getExtension();
await extension.startup();
await extension.awaitMessage("requestsCompleted");
await extension.unload();
});
</script>
</body>
</html>