Source code

Revision control

Copy as Markdown

Other Tools

Test Info: Warnings

<title>Test for content script</title>
<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"/>
<script type="text/javascript">
"use strict";
add_task(async function test_contentscript() {
function background() {
browser.test.onMessage.addListener(async url => {
let tab = await browser.tabs.create({url});
let executed = true;
try {
await browser.tabs.executeScript(, {code: "true;"});
} catch (e) {
executed = false;
await browser.tabs.remove([]);
browser.test.sendMessage("executed", executed);
let extensionData = {
manifest: {
permissions: ["<all_urls>"],
let extension = ExtensionTestUtils.loadExtension(extensionData);
await extension.startup();
let result = await extension.awaitMessage("executed");
is(result, true, "Content script can be run in a page without mozAddonManager");
await SpecialPowers.pushPrefEnv({
set: [["extensions.webapi.testing", true]],
result = await extension.awaitMessage("executed");
is(result, false, "Content script cannot be run in a page with mozAddonManager");
await extension.unload();