michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: function observeOneRestore(callback) { michael@0: let topic = "sessionstore-browser-state-restored"; michael@0: Services.obs.addObserver(function onRestore() { michael@0: Services.obs.removeObserver(onRestore, topic); michael@0: callback(); michael@0: }, topic, false); michael@0: }; michael@0: michael@0: function test() { michael@0: waitForExplicitFinish(); michael@0: michael@0: // Disable Panorama, since it conflicts with this test. michael@0: let tabview = document.getElementById("tab-view"); michael@0: if (tabview) { michael@0: document.getElementById("tab-view").contentWindow.UI.uninit(); michael@0: TabView.uninit(); michael@0: } michael@0: michael@0: // There should be one tab when we start the test michael@0: let [origTab] = gBrowser.visibleTabs; michael@0: let hiddenTab = gBrowser.addTab(); michael@0: michael@0: is(gBrowser.visibleTabs.length, 2, "should have 2 tabs before hiding"); michael@0: gBrowser.showOnlyTheseTabs([origTab]); michael@0: is(gBrowser.visibleTabs.length, 1, "only 1 after hiding"); michael@0: ok(hiddenTab.hidden, "sanity check that it's hidden"); michael@0: michael@0: let extraTab = gBrowser.addTab(); michael@0: let state = ss.getBrowserState(); michael@0: let stateObj = JSON.parse(state); michael@0: let tabs = stateObj.windows[0].tabs; michael@0: is(tabs.length, 3, "just checking that browser state is correct"); michael@0: ok(!tabs[0].hidden, "first tab is visible"); michael@0: ok(tabs[1].hidden, "second is hidden"); michael@0: ok(!tabs[2].hidden, "third is visible"); michael@0: michael@0: // Make the third tab hidden and then restore the modified state object michael@0: tabs[2].hidden = true; michael@0: michael@0: observeOneRestore(function() { michael@0: let testWindow = Services.wm.getEnumerator("navigator:browser").getNext(); michael@0: is(testWindow.gBrowser.visibleTabs.length, 1, "only restored 1 visible tab"); michael@0: let tabs = testWindow.gBrowser.tabs; michael@0: ok(!tabs[0].hidden, "first is still visible"); michael@0: ok(tabs[1].hidden, "second tab is still hidden"); michael@0: ok(tabs[2].hidden, "third tab is now hidden"); michael@0: michael@0: // Restore the original state and clean up now that we're done michael@0: gBrowser.removeTab(hiddenTab); michael@0: gBrowser.removeTab(extraTab); michael@0: michael@0: // Re-enable Panorama. michael@0: if (tabview) { michael@0: TabView.init(); michael@0: } michael@0: michael@0: finish(); michael@0: }); michael@0: ss.setBrowserState(JSON.stringify(stateObj)); michael@0: }