1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/components/sessionstore/test/browser_625016.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,86 @@ 1.4 +/* Any copyright is dedicated to the Public Domain. 1.5 + http://creativecommons.org/publicdomain/zero/1.0/ */ 1.6 + 1.7 +add_task(function* setup() { 1.8 + /** Test for Bug 625016 - Restore windows closed in succession to quit (non-OSX only) **/ 1.9 + 1.10 + // We'll test this by opening a new window, waiting for the save 1.11 + // event, then closing that window. We'll observe the 1.12 + // "sessionstore-state-write-complete" notification and check that 1.13 + // the state contains no _closedWindows. We'll then add a new tab 1.14 + // and make sure that the state following that was reset and the 1.15 + // closed window is now in _closedWindows. 1.16 + 1.17 + requestLongerTimeout(2); 1.18 + 1.19 + yield forceSaveState(); 1.20 + 1.21 + // We'll clear all closed windows to make sure our state is clean 1.22 + // forgetClosedWindow doesn't trigger a delayed save 1.23 + while (ss.getClosedWindowCount()) { 1.24 + ss.forgetClosedWindow(0); 1.25 + } 1.26 + is(ss.getClosedWindowCount(), 0, "starting with no closed windows"); 1.27 +}); 1.28 + 1.29 +add_task(function* new_window() { 1.30 + let newWin; 1.31 + try { 1.32 + newWin = yield promiseNewWindowLoaded(); 1.33 + let tab = newWin.gBrowser.addTab("http://example.com/browser_625016.js?" + Math.random()); 1.34 + yield promiseBrowserLoaded(tab.linkedBrowser); 1.35 + 1.36 + // Double check that we have no closed windows 1.37 + is(ss.getClosedWindowCount(), 0, "no closed windows on first save"); 1.38 + 1.39 + yield promiseWindowClosed(newWin); 1.40 + newWin = null; 1.41 + 1.42 + let state = JSON.parse((yield promiseSaveFileContents())); 1.43 + is(state.windows.length, 2, 1.44 + "observe1: 2 windows in data written to disk"); 1.45 + is(state._closedWindows.length, 0, 1.46 + "observe1: no closed windows in data written to disk"); 1.47 + 1.48 + // The API still treats the closed window as closed, so ensure that window is there 1.49 + is(ss.getClosedWindowCount(), 1, 1.50 + "observe1: 1 closed window according to API"); 1.51 + } finally { 1.52 + if (newWin) { 1.53 + yield promiseWindowClosed(newWin); 1.54 + } 1.55 + yield forceSaveState(); 1.56 + } 1.57 +}); 1.58 + 1.59 +// We'll open a tab, which should trigger another state save which would wipe 1.60 +// the _shouldRestore attribute from the closed window 1.61 +add_task(function* new_tab() { 1.62 + let newTab; 1.63 + try { 1.64 + newTab = gBrowser.addTab("about:mozilla"); 1.65 + 1.66 + let state = JSON.parse((yield promiseSaveFileContents())); 1.67 + is(state.windows.length, 1, 1.68 + "observe2: 1 window in data being written to disk"); 1.69 + is(state._closedWindows.length, 1, 1.70 + "observe2: 1 closed window in data being written to disk"); 1.71 + 1.72 + // The API still treats the closed window as closed, so ensure that window is there 1.73 + is(ss.getClosedWindowCount(), 1, 1.74 + "observe2: 1 closed window according to API"); 1.75 + } finally { 1.76 + gBrowser.removeTab(newTab); 1.77 + } 1.78 +}); 1.79 + 1.80 + 1.81 +add_task(function* done() { 1.82 + // The API still represents the closed window as closed, so we can clear it 1.83 + // with the API, but just to make sure... 1.84 +// is(ss.getClosedWindowCount(), 1, "1 closed window according to API"); 1.85 + while (ss.getClosedWindowCount()) { 1.86 + ss.forgetClosedWindow(0); 1.87 + } 1.88 + Services.prefs.clearUserPref("browser.sessionstore.interval"); 1.89 +});