fune/toolkit/mozapps/extensions/test/xpinstall/browser_badargs.js
Kris Maglione 0b1a146519 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
2019-12-13 20:36:36 +00:00

46 lines
1.4 KiB
JavaScript

// ----------------------------------------------------------------------------
// Test whether passing a simple string to InstallTrigger.install throws an
// exception
function test() {
waitForExplicitFinish();
var triggers = encodeURIComponent(JSON.stringify(TESTROOT + "amosigned.xpi"));
gBrowser.selectedTab = BrowserTestUtils.addTab(gBrowser, TESTROOT);
ContentTask.spawn(gBrowser.selectedBrowser, null, function() {
return new Promise(resolve => {
addEventListener(
"load",
() => {
content.addEventListener("InstallTriggered", () => {
resolve(content.document.getElementById("return").textContent);
});
},
true
);
});
}).then(page_loaded);
// In non-e10s the exception in the content page would trigger a test failure
if (!gMultiProcessBrowser) {
expectUncaughtException();
}
BrowserTestUtils.loadURI(
gBrowser,
TESTROOT + "installtrigger.html?" + triggers
);
}
function page_loaded(result) {
is(result, "exception", "installTrigger should have failed");
// In non-e10s the exception from the page is thrown after the event so we
// have to spin the event loop to make sure it arrives so expectUncaughtException
// sees it.
executeSoon(() => {
gBrowser.removeCurrentTab();
finish();
});
}
// ----------------------------------------------------------------------------