browser/components/sessionstore/test/browser_586068-multi_window.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-multi_window.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,66 @@
     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 +
    1.10 +function test() {
    1.11 +  TestRunner.run();
    1.12 +}
    1.13 +
    1.14 +function runTests() {
    1.15 +  Services.prefs.setBoolPref(PREF_RESTORE_ON_DEMAND, false);
    1.16 +  registerCleanupFunction(function () {
    1.17 +    Services.prefs.clearUserPref(PREF_RESTORE_ON_DEMAND);
    1.18 +  });
    1.19 +
    1.20 +  // The first window will be put into the already open window and the second
    1.21 +  // window will be opened with _openWindowWithState, which is the source of the problem.
    1.22 +  let state = { windows: [
    1.23 +    {
    1.24 +      tabs: [
    1.25 +        { entries: [{ url: "http://example.org#0" }], extData: { "uniq": r() } }
    1.26 +      ],
    1.27 +      selected: 1
    1.28 +    },
    1.29 +    {
    1.30 +      tabs: [
    1.31 +        { entries: [{ url: "http://example.com#1" }], extData: { "uniq": r() } },
    1.32 +        { entries: [{ url: "http://example.com#2" }], extData: { "uniq": r() } },
    1.33 +        { entries: [{ url: "http://example.com#3" }], extData: { "uniq": r() } },
    1.34 +        { entries: [{ url: "http://example.com#4" }], extData: { "uniq": r() } },
    1.35 +        { entries: [{ url: "http://example.com#5" }], extData: { "uniq": r() } },
    1.36 +        { entries: [{ url: "http://example.com#6" }], extData: { "uniq": r() } }
    1.37 +      ],
    1.38 +      selected: 4
    1.39 +    }
    1.40 +  ] };
    1.41 +  let numTabs = state.windows[0].tabs.length + state.windows[1].tabs.length;
    1.42 +
    1.43 +  let loadCount = 0;
    1.44 +  gProgressListener.setCallback(function (aBrowser, aNeedRestore, aRestoring, aRestored) {
    1.45 +    if (++loadCount == numTabs) {
    1.46 +      // We don't actually care about load order in this test, just that they all
    1.47 +      // do load.
    1.48 +      is(loadCount, numTabs, "all tabs were restored");
    1.49 +      is(aNeedRestore, 0, "there are no tabs left needing restore");
    1.50 +
    1.51 +      gProgressListener.unsetCallback();
    1.52 +      executeSoon(next);
    1.53 +    }
    1.54 +  });
    1.55 +
    1.56 +  // We also want to catch the 2nd window, so we need to observe domwindowopened
    1.57 +  Services.ww.registerNotification(function observer(aSubject, aTopic, aData) {
    1.58 +    if (aTopic == "domwindowopened") {
    1.59 +      let win = aSubject.QueryInterface(Ci.nsIDOMWindow);
    1.60 +      win.addEventListener("load", function onLoad() {
    1.61 +        win.removeEventListener("load", onLoad);
    1.62 +        Services.ww.unregisterNotification(observer);
    1.63 +        win.gBrowser.addTabsProgressListener(gProgressListener);
    1.64 +      });
    1.65 +    }
    1.66 +  });
    1.67 +
    1.68 +  yield ss.setBrowserState(JSON.stringify(state));
    1.69 +}

mercurial