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