browser/components/sessionstore/test/browser_599909.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/browser/components/sessionstore/test/browser_599909.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,113 @@
     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 599909 - to-be-reloaded tabs don't show up in switch-to-tab **/
    1.21 +  waitForExplicitFinish();
    1.22 +
    1.23 +  // Set the pref to true so we know exactly how many tabs should be restoring at
    1.24 +  // any given time. This guarantees that a finishing load won't start another.
    1.25 +  Services.prefs.setBoolPref("browser.sessionstore.restore_on_demand", true);
    1.26 +
    1.27 +  let state = { windows: [{ tabs: [
    1.28 +    { entries: [{ url: "http://example.org/#1" }] },
    1.29 +    { entries: [{ url: "http://example.org/#2" }] },
    1.30 +    { entries: [{ url: "http://example.org/#3" }] },
    1.31 +    { entries: [{ url: "http://example.org/#4" }] }
    1.32 +  ], selected: 1 }] };
    1.33 +
    1.34 +  let tabsForEnsure = {};
    1.35 +  state.windows[0].tabs.forEach(function(tab) {
    1.36 +    tabsForEnsure[tab.entries[0].url] = 1;
    1.37 +  });
    1.38 +
    1.39 +  let tabsRestoring = 0;
    1.40 +  let tabsRestored = 0;
    1.41 +
    1.42 +  function handleEvent(aEvent) {
    1.43 +    if (aEvent.type == "SSTabRestoring")
    1.44 +      tabsRestoring++;
    1.45 +    else
    1.46 +      tabsRestored++;
    1.47 +
    1.48 +    if (tabsRestoring < state.windows[0].tabs.length ||
    1.49 +        tabsRestored < 1)
    1.50 +      return;
    1.51 +
    1.52 +    gBrowser.tabContainer.removeEventListener("SSTabRestoring", handleEvent, true);
    1.53 +    gBrowser.tabContainer.removeEventListener("SSTabRestored", handleEvent, true);
    1.54 +    executeSoon(function() {
    1.55 +      checkAutocompleteResults(tabsForEnsure, cleanup);
    1.56 +    });
    1.57 +  }
    1.58 +
    1.59 +  // currentURI is set before SSTabRestoring is fired, so we can sucessfully check
    1.60 +  // after that has fired for all tabs. Since 1 tab will be restored though, we
    1.61 +  // also need to wait for 1 SSTabRestored since currentURI will be set, unset, then set.
    1.62 +  gBrowser.tabContainer.addEventListener("SSTabRestoring", handleEvent, true);
    1.63 +  gBrowser.tabContainer.addEventListener("SSTabRestored", handleEvent, true);
    1.64 +  ss.setBrowserState(JSON.stringify(state));
    1.65 +}
    1.66 +
    1.67 +// The following was taken from browser/base/content/test/general/browser_tabMatchesInAwesomebar.js
    1.68 +// so that we could do the same sort of checking.
    1.69 +var gController = Cc["@mozilla.org/autocomplete/controller;1"].
    1.70 +                  getService(Ci.nsIAutoCompleteController);
    1.71 +
    1.72 +function checkAutocompleteResults(aExpected, aCallback) {
    1.73 +  gController.input = {
    1.74 +    timeout: 10,
    1.75 +    textValue: "",
    1.76 +    searches: ["history"],
    1.77 +    searchParam: "enable-actions",
    1.78 +    popupOpen: false,
    1.79 +    minResultsForPopup: 0,
    1.80 +    invalidate: function() {},
    1.81 +    disableAutoComplete: false,
    1.82 +    completeDefaultIndex: false,
    1.83 +    get popup() { return this; },
    1.84 +    onSearchBegin: function() {},
    1.85 +    onSearchComplete:  function ()
    1.86 +    {
    1.87 +      info("Found " + gController.matchCount + " matches.");
    1.88 +      // Check to see the expected uris and titles match up (in any order)
    1.89 +      for (let i = 0; i < gController.matchCount; i++) {
    1.90 +        let uri = gController.getValueAt(i).replace(/^moz-action:[^,]+,/i, "");
    1.91 +
    1.92 +        info("Search for '" + uri + "' in open tabs.");
    1.93 +        ok(uri in aExpected, "Registered open page found in autocomplete.");
    1.94 +        // Remove the found entry from expected results.
    1.95 +        delete aExpected[uri];
    1.96 +      }
    1.97 +
    1.98 +      // Make sure there is no reported open page that is not open.
    1.99 +      for (let entry in aExpected) {
   1.100 +        ok(false, "'" + entry + "' not found in autocomplete.");
   1.101 +      }
   1.102 +
   1.103 +      executeSoon(aCallback);
   1.104 +    },
   1.105 +    setSelectedIndex: function() {},
   1.106 +    get searchCount() { return this.searches.length; },
   1.107 +    getSearchAt: function(aIndex) this.searches[aIndex],
   1.108 +    QueryInterface: XPCOMUtils.generateQI([
   1.109 +      Ci.nsIAutoCompleteInput,
   1.110 +      Ci.nsIAutoCompletePopup,
   1.111 +    ])
   1.112 +  };
   1.113 +
   1.114 +  info("Searching open pages.");
   1.115 +  gController.startSearch(Services.prefs.getCharPref("browser.urlbar.restrict.openpage"));
   1.116 +}

mercurial