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 /* Any copyright is dedicated to the Public Domain.
2 http://creativecommons.org/publicdomain/zero/1.0/ */
4 const TEST_URL = "http://mochi.test:8888/browser/browser/components/" +
5 "sessionstore/test/browser_637020_slow.sjs";
7 const TEST_STATE = {
8 windows: [{
9 tabs: [
10 { entries: [{ url: "about:mozilla" }] },
11 { entries: [{ url: "about:robots" }] }
12 ]
13 }, {
14 tabs: [
15 { entries: [{ url: TEST_URL }] },
16 { entries: [{ url: TEST_URL }] }
17 ]
18 }]
19 };
21 function test() {
22 TestRunner.run();
23 }
25 /**
26 * This test ensures that windows that have just been restored will be marked
27 * as dirty, otherwise _getCurrentState() might ignore them when collecting
28 * state for the first time and we'd just save them as empty objects.
29 *
30 * The dirty state acts as a cache to not collect data from all windows all the
31 * time, so at the beginning, each window must be dirty so that we collect
32 * their state at least once.
33 */
35 function runTests() {
36 let win;
38 // Wait until the new window has been opened.
39 Services.obs.addObserver(function onOpened(subject) {
40 Services.obs.removeObserver(onOpened, "domwindowopened");
41 win = subject;
42 executeSoon(next);
43 }, "domwindowopened", false);
45 // Set the new browser state that will
46 // restore a window with two slowly loading tabs.
47 yield SessionStore.setBrowserState(JSON.stringify(TEST_STATE));
49 // The window has now been opened. Check the state that is returned,
50 // this should come from the cache while the window isn't restored, yet.
51 info("the window has been opened");
52 checkWindows();
54 // The history has now been restored and the tabs are loading. The data must
55 // now come from the window, if it's correctly been marked as dirty before.
56 yield whenDelayedStartupFinished(win, next);
57 info("the delayed startup has finished");
58 checkWindows();
59 }
61 function checkWindows() {
62 let state = JSON.parse(SessionStore.getBrowserState());
63 is(state.windows[0].tabs.length, 2, "first window has two tabs");
64 is(state.windows[1].tabs.length, 2, "second window has two tabs");
65 }