browser/components/sessionstore/test/browser_586068-apptabs_ondemand.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/browser/components/sessionstore/test/browser_586068-apptabs_ondemand.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,50 @@
     1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.7 +
     1.8 +const PREF_RESTORE_ON_DEMAND = "browser.sessionstore.restore_on_demand";
     1.9 +const PREF_RESTORE_PINNED_TABS_ON_DEMAND = "browser.sessionstore.restore_pinned_tabs_on_demand";
    1.10 +
    1.11 +function test() {
    1.12 +  TestRunner.run();
    1.13 +}
    1.14 +
    1.15 +function runTests() {
    1.16 +  Services.prefs.setBoolPref(PREF_RESTORE_ON_DEMAND, true);
    1.17 +  Services.prefs.setBoolPref(PREF_RESTORE_PINNED_TABS_ON_DEMAND, true);
    1.18 +
    1.19 +  registerCleanupFunction(function () {
    1.20 +    Services.prefs.clearUserPref(PREF_RESTORE_ON_DEMAND);
    1.21 +    Services.prefs.clearUserPref(PREF_RESTORE_PINNED_TABS_ON_DEMAND);
    1.22 +  });
    1.23 +
    1.24 +  let state = { windows: [{ tabs: [
    1.25 +    { entries: [{ url: "http://example.org/#1" }], extData: { "uniq": r() }, pinned: true },
    1.26 +    { entries: [{ url: "http://example.org/#2" }], extData: { "uniq": r() }, pinned: true },
    1.27 +    { entries: [{ url: "http://example.org/#3" }], extData: { "uniq": r() }, pinned: true },
    1.28 +    { entries: [{ url: "http://example.org/#4" }], extData: { "uniq": r() } },
    1.29 +    { entries: [{ url: "http://example.org/#5" }], extData: { "uniq": r() } },
    1.30 +    { entries: [{ url: "http://example.org/#6" }], extData: { "uniq": r() } },
    1.31 +    { entries: [{ url: "http://example.org/#7" }], extData: { "uniq": r() } },
    1.32 +  ], selected: 5 }] };
    1.33 +
    1.34 +  gProgressListener.setCallback(function (aBrowser, aNeedRestore, aRestoring, aRestored) {
    1.35 +    // get the tab
    1.36 +    let tab;
    1.37 +    for (let i = 0; i < window.gBrowser.tabs.length; i++) {
    1.38 +      if (!tab && window.gBrowser.tabs[i].linkedBrowser == aBrowser)
    1.39 +        tab = window.gBrowser.tabs[i];
    1.40 +    }
    1.41 +
    1.42 +    // Check that the load only comes from the selected tab.
    1.43 +    ok(tab.selected, "load came from selected tab");
    1.44 +    is(aNeedRestore, 6, "six tabs left to restore");
    1.45 +    is(aRestoring, 1, "one tab is restoring");
    1.46 +    is(aRestored, 0, "no tabs have been restored, yet");
    1.47 +
    1.48 +    gProgressListener.unsetCallback();
    1.49 +    executeSoon(next);
    1.50 +  });
    1.51 +
    1.52 +  yield ss.setBrowserState(JSON.stringify(state));
    1.53 +}

mercurial