michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: const TEST_URL = "http://mochi.test:8888/browser/browser/components/" + michael@0: "sessionstore/test/browser_637020_slow.sjs"; michael@0: michael@0: const TEST_STATE = { michael@0: windows: [{ michael@0: tabs: [ michael@0: { entries: [{ url: "about:mozilla" }] }, michael@0: { entries: [{ url: "about:robots" }] } michael@0: ] michael@0: }, { michael@0: tabs: [ michael@0: { entries: [{ url: TEST_URL }] }, michael@0: { entries: [{ url: TEST_URL }] } michael@0: ] michael@0: }] michael@0: }; michael@0: michael@0: function test() { michael@0: TestRunner.run(); michael@0: } michael@0: michael@0: /** michael@0: * This test ensures that windows that have just been restored will be marked michael@0: * as dirty, otherwise _getCurrentState() might ignore them when collecting michael@0: * state for the first time and we'd just save them as empty objects. michael@0: * michael@0: * The dirty state acts as a cache to not collect data from all windows all the michael@0: * time, so at the beginning, each window must be dirty so that we collect michael@0: * their state at least once. michael@0: */ michael@0: michael@0: function runTests() { michael@0: let win; michael@0: michael@0: // Wait until the new window has been opened. michael@0: Services.obs.addObserver(function onOpened(subject) { michael@0: Services.obs.removeObserver(onOpened, "domwindowopened"); michael@0: win = subject; michael@0: executeSoon(next); michael@0: }, "domwindowopened", false); michael@0: michael@0: // Set the new browser state that will michael@0: // restore a window with two slowly loading tabs. michael@0: yield SessionStore.setBrowserState(JSON.stringify(TEST_STATE)); michael@0: michael@0: // The window has now been opened. Check the state that is returned, michael@0: // this should come from the cache while the window isn't restored, yet. michael@0: info("the window has been opened"); michael@0: checkWindows(); michael@0: michael@0: // The history has now been restored and the tabs are loading. The data must michael@0: // now come from the window, if it's correctly been marked as dirty before. michael@0: yield whenDelayedStartupFinished(win, next); michael@0: info("the delayed startup has finished"); michael@0: checkWindows(); michael@0: } michael@0: michael@0: function checkWindows() { michael@0: let state = JSON.parse(SessionStore.getBrowserState()); michael@0: is(state.windows[0].tabs.length, 2, "first window has two tabs"); michael@0: is(state.windows[1].tabs.length, 2, "second window has two tabs"); michael@0: }