|
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 let stateBackup = ss.getBrowserState(); |
|
6 |
|
7 function cleanup() { |
|
8 // Reset the pref |
|
9 try { |
|
10 Services.prefs.clearUserPref("browser.sessionstore.restore_on_demand"); |
|
11 } catch (e) {} |
|
12 ss.setBrowserState(stateBackup); |
|
13 executeSoon(finish); |
|
14 } |
|
15 |
|
16 function test() { |
|
17 /** Bug 607016 - If a tab is never restored, attributes (eg. hidden) aren't updated correctly **/ |
|
18 waitForExplicitFinish(); |
|
19 ignoreAllUncaughtExceptions(); |
|
20 |
|
21 // Set the pref to true so we know exactly how many tabs should be restoring at |
|
22 // any given time. This guarantees that a finishing load won't start another. |
|
23 Services.prefs.setBoolPref("browser.sessionstore.restore_on_demand", true); |
|
24 |
|
25 // We have our own progress listener for this test, which we'll attach before our state is set |
|
26 let progressListener = { |
|
27 onStateChange: function (aBrowser, aWebProgress, aRequest, aStateFlags, aStatus) { |
|
28 if (aBrowser.__SS_restoreState == TAB_STATE_RESTORING && |
|
29 aStateFlags & Ci.nsIWebProgressListener.STATE_STOP && |
|
30 aStateFlags & Ci.nsIWebProgressListener.STATE_IS_NETWORK && |
|
31 aStateFlags & Ci.nsIWebProgressListener.STATE_IS_WINDOW) |
|
32 progressCallback(aBrowser); |
|
33 } |
|
34 } |
|
35 |
|
36 let state = { windows: [{ tabs: [ |
|
37 { entries: [{ url: "http://example.org#1" }], extData: { "uniq": r() } }, |
|
38 { entries: [{ url: "http://example.org#2" }], extData: { "uniq": r() } }, // overwriting |
|
39 { entries: [{ url: "http://example.org#3" }], extData: { "uniq": r() } }, // hiding |
|
40 { entries: [{ url: "http://example.org#4" }], extData: { "uniq": r() } }, // adding |
|
41 { entries: [{ url: "http://example.org#5" }], extData: { "uniq": r() } }, // deleting |
|
42 { entries: [{ url: "http://example.org#6" }] } // creating |
|
43 ], selected: 1 }] }; |
|
44 |
|
45 function progressCallback(aBrowser) { |
|
46 // We'll remove the progress listener after the first one because we aren't |
|
47 // loading any other tabs |
|
48 window.gBrowser.removeTabsProgressListener(progressListener); |
|
49 |
|
50 let curState = JSON.parse(ss.getBrowserState()); |
|
51 for (let i = 0; i < curState.windows[0].tabs.length; i++) { |
|
52 let tabState = state.windows[0].tabs[i]; |
|
53 let tabCurState = curState.windows[0].tabs[i]; |
|
54 if (tabState.extData) { |
|
55 is(tabCurState.extData["uniq"], tabState.extData["uniq"], |
|
56 "sanity check that tab has correct extData"); |
|
57 } |
|
58 else { |
|
59 // We aren't expecting there to be any data on extData, but panorama |
|
60 // may be setting something, so we need to make sure that if we do have |
|
61 // data, we just don't have anything for "uniq". |
|
62 ok(!("extData" in tabCurState) || !("uniq" in tabCurState.extData), |
|
63 "sanity check that tab doesn't have extData or extData doesn't have 'uniq'"); |
|
64 } |
|
65 } |
|
66 |
|
67 // Now we'll set a new unique value on 1 of the tabs |
|
68 let newUniq = r(); |
|
69 ss.setTabValue(gBrowser.tabs[1], "uniq", newUniq); |
|
70 gBrowser.removeTab(gBrowser.tabs[1]); |
|
71 let closedTabData = (JSON.parse(ss.getClosedTabData(window)))[0]; |
|
72 is(closedTabData.state.extData.uniq, newUniq, |
|
73 "(overwriting) new data is stored in extData"); |
|
74 |
|
75 // hide the next tab before closing it |
|
76 gBrowser.hideTab(gBrowser.tabs[1]); |
|
77 gBrowser.removeTab(gBrowser.tabs[1]); |
|
78 closedTabData = (JSON.parse(ss.getClosedTabData(window)))[0]; |
|
79 ok(closedTabData.state.hidden, "(hiding) tab data has hidden == true"); |
|
80 |
|
81 // set data that's not in a conflicting key |
|
82 let stillUniq = r(); |
|
83 ss.setTabValue(gBrowser.tabs[1], "stillUniq", stillUniq); |
|
84 gBrowser.removeTab(gBrowser.tabs[1]); |
|
85 closedTabData = (JSON.parse(ss.getClosedTabData(window)))[0]; |
|
86 is(closedTabData.state.extData.stillUniq, stillUniq, |
|
87 "(adding) new data is stored in extData"); |
|
88 |
|
89 // remove the uniq value and make sure it's not there in the closed data |
|
90 ss.deleteTabValue(gBrowser.tabs[1], "uniq"); |
|
91 gBrowser.removeTab(gBrowser.tabs[1]); |
|
92 closedTabData = (JSON.parse(ss.getClosedTabData(window)))[0]; |
|
93 // Since Panorama might have put data in, first check if there is extData. |
|
94 // If there is explicitly check that "uniq" isn't in it. Otherwise, we're ok |
|
95 if ("extData" in closedTabData.state) { |
|
96 ok(!("uniq" in closedTabData.state.extData), |
|
97 "(deleting) uniq not in existing extData"); |
|
98 } |
|
99 else { |
|
100 ok(true, "(deleting) no data is stored in extData"); |
|
101 } |
|
102 |
|
103 // set unique data on the tab that never had any set, make sure that's saved |
|
104 let newUniq2 = r(); |
|
105 ss.setTabValue(gBrowser.tabs[1], "uniq", newUniq2); |
|
106 gBrowser.removeTab(gBrowser.tabs[1]); |
|
107 closedTabData = (JSON.parse(ss.getClosedTabData(window)))[0]; |
|
108 is(closedTabData.state.extData.uniq, newUniq2, |
|
109 "(creating) new data is stored in extData where there was none"); |
|
110 |
|
111 cleanup(); |
|
112 } |
|
113 |
|
114 window.gBrowser.addTabsProgressListener(progressListener); |
|
115 ss.setBrowserState(JSON.stringify(state)); |
|
116 } |
|
117 |