2011-06-21 11:09:07 -07:00
|
|
|
/* Any copyright is dedicated to the Public Domain.
|
|
|
|
http://creativecommons.org/publicdomain/zero/1.0/ */
|
|
|
|
|
|
|
|
let newWin;
|
|
|
|
let newTab;
|
|
|
|
|
|
|
|
function test() {
|
|
|
|
/** Test for Bug 625016 - Restore windows closed in succession to quit (non-OSX only) **/
|
|
|
|
|
|
|
|
// We'll test this by opening a new window, waiting for the save event, then
|
|
|
|
// closing that window. We'll observe the "sessionstore-state-write" notification
|
|
|
|
// and check that the state contains no _closedWindows. We'll then add a new
|
|
|
|
// tab and make sure that the state following that was reset and the closed
|
|
|
|
// window is now in _closedWindows.
|
|
|
|
|
|
|
|
waitForExplicitFinish();
|
2012-03-14 16:11:20 -07:00
|
|
|
requestLongerTimeout(2);
|
2011-06-21 11:09:07 -07:00
|
|
|
|
|
|
|
// We speed up the interval between session saves to ensure that the test
|
|
|
|
// runs quickly.
|
2012-03-14 16:11:20 -07:00
|
|
|
Services.prefs.setIntPref("browser.sessionstore.interval", 4000);
|
|
|
|
registerCleanupFunction(function () {
|
|
|
|
Services.prefs.clearUserPref("browser.sessionstore.interval");
|
|
|
|
});
|
2011-06-21 11:09:07 -07:00
|
|
|
|
2012-03-19 03:14:30 -07:00
|
|
|
waitForSaveState(setup);
|
|
|
|
}
|
|
|
|
|
|
|
|
function setup() {
|
2011-06-21 11:09:07 -07:00
|
|
|
// We'll clear all closed windows to make sure our state is clean
|
|
|
|
// forgetClosedWindow doesn't trigger a delayed save
|
2011-06-25 14:38:31 -07:00
|
|
|
while (ss.getClosedWindowCount()) {
|
|
|
|
ss.forgetClosedWindow(0);
|
2011-06-21 11:09:07 -07:00
|
|
|
}
|
2011-06-25 14:38:31 -07:00
|
|
|
is(ss.getClosedWindowCount(), 0, "starting with no closed windows");
|
2011-06-21 11:09:07 -07:00
|
|
|
|
|
|
|
// Open a new window, which should trigger a save event soon.
|
|
|
|
waitForSaveState(onSaveState);
|
2012-02-22 17:18:13 -08:00
|
|
|
newWin = openDialog(location, "_blank", "chrome,all,dialog=no", "about:rights");
|
2011-06-21 11:09:07 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
function onSaveState() {
|
2013-11-08 08:59:49 -08:00
|
|
|
try {
|
|
|
|
ss.getWindowValue(newWin, "foobar");
|
|
|
|
} catch (e) {
|
2013-11-21 08:16:13 -08:00
|
|
|
// The window is untracked which means that the saveState() call isn't the
|
|
|
|
// one we're waiting for. It's most likely been triggered by an async
|
|
|
|
// collection running in the background.
|
|
|
|
waitForSaveState(onSaveState);
|
|
|
|
return;
|
2013-11-08 08:59:49 -08:00
|
|
|
}
|
|
|
|
|
2013-11-21 08:16:13 -08:00
|
|
|
// Double check that we have no closed windows
|
|
|
|
is(ss.getClosedWindowCount(), 0, "no closed windows on first save");
|
|
|
|
|
|
|
|
Services.obs.addObserver(observe1, "sessionstore-state-write", false);
|
|
|
|
|
2011-06-21 11:09:07 -07:00
|
|
|
// Now close the new window, which should trigger another save event
|
|
|
|
newWin.close();
|
|
|
|
}
|
|
|
|
|
|
|
|
function observe1(aSubject, aTopic, aData) {
|
|
|
|
info("observe1: " + aTopic);
|
2011-06-25 14:38:31 -07:00
|
|
|
switch (aTopic) {
|
2011-06-21 11:09:07 -07:00
|
|
|
case "sessionstore-state-write":
|
|
|
|
aSubject.QueryInterface(Ci.nsISupportsString);
|
|
|
|
let state = JSON.parse(aSubject.data);
|
|
|
|
is(state.windows.length, 2,
|
|
|
|
"observe1: 2 windows in data being writted to disk");
|
|
|
|
is(state._closedWindows.length, 0,
|
|
|
|
"observe1: no closed windows in data being writted to disk");
|
|
|
|
|
|
|
|
// The API still treats the closed window as closed, so ensure that window is there
|
2011-06-25 14:38:31 -07:00
|
|
|
is(ss.getClosedWindowCount(), 1,
|
2011-06-21 11:09:07 -07:00
|
|
|
"observe1: 1 closed window according to API");
|
2013-04-06 11:46:35 -07:00
|
|
|
Services.obs.removeObserver(observe1, "sessionstore-state-write");
|
2011-06-21 11:09:07 -07:00
|
|
|
Services.obs.addObserver(observe1, "sessionstore-state-write-complete", false);
|
|
|
|
break;
|
|
|
|
case "sessionstore-state-write-complete":
|
2013-04-06 11:46:35 -07:00
|
|
|
Services.obs.removeObserver(observe1, "sessionstore-state-write-complete");
|
2011-06-21 11:09:07 -07:00
|
|
|
openTab();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function observe2(aSubject, aTopic, aData) {
|
|
|
|
info("observe2: " + aTopic);
|
2011-06-25 14:38:31 -07:00
|
|
|
switch (aTopic) {
|
2011-06-21 11:09:07 -07:00
|
|
|
case "sessionstore-state-write":
|
|
|
|
aSubject.QueryInterface(Ci.nsISupportsString);
|
|
|
|
let state = JSON.parse(aSubject.data);
|
|
|
|
is(state.windows.length, 1,
|
|
|
|
"observe2: 1 window in data being writted to disk");
|
|
|
|
is(state._closedWindows.length, 1,
|
|
|
|
"observe2: 1 closed window in data being writted to disk");
|
|
|
|
|
|
|
|
// The API still treats the closed window as closed, so ensure that window is there
|
2011-06-25 14:38:31 -07:00
|
|
|
is(ss.getClosedWindowCount(), 1,
|
2011-06-21 11:09:07 -07:00
|
|
|
"observe2: 1 closed window according to API");
|
2013-04-06 11:46:35 -07:00
|
|
|
Services.obs.removeObserver(observe2, "sessionstore-state-write");
|
2011-06-21 11:09:07 -07:00
|
|
|
Services.obs.addObserver(observe2, "sessionstore-state-write-complete", false);
|
|
|
|
break;
|
|
|
|
case "sessionstore-state-write-complete":
|
2013-04-06 11:46:35 -07:00
|
|
|
Services.obs.removeObserver(observe2, "sessionstore-state-write-complete");
|
2011-06-21 11:09:07 -07:00
|
|
|
done();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// We'll open a tab, which should trigger another state save which would wipe
|
|
|
|
// the _shouldRestore attribute from the closed window
|
|
|
|
function openTab() {
|
|
|
|
Services.obs.addObserver(observe2, "sessionstore-state-write", false);
|
|
|
|
newTab = gBrowser.addTab("about:mozilla");
|
|
|
|
}
|
|
|
|
|
|
|
|
function done() {
|
|
|
|
gBrowser.removeTab(newTab);
|
|
|
|
// The API still represents the closed window as closed, so we can clear it
|
|
|
|
// with the API, but just to make sure...
|
2011-06-25 14:38:31 -07:00
|
|
|
is(ss.getClosedWindowCount(), 1, "1 closed window according to API");
|
|
|
|
ss.forgetClosedWindow(0);
|
2011-06-21 11:09:07 -07:00
|
|
|
executeSoon(finish);
|
|
|
|
}
|
|
|
|
|