browser/components/sessionstore/test/browser_586147.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 observeOneRestore(callback) {
michael@0 6 let topic = "sessionstore-browser-state-restored";
michael@0 7 Services.obs.addObserver(function onRestore() {
michael@0 8 Services.obs.removeObserver(onRestore, topic);
michael@0 9 callback();
michael@0 10 }, topic, false);
michael@0 11 };
michael@0 12
michael@0 13 function test() {
michael@0 14 waitForExplicitFinish();
michael@0 15
michael@0 16 // Disable Panorama, since it conflicts with this test.
michael@0 17 let tabview = document.getElementById("tab-view");
michael@0 18 if (tabview) {
michael@0 19 document.getElementById("tab-view").contentWindow.UI.uninit();
michael@0 20 TabView.uninit();
michael@0 21 }
michael@0 22
michael@0 23 // There should be one tab when we start the test
michael@0 24 let [origTab] = gBrowser.visibleTabs;
michael@0 25 let hiddenTab = gBrowser.addTab();
michael@0 26
michael@0 27 is(gBrowser.visibleTabs.length, 2, "should have 2 tabs before hiding");
michael@0 28 gBrowser.showOnlyTheseTabs([origTab]);
michael@0 29 is(gBrowser.visibleTabs.length, 1, "only 1 after hiding");
michael@0 30 ok(hiddenTab.hidden, "sanity check that it's hidden");
michael@0 31
michael@0 32 let extraTab = gBrowser.addTab();
michael@0 33 let state = ss.getBrowserState();
michael@0 34 let stateObj = JSON.parse(state);
michael@0 35 let tabs = stateObj.windows[0].tabs;
michael@0 36 is(tabs.length, 3, "just checking that browser state is correct");
michael@0 37 ok(!tabs[0].hidden, "first tab is visible");
michael@0 38 ok(tabs[1].hidden, "second is hidden");
michael@0 39 ok(!tabs[2].hidden, "third is visible");
michael@0 40
michael@0 41 // Make the third tab hidden and then restore the modified state object
michael@0 42 tabs[2].hidden = true;
michael@0 43
michael@0 44 observeOneRestore(function() {
michael@0 45 let testWindow = Services.wm.getEnumerator("navigator:browser").getNext();
michael@0 46 is(testWindow.gBrowser.visibleTabs.length, 1, "only restored 1 visible tab");
michael@0 47 let tabs = testWindow.gBrowser.tabs;
michael@0 48 ok(!tabs[0].hidden, "first is still visible");
michael@0 49 ok(tabs[1].hidden, "second tab is still hidden");
michael@0 50 ok(tabs[2].hidden, "third tab is now hidden");
michael@0 51
michael@0 52 // Restore the original state and clean up now that we're done
michael@0 53 gBrowser.removeTab(hiddenTab);
michael@0 54 gBrowser.removeTab(extraTab);
michael@0 55
michael@0 56 // Re-enable Panorama.
michael@0 57 if (tabview) {
michael@0 58 TabView.init();
michael@0 59 }
michael@0 60
michael@0 61 finish();
michael@0 62 });
michael@0 63 ss.setBrowserState(JSON.stringify(stateObj));
michael@0 64 }

mercurial