Bug 1522530 - Port session store test browser_599909.js to QuantumBar. r=mikedeboer
authorMark Banner <standard8@mozilla.com>
Wed, 27 Feb 2019 14:35:17 +0000
changeset 519327 f6bf5eeec2734b7427e50a3d5b71c80e6048d60c
parent 519326 46246cd080fa6c1278d967277bf91578ea94d70e
child 519328 82df15131f157d4985c85607440032cc4cf19c30
push id10862
push userffxbld-merge
push dateMon, 11 Mar 2019 13:01:11 +0000
treeherdermozilla-beta@a2e7f5c935da [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmikedeboer
bugs1522530
milestone67.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1522530 - Port session store test browser_599909.js to QuantumBar. r=mikedeboer Differential Revision: https://phabricator.services.mozilla.com/D21225
browser/components/sessionstore/test/browser.ini
browser/components/sessionstore/test/browser_599909.js
browser/components/sessionstore/test/browser_tabs_in_urlbar.js
--- a/browser/components/sessionstore/test/browser.ini
+++ b/browser/components/sessionstore/test/browser.ini
@@ -196,17 +196,16 @@ skip-if = (verify && (os == 'mac' || os 
 [browser_586068-window_state.js]
 [browser_586068-window_state_override.js]
 [browser_588426.js]
 [browser_590268.js]
 [browser_590563.js]
 [browser_595601-restore_hidden.js]
 [browser_597071.js]
 skip-if = true # Needs to be rewritten as Marionette test, bug 995916
-[browser_599909.js]
 [browser_600545.js]
 [browser_601955.js]
 [browser_607016.js]
 [browser_615394-SSWindowState_events_duplicateTab.js]
 [browser_615394-SSWindowState_events_setBrowserState.js]
 skip-if = verify && debug && os == 'mac'
 [browser_615394-SSWindowState_events_setTabState.js]
 [browser_615394-SSWindowState_events_setWindowState.js]
@@ -279,16 +278,17 @@ run-if = e10s && crashreporter
 skip-if = debug
 [browser_docshell_uuid_consistency.js]
 
 [browser_closed_objects_changed_notifications_tabs.js]
 [browser_closed_objects_changed_notifications_windows.js]
 [browser_duplicate_history.js]
 [browser_tabicon_after_bg_tab_crash.js]
 skip-if = !crashreporter || !e10s # Tabs can't crash without e10s
+[browser_tabs_in_urlbar.js]
 
 [browser_cookies.js]
 [browser_cookies_legacy.js]
 [browser_cookies_privacy.js]
 [browser_speculative_connect.js]
 [browser_1446343-windowsize.js]
 [browser_restore_reversed_z_order.js]
 skip-if = true #Bug 1455602
rename from browser/components/sessionstore/test/browser_599909.js
rename to browser/components/sessionstore/test/browser_tabs_in_urlbar.js
--- a/browser/components/sessionstore/test/browser_599909.js
+++ b/browser/components/sessionstore/test/browser_tabs_in_urlbar.js
@@ -1,122 +1,94 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
+/**
+ * Tests that tabs which aren't displayed yet (i.e. need to be reloaded) are
+ * still displayed in the address bar results.
+ */
+
 const RESTRICT_TOKEN_OPENPAGE = "%";
 
+const {UrlbarTestUtils} = ChromeUtils.import("resource://testing-common/UrlbarTestUtils.jsm");
+
 var stateBackup = ss.getBrowserState();
 
-function cleanup() {
-  // Reset the prefs
-  Services.prefs.clearUserPref("browser.sessionstore.restore_on_demand");
-  Services.prefs.clearUserPref("browser.sessionstore.restore_tabs_lazily");
-  ss.setBrowserState(stateBackup);
-  executeSoon(finish);
-}
+add_task(async function setup() {
+  await SpecialPowers.pushPrefEnv({set: [
+    // Set the pref to true so we know exactly how many tabs should be restoring at
+    // any given time. This guarantees that a finishing load won't start another.
+    ["browser.sessionstore.restore_on_demand", true],
+    // Don't restore tabs lazily.
+    ["browser.sessionstore.restore_tabs_lazily", false],
+  ]});
 
-function test() {
-  /** Bug 599909 - to-be-reloaded tabs don't show up in switch-to-tab **/
-  waitForExplicitFinish();
+  registerCleanupFunction(() => {
+    ss.setBrowserState(stateBackup);
+  });
+});
 
-  // Set the pref to true so we know exactly how many tabs should be restoring at
-  // any given time. This guarantees that a finishing load won't start another.
-  Services.prefs.setBoolPref("browser.sessionstore.restore_on_demand", true);
-  // Don't restore tabs lazily.
-  Services.prefs.setBoolPref("browser.sessionstore.restore_tabs_lazily", false);
-
-  let state = { windows: [{ tabs: [
+add_task(async function test_unrestored_tabs_listed() {
+  const state = { windows: [{ tabs: [
     { entries: [{ url: "http://example.org/#1", triggeringPrincipal_base64 }] },
     { entries: [{ url: "http://example.org/#2", triggeringPrincipal_base64 }] },
     { entries: [{ url: "http://example.org/#3", triggeringPrincipal_base64 }] },
     { entries: [{ url: "http://example.org/#4", triggeringPrincipal_base64 }] },
   ], selected: 1 }] };
 
-  let tabsForEnsure = {};
+  const tabsForEnsure = {};
   state.windows[0].tabs.forEach(function(tab) {
     tabsForEnsure[tab.entries[0].url] = 1;
   });
 
   let tabsRestoring = 0;
   let tabsRestored = 0;
 
-  function handleEvent(aEvent) {
-    if (aEvent.type == "SSTabRestoring")
-      tabsRestoring++;
-    else
-      tabsRestored++;
-
-    if (tabsRestoring < state.windows[0].tabs.length ||
-        tabsRestored < 1)
-      return;
-
-    gBrowser.tabContainer.removeEventListener("SSTabRestoring", handleEvent, true);
-    gBrowser.tabContainer.removeEventListener("SSTabRestored", handleEvent, true);
-    executeSoon(function() {
-      checkAutocompleteResults(tabsForEnsure, cleanup);
-    });
-  }
-
-  // currentURI is set before SSTabRestoring is fired, so we can sucessfully check
-  // after that has fired for all tabs. Since 1 tab will be restored though, we
-  // also need to wait for 1 SSTabRestored since currentURI will be set, unset, then set.
-  gBrowser.tabContainer.addEventListener("SSTabRestoring", handleEvent, true);
-  gBrowser.tabContainer.addEventListener("SSTabRestored", handleEvent, true);
-  ss.setBrowserState(JSON.stringify(state));
-}
-
-// The following was taken from browser/base/content/test/general/browser_tabMatchesInAwesomebar.js
-// so that we could do the same sort of checking.
-var gController = Cc["@mozilla.org/autocomplete/controller;1"].
-                  getService(Ci.nsIAutoCompleteController);
-
-function checkAutocompleteResults(aExpected, aCallback) {
-  gController.input = {
-    timeout: 10,
-    textValue: "",
-    searches: ["unifiedcomplete"],
-    searchParam: "enable-actions",
-    popupOpen: false,
-    minResultsForPopup: 0,
-    invalidate() {},
-    disableAutoComplete: false,
-    completeDefaultIndex: false,
-    get popup() { return this; },
-    onSearchBegin() {},
-    onSearchComplete() {
-      info("Found " + gController.matchCount + " matches.");
-      // Check to see the expected uris and titles match up (in any order)
-      for (let i = 0; i < gController.matchCount; i++) {
-        if (gController.getStyleAt(i).includes("heuristic")) {
-          info("Skip heuristic match");
-          continue;
-        }
-        let action = gURLBar.popup.input._parseActionUrl(gController.getValueAt(i));
-        let uri = action.params.url;
-
-        info("Search for '" + uri + "' in open tabs.");
-        ok(uri in aExpected, "Registered open page found in autocomplete.");
-        // Remove the found entry from expected results.
-        delete aExpected[uri];
+  await new Promise(resolve => {
+    function handleEvent(aEvent) {
+      if (aEvent.type == "SSTabRestoring") {
+        tabsRestoring++;
+      } else {
+        tabsRestored++;
       }
 
-      // Make sure there is no reported open page that is not open.
-      for (let entry in aExpected) {
-        ok(false, "'" + entry + "' not found in autocomplete.");
-      }
+      if (tabsRestoring < state.windows[0].tabs.length ||
+          tabsRestored < 1)
+        return;
 
-      executeSoon(aCallback);
-    },
-    setSelectedIndex() {},
-    get searchCount() { return this.searches.length; },
-    getSearchAt(aIndex) {
-      return this.searches[aIndex];
-    },
-    QueryInterface: ChromeUtils.generateQI([
-      Ci.nsIAutoCompleteInput,
-      Ci.nsIAutoCompletePopup,
-    ]),
-  };
+      gBrowser.tabContainer.removeEventListener("SSTabRestoring", handleEvent, true);
+      gBrowser.tabContainer.removeEventListener("SSTabRestored", handleEvent, true);
+      executeSoon(resolve);
+    }
+
+    // currentURI is set before SSTabRestoring is fired, so we can sucessfully check
+    // after that has fired for all tabs. Since 1 tab will be restored though, we
+    // also need to wait for 1 SSTabRestored since currentURI will be set, unset, then set.
+    gBrowser.tabContainer.addEventListener("SSTabRestoring", handleEvent, true);
+    gBrowser.tabContainer.addEventListener("SSTabRestored", handleEvent, true);
+    ss.setBrowserState(JSON.stringify(state));
+  });
 
   info("Searching open pages.");
-  gController.startSearch(RESTRICT_TOKEN_OPENPAGE);
-}
+  await UrlbarTestUtils.promiseAutocompleteResultPopup(window, RESTRICT_TOKEN_OPENPAGE, waitForFocus);
+  const total = UrlbarTestUtils.getResultCount(window);
+  info(`Found ${total} matches`);
+  const quantumbar = UrlbarPrefs.get("quantumbar");
+
+  // Check to see the expected uris and titles match up (in any order)
+  for (let i = 0; i < total; i++) {
+    const result = await UrlbarTestUtils.getDetailsOfResultAt(window, i);
+    if (result.heuristic) {
+      info("Skip heuristic match");
+      continue;
+    }
+    const url = quantumbar ? result.url : PlacesUtils.parseActionUrl(result.url).params.url;
+    Assert.ok(url in tabsForEnsure,
+      `Should have the found result '${url}' in the expected list of entries`);
+    // Remove the found entry from expected results.
+    delete tabsForEnsure[url];
+  }
+  // Make sure there is no reported open page that is not open.
+  for (const entry in tabsForEnsure) {
+    Assert.ok(!entry, `'${entry}' should have been in autocomplete results.`);
+  }
+});