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
- Manifest: toolkit/components/extensions/test/xpcshell/xpcshell-serviceworker.toml
"use strict";
const server = createHttpServer();
server.registerDirectory("/data/", do_get_file("data"));
// ExtensionContent.sys.mjs needs to know when it's running from xpcshell, to use
// the right timeout for content scripts executed at document_idle.
ExtensionTestUtils.mockAppInfo();
Services.prefs.setBoolPref("extensions.manifestV3.enabled", true);
const makeExtension = ({ manifest: manifestProps, ...otherProps }) => {
return ExtensionTestUtils.loadExtension({
manifest: {
manifest_version: 3,
permissions: ["scripting"],
granted_host_permissions: true,
...manifestProps,
},
temporarilyInstalled: true,
...otherProps,
});
};
add_task(async function test_scripting_updateContentScripts() {
let extension = makeExtension({
async background() {
const script = {
id: "a-script",
js: ["script-1.js"],
persistAcrossSessions: false,
};
await browser.scripting.registerContentScripts([script]);
await browser.scripting.updateContentScripts([
{
id: script.id,
js: ["script-2.js"],
},
]);
let scripts = await browser.scripting.getRegisteredContentScripts();
browser.test.assertEq(1, scripts.length, "expected 1 registered script");
browser.test.sendMessage("background-ready");
},
files: {
"script-1.js": () => {
browser.test.fail("script-1 should not be executed");
},
"script-2.js": () => {
browser.test.sendMessage(
`script-2 executed in ${location.pathname.split("/").pop()}`
);
},
},
});
await extension.startup();
await extension.awaitMessage("background-ready");
let contentPage = await ExtensionTestUtils.loadContentPage(
`${BASE_URL}/file_sample.html`
);
await extension.awaitMessage("script-2 executed in file_sample.html");
await extension.unload();
await contentPage.close();
});
add_task(
async function test_scripting_updateContentScripts_non_default_values() {
let extension = makeExtension({
async background() {
const script = {
id: "a-script",
allFrames: true,
matchOriginAsFallback: true,
runAt: "document_start",
world: "MAIN",
persistAcrossSessions: false,
css: ["style.js"],
js: ["script.js"],
};
await browser.scripting.registerContentScripts([script]);
// This should not modify the previously registered script.
await browser.scripting.updateContentScripts([{ id: script.id }]);
let scripts = await browser.scripting.getRegisteredContentScripts();
browser.test.assertEq(
JSON.stringify([script]),
JSON.stringify(scripts),
"expected unmodified registered script"
);
browser.test.sendMessage("background-done");
},
files: {
"script.js": "",
"style.css": "",
},
});
await extension.startup();
await extension.awaitMessage("background-done");
await extension.unload();
}
);