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 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 function test() {
6 /** Test for Bug 526613 **/
8 // test setup
9 waitForExplicitFinish();
11 function browserWindowsCount(expected) {
12 let count = 0;
13 let e = Services.wm.getEnumerator("navigator:browser");
14 while (e.hasMoreElements()) {
15 if (!e.getNext().closed)
16 ++count;
17 }
18 is(count, expected,
19 "number of open browser windows according to nsIWindowMediator");
20 let state = ss.getBrowserState();
21 info(state);
22 is(JSON.parse(state).windows.length, expected,
23 "number of open browser windows according to getBrowserState");
24 }
26 browserWindowsCount(1);
28 // backup old state
29 let oldState = ss.getBrowserState();
30 // create a new state for testing
31 let testState = {
32 windows: [
33 { tabs: [{ entries: [{ url: "http://example.com/" }] }], selected: 1 },
34 { tabs: [{ entries: [{ url: "about:mozilla" }] }], selected: 1 },
35 ],
36 // make sure the first window is focused, otherwise when restoring the
37 // old state, the first window is closed and the test harness gets unloaded
38 selectedWindow: 1
39 };
41 let pass = 1;
42 function observer(aSubject, aTopic, aData) {
43 is(aTopic, "sessionstore-browser-state-restored",
44 "The sessionstore-browser-state-restored notification was observed");
46 if (pass++ == 1) {
47 browserWindowsCount(2);
49 // let the first window be focused (see above)
50 function pollMostRecentWindow() {
51 if (Services.wm.getMostRecentWindow("navigator:browser") == window) {
52 ss.setBrowserState(oldState);
53 } else {
54 info("waiting for the current window to become active");
55 setTimeout(pollMostRecentWindow, 0);
56 window.focus(); //XXX Why is this needed?
57 }
58 }
59 pollMostRecentWindow();
60 }
61 else {
62 browserWindowsCount(1);
63 ok(!window.closed, "Restoring the old state should have left this window open");
64 Services.obs.removeObserver(observer, "sessionstore-browser-state-restored");
65 finish();
66 }
67 }
68 Services.obs.addObserver(observer, "sessionstore-browser-state-restored", false);
70 // set browser to test state
71 ss.setBrowserState(JSON.stringify(testState));
72 }