Some cleanup of test browser_394759.js, possibly involved in subsequent tests timeouts (see bug 518970).

This commit is contained in:
Marco Bonardo 2009-11-06 16:25:04 +01:00
Родитель d7535a036b
Коммит 093665ef14
1 изменённых файлов: 81 добавлений и 72 удалений

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

@ -37,45 +37,47 @@
function test() {
/** Test for Bug 394759 **/
// test setup
let ss = Cc["@mozilla.org/browser/sessionstore;1"].getService(Ci.nsISessionStore);
let pb = Cc["@mozilla.org/privatebrowsing;1"].getService(Ci.nsIPrivateBrowsingService);
let ss = Cc["@mozilla.org/browser/sessionstore;1"].
getService(Ci.nsISessionStore);
let pb = Cc["@mozilla.org/privatebrowsing;1"].
getService(Ci.nsIPrivateBrowsingService);
waitForExplicitFinish();
function test_basic(callback) {
let testURL = "about:config";
let uniqueKey = "bug 394759";
let uniqueValue = "unik" + Date.now();
let uniqueText = "pi != " + Math.random();
const PREF_MAX_WIN_UNDO = "browser.sessionstore.max_windows_undo";
const TEST_URL = "about:config";
const UNIQUE_KEY = "bug 394759";
const UNIQUE_VALUE = "unik" + Date.now();
const UNIQUE_TEXT = "pi != " + Math.random();
// make sure that the next closed window will increase getClosedWindowCount
let max_windows_undo = gPrefService.getIntPref("browser.sessionstore.max_windows_undo");
gPrefService.setIntPref("browser.sessionstore.max_windows_undo", max_windows_undo + 1);
let max_windows_undo = gPrefService.getIntPref(PREF_MAX_WIN_UNDO);
gPrefService.setIntPref(PREF_MAX_WIN_UNDO, max_windows_undo + 1);
let closedWindowCount = ss.getClosedWindowCount();
let newWin = openDialog(location, "_blank", "chrome,all,dialog=no", testURL);
let newWin = openDialog(location, "_blank", "chrome,all,dialog=no", TEST_URL);
newWin.addEventListener("load", function(aEvent) {
newWin.removeEventListener("load", arguments.callee, false);
newWin.gBrowser.addEventListener("load", function(aEvent) {
newWin.gBrowser.removeEventListener("load", arguments.callee, true);
executeSoon(function() {
newWin.gBrowser.addTab().linkedBrowser.stop();
executeSoon(function() {
// mark the window with some unique data to be restored later on
ss.setWindowValue(newWin, uniqueKey, uniqueValue);
ss.setWindowValue(newWin, UNIQUE_KEY, UNIQUE_VALUE);
let textbox = newWin.content.document.getElementById("textbox");
textbox.wrappedJSObject.value = uniqueText;
textbox.wrappedJSObject.value = UNIQUE_TEXT;
newWin.close();
is(ss.getClosedWindowCount(), closedWindowCount + 1,
"The closed window was added to Recently Closed Windows");
let data = JSON.parse(ss.getClosedWindowData())[0];
ok(data.title == testURL && data.toSource().indexOf(uniqueText) > -1,
ok(data.title == TEST_URL &&
data.toSource().indexOf(UNIQUE_TEXT) > -1,
"The closed window data was stored correctly");
// reopen the closed window and ensure its integrity
@ -87,26 +89,28 @@ function test() {
"The reopened window was removed from Recently Closed Windows");
newWin2.addEventListener("load", function(aEvent) {
this.removeEventListener("load", arguments.callee, false);
newWin2.removeEventListener("load", arguments.callee, false);
newWin2.gBrowser.addEventListener("SSTabRestored", function(aEvent) {
newWin2.gBrowser.removeEventListener("SSTabRestored", arguments.callee, true);
executeSoon(function() {
is(newWin2.gBrowser.tabContainer.childNodes.length, 2,
"The window correctly restored 2 tabs");
is(newWin2.gBrowser.currentURI.spec, TEST_URL,
"The window correctly restored the URL");
is(newWin2.gBrowser.tabContainer.childNodes.length, 2,
"The window correctly restored 2 tabs");
is(newWin2.gBrowser.currentURI.spec, testURL,
"The window correctly restored the URL");
let textbox = newWin2.content.document.getElementById("textbox");
is(textbox.wrappedJSObject.value, UNIQUE_TEXT,
"The window correctly restored the form");
is(ss.getWindowValue(newWin2, UNIQUE_KEY), UNIQUE_VALUE,
"The window correctly restored the data associated with it");
let textbox = newWin2.content.document.getElementById("textbox");
is(textbox.wrappedJSObject.value, uniqueText,
"The window correctly restored the form");
is(ss.getWindowValue(newWin2, uniqueKey), uniqueValue,
"The window correctly restored the data associated with it");
newWin2.close();
// clean up
newWin2.close();
if (gPrefService.prefHasUserValue("browser.sessionstore.max_windows_undo"))
gPrefService.clearUserPref("browser.sessionstore.max_windows_undo");
executeSoon(callback);
if (gPrefService.prefHasUserValue(PREF_MAX_WIN_UNDO))
gPrefService.clearUserPref(PREF_MAX_WIN_UNDO);
executeSoon(callback);
});
}, true);
}, false);
});
@ -137,29 +141,30 @@ 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://window" + windowsToOpen.length + ".example.com";
let window = openDialog(location, "_blank", settings, url);
window.addEventListener("load", function(aEvent) {
this.removeEventListener("load", arguments.callee, true);
window.gBrowser.addEventListener("load", function(aEvent) {
this.removeEventListener("load", arguments.callee, true);
// the window _should_ have state with a tab of url, but it doesn't
// always happend before window.close(). addTab ensure we don't treat
// this window as a stateless window
window.gBrowser.addTab();
let newWin = openDialog(location, "_blank", settings, url);
newWin.addEventListener("load", function(aEvent) {
newWin.removeEventListener("load", arguments.callee, false);
newWin.gBrowser.addEventListener("load", function(aEvent) {
newWin.gBrowser.removeEventListener("load", arguments.callee, true);
executeSoon(function() {
window.close();
// the window _should_ have state with a tab of url, but it doesn't
// always happend before window.close(). addTab ensure we don't treat
// this window as a stateless window
newWin.gBrowser.addTab().linkedBrowser.stop();
executeSoon(function() {
newWin.close();
openWindowRec(windowsToOpen, expectedResults, recCallback);
});
});
}, true);
}, true);
}, false);
}
let windowsToOpen = [{isPopup: false},
@ -180,7 +185,7 @@ function test() {
openWindowRec(windowsToOpen2, expectedResults2, callback);
});
}
function test_purge(callback) {
// utility functions
function countClosedTabsByTitle(aClosedTabList, aTitle)
@ -189,8 +194,6 @@ function test() {
function countOpenTabsByTitle(aOpenTabList, aTitle)
aOpenTabList.filter(function(aData) aData.entries.some(function(aEntry) aEntry.title == aTitle) ).length
// backup old state
let oldState = ss.getBrowserState();
// create a new state for testing
const REMEMBER = Date.now(), FORGET = Math.random();
let testState = {
@ -247,7 +250,7 @@ function test() {
}
]
};
// set browser to test state
ss.setBrowserState(JSON.stringify(testState));
@ -257,42 +260,48 @@ function test() {
let closedWindowData = JSON.parse(ss.getClosedWindowData());
// First set of tests for _closedWindows[0] - tests basics
let window = closedWindowData[0];
is(window.tabs.length, 1, "1 tab was removed");
is(countOpenTabsByTitle(window.tabs, FORGET), 0,
let win = closedWindowData[0];
is(win.tabs.length, 1, "1 tab was removed");
is(countOpenTabsByTitle(win.tabs, FORGET), 0,
"The correct tab was removed");
is(countOpenTabsByTitle(window.tabs, REMEMBER), 1,
is(countOpenTabsByTitle(win.tabs, REMEMBER), 1,
"The correct tab was remembered");
is(window.selected, 1, "Selected tab has changed");
is(window.title, REMEMBER, "The window title was correctly updated");
is(win.selected, 1, "Selected tab has changed");
is(win.title, REMEMBER, "The window title was correctly updated");
// Test more complicated case
window = closedWindowData[1];
is(window.tabs.length, 3, "2 tabs were removed");
is(countOpenTabsByTitle(window.tabs, FORGET), 0,
win = closedWindowData[1];
is(win.tabs.length, 3, "2 tabs were removed");
is(countOpenTabsByTitle(win.tabs, FORGET), 0,
"The correct tabs were removed");
is(countOpenTabsByTitle(window.tabs, REMEMBER), 3,
is(countOpenTabsByTitle(win.tabs, REMEMBER), 3,
"The correct tabs were remembered");
is(window.selected, 3, "Selected tab has changed");
is(window.title, REMEMBER, "The window title was correctly updated");
is(win.selected, 3, "Selected tab has changed");
is(win.title, REMEMBER, "The window title was correctly updated");
// Tests handling of _closedTabs
window = closedWindowData[2];
is(countClosedTabsByTitle(window._closedTabs, REMEMBER), 1,
win = closedWindowData[2];
is(countClosedTabsByTitle(win._closedTabs, REMEMBER), 1,
"The correct number of tabs were removed, and the correct ones");
is(countClosedTabsByTitle(window._closedTabs, FORGET), 0,
is(countClosedTabsByTitle(win._closedTabs, FORGET), 0,
"All tabs to be forgotten were indeed removed");
// restore pre-test state
ss.setBrowserState(oldState);
// Restore blank state.
let blankState = JSON.stringify({
windows: [{
tabs: [{ entries: [{ url: "about:blank" }] }],
_closedTabs: []
}],
_closedWindows: []
});
ss.setBrowserState(blankState);
executeSoon(callback);
}
test_basic(function() {
test_behavior(function() {
test_purge(function() {
finish();
});
test_purge(finish);
});
});
}