Bug 1596918: Part 4c - Fix callers which depend on document lifecycle changes. r=mccr8

ContentTask tasks have a different lifetime than SpecialPowers tasks, with the
former being tied to the lifetime of a message manager and the latter tied to
the lifetime of a window global. That means that existing ContentTask callers
which expect to be able to register load listeners before the creation of a
window global, or which expect to persist after a page has navigated, won't
work as SpecialPowers tasks.

Since those sorts of tasks are not really resilient in the face of Fission,
they should really be written to work differently, but this patch mostly just
reverts them to using ContentTask for the time being.

Differential Revision: https://phabricator.services.mozilla.com/D53744

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Kris Maglione 2019-12-13 20:36:36 +00:00
parent 4c36a24ea9
commit 0b1a146519
60 changed files with 209 additions and 294 deletions

View File

@ -18,14 +18,11 @@ async function requestNotificationPermission(browser) {
}
async function requestCameraPermission(browser) {
return SpecialPowers.spawn(browser, [], () => {
return new Promise(resolve => {
content.navigator.mediaDevices
.getUserMedia({ video: true, fake: true })
.catch(resolve(false))
.then(resolve(true));
});
});
return SpecialPowers.spawn(browser, [], () =>
content.navigator.mediaDevices
.getUserMedia({ video: true, fake: true })
.then(() => true, () => false)
);
}
add_task(async function test_fullscreen_closes_permissionui_prompt() {
@ -145,7 +142,7 @@ add_task(async function test_permission_prompt_closes_fullscreen() {
let fullScreenExit = waitForFullScreenState(browser, false);
info("Requesting notification permission");
requestNotificationPermission(browser);
requestNotificationPermission(browser).catch(() => {});
await popupShown;
info("Waiting for full-screen exit");

View File

@ -52,14 +52,10 @@ async function openNewTab(aWindow, aExpectedURL) {
false,
aExpectedURL
);
let alreadyLoaded = await SpecialPowers.spawn(
browser,
[aExpectedURL],
url => {
let doc = content.document;
return doc && doc.readyState === "complete" && doc.location.href == url;
}
);
let alreadyLoaded = await ContentTask.spawn(browser, aExpectedURL, url => {
let doc = content.document;
return doc && doc.readyState === "complete" && doc.location.href == url;
});
if (!alreadyLoaded) {
await loadPromise;
}

View File

@ -71,14 +71,10 @@ async function openNewTab(aWindow, aExpectedURL) {
false,
aExpectedURL
);
let alreadyLoaded = await SpecialPowers.spawn(
browser,
[aExpectedURL],
url => {
let doc = content.document;
return doc && doc.readyState === "complete" && doc.location.href == url;
}
);
let alreadyLoaded = await ContentTask.spawn(browser, aExpectedURL, url => {
let doc = content.document;
return doc && doc.readyState === "complete" && doc.location.href == url;
});
if (!alreadyLoaded) {
await loadPromise;
}

View File

@ -24,9 +24,7 @@ function getParentTabState(aTab) {
}
function getChildTabState(aTab) {
return SpecialPowers.spawn(aTab.linkedBrowser, [], async function() {
return docShell.isActive;
});
return ContentTask.spawn(aTab.linkedBrowser, null, () => docShell.isActive);
}
function checkState(parentSide, childSide, value, message) {

View File

@ -41,7 +41,7 @@ add_task(async function test_opening_blocked_popups() {
ok(notification, "Should have notification.");
await SpecialPowers.spawn(tab.linkedBrowser, [baseURL], async function(uri) {
await ContentTask.spawn(tab.linkedBrowser, baseURL, async function(uri) {
let iframe = content.document.createElement("iframe");
let pageHideHappened = ContentTaskUtils.waitForEvent(
this,
@ -59,7 +59,7 @@ add_task(async function test_opening_blocked_popups() {
ok(notification, "Should still have notification");
// Now navigate the subframe.
await SpecialPowers.spawn(tab.linkedBrowser, [], async function() {
await ContentTask.spawn(tab.linkedBrowser, null, async function() {
let pageHideHappened = ContentTaskUtils.waitForEvent(
this,
"pagehide",

View File

@ -276,9 +276,9 @@ function expectObserverCalledOnClose(
}
function promiseMessage(aMessage, aAction, aCount = 1) {
let promise = SpecialPowers.spawn(
let promise = ContentTask.spawn(
gBrowser.selectedBrowser,
[[aMessage, aCount]],
[aMessage, aCount],
async function([expectedMessage, expectedCount]) {
return new Promise(resolve => {
function listenForMessage({ data }) {
@ -509,10 +509,8 @@ async function reloadAndAssertClosedStreams() {
await disableObserverVerification();
let loadedPromise = BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser);
await SpecialPowers.spawn(
gBrowser.selectedBrowser,
[],
"() => content.location.reload()"
await ContentTask.spawn(gBrowser.selectedBrowser, null, () =>
content.location.reload()
);
await loadedPromise;

View File

@ -23,9 +23,9 @@ add_task(async function test_sort_order_persisted() {
url: "about:logins",
},
async function(browser) {
await SpecialPowers.spawn(
await ContentTask.spawn(
browser,
[[TEST_LOGIN1, TEST_LOGIN2]],
[TEST_LOGIN1, TEST_LOGIN2],
async function([testLogin1, testLogin2]) {
let loginList = Cu.waiveXrays(
content.document.querySelector("login-list")
@ -65,9 +65,7 @@ add_task(async function test_sort_order_persisted() {
url: "about:logins",
},
async function(browser) {
await SpecialPowers.spawn(browser, [TEST_LOGIN1], async function(
testLogin1
) {
await ContentTask.spawn(browser, TEST_LOGIN1, async function(testLogin1) {
let loginList = Cu.waiveXrays(
content.document.querySelector("login-list")
);

View File

@ -303,7 +303,7 @@ async function focusButtonAndPressKey(key, elem, modifiers) {
}
var awaitBrowserLoaded = browser =>
SpecialPowers.spawn(browser, [], () => {
ContentTask.spawn(browser, null, () => {
if (
content.document.readyState !== "complete" ||
content.document.documentURI === "about:blank"

View File

@ -38,9 +38,9 @@ async function test_trailhead_branch(
);
let browser = tab.linkedBrowser;
await SpecialPowers.spawn(
await ContentTask.spawn(
browser,
[{ expectedSelectors, branchName, unexpectedSelectors }],
{ expectedSelectors, branchName, unexpectedSelectors },
async ({
expectedSelectors: expected,
branchName: branch,

View File

@ -15,9 +15,9 @@ async function checkNewtabLoads(selector, message) {
await waitForPreloaded(browser);
// check what the content task thinks has been loaded.
let found = await SpecialPowers.spawn(
let found = await ContentTask.spawn(
browser,
[selector],
selector,
arg => content.document.querySelector(arg) !== null
);
ok(found, message);

View File

@ -47,9 +47,9 @@ async function clearHistoryAndBookmarks() {
* not necessarily have had all its javascript/render logic executed.
*/
async function waitForPreloaded(browser) {
let readyState = await SpecialPowers.spawn(
let readyState = await ContentTask.spawn(
browser,
[],
null,
() => content.document.readyState
);
if (readyState !== "complete") {

View File

@ -1986,9 +1986,9 @@ async function testKeyEvent(aTab, aTestCase) {
let allKeyEventPromises = [];
for (let testEvent of testEvents) {
let keyEventPromise = SpecialPowers.spawn(
let keyEventPromise = ContentTask.spawn(
aTab.linkedBrowser,
[{ testEvent, result: aTestCase.result, kSameKeyCodeAndCharCodeValue }],
{ testEvent, result: aTestCase.result, kSameKeyCodeAndCharCodeValue },
async aInput => {
function verifyKeyboardEvent(
aEvent,
@ -2217,9 +2217,9 @@ add_task(async function runTestForSuppressModifierKeys() {
for (let eventType of ["keydown", "keyup"]) {
for (let modifierKey of ["Alt", "Shift", "Control"]) {
let testPromise = SpecialPowers.spawn(
let testPromise = ContentTask.spawn(
tab.linkedBrowser,
[eventType],
eventType,
async aEventType => {
let inputBox = content.document.getElementById("test");

View File

@ -38,7 +38,7 @@ add_task(async function test() {
await loadedPromise;
await SpecialPowers.spawn(browser, [], function({}) {
await SpecialPowers.spawn(browser, [], function() {
// eslint-disable-line
// the data: URI inherits the CSP and the inline script needs to be blocked
is(
@ -56,7 +56,7 @@ add_task(async function test() {
await promiseTabRestored(tab);
browser = tab.linkedBrowser;
await SpecialPowers.spawn(browser, [], function({}) {
await SpecialPowers.spawn(browser, [], function() {
// eslint-disable-line
// the data: URI should be restored including the inherited CSP and the
// inline script should be blocked.

View File

@ -27,8 +27,8 @@ add_task(async function test_frametree() {
is(await countNonDynamicFrames(browser), 2, "two non-dynamic child frames");
// Go back in history.
let pageShowPromise = SpecialPowers.spawn(browser, [], async () => {
return ContentTaskUtils.waitForEvent(this, "pageshow", true);
let pageShowPromise = ContentTask.spawn(browser, null, async () => {
await ContentTaskUtils.waitForEvent(this, "pageshow", true);
});
browser.goBack();
await pageShowPromise;

View File

@ -41,7 +41,7 @@ add_task(async function() {
// Open a browser, configure it to cause OOM.
let newTab = BrowserTestUtils.addTab(gBrowser, "about:robots");
let browser = newTab.linkedBrowser;
await SpecialPowers.spawn(browser, [], frameScript);
await ContentTask.spawn(browser, null, frameScript);
let promiseReported = new Promise(resolve => {
browser.messageManager.addMessageListener("SessionStore:error", resolve);

View File

@ -82,8 +82,8 @@ add_task(async function test_pageshow() {
await promiseBrowserLoaded(browser);
// Wait until shistory changes.
let pageShowPromise = SpecialPowers.spawn(browser, [], async () => {
return ContentTaskUtils.waitForEvent(this, "pageshow", true);
let pageShowPromise = ContentTask.spawn(browser, null, async () => {
await ContentTaskUtils.waitForEvent(this, "pageshow", true);
});
// Go back to the previous url which is loaded from the bfcache.

View File

@ -52,7 +52,7 @@ add_task(async function() {
for (let i = 0; i < 4; i++) {
let browser = win2.gBrowser.tabs[i].linkedBrowser;
await SpecialPowers.spawn(browser, [{ expectedId: i + 1 }], async function(
await ContentTask.spawn(browser, { expectedId: i + 1 }, async function(
args
) {
Assert.equal(
@ -129,9 +129,7 @@ add_task(async function() {
for (let i = 0; i < 2; i++) {
let browser = win2.gBrowser.tabs[i].linkedBrowser;
await SpecialPowers.spawn(browser, [{ expectedId: i }], async function(
args
) {
await ContentTask.spawn(browser, { expectedId: i }, async function(args) {
Assert.equal(
docShell.getOriginAttributes().userContextId,
args.expectedId,

View File

@ -278,7 +278,7 @@ function promiseCheckChildNoFocusedElement(browser) {
return null;
}
return SpecialPowers.spawn(browser, [], async function() {
return ContentTask.spawn(browser, null, async function() {
Assert.equal(
Services.focus.focusedElement,
null,

View File

@ -13,7 +13,7 @@ add_task(async function test_ignoreFragment() {
switchTab("about:home#1", true);
switchTab("about:mozilla", true);
let hashChangePromise = SpecialPowers.spawn(
let hashChangePromise = ContentTask.spawn(
tabRefAboutHome.linkedBrowser,
[],
async function() {

View File

@ -72,7 +72,7 @@ add_task(async function moving_works() {
return ContentTaskUtils.waitForCondition(() => {
return content.document.readyState == "complete";
});
});
}).catch(Cu.reportError);
ok(true, "Managed to open a tab in the original window still.");

View File

@ -726,9 +726,9 @@ function openContextMenuAndGetAllItems(inspector, options) {
*/
async function waitUntilVisitedState(tab, selectors) {
await asyncWaitUntil(async () => {
const hasVisitedState = await SpecialPowers.spawn(
const hasVisitedState = await ContentTask.spawn(
tab.linkedBrowser,
[selectors],
selectors,
args => {
const NS_EVENT_STATE_VISITED = 1 << 24;

View File

@ -194,7 +194,7 @@ function addRDMTask(rdmUrl, rdmTask, includeBrowserEmbeddedUI) {
}
function spawnViewportTask(ui, args, task) {
return SpecialPowers.spawn(ui.getViewportBrowser(), [args], task);
return ContentTask.spawn(ui.getViewportBrowser(), args, task);
}
function waitForFrameLoad(ui, targetURL) {
@ -442,7 +442,7 @@ const selectNetworkThrottling = (ui, value) =>
]);
function getSessionHistory(browser) {
return SpecialPowers.spawn(browser, [], async function() {
return ContentTask.spawn(browser, null, function() {
/* eslint-disable no-undef */
const { SessionHistory } = ChromeUtils.import(
"resource://gre/modules/sessionstore/SessionHistory.jsm"

View File

@ -75,7 +75,7 @@ async function testNewWindow(client, win) {
async function testFocusFirst(client) {
const tab = window.gBrowser.selectedTab;
await SpecialPowers.spawn(tab.linkedBrowser, [], async function() {
await ContentTask.spawn(tab.linkedBrowser, null, async function() {
const onFocus = new Promise(resolve => {
content.addEventListener("focus", resolve, { once: true });
});

View File

@ -1351,9 +1351,9 @@ async function selectFrame(dbg, frame) {
async function pauseDebugger(dbg) {
info("Waiting for debugger to pause");
const onPaused = waitForPaused(dbg);
SpecialPowers.spawn(gBrowser.selectedBrowser, [], async function() {
SpecialPowers.spawn(gBrowser.selectedBrowser, [], function() {
content.wrappedJSObject.firstCall();
});
}).catch(() => {});
await onPaused;
}

View File

@ -2,7 +2,7 @@ add_task(async function test() {
const uris = [undefined, "about:blank"];
function checkContentProcess(newBrowser, uri) {
return SpecialPowers.spawn(newBrowser, [uri], async function(uri) {
return ContentTask.spawn(newBrowser, [uri], async function(uri) {
var prin = content.document.nodePrincipal;
Assert.notEqual(
prin,

View File

@ -37,7 +37,7 @@ function test() {
gBrowser.selectedTab = newTab;
newBrowser = gBrowser.getBrowserForTab(newTab);
SpecialPowers.spawn(newBrowser, [], task).then(() => {
ContentTask.spawn(newBrowser, null, task).then(() => {
gBrowser.removeCurrentTab();
finish();
});

View File

@ -16,7 +16,7 @@ add_task(async function test() {
{ gBrowser, url: "about:blank" },
async function(browser) {
if (!SpecialPowers.getBoolPref("fission.sessionHistoryInParent")) {
await SpecialPowers.spawn(browser, [URL], async function(URL) {
await ContentTask.spawn(browser, URL, async function(URL) {
let history = docShell.QueryInterface(Ci.nsIWebNavigation)
.sessionHistory;
let count = 0;
@ -29,22 +29,16 @@ add_task(async function test() {
let listener = {
OnHistoryNewEntry(aNewURI) {
if (aNewURI.spec == URL && 5 == ++count) {
docShell.chromeEventHandler.addEventListener(
addEventListener(
"load",
function onLoad() {
docShell.chromeEventHandler.removeEventListener(
"load",
onLoad,
true
);
Assert.ok(
history.index < history.count,
"history.index is valid"
);
testDone.resolve();
},
true
{ capture: true, once: true }
);
history.legacySHistory.removeSHistoryListener(listener);
@ -98,9 +92,9 @@ add_task(async function test() {
async OnHistoryNewEntry(aNewURI) {
if (aNewURI.spec == URL && 5 == ++count) {
history.removeSHistoryListener(listener);
await SpecialPowers.spawn(browser, [], async () => {
let promise = new Promise(resolve => {
docShell.chromeEventHandler.addEventListener(
await ContentTask.spawn(browser, null, () => {
return new Promise(resolve => {
addEventListener(
"load",
evt => {
let history = docShell.QueryInterface(Ci.nsIWebNavigation)
@ -113,10 +107,9 @@ add_task(async function test() {
},
{ capture: true, once: true }
);
});
content.location.reload();
await promise;
content.location.reload();
});
});
testDone.resolve();
}

View File

@ -23,9 +23,9 @@ function test() {
let taskFinished;
let tab = BrowserTestUtils.addTab(gBrowser, doc, {}, tab => {
taskFinished = SpecialPowers.spawn(tab.linkedBrowser, [], () => {
taskFinished = ContentTask.spawn(tab.linkedBrowser, null, () => {
return new Promise(resolve => {
docShell.chromeEventHandler.addEventListener(
addEventListener(
"load",
function() {
// The main page has loaded. Now wait for the iframe to load.

View File

@ -203,7 +203,7 @@ add_task(async function test_swap_frameloader_pagevisibility_events() {
// Wait for that initial browser to show its pageshow event if it hasn't
// happened so that we don't confuse it with the other expected events.
await SpecialPowers.spawn(emptyBrowser, [], async () => {
await ContentTask.spawn(emptyBrowser, null, async () => {
if (content.document.visibilityState === "hidden") {
info("waiting for hidden emptyBrowser to pageshow");
await ContentTaskUtils.waitForEvent(content, "pageshow", {});

View File

@ -16,7 +16,7 @@ function expectNotAllowedError(aResult) {
}
function promiseMakeCredential(tab) {
return SpecialPowers.spawn(tab.linkedBrowser, [], async function() {
return ContentTask.spawn(tab.linkedBrowser, null, async function() {
const cose_alg_ECDSA_w_SHA256 = -7;
let publicKey = {
@ -37,7 +37,7 @@ function promiseMakeCredential(tab) {
}
function promiseGetAssertion(tab) {
return SpecialPowers.spawn(tab.linkedBrowser, [], async function() {
return ContentTask.spawn(tab.linkedBrowser, null, async function() {
let newCredential = {
type: "public-key",
id: content.crypto.getRandomValues(new Uint8Array(16)),

View File

@ -3,27 +3,16 @@ add_task(async function() {
let tab = BrowserTestUtils.addTab(gBrowser);
let uri = "data:text/html;charset=utf-8,<html/>";
let eventPromise = SpecialPowers.spawn(tab.linkedBrowser, [], function() {
const { PromiseUtils } = ChromeUtils.import(
"resource://gre/modules/PromiseUtils.jsm"
);
let deferred = PromiseUtils.defer();
let listener = event => {
docShell.chromeEventHandler.removeEventListener(
let eventPromise = ContentTask.spawn(tab.linkedBrowser, null, function() {
return new Promise(resolve => {
addEventListener(
"DOMDocElementInserted",
listener,
true
event => resolve(event.target.documentURIObject.spec),
{
once: true,
}
);
deferred.resolve(event.target.documentURIObject.spec);
};
docShell.chromeEventHandler.addEventListener(
"DOMDocElementInserted",
listener,
true
);
return deferred.promise;
});
});
BrowserTestUtils.loadURI(tab.linkedBrowser, uri);

View File

@ -23,7 +23,7 @@ function enableOnAppInstalledPref() {
// This cause file_reg_install_event.html to be dynamically change.
async function theTest(aBrowser) {
aBrowser.allowEvents = true;
let waitForInstall = SpecialPowers.spawn(aBrowser, [], async function() {
let waitForInstall = ContentTask.spawn(aBrowser, null, async function() {
await ContentTaskUtils.waitForEvent(content.window, "appinstalled");
});
const {

View File

@ -223,7 +223,7 @@ function waitForNetObserver(aBrowser, aTest) {
return Promise.resolve();
}
return SpecialPowers.spawn(aBrowser, [], () => {
return ContentTask.spawn(aBrowser, [], () => {
return new Promise(resolve => {
function observe(subject, topic) {
Services.obs.removeObserver(observe, "csp-on-violate-policy");

View File

@ -24,7 +24,7 @@ add_task(async function() {
gBrowser.selectedTab = tab;
var browser = gBrowser.selectedBrowser;
let observerPromise = SpecialPowers.spawn(browser, [], async function(opt) {
let observerPromise = ContentTask.spawn(browser, null, async function(opt) {
const TEST_URI =
"http://example.com/browser/dom/tests/browser/test-console-api.html";
let ConsoleAPIStorage = Cc["@mozilla.org/consoleAPI-storage;1"].getService(
@ -93,9 +93,7 @@ add_task(async function() {
browser = gBrowser.selectedBrowser;
// Spin the event loop to make sure everything is cleared.
await SpecialPowers.spawn(browser, [], function() {
return Promise.resolve();
});
await SpecialPowers.spawn(browser, [], () => {});
await SpecialPowers.spawn(browser, [windowId], function(windowId) {
var ConsoleAPIStorage = Cc["@mozilla.org/consoleAPI-storage;1"].getService(

View File

@ -313,7 +313,7 @@ function controlFrameAt(browser, frameDepth, command) {
break;
}
}
});
}).catch(Cu.reportError);
}
/**

View File

@ -41,13 +41,13 @@ function expectNoProcess() {
}
function getPID(aBrowser) {
return SpecialPowers.spawn(aBrowser, [], () => {
return ContentTask.spawn(aBrowser, [], () => {
return Services.appinfo.processID;
});
}
function getInLAProc(aBrowser) {
return SpecialPowers.spawn(aBrowser, [], () => {
return ContentTask.spawn(aBrowser, [], () => {
return Services.appinfo.remoteType == "webLargeAllocation";
});
}
@ -80,7 +80,7 @@ async function largeAllocSuccessTests() {
is(false, await getInLAProc(aBrowser));
let epc = expectProcessCreated();
await SpecialPowers.spawn(aBrowser, [TEST_URI], TEST_URI => {
await ContentTask.spawn(aBrowser, TEST_URI, TEST_URI => {
content.document.location = TEST_URI;
});
@ -107,7 +107,7 @@ async function largeAllocSuccessTests() {
// Fail the test if we create a process
let stopExpectNoProcess = expectNoProcess();
await SpecialPowers.spawn(aBrowser, [TEST_URI], TEST_URI => {
await ContentTask.spawn(aBrowser, TEST_URI, TEST_URI => {
// eslint-disable-next-line no-unsanitized/property
content.document.body.innerHTML = `<iframe src='${TEST_URI}'></iframe>`;
@ -138,7 +138,7 @@ async function largeAllocSuccessTests() {
// Fail the test if we create a process
let stopExpectNoProcess = expectNoProcess();
let loaded = SpecialPowers.spawn(aBrowser, [TEST_URI], TEST_URI => {
let loaded = ContentTask.spawn(aBrowser, TEST_URI, TEST_URI => {
content.document.body.innerHTML = "<button>CLICK ME</button>";
return new Promise(resolve => {
@ -173,7 +173,7 @@ async function largeAllocSuccessTests() {
let epc = expectProcessCreated();
await SpecialPowers.spawn(aBrowser, [TEST_URI], TEST_URI => {
await ContentTask.spawn(aBrowser, TEST_URI, TEST_URI => {
content.document.location = TEST_URI;
});
@ -186,7 +186,7 @@ async function largeAllocSuccessTests() {
await BrowserTestUtils.browserLoaded(aBrowser);
await SpecialPowers.spawn(
await ContentTask.spawn(
aBrowser,
[],
() => (content.document.location = "about:blank")
@ -200,7 +200,7 @@ async function largeAllocSuccessTests() {
epc = expectProcessCreated();
await SpecialPowers.spawn(aBrowser, [TEST_URI], TEST_URI => {
await ContentTask.spawn(aBrowser, TEST_URI, TEST_URI => {
content.document.location = TEST_URI;
});
@ -221,7 +221,7 @@ async function largeAllocSuccessTests() {
let epc = expectProcessCreated();
await SpecialPowers.spawn(aBrowser, [TEST_URI], TEST_URI => {
await ContentTask.spawn(aBrowser, TEST_URI, TEST_URI => {
content.document.location = TEST_URI;
});
@ -235,7 +235,7 @@ async function largeAllocSuccessTests() {
await BrowserTestUtils.browserLoaded(aBrowser);
// Switch to about:blank, so we can navigate back
await SpecialPowers.spawn(aBrowser, [], () => {
await ContentTask.spawn(aBrowser, [], () => {
content.document.location = "about:blank";
});
@ -251,7 +251,7 @@ async function largeAllocSuccessTests() {
// Navigate back to the previous page. As the large alloation process was
// left, it won't be in bfcache and will have to be loaded fresh.
await SpecialPowers.spawn(aBrowser, [TEST_URI], TEST_URI => {
await ContentTask.spawn(aBrowser, TEST_URI, TEST_URI => {
content.window.history.back();
});
@ -276,7 +276,7 @@ async function largeAllocSuccessTests() {
BrowserTestUtils.browserLoaded(aBrowser),
]);
await SpecialPowers.spawn(aBrowser, [TEST_URI], TEST_URI => {
await ContentTask.spawn(aBrowser, TEST_URI, TEST_URI => {
content.document.location = TEST_URI;
});
@ -289,7 +289,7 @@ async function largeAllocSuccessTests() {
let epc = expectProcessCreated();
await SpecialPowers.spawn(aBrowser, [TEST_URI_2], TEST_URI_2 => {
await ContentTask.spawn(aBrowser, TEST_URI_2, TEST_URI_2 => {
content.document.location = TEST_URI_2;
});
@ -327,7 +327,7 @@ async function largeAllocSuccessTests() {
BrowserTestUtils.browserLoaded(aBrowser),
]);
await SpecialPowers.spawn(aBrowser, [TEST_URI], TEST_URI => {
await ContentTask.spawn(aBrowser, TEST_URI, TEST_URI => {
content.document.location = TEST_URI;
});
@ -340,7 +340,7 @@ async function largeAllocSuccessTests() {
let stopExpectNoProcess = expectNoProcess();
await SpecialPowers.spawn(aBrowser, [], () => {
await ContentTask.spawn(aBrowser, [], () => {
this.__newWindow = content.window.open("about:blank");
content.document.location = "about:blank";
});
@ -354,7 +354,7 @@ async function largeAllocSuccessTests() {
stopExpectNoProcess();
await SpecialPowers.spawn(aBrowser, [], () => {
await ContentTask.spawn(aBrowser, [], () => {
ok(this.__newWindow, "The window should have been stored");
this.__newWindow.close();
});
@ -372,7 +372,7 @@ async function largeAllocSuccessTests() {
BrowserTestUtils.browserLoaded(aBrowser),
]);
await SpecialPowers.spawn(aBrowser, [TEST_URI], TEST_URI => {
await ContentTask.spawn(aBrowser, TEST_URI, TEST_URI => {
content.document.location = TEST_URI;
});
@ -390,7 +390,7 @@ async function largeAllocSuccessTests() {
gBrowser,
"about:blank"
);
await SpecialPowers.spawn(aBrowser, [], () => {
await ContentTask.spawn(aBrowser, [], () => {
this.__newWindow = content.window.open("about:blank");
});
await promiseTabOpened;
@ -410,7 +410,7 @@ async function largeAllocSuccessTests() {
stopExpectNoProcess();
await SpecialPowers.spawn(aBrowser, [], () => {
await ContentTask.spawn(aBrowser, [], () => {
ok(this.__newWindow, "The window should have been stored");
this.__newWindow.close();
});
@ -428,7 +428,7 @@ async function largeAllocSuccessTests() {
expectProcessCreated(),
BrowserTestUtils.browserLoaded(aBrowser),
]);
await SpecialPowers.spawn(aBrowser, [TEST_URI], TEST_URI => {
await ContentTask.spawn(aBrowser, TEST_URI, TEST_URI => {
content.document.location = TEST_URI;
});
@ -476,7 +476,7 @@ async function largeAllocSuccessTests() {
BrowserTestUtils.browserLoaded(aBrowser),
]);
await SpecialPowers.spawn(aBrowser, [TEST_URI], TEST_URI => {
await ContentTask.spawn(aBrowser, TEST_URI, TEST_URI => {
content.document.location = TEST_URI;
});
@ -493,7 +493,7 @@ async function largeAllocSuccessTests() {
is(false, await getInLAProc(aBrowser));
let ready = Promise.all([BrowserTestUtils.browserLoaded(aBrowser)]);
await SpecialPowers.spawn(aBrowser, [TEST_URI], TEST_URI => {
await ContentTask.spawn(aBrowser, TEST_URI, TEST_URI => {
content.document.location = TEST_URI;
});
await ready;
@ -517,7 +517,7 @@ async function largeAllocSuccessTests() {
// Fail the test if we create a process
let stopExpectNoProcess = expectNoProcess();
await SpecialPowers.spawn(aBrowser, [], () => {
await ContentTask.spawn(aBrowser, [], () => {
content.document.location = "view-source:http://example.com";
});
@ -546,7 +546,7 @@ async function largeAllocSuccessTests() {
expectProcessCreated(),
BrowserTestUtils.browserLoaded(aBrowser),
]);
await SpecialPowers.spawn(aBrowser, [TEST_URI], TEST_URI => {
await ContentTask.spawn(aBrowser, TEST_URI, TEST_URI => {
content.document.location = TEST_URI;
});
@ -588,7 +588,7 @@ async function largeAllocSuccessTests() {
expectProcessCreated(),
BrowserTestUtils.browserLoaded(aBrowser),
]);
await SpecialPowers.spawn(aBrowser, [TEST_URI], TEST_URI => {
await ContentTask.spawn(aBrowser, TEST_URI, TEST_URI => {
content.document.location = TEST_URI;
});
@ -600,7 +600,7 @@ async function largeAllocSuccessTests() {
is(true, await getInLAProc(aBrowser));
await Promise.all([
SpecialPowers.spawn(aBrowser, [], () => {
ContentTask.spawn(aBrowser, null, () => {
content.document.querySelector("#submit").click();
}),
BrowserTestUtils.browserLoaded(aBrowser),
@ -632,7 +632,7 @@ async function largeAllocFailTests() {
// Fail the test if we create a process
let stopExpectNoProcess = expectNoProcess();
await SpecialPowers.spawn(aBrowser, [TEST_URI], TEST_URI => {
await ContentTask.spawn(aBrowser, TEST_URI, TEST_URI => {
content.document.location = TEST_URI;
});

View File

@ -52,7 +52,7 @@ function promiseU2FRegister(tab, app_id) {
}
function promiseWebAuthnRegister(tab, appid) {
return SpecialPowers.spawn(tab.linkedBrowser, [[appid]], ([appid]) => {
return ContentTask.spawn(tab.linkedBrowser, appid, appid => {
const cose_alg_ECDSA_w_SHA256 = -7;
let challenge = content.crypto.getRandomValues(new Uint8Array(16));
@ -84,9 +84,9 @@ function promiseWebAuthnRegister(tab, appid) {
}
function promiseWebAuthnSign(tab, key_handle, extensions = {}) {
return SpecialPowers.spawn(
return ContentTask.spawn(
tab.linkedBrowser,
[[key_handle, extensions]],
[key_handle, extensions],
([key_handle, extensions]) => {
let challenge = content.crypto.getRandomValues(new Uint8Array(16));

View File

@ -51,44 +51,40 @@ function verifyDirectCertificate(attestationObject) {
function promiseWebAuthnRegister(tab, attestation = "indirect") {
/* eslint-disable no-shadow */
return SpecialPowers.spawn(
tab.linkedBrowser,
[[attestation]],
([attestation]) => {
const cose_alg_ECDSA_w_SHA256 = -7;
return ContentTask.spawn(tab.linkedBrowser, attestation, attestation => {
const cose_alg_ECDSA_w_SHA256 = -7;
let challenge = content.crypto.getRandomValues(new Uint8Array(16));
let challenge = content.crypto.getRandomValues(new Uint8Array(16));
let pubKeyCredParams = [
{
type: "public-key",
alg: cose_alg_ECDSA_w_SHA256,
},
];
let pubKeyCredParams = [
{
type: "public-key",
alg: cose_alg_ECDSA_w_SHA256,
},
];
let publicKey = {
rp: { id: content.document.domain, name: "none", icon: "none" },
user: {
id: new Uint8Array(),
name: "none",
icon: "none",
displayName: "none",
},
pubKeyCredParams,
attestation,
challenge,
};
let publicKey = {
rp: { id: content.document.domain, name: "none", icon: "none" },
user: {
id: new Uint8Array(),
name: "none",
icon: "none",
displayName: "none",
},
pubKeyCredParams,
attestation,
challenge,
};
return content.navigator.credentials
.create({ publicKey })
.then(cred => cred.response.attestationObject);
}
);
return content.navigator.credentials
.create({ publicKey })
.then(cred => cred.response.attestationObject);
});
/* eslint-enable no-shadow */
}
function promiseWebAuthnSign(tab) {
return SpecialPowers.spawn(tab.linkedBrowser, [[]], () => {
return ContentTask.spawn(tab.linkedBrowser, null, () => {
let challenge = content.crypto.getRandomValues(new Uint8Array(16));
let key_handle = content.crypto.getRandomValues(new Uint8Array(16));

View File

@ -18,7 +18,7 @@ add_task(async function test() {
"http://mochi.test:8888/browser/dom/xhr/tests/browser_xhr_onchange_leak.html";
let newTab = await BrowserTestUtils.openNewForegroundTab(gBrowser, url);
let browser = gBrowser.selectedBrowser;
let done = await SpecialPowers.spawn(browser, [], async function() {
let done = await ContentTask.spawn(browser, null, async function() {
let promise = ContentTaskUtils.waitForEvent(this, "DOMContentLoaded", true);
content.location = "http://mochi.test:8888/";
await promise;

View File

@ -11,9 +11,9 @@ add_task(async function test() {
let newTab = await BrowserTestUtils.openNewForegroundTab(gBrowser, url);
let browser = gBrowser.selectedBrowser;
let innerWindowId = browser.innerWindowID;
let contentDocDead = await SpecialPowers.spawn(
let contentDocDead = await ContentTask.spawn(
browser,
[{ innerWindowId }],
{ innerWindowId },
async function(args) {
let doc = content.document;
let { TestUtils } = ChromeUtils.import(

View File

@ -12,9 +12,9 @@ add_task(async function test() {
let browser = gBrowser.selectedBrowser;
let innerWindowId = browser.innerWindowID;
let stackTraceEmpty = await SpecialPowers.spawn(
let stackTraceEmpty = await ContentTask.spawn(
browser,
[{ innerWindowId }],
{ innerWindowId },
async function(args) {
let { TestUtils } = ChromeUtils.import(
"resource://testing-common/TestUtils.jsm"

View File

@ -30,6 +30,7 @@ const { OS } = ChromeUtils.import("resource://gre/modules/osfile.jsm");
XPCOMUtils.defineLazyModuleGetters(this, {
BrowserWindowTracker: "resource:///modules/BrowserWindowTracker.jsm",
ContentTask: "resource://testing-common/ContentTask.jsm",
E10SUtils: "resource://gre/modules/E10SUtils.jsm",
});
@ -852,18 +853,14 @@ var BrowserTestUtils = {
// We cannot use the regular BrowserTestUtils helper for waiting here, since that
// would try to insert the preloaded browser, which would only break things.
await gBrowser.preloadedBrowser.ownerGlobal.SpecialPowers.spawn(
gBrowser.preloadedBrowser,
[],
async () => {
await ContentTaskUtils.waitForCondition(() => {
return (
this.content.document &&
this.content.document.readyState == "complete"
);
});
}
);
await ContentTask.spawn(gBrowser.preloadedBrowser, [], async () => {
await ContentTaskUtils.waitForCondition(() => {
return (
this.content.document &&
this.content.document.readyState == "complete"
);
});
});
},
/**

View File

@ -92,7 +92,7 @@ function task(contentIds) {
add_task(async function() {
let tab = (gBrowser.selectedTab = BrowserTestUtils.addTab(gBrowser));
let promise = SpecialPowers.spawn(tab.linkedBrowser, [ids], task);
let promise = ContentTask.spawn(tab.linkedBrowser, ids, task);
BrowserTestUtils.loadURI(
tab.linkedBrowser,
"data:text/html;charset=utf-8," +

View File

@ -106,7 +106,7 @@ function task(contentConsts) {
add_task(async function() {
let tab = (gBrowser.selectedTab = BrowserTestUtils.addTab(gBrowser));
let promise = SpecialPowers.spawn(tab.linkedBrowser, [consts], task);
let promise = ContentTask.spawn(tab.linkedBrowser, consts, task);
BrowserTestUtils.loadURI(
tab.linkedBrowser,
"data:text/html;charset=utf-8," +

View File

@ -449,9 +449,7 @@ async function assertContextMenuFill(
formId,
unchangedSelector,
};
let continuePromise = SpecialPowers.spawn(browser, [data], async function(
data
) {
let continuePromise = ContentTask.spawn(browser, data, async function(data) {
let {
username,
password,

View File

@ -301,9 +301,9 @@ add_task(async function fill_generated_password_with_matching_logins() {
await openPasswordContextMenu(browser, passwordInputSelector);
// Execute the command of the first login menuitem found at the context menu.
let passwordChangedPromise = SpecialPowers.spawn(
let passwordChangedPromise = ContentTask.spawn(
browser,
[],
null,
async function() {
let passwordInput = content.document.getElementById(
"form-basic-password"

View File

@ -168,15 +168,13 @@ async function getFormSubmitResponseResult(
{ username = "#user", password = "#pass" } = {}
) {
// default selectors are for the response page produced by formsubmit.sjs
let fieldValues = await SpecialPowers.spawn(
let fieldValues = await ContentTask.spawn(
browser,
[
{
resultURL,
usernameSelector: username,
passwordSelector: password,
},
],
{
resultURL,
usernameSelector: username,
passwordSelector: password,
},
async function({ resultURL, usernameSelector, passwordSelector }) {
await ContentTaskUtils.waitForCondition(() => {
return (

View File

@ -92,9 +92,9 @@ function get_video_decoding_suspend_promise(browser, reload) {
function get_video_decoding_resume_promise(browser) {
let suspend = false;
let reload = false;
return SpecialPowers.spawn(
return ContentTask.spawn(
browser,
[{ suspend, reload }],
{ suspend, reload },
check_video_decoding_state
);
}

View File

@ -18,7 +18,7 @@ find-menu appears in editor element which has had makeEditable() called but desi
<script type="application/javascript"><![CDATA[
const {BrowserTestUtils} = ChromeUtils.import("resource://testing-common/BrowserTestUtils.jsm");
;
const {ContentTask} = ChromeUtils.import("resource://testing-common/ContentTask.jsm");
ContentTask.setTestScope(window.arguments[0]);
var gFindBar = null;
@ -45,12 +45,9 @@ find-menu appears in editor element which has had makeEditable() called but desi
info("Starting test with browser '" + browserId + "'");
gBrowser = document.getElementById(browserId);
gFindBar.browser = gBrowser;
let promise = SpecialPowers.spawn(gBrowser, [], async function() {
let promise = ContentTask.spawn(gBrowser, [], async function() {
return new Promise(resolve => {
docShell.chromeEventHandler.addEventListener("DOMContentLoaded", function listener() {
docShell.chromeEventHandler.removeEventListener("DOMContentLoaded", listener);
resolve();
});
addEventListener("DOMContentLoaded", () => resolve(), { once: true });
});
});
BrowserTestUtils.loadURI(gBrowser, "data:text/html;charset=utf-8,some%20random%20text");
@ -59,7 +56,7 @@ find-menu appears in editor element which has had makeEditable() called but desi
}
async function onDocumentLoaded() {
await SpecialPowers.spawn(gBrowser, [], async function() {
await ContentTask.spawn(gBrowser, [], async function() {
var edsession = content.docShell.editingSession;
edsession.makeWindowEditable(content, "html", false, true, false);
content.focus();
@ -74,7 +71,7 @@ find-menu appears in editor element which has had makeEditable() called but desi
async function enterStringIntoEditor(aString) {
for (let i = 0; i < aString.length; i++) {
await SpecialPowers.spawn(gBrowser, [{ charCode: aString.charCodeAt(i) }], async function(args) {
await ContentTask.spawn(gBrowser, [{ charCode: aString.charCodeAt(i) }], async function(args) {
let event = content.document.createEvent("KeyboardEvent");
event.initKeyEvent("keypress", true, true, null, false, false,
false, false, 0, args.charCode);

View File

@ -18,8 +18,8 @@
title="360437 test">
<script type="application/javascript"><![CDATA[
;
const {BrowserTestUtils} = ChromeUtils.import("resource://testing-common/BrowserTestUtils.jsm");
const {ContentTask} = ChromeUtils.import("resource://testing-common/ContentTask.jsm");
ContentTask.setTestScope(window.arguments[0]);
var gFindBar = null;
@ -48,12 +48,9 @@
gFindBar.browser = gBrowser;
let loadedPromise = BrowserTestUtils.browserLoaded(gBrowser);
let contentLoadedPromise = SpecialPowers.spawn(gBrowser, [], async function() {
let contentLoadedPromise = ContentTask.spawn(gBrowser, null, async function() {
return new Promise(resolve => {
docShell.chromeEventHandler.addEventListener("DOMContentLoaded", function listener() {
docShell.chromeEventHandler.removeEventListener("DOMContentLoaded", listener);
resolve();
});
addEventListener("DOMContentLoaded", () => resolve(), { once: true });
});
});
BrowserTestUtils.loadURI(gBrowser, "data:text/html,<form><input id='input' type='text' value='text inside an input element'></form>");

View File

@ -19,8 +19,7 @@
<script type="application/javascript"><![CDATA[
const {BrowserTestUtils} = ChromeUtils.import("resource://testing-common/BrowserTestUtils.jsm");
;
ContentTask.setTestScope(window.arguments[0]);
const {ContentTask} = ChromeUtils.import("resource://testing-common/ContentTask.jsm");
var gFindBar = null;
var gBrowser;
@ -123,14 +122,11 @@
gBrowser = document.getElementById(browserId);
gFindBar.browser = gBrowser;
let promise = SpecialPowers.spawn(gBrowser, [], async function() {
return new Promise(resolve => {
docShell.chromeEventHandler.addEventListener("DOMContentLoaded", function listener() {
docShell.chromeEventHandler.removeEventListener("DOMContentLoaded", listener);
resolve();
});
});
});
let promise = ContentTask.spawn(gBrowser, null, () =>
new Promise(resolve => {
addEventListener("DOMContentLoaded", () => resolve(), { once: true });
})
);
BrowserTestUtils.loadURI(gBrowser, kBaseURL + "/sample_entireword_" + testName + ".html");
await promise;
await onDocumentLoaded(testName);

View File

@ -10,12 +10,11 @@
<script>
<![CDATA[
;
const { ContentTask } = ChromeUtils.import("resource://testing-common/ContentTask.jsm");
function dropOnRemoteBrowserAsync(browser, data, shouldExpectStateChange) {
ContentTask.setTestScope(window); // Need this so is/isnot/ok are available inside the contenttask
return SpecialPowers.spawn(browser, [{data, shouldExpectStateChange}], async function({data, shouldExpectStateChange}) {
ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
return ContentTask.spawn(browser, {data, shouldExpectStateChange}, async function({data, shouldExpectStateChange}) {
const {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
if (!content.document.documentElement) {

View File

@ -7,9 +7,9 @@ function test() {
var triggers = encodeURIComponent(JSON.stringify(TESTROOT + "amosigned.xpi"));
gBrowser.selectedTab = BrowserTestUtils.addTab(gBrowser, TESTROOT);
SpecialPowers.spawn(gBrowser.selectedBrowser, [], function() {
ContentTask.spawn(gBrowser.selectedBrowser, null, function() {
return new Promise(resolve => {
docShell.chromeEventHandler.addEventListener(
addEventListener(
"load",
() => {
content.addEventListener("InstallTriggered", () => {

View File

@ -13,9 +13,9 @@ function test() {
);
gBrowser.selectedTab = BrowserTestUtils.addTab(gBrowser, TESTROOT);
SpecialPowers.spawn(gBrowser.selectedBrowser, [], function() {
ContentTask.spawn(gBrowser.selectedBrowser, null, function() {
return new Promise(resolve => {
docShell.chromeEventHandler.addEventListener(
addEventListener(
"load",
() => {
content.addEventListener("InstallTriggered", () => {

View File

@ -5,9 +5,9 @@ function test() {
gBrowser.selectedTab = BrowserTestUtils.addTab(gBrowser, TESTROOT);
SpecialPowers.spawn(
ContentTask.spawn(
gBrowser.selectedBrowser,
[TESTROOT + "enabled.html"],
TESTROOT + "enabled.html",
function(url) {
return new Promise(resolve => {
function page_loaded() {
@ -16,19 +16,11 @@ function test() {
}
function load_listener() {
docShell.chromeEventHandler.removeEventListener(
"load",
load_listener,
true
);
removeEventListener("load", load_listener, true);
content.addEventListener("PageLoaded", page_loaded);
}
docShell.chromeEventHandler.addEventListener(
"load",
load_listener,
true
);
addEventListener("load", load_listener, true);
content.location.href = url;
});

View File

@ -7,9 +7,9 @@ function test() {
gBrowser.selectedTab = BrowserTestUtils.addTab(gBrowser, TESTROOT);
SpecialPowers.spawn(
ContentTask.spawn(
gBrowser.selectedBrowser,
[TESTROOT + "enabled.html"],
TESTROOT + "enabled.html",
function(url) {
return new Promise(resolve => {
function page_loaded() {
@ -18,19 +18,11 @@ function test() {
}
function load_listener() {
docShell.chromeEventHandler.removeEventListener(
"load",
load_listener,
true
);
removeEventListener("load", load_listener, true);
content.addEventListener("PageLoaded", page_loaded);
}
docShell.chromeEventHandler.addEventListener(
"load",
load_listener,
true
);
addEventListener("load", load_listener, true);
content.location.href = url;
});

View File

@ -15,9 +15,9 @@ function test() {
);
gBrowser.selectedTab = BrowserTestUtils.addTab(gBrowser, TESTROOT);
SpecialPowers.spawn(
ContentTask.spawn(
gBrowser.selectedBrowser,
[TESTROOT + "installtrigger.html?" + triggers],
TESTROOT + "installtrigger.html?" + triggers,
url => {
return new Promise(resolve => {
function page_loaded() {
@ -26,19 +26,11 @@ function test() {
}
function load_listener() {
docShell.chromeEventHandler.removeEventListener(
"load",
load_listener,
true
);
removeEventListener("load", load_listener, true);
content.addEventListener("InstallTriggered", page_loaded);
}
docShell.chromeEventHandler.addEventListener(
"load",
load_listener,
true
);
addEventListener("load", load_listener, true);
content.location.href = url;
});

View File

@ -32,9 +32,13 @@ add_task(async function test() {
await SpecialPowers.spawn(browser, [URI], async function(URI) {
content.location.href = URI;
let loaded = ContentTaskUtils.waitForEvent(this, "load", true);
let loaded = ContentTaskUtils.waitForEvent(
docShell.chromeEventHandler,
"load",
true
);
let installTriggered = ContentTaskUtils.waitForEvent(
this,
docShell.chromeEventHandler,
"InstallTriggered",
true,
null,

View File

@ -41,7 +41,7 @@ function finish_test(count) {
info("Checking if the browser is still offline...");
let tab = gBrowser.selectedTab;
SpecialPowers.spawn(tab.linkedBrowser, [], async function() {
ContentTask.spawn(tab.linkedBrowser, null, async function() {
await ContentTaskUtils.waitForEvent(this, "DOMContentLoaded", true);
return content.document.documentURI;
}).then(url => {

View File

@ -72,16 +72,12 @@ add_task(async function test_profile_feature_preferencereads() {
startProfiler({ features: ["threads", "leaf"] });
// Now reload the tab with a clean run.
await SpecialPowers.spawn(contentBrowser, [], () => {
await ContentTask.spawn(contentBrowser, null, () => {
return new Promise(resolve => {
docShell.chromeEventHandler.addEventListener(
"pageshow",
() => resolve(),
{
capturing: true,
once: true,
}
);
addEventListener("pageshow", () => resolve(), {
capturing: true,
once: true,
});
content.location.reload();
});
});