Bug 1086169: Wait for page load event listener to run in tests. r=Unfocused

This commit is contained in:
Dave Townsend 2014-10-21 17:29:33 -07:00
parent 776c0e0ebd
commit 5624fed4c4
3 changed files with 48 additions and 21 deletions

View File

@ -6,11 +6,13 @@ function test() {
var triggers = encodeURIComponent(JSON.stringify(TESTROOT + "unsigned.xpi"));
gBrowser.selectedTab = gBrowser.addTab();
gBrowser.selectedBrowser.addEventListener("load", function() {
gBrowser.selectedBrowser.removeEventListener("load", arguments.callee, true);
// Allow the in-page load handler to run first
executeSoon(page_loaded);
}, true);
function loadListener() {
gBrowser.selectedBrowser.removeEventListener("load", loadListener, true);
gBrowser.contentWindow.addEventListener("InstallTriggered", page_loaded, false);
}
gBrowser.selectedBrowser.addEventListener("load", loadListener, true);
// In non-e10s the exception in the content page would trigger a test failure
if (!gMultiProcessBrowser)
@ -20,9 +22,16 @@ function test() {
}
function page_loaded() {
gBrowser.contentWindow.removeEventListener("InstallTriggered", page_loaded, false);
var doc = gBrowser.contentDocument;
is(doc.getElementById("return").textContent, "exception", "installTrigger should have failed");
gBrowser.removeCurrentTab();
finish();
// 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();
});
}
// ----------------------------------------------------------------------------

View File

@ -10,11 +10,13 @@ function test() {
}
}));
gBrowser.selectedTab = gBrowser.addTab();
gBrowser.selectedBrowser.addEventListener("load", function() {
gBrowser.selectedBrowser.removeEventListener("load", arguments.callee, true);
// Allow the in-page load handler to run first
executeSoon(page_loaded);
}, true);
function loadListener() {
gBrowser.selectedBrowser.removeEventListener("load", loadListener, true);
gBrowser.contentWindow.addEventListener("InstallTriggered", page_loaded, false);
}
gBrowser.selectedBrowser.addEventListener("load", loadListener, true);
// In non-e10s the exception in the content page would trigger a test failure
if (!gMultiProcessBrowser)
@ -24,9 +26,16 @@ function test() {
}
function page_loaded() {
gBrowser.contentWindow.removeEventListener("InstallTriggered", page_loaded, false);
var doc = gBrowser.contentDocument;
is(doc.getElementById("return").textContent, "exception", "installTrigger should have failed");
gBrowser.removeCurrentTab();
finish();
// 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();
});
}
// ----------------------------------------------------------------------------

View File

@ -18,11 +18,13 @@ function test() {
"Unsigned XPI": xpipath
}));
gBrowser.selectedTab = gBrowser.addTab();
gBrowser.selectedBrowser.addEventListener("load", function() {
gBrowser.selectedBrowser.removeEventListener("load", arguments.callee, true);
// Allow the in-page load handler to run first
executeSoon(page_loaded);
}, true);
function loadListener() {
gBrowser.selectedBrowser.removeEventListener("load", loadListener, true);
gBrowser.contentWindow.addEventListener("InstallTriggered", page_loaded, false);
}
gBrowser.selectedBrowser.addEventListener("load", loadListener, true);
// In non-e10s the exception in the content page would trigger a test failure
if (!gMultiProcessBrowser)
@ -32,9 +34,16 @@ function test() {
}
function page_loaded() {
gBrowser.contentWindow.removeEventListener("InstallTriggered", page_loaded, false);
var doc = gBrowser.contentDocument;
is(doc.getElementById("return").textContent, "exception", "installTrigger should have failed");
gBrowser.removeCurrentTab();
finish();
// 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();
});
}
// ----------------------------------------------------------------------------