diff --git a/browser/components/sessionstore/test/browser_394759_basic.js b/browser/components/sessionstore/test/browser_394759_basic.js index 7540698585f..fc162586d75 100644 --- a/browser/components/sessionstore/test/browser_394759_basic.js +++ b/browser/components/sessionstore/test/browser_394759_basic.js @@ -35,36 +35,6 @@ * * ***** END LICENSE BLOCK ***** */ -function provideWindow(aCallback, aURL, aFeatures) { - function callback() { - executeSoon(function () { - aCallback(win); - }); - } - - let win = openDialog(getBrowserURL(), "", aFeatures || "chrome,all,dialog=no", aURL); - - whenWindowLoaded(win, function () { - if (!aURL) { - callback(); - return; - } - win.gBrowser.selectedBrowser.addEventListener("load", function() { - win.gBrowser.selectedBrowser.removeEventListener("load", arguments.callee, true); - callback(); - }, true); - }); -} - -function whenWindowLoaded(aWin, aCallback) { - aWin.addEventListener("load", function () { - aWin.removeEventListener("load", arguments.callee, false); - executeSoon(function () { - aCallback(aWin); - }); - }, false); -} - function test() { waitForExplicitFinish(); diff --git a/browser/components/sessionstore/test/browser_394759_behavior.js b/browser/components/sessionstore/test/browser_394759_behavior.js index a2d8f8a84a9..cfecaa5051a 100644 --- a/browser/components/sessionstore/test/browser_394759_behavior.js +++ b/browser/components/sessionstore/test/browser_394759_behavior.js @@ -35,43 +35,13 @@ * * ***** END LICENSE BLOCK ***** */ -function provideWindow(aCallback, aURL, aFeatures) { - function callback() { - executeSoon(function () { - aCallback(win); - }); - } - - let win = openDialog(getBrowserURL(), "", aFeatures || "chrome,all,dialog=no", aURL); - - whenWindowLoaded(win, function () { - if (!aURL) { - callback(); - return; - } - win.gBrowser.selectedBrowser.addEventListener("load", function() { - win.gBrowser.selectedBrowser.removeEventListener("load", arguments.callee, true); - callback(); - }, true); - }); -} - -function whenWindowLoaded(aWin, aCallback) { - aWin.addEventListener("load", function () { - aWin.removeEventListener("load", arguments.callee, false); - executeSoon(function () { - aCallback(aWin); - }); - }, false); -} - function test() { // This test takes quite some time, and timeouts frequently, so we require // more time to run. // See Bug 518970. requestLongerTimeout(2); - waitForExplicitFinish(); + waitForExplicitFinish(); // helper function that does the actual testing function openWindowRec(windowsToOpen, expectedResults, recCallback) { @@ -94,13 +64,14 @@ function test() { executeSoon(recCallback); return; } + // hack to force window to be considered a popup (toolbar=no didn't work) let winData = windowsToOpen.shift(); let settings = "chrome,dialog=no," + (winData.isPopup ? "all=no" : "all"); let url = "http://example.com/?window=" + windowsToOpen.length; - provideWindow(function (win) { + provideWindow(function onTestURLLoaded(win) { win.close(); openWindowRec(windowsToOpen, expectedResults, recCallback); }, url, settings); diff --git a/browser/components/sessionstore/test/browser_595601-restore_hidden.js b/browser/components/sessionstore/test/browser_595601-restore_hidden.js index 3971a51d2a2..b53d92308a7 100644 --- a/browser/components/sessionstore/test/browser_595601-restore_hidden.js +++ b/browser/components/sessionstore/test/browser_595601-restore_hidden.js @@ -93,14 +93,6 @@ let TabsProgressListener = { } } -// ---------- -function whenWindowLoaded(win, callback) { - win.addEventListener("load", function onLoad() { - win.removeEventListener("load", onLoad, false); - executeSoon(callback); - }, false); -} - // ---------- function newWindowWithState(state, callback) { let opts = "chrome,all,dialog=no,height=800,width=800"; @@ -108,10 +100,10 @@ function newWindowWithState(state, callback) { registerCleanupFunction(function () win.close()); - whenWindowLoaded(win, function () { - TabsProgressListener.init(win); + whenWindowLoaded(win, function onWindowLoaded(aWin) { + TabsProgressListener.init(aWin); TabsProgressListener.setCallback(callback); - ss.setWindowState(win, JSON.stringify(state), true); + ss.setWindowState(aWin, JSON.stringify(state), true); }); } diff --git a/browser/components/sessionstore/test/browser_701377.js b/browser/components/sessionstore/test/browser_701377.js index e0c363dada4..e526b7eb745 100644 --- a/browser/components/sessionstore/test/browser_701377.js +++ b/browser/components/sessionstore/test/browser_701377.js @@ -27,14 +27,6 @@ function test() { }); } -// ---------- -function whenWindowLoaded(aWindow, aCallback) { - aWindow.addEventListener("load", function onLoad() { - aWindow.removeEventListener("load", onLoad, false); - executeSoon(aCallback); - }, false); -} - // ---------- function newWindowWithState(aState, aCallback) { let opts = "chrome,all,dialog=no,height=800,width=800"; @@ -42,8 +34,8 @@ function newWindowWithState(aState, aCallback) { registerCleanupFunction(function () win.close()); - whenWindowLoaded(win, function () { - ss.setWindowState(win, JSON.stringify(aState), true); - executeSoon(function () aCallback(win)); + whenWindowLoaded(win, function onWindowLoaded(aWin) { + ss.setWindowState(aWin, JSON.stringify(aState), true); + executeSoon(function () aCallback(aWin)); }); } diff --git a/browser/components/sessionstore/test/head.js b/browser/components/sessionstore/test/head.js index a5f451d52c1..45715bbc10d 100644 --- a/browser/components/sessionstore/test/head.js +++ b/browser/components/sessionstore/test/head.js @@ -49,6 +49,28 @@ registerCleanupFunction(function () { // session restore tests to be run standalone without triggering errors. Cc["@mozilla.org/browser/clh;1"].getService(Ci.nsIBrowserHandler).defaultArgs; +function provideWindow(aCallback, aURL, aFeatures) { + function callbackSoon(aWindow) { + executeSoon(function executeCallbackSoon() { + aCallback(aWindow); + }); + } + + let win = openDialog(getBrowserURL(), "", aFeatures || "chrome,all,dialog=no", aURL); + whenWindowLoaded(win, function onWindowLoaded(aWin) { + if (!aURL) { + info("Loaded a blank window."); + callbackSoon(aWin); + return; + } + + aWin.gBrowser.selectedBrowser.addEventListener("load", function selectedBrowserLoadListener() { + aWin.gBrowser.selectedBrowser.removeEventListener("load", selectedBrowserLoadListener, true); + callbackSoon(aWin); + }, true); + }); +} + // This assumes that tests will at least have some state/entries function waitForBrowserState(aState, aSetStateCallback) { let windows = [window]; @@ -198,6 +220,15 @@ function whenBrowserLoaded(aBrowser, aCallback) { }, true); } +function whenWindowLoaded(aWindow, aCallback) { + aWindow.addEventListener("load", function windowLoadListener() { + aWindow.removeEventListener("load", windowLoadListener, false); + executeSoon(function executeWhenWindowLoaded() { + aCallback(aWindow); + }); + }, false); +} + var gUniqueCounter = 0; function r() { return Date.now() + "-" + (++gUniqueCounter);