Bug 494749 - mochitest-browser-chrome: browser_490040.js times out intermittently, refactoring of the test, r=dietrich

This commit is contained in:
Marco Bonardo 2009-07-29 23:50:42 +02:00
Родитель e2442097d1
Коммит 6b8bdbf71a
1 изменённых файлов: 65 добавлений и 46 удалений

Просмотреть файл

@ -38,51 +38,69 @@
function test() { function test() {
/** Test for Bug 490040 **/ /** Test for Bug 490040 **/
let ss = Cc["@mozilla.org/browser/sessionstore;1"].getService(Ci.nsISessionStore); let ss = Cc["@mozilla.org/browser/sessionstore;1"].
let os = Cc["@mozilla.org/observer-service;1"].getService(Ci.nsIObserverService); getService(Ci.nsISessionStore);
let os = Cc["@mozilla.org/observer-service;1"].
getService(Ci.nsIObserverService);
let ww = Cc["@mozilla.org/embedcomp/window-watcher;1"].
getService(Ci.nsIWindowWatcher);
waitForExplicitFinish(); waitForExplicitFinish();
function testWithState(aState, aCallback) { function testWithState(aState) {
// ensure we can store the window if need be // Ensure we can store the window if needed.
let curClosedWindowCount = ss.getClosedWindowCount(); let curClosedWindowCount = ss.getClosedWindowCount();
gPrefService.setIntPref("browser.sessionstore.max_windows_undo", curClosedWindowCount + 1); gPrefService.setIntPref("browser.sessionstore.max_windows_undo",
curClosedWindowCount + 1);
let theWin = openDialog(location, "_blank", "chrome,all,dialog=no"); let windowObserver = {
theWin.addEventListener("load", function(aEvent) { observe: function(aSubject, aTopic, aData) {
theWin.removeEventListener("load", arguments.callee, true); let theWin = aSubject.QueryInterface(Ci.nsIDOMWindow);
ss.setWindowState(theWin, JSON.stringify(aState.windowState), true); switch(aTopic) {
case "domwindowopened":
theWin.addEventListener("load", function () {
theWin.removeEventListener("load", arguments.callee, false);
executeSoon(function() {
// Close the window as soon as the first tab loads, or
// immediately if there are no tabs.
if (aState.windowState.windows[0].tabs[0].entries.length) {
theWin.gBrowser.addEventListener("load", function() {
theWin.gBrowser.removeEventListener("load",
arguments.callee, true);
theWin.close();
}, true);
} else {
executeSoon(function() {
theWin.close();
});
}
ss.setWindowState(theWin, JSON.stringify(aState.windowState),
true);
});
}, false);
break;
let observer = { case "domwindowclosed":
QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver, ww.unregisterNotification(this);
Ci.nsISupportsWeakReference]), // Use executeSoon to ensure this happens after SS observer.
observe: function(aSubject, aTopic, aData) { executeSoon(function() {
let _this = this; is(ss.getClosedWindowCount(),
// use executeSoon to ensure this happens after SS observer curClosedWindowCount + (aState.shouldBeAdded ? 1 : 0),
executeSoon(function() { "That window should " + (aState.shouldBeAdded ? "" : "not ") +
is(ss.getClosedWindowCount(), curClosedWindowCount + (aState.shouldBeAdded ? 1 : 0), "be restorable");
"That window should " + (aState.shouldBeAdded ? "" : "not ") + "be restorable"); executeSoon(runNextTest);
os.removeObserver(_this, "domwindowclosed"); });
executeSoon(aCallback); break;
});
} }
};
os.addObserver(observer, "domwindowclosed", true);
// Close the window as soon as the first tab loads, or immediately if
// there are no tabs.
if (aState.windowState.windows[0].tabs[0].entries.length) {
theWin.gBrowser.addEventListener("load", function() {
theWin.gBrowser.removeEventListener("load", arguments.callee, true);
theWin.close();
}, true);
} else {
executeSoon(function() {
theWin.close();
});
} }
}, true); }
ww.registerNotification(windowObserver);
ww.openWindow(null,
location,
"_blank",
"chrome,all,dialog=no",
null);
} }
// Only windows with open tabs are restorable. Windows where a lone tab is // Only windows with open tabs are restorable. Windows where a lone tab is
@ -128,15 +146,16 @@ function test() {
} }
]; ];
testWithState(states[0], function() { function runNextTest() {
testWithState(states[1], function() { if (states.length) {
testWithState(states[2], function() { let state = states.shift();
testWithState(states[3], function() { testWithState(state);
gPrefService.clearUserPref("browser.sessionstore.max_windows_undo"); }
finish(); else {
}); gPrefService.clearUserPref("browser.sessionstore.max_windows_undo");
}); finish();
}); }
}); }
runNextTest();
} }