зеркало из https://github.com/mozilla/pjs.git
Revert changeset fc4702c75a04 since it is likely causing bug 527074.
This commit is contained in:
Родитель
8246effbea
Коммит
ba4fd02e3d
|
@ -38,46 +38,44 @@
|
|||
function test() {
|
||||
/** Test for Bug 394759 **/
|
||||
|
||||
let ss = Cc["@mozilla.org/browser/sessionstore;1"].
|
||||
getService(Ci.nsISessionStore);
|
||||
let pb = Cc["@mozilla.org/privatebrowsing;1"].
|
||||
getService(Ci.nsIPrivateBrowsingService);
|
||||
|
||||
// test setup
|
||||
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) {
|
||||
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();
|
||||
|
||||
let testURL = "about:config";
|
||||
let uniqueKey = "bug 394759";
|
||||
let uniqueValue = "unik" + Date.now();
|
||||
let uniqueText = "pi != " + Math.random();
|
||||
|
||||
|
||||
// make sure that the next closed window will increase getClosedWindowCount
|
||||
let max_windows_undo = gPrefService.getIntPref(PREF_MAX_WIN_UNDO);
|
||||
gPrefService.setIntPref(PREF_MAX_WIN_UNDO, max_windows_undo + 1);
|
||||
let max_windows_undo = gPrefService.getIntPref("browser.sessionstore.max_windows_undo");
|
||||
gPrefService.setIntPref("browser.sessionstore.max_windows_undo", max_windows_undo + 1);
|
||||
let closedWindowCount = ss.getClosedWindowCount();
|
||||
|
||||
let newWin = openDialog(location, "_blank", "chrome,all,dialog=no", TEST_URL);
|
||||
let newWin = openDialog(location, "_blank", "chrome,all,dialog=no", testURL);
|
||||
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, UNIQUE_KEY, UNIQUE_VALUE);
|
||||
ss.setWindowValue(newWin, uniqueKey, uniqueValue);
|
||||
let textbox = newWin.content.document.getElementById("textbox");
|
||||
textbox.wrappedJSObject.value = UNIQUE_TEXT;
|
||||
textbox.wrappedJSObject.value = uniqueText;
|
||||
|
||||
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 == TEST_URL &&
|
||||
data.toSource().indexOf(UNIQUE_TEXT) > -1,
|
||||
ok(data.title == testURL && data.toSource().indexOf(uniqueText) > -1,
|
||||
"The closed window data was stored correctly");
|
||||
|
||||
// reopen the closed window and ensure its integrity
|
||||
|
@ -89,28 +87,26 @@ function test() {
|
|||
"The reopened window was removed from Recently Closed Windows");
|
||||
|
||||
newWin2.addEventListener("load", function(aEvent) {
|
||||
newWin2.removeEventListener("load", arguments.callee, false);
|
||||
this.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");
|
||||
|
||||
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");
|
||||
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");
|
||||
|
||||
newWin2.close();
|
||||
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");
|
||||
|
||||
if (gPrefService.prefHasUserValue(PREF_MAX_WIN_UNDO))
|
||||
gPrefService.clearUserPref(PREF_MAX_WIN_UNDO);
|
||||
|
||||
executeSoon(callback);
|
||||
});
|
||||
// clean up
|
||||
newWin2.close();
|
||||
if (gPrefService.prefHasUserValue("browser.sessionstore.max_windows_undo"))
|
||||
gPrefService.clearUserPref("browser.sessionstore.max_windows_undo");
|
||||
executeSoon(callback);
|
||||
}, true);
|
||||
}, false);
|
||||
});
|
||||
|
@ -141,30 +137,29 @@ 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 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() {
|
||||
// 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();
|
||||
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();
|
||||
|
||||
executeSoon(function() {
|
||||
window.close();
|
||||
executeSoon(function() {
|
||||
openWindowRec(windowsToOpen, expectedResults, recCallback);
|
||||
});
|
||||
});
|
||||
}, true);
|
||||
}, false);
|
||||
}, true);
|
||||
}
|
||||
|
||||
let windowsToOpen = [{isPopup: false},
|
||||
|
@ -194,6 +189,8 @@ 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 = {
|
||||
|
@ -260,48 +257,42 @@ function test() {
|
|||
let closedWindowData = JSON.parse(ss.getClosedWindowData());
|
||||
|
||||
// First set of tests for _closedWindows[0] - tests basics
|
||||
let win = closedWindowData[0];
|
||||
is(win.tabs.length, 1, "1 tab was removed");
|
||||
is(countOpenTabsByTitle(win.tabs, FORGET), 0,
|
||||
let window = closedWindowData[0];
|
||||
is(window.tabs.length, 1, "1 tab was removed");
|
||||
is(countOpenTabsByTitle(window.tabs, FORGET), 0,
|
||||
"The correct tab was removed");
|
||||
is(countOpenTabsByTitle(win.tabs, REMEMBER), 1,
|
||||
is(countOpenTabsByTitle(window.tabs, REMEMBER), 1,
|
||||
"The correct tab was remembered");
|
||||
is(win.selected, 1, "Selected tab has changed");
|
||||
is(win.title, REMEMBER, "The window title was correctly updated");
|
||||
is(window.selected, 1, "Selected tab has changed");
|
||||
is(window.title, REMEMBER, "The window title was correctly updated");
|
||||
|
||||
// Test more complicated case
|
||||
win = closedWindowData[1];
|
||||
is(win.tabs.length, 3, "2 tabs were removed");
|
||||
is(countOpenTabsByTitle(win.tabs, FORGET), 0,
|
||||
window = closedWindowData[1];
|
||||
is(window.tabs.length, 3, "2 tabs were removed");
|
||||
is(countOpenTabsByTitle(window.tabs, FORGET), 0,
|
||||
"The correct tabs were removed");
|
||||
is(countOpenTabsByTitle(win.tabs, REMEMBER), 3,
|
||||
is(countOpenTabsByTitle(window.tabs, REMEMBER), 3,
|
||||
"The correct tabs were remembered");
|
||||
is(win.selected, 3, "Selected tab has changed");
|
||||
is(win.title, REMEMBER, "The window title was correctly updated");
|
||||
is(window.selected, 3, "Selected tab has changed");
|
||||
is(window.title, REMEMBER, "The window title was correctly updated");
|
||||
|
||||
// Tests handling of _closedTabs
|
||||
win = closedWindowData[2];
|
||||
is(countClosedTabsByTitle(win._closedTabs, REMEMBER), 1,
|
||||
window = closedWindowData[2];
|
||||
is(countClosedTabsByTitle(window._closedTabs, REMEMBER), 1,
|
||||
"The correct number of tabs were removed, and the correct ones");
|
||||
is(countClosedTabsByTitle(win._closedTabs, FORGET), 0,
|
||||
is(countClosedTabsByTitle(window._closedTabs, FORGET), 0,
|
||||
"All tabs to be forgotten were indeed removed");
|
||||
|
||||
// Restore blank state.
|
||||
let blankState = JSON.stringify({
|
||||
windows: [{
|
||||
tabs: [{ entries: [{ url: "about:blank" }] }],
|
||||
_closedTabs: []
|
||||
}],
|
||||
_closedWindows: []
|
||||
});
|
||||
ss.setBrowserState(blankState);
|
||||
|
||||
// restore pre-test state
|
||||
ss.setBrowserState(oldState);
|
||||
executeSoon(callback);
|
||||
}
|
||||
|
||||
test_basic(function() {
|
||||
test_behavior(function() {
|
||||
test_purge(finish);
|
||||
test_purge(function() {
|
||||
finish();
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче