browser/components/sessionstore/test/browser_637020.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/browser/components/sessionstore/test/browser_637020.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,65 @@
     1.4 +/* Any copyright is dedicated to the Public Domain.
     1.5 +   http://creativecommons.org/publicdomain/zero/1.0/ */
     1.6 +
     1.7 +const TEST_URL = "http://mochi.test:8888/browser/browser/components/" +
     1.8 +                 "sessionstore/test/browser_637020_slow.sjs";
     1.9 +
    1.10 +const TEST_STATE = {
    1.11 +  windows: [{
    1.12 +    tabs: [
    1.13 +      { entries: [{ url: "about:mozilla" }] },
    1.14 +      { entries: [{ url: "about:robots" }] }
    1.15 +    ]
    1.16 +  }, {
    1.17 +    tabs: [
    1.18 +      { entries: [{ url: TEST_URL }] },
    1.19 +      { entries: [{ url: TEST_URL }] }
    1.20 +    ]
    1.21 +  }]
    1.22 +};
    1.23 +
    1.24 +function test() {
    1.25 +  TestRunner.run();
    1.26 +}
    1.27 +
    1.28 +/**
    1.29 + * This test ensures that windows that have just been restored will be marked
    1.30 + * as dirty, otherwise _getCurrentState() might ignore them when collecting
    1.31 + * state for the first time and we'd just save them as empty objects.
    1.32 + *
    1.33 + * The dirty state acts as a cache to not collect data from all windows all the
    1.34 + * time, so at the beginning, each window must be dirty so that we collect
    1.35 + * their state at least once.
    1.36 + */
    1.37 +
    1.38 +function runTests() {
    1.39 +  let win;
    1.40 +
    1.41 +  // Wait until the new window has been opened.
    1.42 +  Services.obs.addObserver(function onOpened(subject) {
    1.43 +    Services.obs.removeObserver(onOpened, "domwindowopened");
    1.44 +    win = subject;
    1.45 +    executeSoon(next);
    1.46 +  }, "domwindowopened", false);
    1.47 +
    1.48 +  // Set the new browser state that will
    1.49 +  // restore a window with two slowly loading tabs.
    1.50 +  yield SessionStore.setBrowserState(JSON.stringify(TEST_STATE));
    1.51 +
    1.52 +  // The window has now been opened. Check the state that is returned,
    1.53 +  // this should come from the cache while the window isn't restored, yet.
    1.54 +  info("the window has been opened");
    1.55 +  checkWindows();
    1.56 +
    1.57 +  // The history has now been restored and the tabs are loading. The data must
    1.58 +  // now come from the window, if it's correctly been marked as dirty before.
    1.59 +  yield whenDelayedStartupFinished(win, next);
    1.60 +  info("the delayed startup has finished");
    1.61 +  checkWindows();
    1.62 +}
    1.63 +
    1.64 +function checkWindows() {
    1.65 +  let state = JSON.parse(SessionStore.getBrowserState());
    1.66 +  is(state.windows[0].tabs.length, 2, "first window has two tabs");
    1.67 +  is(state.windows[1].tabs.length, 2, "second window has two tabs");
    1.68 +}

mercurial