Source code

Revision control

Other Tools

Test Info:

  • This test ran 314 times in the preceding 7 days with an average run time of 0.46 secs.
<meta charset="utf-8">
<title>Tabs executeScript noCreate 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"/>
<script type="text/javascript">
"use strict";
add_task(async function testExecuteScriptAtOnUpdated() {
const URL = BASE + "file_iframe_document.html";
// This is a regression test for bug 1325830.
// The bug (executeScript not completing any more) occurred when executeScript
// was called early at the onUpdated event, unless the tabs.create method is
// called. So this test does not use tabs.create to open new tabs.
// Note that if this test is run together with other tests that do call
// tabs.create, then this test case does not properly test the conditions of
// the regression any more. To verify that the regression has been resolved,
// this test must be run in isolation.
function background() {
// Using variables to prevent listeners from running more than once, instead
// of removing the listener. This is to minimize any IPC, since the bug that
// is being tested is sensitive to timing.
let ignore = false;
let url;
browser.tabs.onUpdated.addListener((tabId, changeInfo, tab) => {
if (url && changeInfo.status === "loading" && tab.url === url && !ignore) {
ignore = true;
browser.tabs.executeScript(tabId, {
code: "document.URL",
}).then(results => {
browser.test.assertEq(url, results[0], "Content script should run");
}, error => {`Unexpected error: ${error} :: ${error.stack}`);
// (running this log call after executeScript to minimize IPC between
// onUpdated and executeScript.)
browser.test.log(`Found expected navigation to ${url}`);
} else {
// The bug occurs when executeScript is called before a tab is
// initialized.
browser.tabs.executeScript(tabId, {code: ""});
browser.test.onMessage.addListener(testUrl => {
url = testUrl;
const extension = ExtensionTestUtils.loadExtension({
manifest: {
"permissions": ["http://mochi.test/", "tabs"],
await extension.startup();
await extension.awaitMessage("open-test-tab");
const tab =;
await extension.awaitFinish("executeScript-at-onUpdated");
await extension.unload();