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