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

branch
TOR_BUG_9701
changeset 15
b8a032363ba2
equal deleted inserted replaced
-1:000000000000 0:6aba5c1bdabc
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, false);
13 registerCleanupFunction(function () {
14 Services.prefs.clearUserPref(PREF_RESTORE_ON_DEMAND);
15 });
16
17 // We'll use 2 states so that we can make sure calling setWindowState doesn't
18 // wipe out currently restoring data.
19 let state1 = { windows: [{ tabs: [
20 { entries: [{ url: "http://example.com#1" }] },
21 { entries: [{ url: "http://example.com#2" }] },
22 { entries: [{ url: "http://example.com#3" }] },
23 { entries: [{ url: "http://example.com#4" }] },
24 { entries: [{ url: "http://example.com#5" }] },
25 ] }] };
26 let state2 = { windows: [{ tabs: [
27 { entries: [{ url: "http://example.org#1" }] },
28 { entries: [{ url: "http://example.org#2" }] },
29 { entries: [{ url: "http://example.org#3" }] },
30 { entries: [{ url: "http://example.org#4" }] },
31 { entries: [{ url: "http://example.org#5" }] }
32 ] }] };
33 let numTabs = state1.windows[0].tabs.length + state2.windows[0].tabs.length;
34
35 let loadCount = 0;
36 gProgressListener.setCallback(function (aBrowser, aNeedRestore, aRestoring, aRestored) {
37 // When loadCount == 2, we'll also restore state2 into the window
38 if (++loadCount == 2) {
39 ss.setWindowState(window, JSON.stringify(state2), false);
40 }
41
42 if (loadCount < numTabs) {
43 return;
44 }
45
46 // We don't actually care about load order in this test, just that they all
47 // do load.
48 is(loadCount, numTabs, "test_setWindowStateNoOverwrite: all tabs were restored");
49 is(aNeedRestore, 0, "there are no tabs left needing restore");
50
51 gProgressListener.unsetCallback();
52 executeSoon(next);
53 });
54
55 yield ss.setWindowState(window, JSON.stringify(state1), true);
56 }

mercurial