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

mercurial