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 let stateBackup = JSON.parse(ss.getBrowserState());
7 function test() {
8 /** Test for Bug 600545 **/
9 waitForExplicitFinish();
10 testBug600545();
11 }
13 function testBug600545() {
14 // Set the pref to false to cause non-app tabs to be stripped out on a save
15 Services.prefs.setBoolPref("browser.sessionstore.resume_from_crash", false);
16 Services.prefs.setIntPref("browser.sessionstore.interval", 2000);
18 registerCleanupFunction(function () {
19 Services.prefs.clearUserPref("browser.sessionstore.resume_from_crash");
20 Services.prefs.clearUserPref("browser.sessionstore.interval");
21 });
23 // This tests the following use case: When multiple windows are open
24 // and browser.sessionstore.resume_from_crash preference is false,
25 // tab session data for non-active window is stripped for non-pinned
26 // tabs. This occurs after "sessionstore-state-write-complete"
27 // fires which will only fire in this case if there is at least one
28 // pinned tab.
29 let state = { windows: [
30 {
31 tabs: [
32 { entries: [{ url: "http://example.org#0" }], pinned:true },
33 { entries: [{ url: "http://example.com#1" }] },
34 { entries: [{ url: "http://example.com#2" }] },
35 ],
36 selected: 2
37 },
38 {
39 tabs: [
40 { entries: [{ url: "http://example.com#3" }] },
41 { entries: [{ url: "http://example.com#4" }] },
42 { entries: [{ url: "http://example.com#5" }] },
43 { entries: [{ url: "http://example.com#6" }] }
44 ],
45 selected: 3
46 }
47 ] };
49 waitForBrowserState(state, function() {
50 // Need to wait for SessionStore's saveState function to be called
51 // so that non-pinned tabs will be stripped from non-active window
52 waitForSaveState(function () {
53 let expectedNumberOfTabs = getStateTabCount(state);
54 let retrievedState = JSON.parse(ss.getBrowserState());
55 let actualNumberOfTabs = getStateTabCount(retrievedState);
57 is(actualNumberOfTabs, expectedNumberOfTabs,
58 "Number of tabs in retreived session data, matches number of tabs set.");
60 done();
61 });
62 });
63 }
65 function done() {
66 // Enumerate windows and close everything but our primary window. We can't
67 // use waitForFocus() because apparently it's buggy. See bug 599253.
68 let windowsEnum = Services.wm.getEnumerator("navigator:browser");
69 while (windowsEnum.hasMoreElements()) {
70 let currentWindow = windowsEnum.getNext();
71 if (currentWindow != window)
72 currentWindow.close();
73 }
75 waitForBrowserState(stateBackup, finish);
76 }
78 // Count up the number of tabs in the state data
79 function getStateTabCount(aState) {
80 let tabCount = 0;
81 for (let i in aState.windows)
82 tabCount += aState.windows[i].tabs.length;
83 return tabCount;
84 }