Source code
Revision control
Copy as Markdown
Other Tools
Test Info:
<!DOCTYPE HTML>
<html>
<head>
<title>Test for simple WebExtension</title>
<script type="text/javascript" src="head.js"></script>
</head>
<body>
<script type="text/javascript">
"use strict";
const {webrequest_test} = ChromeUtils.importESModule(
SimpleTest.getTestFileURL("webrequest_test.sys.mjs")
);
let {testFetch, testXHR} = webrequest_test;
// Here we test that any requests originating from a system principal are not
// accessible through WebRequest. text_ext_webrequest_background_events tests
// non-system principal requests.
let testExtension = {
manifest: {
permissions: [
"webRequest",
"<all_urls>",
],
},
background() {
let eventNames = [
"onBeforeRequest",
"onBeforeSendHeaders",
"onSendHeaders",
"onHeadersReceived",
"onResponseStarted",
"onCompleted",
];
function listener(name) {
// If we get anything, we failed. Removing the system principal check
// in ext-webrequest triggers this failure.
browser.test.fail(`received ${name}`);
}
for (let name of eventNames) {
browser.webRequest[name].addListener(
listener.bind(null, name),
);
}
},
};
add_task(async function test_webRequest_chromeworker_events() {
let extension = ExtensionTestUtils.loadExtension(testExtension);
await extension.startup();
await new Promise(resolve => {
let worker = new ChromeWorker("webrequest_chrome.worker.js");
worker.onmessage = () => {
ok("chrome worker fetch finished");
resolve();
};
worker.postMessage("go");
});
await extension.unload();
});
add_task(async function test_webRequest_chromepage_events() {
let extension = ExtensionTestUtils.loadExtension(testExtension);
await extension.startup();
await new Promise(resolve => {
ok("test page loaded");
resolve();
});
});
await extension.unload();
});
add_task(async function test_webRequest_jsm_events() {
let extension = ExtensionTestUtils.loadExtension(testExtension);
await extension.startup();
ok("fetch page loaded");
});
ok("xhr page loaded");
});
await extension.unload();
});
</script>
</body>
</html>