Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
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/. */
5 const PREF_RESTORE_ON_DEMAND = "browser.sessionstore.restore_on_demand";
7 function test() {
8 TestRunner.run();
9 }
11 function runTests() {
12 Services.prefs.setBoolPref(PREF_RESTORE_ON_DEMAND, false);
13 registerCleanupFunction(function () {
14 Services.prefs.clearUserPref(PREF_RESTORE_ON_DEMAND);
15 });
17 // The first state will be loaded using setBrowserState, followed by the 2nd
18 // state also being loaded using setBrowserState, interrupting the first restore.
19 let state1 = { windows: [
20 {
21 tabs: [
22 { entries: [{ url: "http://example.org#1" }], extData: { "uniq": r() } },
23 { entries: [{ url: "http://example.org#2" }], extData: { "uniq": r() } },
24 { entries: [{ url: "http://example.org#3" }], extData: { "uniq": r() } },
25 { entries: [{ url: "http://example.org#4" }], extData: { "uniq": r() } }
26 ],
27 selected: 1
28 },
29 {
30 tabs: [
31 { entries: [{ url: "http://example.com#1" }], extData: { "uniq": r() } },
32 { entries: [{ url: "http://example.com#2" }], extData: { "uniq": r() } },
33 { entries: [{ url: "http://example.com#3" }], extData: { "uniq": r() } },
34 { entries: [{ url: "http://example.com#4" }], extData: { "uniq": r() } },
35 ],
36 selected: 3
37 }
38 ] };
39 let state2 = { windows: [
40 {
41 tabs: [
42 { entries: [{ url: "http://example.org#5" }], extData: { "uniq": r() } },
43 { entries: [{ url: "http://example.org#6" }], extData: { "uniq": r() } },
44 { entries: [{ url: "http://example.org#7" }], extData: { "uniq": r() } },
45 { entries: [{ url: "http://example.org#8" }], extData: { "uniq": r() } }
46 ],
47 selected: 3
48 },
49 {
50 tabs: [
51 { entries: [{ url: "http://example.com#5" }], extData: { "uniq": r() } },
52 { entries: [{ url: "http://example.com#6" }], extData: { "uniq": r() } },
53 { entries: [{ url: "http://example.com#7" }], extData: { "uniq": r() } },
54 { entries: [{ url: "http://example.com#8" }], extData: { "uniq": r() } },
55 ],
56 selected: 1
57 }
58 ] };
60 // interruptedAfter will be set after the selected tab from each window have loaded.
61 let interruptedAfter = 0;
62 let loadedWindow1 = false;
63 let loadedWindow2 = false;
64 let numTabs = state2.windows[0].tabs.length + state2.windows[1].tabs.length;
66 let loadCount = 0;
67 gProgressListener.setCallback(function (aBrowser, aNeedRestore, aRestoring, aRestored) {
68 loadCount++;
70 if (aBrowser.currentURI.spec == state1.windows[0].tabs[2].entries[0].url)
71 loadedWindow1 = true;
72 if (aBrowser.currentURI.spec == state1.windows[1].tabs[0].entries[0].url)
73 loadedWindow2 = true;
75 if (!interruptedAfter && loadedWindow1 && loadedWindow2) {
76 interruptedAfter = loadCount;
77 ss.setBrowserState(JSON.stringify(state2));
78 return;
79 }
81 if (loadCount < numTabs + interruptedAfter)
82 return;
84 // We don't actually care about load order in this test, just that they all
85 // do load.
86 is(loadCount, numTabs + interruptedAfter, "all tabs were restored");
87 is(aNeedRestore, 0, "there are no tabs left needing restore");
89 // Remove the progress listener from this window, it will be removed from
90 // theWin when that window is closed (in setBrowserState).
91 gProgressListener.unsetCallback();
92 executeSoon(next);
93 });
95 // We also want to catch the extra windows (there should be 2), so we need to observe domwindowopened
96 Services.ww.registerNotification(function observer(aSubject, aTopic, aData) {
97 if (aTopic == "domwindowopened") {
98 let win = aSubject.QueryInterface(Ci.nsIDOMWindow);
99 win.addEventListener("load", function onLoad() {
100 win.removeEventListener("load", onLoad);
101 Services.ww.unregisterNotification(observer);
102 win.gBrowser.addTabsProgressListener(gProgressListener);
103 });
104 }
105 });
107 yield ss.setBrowserState(JSON.stringify(state1));
108 }