Bug 996988 - use different method to wait for window closure, r=jaws

--HG--
extra : rebase_source : cfb78153229e5722609e10e9e4a417659590c28a
This commit is contained in:
Gijs Kruitbosch 2014-06-02 22:30:02 +01:00
parent b4c07d1a0e
commit 8b6bc6c84e
2 changed files with 16 additions and 5 deletions

View File

@ -85,7 +85,13 @@ add_task(function*() {
ok(otherTB.querySelector("#sync-button"), "Sync button is on other toolbar, too.");
let wasInformedCorrectlyOfAreaDisappearing = false;
let windowClosed = null;
//XXXgijs So we could be using promiseWindowClosed here. However, after
// repeated random oranges, I'm instead relying on onWindowClosed below to
// fire appropriately - it is linked to an unload event as well, and so
// reusing it prevents a potential race between unload handlers where the
// one from promiseWindowClosed could fire before the onWindowClosed
// (and therefore onAreaNodeRegistered) one, causing the test to fail.
let windowCloseDeferred = Promise.defer();
listener = {
onAreaNodeUnregistered: function(aArea, aNode, aReason) {
if (aArea == TOOLBARID) {
@ -96,8 +102,7 @@ add_task(function*() {
},
onWindowClosed: function(aWindow) {
if (aWindow == otherWin) {
info("Got window closed notification for correct window.");
windowClosed = aWindow;
windowCloseDeferred.resolve(aWindow);
} else {
info("Other window was closed!");
info("Other window title: " + (aWindow.document && aWindow.document.title));
@ -106,7 +111,8 @@ add_task(function*() {
},
};
CustomizableUI.addListener(listener);
yield promiseWindowClosed(otherWin);
otherWin.close();
let windowClosed = yield windowCloseDeferred.promise;
is(windowClosed, otherWin, "Window should have sent onWindowClosed notification.");
ok(wasInformedCorrectlyOfAreaDisappearing, "Should be told about window closing.");

View File

@ -249,8 +249,13 @@ function openAndLoadWindow(aOptions, aWaitForDelayedStartup=false) {
}
function promiseWindowClosed(win) {
let deferred = Promise.defer();
win.addEventListener("unload", function onunload() {
win.removeEventListener("unload", onunload);
deferred.resolve();
});
win.close();
return waitForCondition(() => win.closed);
return deferred.promise;
}
function promisePanelShown(win) {