browser/components/sessionstore/test/browser_586068-select.js

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:2ebb9e68c158
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 const PREF_RESTORE_ON_DEMAND = "browser.sessionstore.restore_on_demand";
6
7 function test() {
8 TestRunner.run();
9 }
10
11 function runTests() {
12 Services.prefs.setBoolPref(PREF_RESTORE_ON_DEMAND, true);
13 registerCleanupFunction(function () {
14 Services.prefs.clearUserPref(PREF_RESTORE_ON_DEMAND);
15 });
16
17 let state = { windows: [{ tabs: [
18 { entries: [{ url: "http://example.org" }], extData: { "uniq": r() } },
19 { entries: [{ url: "http://example.org" }], extData: { "uniq": r() } },
20 { entries: [{ url: "http://example.org" }], extData: { "uniq": r() } },
21 { entries: [{ url: "http://example.org" }], extData: { "uniq": r() } },
22 { entries: [{ url: "http://example.org" }], extData: { "uniq": r() } },
23 { entries: [{ url: "http://example.org" }], extData: { "uniq": r() } }
24 ], selected: 1 }] };
25
26 let expectedCounts = [
27 [5, 1, 0],
28 [4, 1, 1],
29 [3, 1, 2],
30 [2, 1, 3],
31 [1, 1, 4],
32 [0, 1, 5]
33 ];
34 let tabOrder = [0, 5, 1, 4, 3, 2];
35
36 let loadCount = 0;
37 gProgressListener.setCallback(function (aBrowser, aNeedRestore, aRestoring, aRestored) {
38 loadCount++;
39 let expected = expectedCounts[loadCount - 1];
40
41 is(aNeedRestore, expected[0], "load " + loadCount + " - # tabs that need to be restored");
42 is(aRestoring, expected[1], "load " + loadCount + " - # tabs that are restoring");
43 is(aRestored, expected[2], "load " + loadCount + " - # tabs that has been restored");
44
45 if (loadCount < state.windows[0].tabs.length) {
46 // double check that this tab was the right one
47 let expectedData = state.windows[0].tabs[tabOrder[loadCount - 1]].extData.uniq;
48 let tab;
49 for (let i = 0; i < window.gBrowser.tabs.length; i++) {
50 if (!tab && window.gBrowser.tabs[i].linkedBrowser == aBrowser)
51 tab = window.gBrowser.tabs[i];
52 }
53
54 is(ss.getTabValue(tab, "uniq"), expectedData,
55 "load " + loadCount + " - correct tab was restored");
56
57 // select the next tab
58 window.gBrowser.selectTabAtIndex(tabOrder[loadCount]);
59 } else {
60 gProgressListener.unsetCallback();
61 executeSoon(next);
62 }
63 });
64
65 yield ss.setBrowserState(JSON.stringify(state));
66 }

mercurial