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

mercurial