1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/components/sessionstore/test/browser_586147.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,64 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 + 1.8 +function observeOneRestore(callback) { 1.9 + let topic = "sessionstore-browser-state-restored"; 1.10 + Services.obs.addObserver(function onRestore() { 1.11 + Services.obs.removeObserver(onRestore, topic); 1.12 + callback(); 1.13 + }, topic, false); 1.14 +}; 1.15 + 1.16 +function test() { 1.17 + waitForExplicitFinish(); 1.18 + 1.19 + // Disable Panorama, since it conflicts with this test. 1.20 + let tabview = document.getElementById("tab-view"); 1.21 + if (tabview) { 1.22 + document.getElementById("tab-view").contentWindow.UI.uninit(); 1.23 + TabView.uninit(); 1.24 + } 1.25 + 1.26 + // There should be one tab when we start the test 1.27 + let [origTab] = gBrowser.visibleTabs; 1.28 + let hiddenTab = gBrowser.addTab(); 1.29 + 1.30 + is(gBrowser.visibleTabs.length, 2, "should have 2 tabs before hiding"); 1.31 + gBrowser.showOnlyTheseTabs([origTab]); 1.32 + is(gBrowser.visibleTabs.length, 1, "only 1 after hiding"); 1.33 + ok(hiddenTab.hidden, "sanity check that it's hidden"); 1.34 + 1.35 + let extraTab = gBrowser.addTab(); 1.36 + let state = ss.getBrowserState(); 1.37 + let stateObj = JSON.parse(state); 1.38 + let tabs = stateObj.windows[0].tabs; 1.39 + is(tabs.length, 3, "just checking that browser state is correct"); 1.40 + ok(!tabs[0].hidden, "first tab is visible"); 1.41 + ok(tabs[1].hidden, "second is hidden"); 1.42 + ok(!tabs[2].hidden, "third is visible"); 1.43 + 1.44 + // Make the third tab hidden and then restore the modified state object 1.45 + tabs[2].hidden = true; 1.46 + 1.47 + observeOneRestore(function() { 1.48 + let testWindow = Services.wm.getEnumerator("navigator:browser").getNext(); 1.49 + is(testWindow.gBrowser.visibleTabs.length, 1, "only restored 1 visible tab"); 1.50 + let tabs = testWindow.gBrowser.tabs; 1.51 + ok(!tabs[0].hidden, "first is still visible"); 1.52 + ok(tabs[1].hidden, "second tab is still hidden"); 1.53 + ok(tabs[2].hidden, "third tab is now hidden"); 1.54 + 1.55 + // Restore the original state and clean up now that we're done 1.56 + gBrowser.removeTab(hiddenTab); 1.57 + gBrowser.removeTab(extraTab); 1.58 + 1.59 + // Re-enable Panorama. 1.60 + if (tabview) { 1.61 + TabView.init(); 1.62 + } 1.63 + 1.64 + finish(); 1.65 + }); 1.66 + ss.setBrowserState(JSON.stringify(stateObj)); 1.67 +}