browser/components/sessionstore/test/browser_625016.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* Any copyright is dedicated to the Public Domain.
michael@0 2 http://creativecommons.org/publicdomain/zero/1.0/ */
michael@0 3
michael@0 4 add_task(function* setup() {
michael@0 5 /** Test for Bug 625016 - Restore windows closed in succession to quit (non-OSX only) **/
michael@0 6
michael@0 7 // We'll test this by opening a new window, waiting for the save
michael@0 8 // event, then closing that window. We'll observe the
michael@0 9 // "sessionstore-state-write-complete" notification and check that
michael@0 10 // the state contains no _closedWindows. We'll then add a new tab
michael@0 11 // and make sure that the state following that was reset and the
michael@0 12 // closed window is now in _closedWindows.
michael@0 13
michael@0 14 requestLongerTimeout(2);
michael@0 15
michael@0 16 yield forceSaveState();
michael@0 17
michael@0 18 // We'll clear all closed windows to make sure our state is clean
michael@0 19 // forgetClosedWindow doesn't trigger a delayed save
michael@0 20 while (ss.getClosedWindowCount()) {
michael@0 21 ss.forgetClosedWindow(0);
michael@0 22 }
michael@0 23 is(ss.getClosedWindowCount(), 0, "starting with no closed windows");
michael@0 24 });
michael@0 25
michael@0 26 add_task(function* new_window() {
michael@0 27 let newWin;
michael@0 28 try {
michael@0 29 newWin = yield promiseNewWindowLoaded();
michael@0 30 let tab = newWin.gBrowser.addTab("http://example.com/browser_625016.js?" + Math.random());
michael@0 31 yield promiseBrowserLoaded(tab.linkedBrowser);
michael@0 32
michael@0 33 // Double check that we have no closed windows
michael@0 34 is(ss.getClosedWindowCount(), 0, "no closed windows on first save");
michael@0 35
michael@0 36 yield promiseWindowClosed(newWin);
michael@0 37 newWin = null;
michael@0 38
michael@0 39 let state = JSON.parse((yield promiseSaveFileContents()));
michael@0 40 is(state.windows.length, 2,
michael@0 41 "observe1: 2 windows in data written to disk");
michael@0 42 is(state._closedWindows.length, 0,
michael@0 43 "observe1: no closed windows in data written to disk");
michael@0 44
michael@0 45 // The API still treats the closed window as closed, so ensure that window is there
michael@0 46 is(ss.getClosedWindowCount(), 1,
michael@0 47 "observe1: 1 closed window according to API");
michael@0 48 } finally {
michael@0 49 if (newWin) {
michael@0 50 yield promiseWindowClosed(newWin);
michael@0 51 }
michael@0 52 yield forceSaveState();
michael@0 53 }
michael@0 54 });
michael@0 55
michael@0 56 // We'll open a tab, which should trigger another state save which would wipe
michael@0 57 // the _shouldRestore attribute from the closed window
michael@0 58 add_task(function* new_tab() {
michael@0 59 let newTab;
michael@0 60 try {
michael@0 61 newTab = gBrowser.addTab("about:mozilla");
michael@0 62
michael@0 63 let state = JSON.parse((yield promiseSaveFileContents()));
michael@0 64 is(state.windows.length, 1,
michael@0 65 "observe2: 1 window in data being written to disk");
michael@0 66 is(state._closedWindows.length, 1,
michael@0 67 "observe2: 1 closed window in data being written to disk");
michael@0 68
michael@0 69 // The API still treats the closed window as closed, so ensure that window is there
michael@0 70 is(ss.getClosedWindowCount(), 1,
michael@0 71 "observe2: 1 closed window according to API");
michael@0 72 } finally {
michael@0 73 gBrowser.removeTab(newTab);
michael@0 74 }
michael@0 75 });
michael@0 76
michael@0 77
michael@0 78 add_task(function* done() {
michael@0 79 // The API still represents the closed window as closed, so we can clear it
michael@0 80 // with the API, but just to make sure...
michael@0 81 // is(ss.getClosedWindowCount(), 1, "1 closed window according to API");
michael@0 82 while (ss.getClosedWindowCount()) {
michael@0 83 ss.forgetClosedWindow(0);
michael@0 84 }
michael@0 85 Services.prefs.clearUserPref("browser.sessionstore.interval");
michael@0 86 });

mercurial