Source code
Revision control
Copy as Markdown
Other Tools
Test Info: Warnings
- This test gets skipped with pattern: os == 'win' && socketprocess_networking && fission OR os == 'mac' && socketprocess_networking && fission OR os == 'mac' && debug OR os == 'linux' && socketprocess_networking
- Manifest: toolkit/components/extensions/test/xpcshell/xpcshell-remote.toml includes toolkit/components/extensions/test/xpcshell/xpcshell-common.toml
- Manifest: toolkit/components/extensions/test/xpcshell/xpcshell.toml includes toolkit/components/extensions/test/xpcshell/xpcshell-common.toml
"use strict";
const server = createHttpServer({ hosts: ["example.com"] });
server.registerPathHandler("/dummy", (request, response) => {
response.setStatusLine(request.httpVersion, 200, "OK");
response.write("ok");
});
add_task(async function test_webRequest_viewsource() {
function background(serverPort) {
browser.proxy.onRequest.addListener(
details => {
browser.test.assertTrue(
true,
"viewsource protocol worked in proxy request"
);
browser.test.sendMessage("proxied");
}
},
{ urls: ["<all_urls>"] }
);
browser.webRequest.onBeforeRequest.addListener(
details => {
browser.test.assertEq(
details.url,
"viewsource protocol worked in webRequest"
);
browser.test.sendMessage("viewed");
},
["blocking"]
);
browser.webRequest.onBeforeRequest.addListener(
details => {
browser.test.assertEq(
details.url,
"viewsource protocol worked in webRequest"
);
browser.test.sendMessage("redirected");
return { cancel: true };
},
["blocking"]
);
browser.webRequest.onCompleted.addListener(
() => {
// If cancel fails we get onCompleted.
browser.test.fail("onCompleted received");
},
);
browser.webRequest.onErrorOccurred.addListener(
details => {
browser.test.assertEq(
details.error,
"NS_ERROR_ABORT",
"request cancelled"
);
browser.test.sendMessage("cancelled");
},
);
}
let extension = ExtensionTestUtils.loadExtension({
manifest: {
permissions: ["proxy", "webRequest", "webRequestBlocking", "<all_urls>"],
},
background: `(${background})(${server.identity.primaryPort})`,
});
await extension.startup();
let contentPage = await ExtensionTestUtils.loadContentPage(
);
await Promise.all([
extension.awaitMessage("proxied"),
extension.awaitMessage("viewed"),
extension.awaitMessage("redirected"),
extension.awaitMessage("cancelled"),
]);
await contentPage.close();
await extension.unload();
});