browser/components/sessionstore/test/browser_600545.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/browser/components/sessionstore/test/browser_600545.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,84 @@
     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 +let stateBackup = JSON.parse(ss.getBrowserState());
     1.9 +
    1.10 +function test() {
    1.11 +  /** Test for Bug 600545 **/
    1.12 +  waitForExplicitFinish();
    1.13 +  testBug600545();
    1.14 +}
    1.15 +
    1.16 +function testBug600545() {
    1.17 +  // Set the pref to false to cause non-app tabs to be stripped out on a save
    1.18 +  Services.prefs.setBoolPref("browser.sessionstore.resume_from_crash", false);
    1.19 +  Services.prefs.setIntPref("browser.sessionstore.interval", 2000);
    1.20 +
    1.21 +  registerCleanupFunction(function () {
    1.22 +    Services.prefs.clearUserPref("browser.sessionstore.resume_from_crash");
    1.23 +    Services.prefs.clearUserPref("browser.sessionstore.interval");
    1.24 +  });
    1.25 +
    1.26 +  // This tests the following use case: When multiple windows are open
    1.27 +  // and browser.sessionstore.resume_from_crash preference is false,
    1.28 +  // tab session data for non-active window is stripped for non-pinned
    1.29 +  // tabs.  This occurs after "sessionstore-state-write-complete"
    1.30 +  // fires which will only fire in this case if there is at least one
    1.31 +  // pinned tab.
    1.32 +  let state = { windows: [
    1.33 +    {
    1.34 +      tabs: [
    1.35 +        { entries: [{ url: "http://example.org#0" }], pinned:true },
    1.36 +        { entries: [{ url: "http://example.com#1" }] },
    1.37 +        { entries: [{ url: "http://example.com#2" }] },
    1.38 +      ],
    1.39 +      selected: 2
    1.40 +    },
    1.41 +    {
    1.42 +      tabs: [
    1.43 +        { entries: [{ url: "http://example.com#3" }] },
    1.44 +        { entries: [{ url: "http://example.com#4" }] },
    1.45 +        { entries: [{ url: "http://example.com#5" }] },
    1.46 +        { entries: [{ url: "http://example.com#6" }] }
    1.47 +      ],
    1.48 +      selected: 3
    1.49 +    }
    1.50 +  ] };
    1.51 +
    1.52 +  waitForBrowserState(state, function() {
    1.53 +    // Need to wait for SessionStore's saveState function to be called
    1.54 +    // so that non-pinned tabs will be stripped from non-active window
    1.55 +    waitForSaveState(function () {
    1.56 +      let expectedNumberOfTabs = getStateTabCount(state);
    1.57 +      let retrievedState = JSON.parse(ss.getBrowserState());
    1.58 +      let actualNumberOfTabs = getStateTabCount(retrievedState);
    1.59 +
    1.60 +      is(actualNumberOfTabs, expectedNumberOfTabs,
    1.61 +        "Number of tabs in retreived session data, matches number of tabs set.");
    1.62 +
    1.63 +      done();
    1.64 +    });
    1.65 +  });
    1.66 +}
    1.67 +
    1.68 +function done() {
    1.69 +  // Enumerate windows and close everything but our primary window. We can't
    1.70 +  // use waitForFocus() because apparently it's buggy. See bug 599253.
    1.71 +  let windowsEnum = Services.wm.getEnumerator("navigator:browser");
    1.72 +  while (windowsEnum.hasMoreElements()) {
    1.73 +    let currentWindow = windowsEnum.getNext();
    1.74 +    if (currentWindow != window)
    1.75 +      currentWindow.close();
    1.76 +  }
    1.77 +
    1.78 +  waitForBrowserState(stateBackup, finish);
    1.79 +}
    1.80 +
    1.81 +// Count up the number of tabs in the state data
    1.82 +function getStateTabCount(aState) {
    1.83 +  let tabCount = 0;
    1.84 +  for (let i in aState.windows)
    1.85 +    tabCount += aState.windows[i].tabs.length;
    1.86 +  return tabCount;
    1.87 +}

mercurial