|
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 let state = { windows: [{ tabs: [ |
|
18 { entries: [{ url: "http://example.com" }], extData: { "uniq": r() } }, |
|
19 { entries: [{ url: "http://example.com" }], extData: { "uniq": r() } }, |
|
20 { entries: [{ url: "http://example.com" }], extData: { "uniq": r() } }, |
|
21 { entries: [{ url: "http://example.com" }], extData: { "uniq": r() } }, |
|
22 { entries: [{ url: "http://example.com" }], extData: { "uniq": r() } }, |
|
23 { entries: [{ url: "http://example.com" }], extData: { "uniq": r() } } |
|
24 ] }] }; |
|
25 |
|
26 let expectedCounts = [ |
|
27 [3, 3, 0], |
|
28 [2, 3, 1], |
|
29 [1, 3, 2], |
|
30 [0, 3, 3], |
|
31 [0, 2, 4], |
|
32 [0, 1, 5] |
|
33 ]; |
|
34 |
|
35 let loadCount = 0; |
|
36 gProgressListener.setCallback(function (aBrowser, aNeedRestore, aRestoring, aRestored) { |
|
37 loadCount++; |
|
38 let expected = expectedCounts[loadCount - 1]; |
|
39 |
|
40 is(aNeedRestore, expected[0], "load " + loadCount + " - # tabs that need to be restored"); |
|
41 is(aRestoring, expected[1], "load " + loadCount + " - # tabs that are restoring"); |
|
42 is(aRestored, expected[2], "load " + loadCount + " - # tabs that has been restored"); |
|
43 |
|
44 if (loadCount == state.windows[0].tabs.length) { |
|
45 gProgressListener.unsetCallback(); |
|
46 executeSoon(next); |
|
47 } |
|
48 }); |
|
49 |
|
50 yield ss.setBrowserState(JSON.stringify(state)); |
|
51 } |