michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: add_task(function* setup() { michael@0: /** Test for Bug 625016 - Restore windows closed in succession to quit (non-OSX only) **/ michael@0: michael@0: // We'll test this by opening a new window, waiting for the save michael@0: // event, then closing that window. We'll observe the michael@0: // "sessionstore-state-write-complete" notification and check that michael@0: // the state contains no _closedWindows. We'll then add a new tab michael@0: // and make sure that the state following that was reset and the michael@0: // closed window is now in _closedWindows. michael@0: michael@0: requestLongerTimeout(2); michael@0: michael@0: yield forceSaveState(); michael@0: michael@0: // We'll clear all closed windows to make sure our state is clean michael@0: // forgetClosedWindow doesn't trigger a delayed save michael@0: while (ss.getClosedWindowCount()) { michael@0: ss.forgetClosedWindow(0); michael@0: } michael@0: is(ss.getClosedWindowCount(), 0, "starting with no closed windows"); michael@0: }); michael@0: michael@0: add_task(function* new_window() { michael@0: let newWin; michael@0: try { michael@0: newWin = yield promiseNewWindowLoaded(); michael@0: let tab = newWin.gBrowser.addTab("http://example.com/browser_625016.js?" + Math.random()); michael@0: yield promiseBrowserLoaded(tab.linkedBrowser); michael@0: michael@0: // Double check that we have no closed windows michael@0: is(ss.getClosedWindowCount(), 0, "no closed windows on first save"); michael@0: michael@0: yield promiseWindowClosed(newWin); michael@0: newWin = null; michael@0: michael@0: let state = JSON.parse((yield promiseSaveFileContents())); michael@0: is(state.windows.length, 2, michael@0: "observe1: 2 windows in data written to disk"); michael@0: is(state._closedWindows.length, 0, michael@0: "observe1: no closed windows in data written to disk"); michael@0: michael@0: // The API still treats the closed window as closed, so ensure that window is there michael@0: is(ss.getClosedWindowCount(), 1, michael@0: "observe1: 1 closed window according to API"); michael@0: } finally { michael@0: if (newWin) { michael@0: yield promiseWindowClosed(newWin); michael@0: } michael@0: yield forceSaveState(); michael@0: } michael@0: }); michael@0: michael@0: // We'll open a tab, which should trigger another state save which would wipe michael@0: // the _shouldRestore attribute from the closed window michael@0: add_task(function* new_tab() { michael@0: let newTab; michael@0: try { michael@0: newTab = gBrowser.addTab("about:mozilla"); michael@0: michael@0: let state = JSON.parse((yield promiseSaveFileContents())); michael@0: is(state.windows.length, 1, michael@0: "observe2: 1 window in data being written to disk"); michael@0: is(state._closedWindows.length, 1, michael@0: "observe2: 1 closed window in data being written to disk"); michael@0: michael@0: // The API still treats the closed window as closed, so ensure that window is there michael@0: is(ss.getClosedWindowCount(), 1, michael@0: "observe2: 1 closed window according to API"); michael@0: } finally { michael@0: gBrowser.removeTab(newTab); michael@0: } michael@0: }); michael@0: michael@0: michael@0: add_task(function* done() { michael@0: // The API still represents the closed window as closed, so we can clear it michael@0: // with the API, but just to make sure... michael@0: // is(ss.getClosedWindowCount(), 1, "1 closed window according to API"); michael@0: while (ss.getClosedWindowCount()) { michael@0: ss.forgetClosedWindow(0); michael@0: } michael@0: Services.prefs.clearUserPref("browser.sessionstore.interval"); michael@0: });