Source code

Revision control

Copy as Markdown

Other Tools

Test Info:

<!DOCTYPE HTML>
<html>
<head>
<title>Script Filenames Test</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" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<script type="text/javascript">
"use strict";
add_task(async function test_tabs_executeScript() {
let validFileName = "script.js";
let invalidFileName = "script.xyz";
async function background() {
await browser.tabs.executeScript({ file: "script.js" });
await browser.test.assertRejects(
browser.tabs.executeScript({ file: "script.xyz" }),
Error,
"invalid filename does not execute"
);
browser.test.notifyPass("execute-script");
}
let extension = ExtensionTestUtils.loadExtension({
manifest: {
permissions: ["<all_urls>"],
},
background,
files: {
[validFileName]: function contentScript1() {
browser.test.sendMessage("content-script-loaded");
},
[invalidFileName]: function contentScript2() {
browser.test.fail("this script should not be loaded");
},
},
});
let tab = await AppTestDelegate.openNewForegroundTab(
window,
true
);
await extension.startup();
await extension.awaitMessage("content-script-loaded");
await extension.awaitFinish("execute-script");
await extension.unload();
await AppTestDelegate.removeTab(window, tab);
});
</script>
</body>
</html>