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