browser/components/sessionstore/test/browser_607016.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/browser/components/sessionstore/test/browser_607016.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,117 @@
     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 = ss.getBrowserState();
     1.9 +
    1.10 +function cleanup() {
    1.11 +  // Reset the pref
    1.12 +  try {
    1.13 +    Services.prefs.clearUserPref("browser.sessionstore.restore_on_demand");
    1.14 +  } catch (e) {}
    1.15 +  ss.setBrowserState(stateBackup);
    1.16 +  executeSoon(finish);
    1.17 +}
    1.18 +
    1.19 +function test() {
    1.20 +  /** Bug 607016 - If a tab is never restored, attributes (eg. hidden) aren't updated correctly **/
    1.21 +  waitForExplicitFinish();
    1.22 +  ignoreAllUncaughtExceptions();
    1.23 +
    1.24 +  // Set the pref to true so we know exactly how many tabs should be restoring at
    1.25 +  // any given time. This guarantees that a finishing load won't start another.
    1.26 +  Services.prefs.setBoolPref("browser.sessionstore.restore_on_demand", true);
    1.27 +
    1.28 +  // We have our own progress listener for this test, which we'll attach before our state is set
    1.29 +  let progressListener = {
    1.30 +    onStateChange: function (aBrowser, aWebProgress, aRequest, aStateFlags, aStatus) {
    1.31 +      if (aBrowser.__SS_restoreState == TAB_STATE_RESTORING &&
    1.32 +          aStateFlags & Ci.nsIWebProgressListener.STATE_STOP &&
    1.33 +          aStateFlags & Ci.nsIWebProgressListener.STATE_IS_NETWORK &&
    1.34 +          aStateFlags & Ci.nsIWebProgressListener.STATE_IS_WINDOW)
    1.35 +        progressCallback(aBrowser);
    1.36 +    }
    1.37 +  }
    1.38 +
    1.39 +  let state = { windows: [{ tabs: [
    1.40 +    { entries: [{ url: "http://example.org#1" }], extData: { "uniq": r() } },
    1.41 +    { entries: [{ url: "http://example.org#2" }], extData: { "uniq": r() } }, // overwriting
    1.42 +    { entries: [{ url: "http://example.org#3" }], extData: { "uniq": r() } }, // hiding
    1.43 +    { entries: [{ url: "http://example.org#4" }], extData: { "uniq": r() } }, // adding
    1.44 +    { entries: [{ url: "http://example.org#5" }], extData: { "uniq": r() } }, // deleting
    1.45 +    { entries: [{ url: "http://example.org#6" }] } // creating
    1.46 +  ], selected: 1 }] };
    1.47 +
    1.48 +  function progressCallback(aBrowser) {
    1.49 +    // We'll remove the progress listener after the first one because we aren't
    1.50 +    // loading any other tabs
    1.51 +    window.gBrowser.removeTabsProgressListener(progressListener);
    1.52 +
    1.53 +    let curState = JSON.parse(ss.getBrowserState());
    1.54 +    for (let i = 0; i < curState.windows[0].tabs.length; i++) {
    1.55 +      let tabState = state.windows[0].tabs[i];
    1.56 +      let tabCurState = curState.windows[0].tabs[i];
    1.57 +      if (tabState.extData) {
    1.58 +        is(tabCurState.extData["uniq"], tabState.extData["uniq"],
    1.59 +           "sanity check that tab has correct extData");
    1.60 +      }
    1.61 +      else {
    1.62 +        // We aren't expecting there to be any data on extData, but panorama
    1.63 +        // may be setting something, so we need to make sure that if we do have
    1.64 +        // data, we just don't have anything for "uniq".
    1.65 +        ok(!("extData" in tabCurState) || !("uniq" in tabCurState.extData),
    1.66 +           "sanity check that tab doesn't have extData or extData doesn't have 'uniq'");
    1.67 +      }
    1.68 +    }
    1.69 +
    1.70 +    // Now we'll set a new unique value on 1 of the tabs
    1.71 +    let newUniq = r();
    1.72 +    ss.setTabValue(gBrowser.tabs[1], "uniq", newUniq);
    1.73 +    gBrowser.removeTab(gBrowser.tabs[1]);
    1.74 +    let closedTabData = (JSON.parse(ss.getClosedTabData(window)))[0];
    1.75 +    is(closedTabData.state.extData.uniq, newUniq,
    1.76 +       "(overwriting) new data is stored in extData");
    1.77 +
    1.78 +    // hide the next tab before closing it
    1.79 +    gBrowser.hideTab(gBrowser.tabs[1]);
    1.80 +    gBrowser.removeTab(gBrowser.tabs[1]);
    1.81 +    closedTabData = (JSON.parse(ss.getClosedTabData(window)))[0];
    1.82 +    ok(closedTabData.state.hidden, "(hiding) tab data has hidden == true");
    1.83 +
    1.84 +    // set data that's not in a conflicting key
    1.85 +    let stillUniq = r();
    1.86 +    ss.setTabValue(gBrowser.tabs[1], "stillUniq", stillUniq);
    1.87 +    gBrowser.removeTab(gBrowser.tabs[1]);
    1.88 +    closedTabData = (JSON.parse(ss.getClosedTabData(window)))[0];
    1.89 +    is(closedTabData.state.extData.stillUniq, stillUniq,
    1.90 +       "(adding) new data is stored in extData");
    1.91 +
    1.92 +    // remove the uniq value and make sure it's not there in the closed data
    1.93 +    ss.deleteTabValue(gBrowser.tabs[1], "uniq");
    1.94 +    gBrowser.removeTab(gBrowser.tabs[1]);
    1.95 +    closedTabData = (JSON.parse(ss.getClosedTabData(window)))[0];
    1.96 +    // Since Panorama might have put data in, first check if there is extData.
    1.97 +    // If there is explicitly check that "uniq" isn't in it. Otherwise, we're ok
    1.98 +    if ("extData" in closedTabData.state) {
    1.99 +      ok(!("uniq" in closedTabData.state.extData),
   1.100 +         "(deleting) uniq not in existing extData");
   1.101 +    }
   1.102 +    else {
   1.103 +      ok(true, "(deleting) no data is stored in extData");
   1.104 +    }
   1.105 +
   1.106 +    // set unique data on the tab that never had any set, make sure that's saved
   1.107 +    let newUniq2 = r();
   1.108 +    ss.setTabValue(gBrowser.tabs[1], "uniq", newUniq2);
   1.109 +    gBrowser.removeTab(gBrowser.tabs[1]);
   1.110 +    closedTabData = (JSON.parse(ss.getClosedTabData(window)))[0];
   1.111 +    is(closedTabData.state.extData.uniq, newUniq2,
   1.112 +       "(creating) new data is stored in extData where there was none");
   1.113 +
   1.114 +    cleanup();
   1.115 +  }
   1.116 +
   1.117 +  window.gBrowser.addTabsProgressListener(progressListener);
   1.118 +  ss.setBrowserState(JSON.stringify(state));
   1.119 +}
   1.120 +

mercurial