browser/components/sessionstore/test/browser_637020.js

branch
TOR_BUG_9701
changeset 15
b8a032363ba2
equal deleted inserted replaced
-1:000000000000 0:20138ead98f1
1 /* Any copyright is dedicated to the Public Domain.
2 http://creativecommons.org/publicdomain/zero/1.0/ */
3
4 const TEST_URL = "http://mochi.test:8888/browser/browser/components/" +
5 "sessionstore/test/browser_637020_slow.sjs";
6
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 };
20
21 function test() {
22 TestRunner.run();
23 }
24
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 */
34
35 function runTests() {
36 let win;
37
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);
44
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));
48
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();
53
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 }
60
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 }

mercurial