Bug 741070. (Cv1a-FF) Sessionstore tests: Improve and merge 'provideWindow()' and 'whenWindowLoaded()' into 'head.js', Add an 'info()' call, Nits. r=paul (a=test-only).

This commit is contained in:
Serge Gautherie 2012-05-02 14:14:18 +02:00
Родитель 653e4d4800
Коммит 6decdbb602
5 изменённых файлов: 40 добавлений и 84 удалений

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

@ -35,36 +35,6 @@
* *
* ***** END LICENSE BLOCK ***** */ * ***** 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() { function test() {
waitForExplicitFinish(); waitForExplicitFinish();

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

@ -35,43 +35,13 @@
* *
* ***** END LICENSE BLOCK ***** */ * ***** 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() { function test() {
// This test takes quite some time, and timeouts frequently, so we require // This test takes quite some time, and timeouts frequently, so we require
// more time to run. // more time to run.
// See Bug 518970. // See Bug 518970.
requestLongerTimeout(2); requestLongerTimeout(2);
waitForExplicitFinish(); waitForExplicitFinish();
// helper function that does the actual testing // helper function that does the actual testing
function openWindowRec(windowsToOpen, expectedResults, recCallback) { function openWindowRec(windowsToOpen, expectedResults, recCallback) {
@ -94,13 +64,14 @@ function test() {
executeSoon(recCallback); executeSoon(recCallback);
return; return;
} }
// hack to force window to be considered a popup (toolbar=no didn't work) // hack to force window to be considered a popup (toolbar=no didn't work)
let winData = windowsToOpen.shift(); let winData = windowsToOpen.shift();
let settings = "chrome,dialog=no," + let settings = "chrome,dialog=no," +
(winData.isPopup ? "all=no" : "all"); (winData.isPopup ? "all=no" : "all");
let url = "http://example.com/?window=" + windowsToOpen.length; let url = "http://example.com/?window=" + windowsToOpen.length;
provideWindow(function (win) { provideWindow(function onTestURLLoaded(win) {
win.close(); win.close();
openWindowRec(windowsToOpen, expectedResults, recCallback); openWindowRec(windowsToOpen, expectedResults, recCallback);
}, url, settings); }, url, settings);

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

@ -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) { function newWindowWithState(state, callback) {
let opts = "chrome,all,dialog=no,height=800,width=800"; let opts = "chrome,all,dialog=no,height=800,width=800";
@ -108,10 +100,10 @@ function newWindowWithState(state, callback) {
registerCleanupFunction(function () win.close()); registerCleanupFunction(function () win.close());
whenWindowLoaded(win, function () { whenWindowLoaded(win, function onWindowLoaded(aWin) {
TabsProgressListener.init(win); TabsProgressListener.init(aWin);
TabsProgressListener.setCallback(callback); TabsProgressListener.setCallback(callback);
ss.setWindowState(win, JSON.stringify(state), true); ss.setWindowState(aWin, JSON.stringify(state), true);
}); });
} }

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

@ -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) { function newWindowWithState(aState, aCallback) {
let opts = "chrome,all,dialog=no,height=800,width=800"; let opts = "chrome,all,dialog=no,height=800,width=800";
@ -42,8 +34,8 @@ function newWindowWithState(aState, aCallback) {
registerCleanupFunction(function () win.close()); registerCleanupFunction(function () win.close());
whenWindowLoaded(win, function () { whenWindowLoaded(win, function onWindowLoaded(aWin) {
ss.setWindowState(win, JSON.stringify(aState), true); ss.setWindowState(aWin, JSON.stringify(aState), true);
executeSoon(function () aCallback(win)); executeSoon(function () aCallback(aWin));
}); });
} }

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

@ -49,6 +49,28 @@ registerCleanupFunction(function () {
// session restore tests to be run standalone without triggering errors. // session restore tests to be run standalone without triggering errors.
Cc["@mozilla.org/browser/clh;1"].getService(Ci.nsIBrowserHandler).defaultArgs; 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 // This assumes that tests will at least have some state/entries
function waitForBrowserState(aState, aSetStateCallback) { function waitForBrowserState(aState, aSetStateCallback) {
let windows = [window]; let windows = [window];
@ -198,6 +220,15 @@ function whenBrowserLoaded(aBrowser, aCallback) {
}, true); }, true);
} }
function whenWindowLoaded(aWindow, aCallback) {
aWindow.addEventListener("load", function windowLoadListener() {
aWindow.removeEventListener("load", windowLoadListener, false);
executeSoon(function executeWhenWindowLoaded() {
aCallback(aWindow);
});
}, false);
}
var gUniqueCounter = 0; var gUniqueCounter = 0;
function r() { function r() {
return Date.now() + "-" + (++gUniqueCounter); return Date.now() + "-" + (++gUniqueCounter);