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