Bug 1531347 - Port remaining browser/components/urlbar tests to QuantumBar. r=mak
☠☠ backed out by 9ee8480e23e7 ☠ ☠
authorMark Banner <standard8@mozilla.com>
Sat, 02 Mar 2019 08:40:20 +0000
changeset 520021 9a7e65e00bc0bfe9b539eb5f5e4467a5a13e3f5e
parent 520020 f6c1385bf921c607a4db0ba1877448c131e7c80b
child 520022 7dc59aadcb9d3e6b9698f0a6e1b0813f2502baa9
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)
reviewersmak
bugs1531347
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 1531347 - Port remaining browser/components/urlbar tests to QuantumBar. r=mak Differential Revision: https://phabricator.services.mozilla.com/D21711
browser/components/urlbar/tests/browser/browser.ini
browser/components/urlbar/tests/browser/browser_keepStateAcrossTabSwitches.js
browser/components/urlbar/tests/browser/browser_privateBrowsingWindowChange.js
browser/components/urlbar/tests/browser/browser_raceWithTabs.js
browser/components/urlbar/tests/browser/browser_searchTelemetry.js
browser/components/urlbar/tests/browser/browser_stop_pending.js
browser/components/urlbar/tests/browser/head.js
browser/components/urlbar/tests/legacy/browser.ini
browser/components/urlbar/tests/legacy/browser_urlbarKeepStateAcrossTabSwitches.js
browser/components/urlbar/tests/legacy/browser_urlbarPrivateBrowsingWindowChange.js
browser/components/urlbar/tests/legacy/browser_urlbarRaceWithTabs.js
browser/components/urlbar/tests/legacy/browser_urlbarSearchTelemetry.js
browser/components/urlbar/tests/legacy/browser_urlbar_stop_pending.js
--- a/browser/components/urlbar/tests/browser/browser.ini
+++ b/browser/components/urlbar/tests/browser/browser.ini
@@ -28,35 +28,47 @@ skip-if = true # Bug 1531348 - Failing w
 [browser_autoFill_canonize.js]
 skip-if = true # Bug 1531348 - Failing with QuantumBar.
 [browser_autoFill_preserveCase.js]
 skip-if = true # Bug 1531348 - Failing with QuantumBar.
 [browser_autoFill_trimURLs.js]
 skip-if = true # Bug 1531348 - Failing with QuantumBar.
 [browser_canonizeURL.js]
 [browser_dragdropURL.js]
+[browser_keepStateAcrossTabSwitches.js]
 [browser_keyword_override.js]
 [browser_keyword_select_and_type.js]
 [browser_keyword.js]
 support-files =
   print_postdata.sjs
 [browser_locationBarCommand.js]
 [browser_locationBarExternalLoad.js]
 [browser_moz_action_link.js]
 [browser_new_tab_urlbar_reset.js]
 [browser_pasteAndGo.js]
 subsuite = clipboard
 [browser_populateAfterPushState.js]
+[browser_privateBrowsingWindowChange.js]
+[browser_raceWithTabs.js]
+skip-if = true # Bug 1531787 - Fails with QuantumBar
+# skip-if = os == "linux" # Bug 1382456
 [browser_redirect_error.js]
 support-files = redirect_error.sjs
 [browser_remotetab.js]
 [browser_removeUnsafeProtocolsFromURLBarPaste.js]
 subsuite = clipboard
 [browser_search_favicon.js]
 skip-if = true # Bug 1526222 - Doesn't currently work with QuantumBar
+[browser_searchTelemetry.js]
+support-files =
+  searchSuggestionEngine.xml
+  searchSuggestionEngine.sjs
+[browser_stop_pending.js]
+support-files =
+  slow-page.sjs
 [browser_switchTab_closesUrlbarPopup.js]
 [browser_switchTab_decodeuri.js]
 [browser_switchTab_override.js]
 skip-if = ((os == 'win') && verify && debug)
 [browser_switchToTab_closes_newtab.js]
 skip-if = true # Bug 1531737 - fails when run after browser_switchTab_override.js
 [browser_switchToTabHavingURI_aOpenParams.js]
 [browser_tabMatchesInAwesomebar_perwindowpb.js]
rename from browser/components/urlbar/tests/legacy/browser_urlbarKeepStateAcrossTabSwitches.js
rename to browser/components/urlbar/tests/browser/browser_keepStateAcrossTabSwitches.js
--- a/browser/components/urlbar/tests/legacy/browser_urlbarKeepStateAcrossTabSwitches.js
+++ b/browser/components/urlbar/tests/browser/browser_keepStateAcrossTabSwitches.js
@@ -1,8 +1,11 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
 "use strict";
 
 /**
  * Verify user typed text remains in the URL bar when tab switching, even when
  * loads fail.
  */
 add_task(async function() {
   let input = "i-definitely-dont-exist.example.com";
@@ -51,9 +54,8 @@ add_task(async function() {
   is(gURLBar.textValue, input, "Text is still in URL bar");
   is(tab.linkedBrowser.userTypedValue, input, "Text still stored on browser");
   await BrowserTestUtils.switchTab(gBrowser, tab.previousElementSibling);
   await BrowserTestUtils.switchTab(gBrowser, tab);
   is(gURLBar.textValue, input, "Text is still in URL bar after tab switch");
   is(tab.linkedBrowser.userTypedValue, input, "Text still stored on browser");
   BrowserTestUtils.removeTab(tab);
 });
-
rename from browser/components/urlbar/tests/legacy/browser_urlbarPrivateBrowsingWindowChange.js
rename to browser/components/urlbar/tests/browser/browser_privateBrowsingWindowChange.js
--- a/browser/components/urlbar/tests/legacy/browser_urlbarPrivateBrowsingWindowChange.js
+++ b/browser/components/urlbar/tests/browser/browser_privateBrowsingWindowChange.js
@@ -1,8 +1,11 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
 "use strict";
 
 /**
  * Test that when opening a private browsing window and typing in it before about:privatebrowsing
  * loads, we don't clear the URL bar.
  */
 add_task(async function() {
   let urlbarTestValue = "Mary had a little lamb";
@@ -10,17 +13,17 @@ add_task(async function() {
   await BrowserTestUtils.waitForEvent(win, "load");
   let urlbar = win.document.getElementById("urlbar");
   urlbar.value = urlbarTestValue;
   // Need this so the autocomplete controller attaches:
   let focusEv = new FocusEvent("focus", {});
   urlbar.dispatchEvent(focusEv);
   // And so we know input happened:
   let inputEv = new InputEvent("input", {data: "", view: win, bubbles: true});
-  urlbar.onInput(inputEv);
+  urlbar.inputField.dispatchEvent(inputEv);
   // Check it worked:
   is(urlbar.value, urlbarTestValue, "URL bar value should be there");
   is(win.gBrowser.selectedBrowser.userTypedValue, urlbarTestValue, "browser object should know the url bar value");
 
   let continueTest;
   let continuePromise = new Promise(resolve => continueTest = resolve);
   let wpl = {
     onLocationChange(aWebProgress, aRequest, aLocation) {
rename from browser/components/urlbar/tests/legacy/browser_urlbarRaceWithTabs.js
rename to browser/components/urlbar/tests/browser/browser_raceWithTabs.js
rename from browser/components/urlbar/tests/legacy/browser_urlbarSearchTelemetry.js
rename to browser/components/urlbar/tests/browser/browser_searchTelemetry.js
--- a/browser/components/urlbar/tests/legacy/browser_urlbarSearchTelemetry.js
+++ b/browser/components/urlbar/tests/browser/browser_searchTelemetry.js
@@ -16,79 +16,80 @@ add_task(async function prepare() {
     Services.prefs.setBoolPref(SUGGEST_URLBAR_PREF, suggestionsEnabled);
     await Services.search.setDefault(oldDefaultEngine);
 
     // Clicking urlbar results causes visits to their associated pages, so clear
     // that history now.
     await PlacesUtils.history.clear();
 
     // Make sure the popup is closed for the next test.
-    gURLBar.blur();
-    Assert.ok(!gURLBar.popup.popupOpen, "popup should be closed");
+    await UrlbarTestUtils.promisePopupClose(window);
   });
 
   // Move the mouse away from the urlbar one-offs so that a one-off engine is
   // not inadvertently selected.
   await new Promise(resolve => {
     EventUtils.synthesizeNativeMouseMove(window.document.documentElement, 0, 0,
                                          resolve);
   });
 });
 
 add_task(async function heuristicResultMouse() {
   await compareCounts(async function() {
     let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser);
     gURLBar.focus();
     await promiseAutocompleteResultPopup("heuristicResult");
-    let action = getActionAtIndex(0);
-    Assert.ok(!!action, "there should be an action at index 0");
-    Assert.equal(action.type, "searchengine", "type should be searchengine");
+    let result = await UrlbarTestUtils.getDetailsOfResultAt(window, 0);
+    Assert.equal(result.type, UrlbarUtils.RESULT_TYPE.SEARCH,
+      "Should be of type search");
     let loadPromise = BrowserTestUtils.browserLoaded(tab.linkedBrowser);
-    gURLBar.popup.richlistbox.getItemAtIndex(0).click();
+    let element = await UrlbarTestUtils.waitForAutocompleteResultAt(window, 0);
+    EventUtils.synthesizeMouseAtCenter(element, {});
     await loadPromise;
     BrowserTestUtils.removeTab(tab);
   });
 });
 
 add_task(async function heuristicResultKeyboard() {
   await compareCounts(async function() {
     let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser);
     gURLBar.focus();
     await promiseAutocompleteResultPopup("heuristicResult");
-    let action = getActionAtIndex(0);
-    Assert.ok(!!action, "there should be an action at index 0");
-    Assert.equal(action.type, "searchengine", "type should be searchengine");
+    let result = await UrlbarTestUtils.getDetailsOfResultAt(window, 0);
+    Assert.equal(result.type, UrlbarUtils.RESULT_TYPE.SEARCH,
+      "Should be of type search");
     let loadPromise = BrowserTestUtils.browserLoaded(tab.linkedBrowser);
     EventUtils.sendKey("return");
     await loadPromise;
     BrowserTestUtils.removeTab(tab);
   });
 });
 
 add_task(async function searchSuggestionMouse() {
   await compareCounts(async function() {
     let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser);
     gURLBar.focus();
     await promiseAutocompleteResultPopup("searchSuggestion");
-    let idx = getFirstSuggestionIndex();
-    Assert.ok(idx >= 0, "there should be a first suggestion");
+    let idx = await getFirstSuggestionIndex();
+    Assert.greaterOrEqual(idx, 0, "there should be a first suggestion");
     let loadPromise = BrowserTestUtils.browserLoaded(tab.linkedBrowser);
-    gURLBar.popup.richlistbox.getItemAtIndex(idx).click();
+    let element = await UrlbarTestUtils.waitForAutocompleteResultAt(window, idx);
+    EventUtils.synthesizeMouseAtCenter(element, {});
     await loadPromise;
     BrowserTestUtils.removeTab(tab);
   });
 });
 
 add_task(async function searchSuggestionKeyboard() {
   await compareCounts(async function() {
     let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser);
     gURLBar.focus();
     await promiseAutocompleteResultPopup("searchSuggestion");
-    let idx = getFirstSuggestionIndex();
-    Assert.ok(idx >= 0, "there should be a first suggestion");
+    let idx = await getFirstSuggestionIndex();
+    Assert.greaterOrEqual(idx, 0, "there should be a first suggestion");
     let loadPromise = BrowserTestUtils.browserLoaded(tab.linkedBrowser);
     while (idx--) {
       EventUtils.sendKey("down");
     }
     EventUtils.sendKey("return");
     await loadPromise;
     BrowserTestUtils.removeTab(tab);
   });
@@ -106,90 +107,38 @@ async function compareCounts(clickCallba
   // Search events triggered by clicks (not the Return key in the urlbar) are
   // recorded in three places:
   // * Telemetry histogram named "SEARCH_COUNTS"
   // * FHR
 
   let engine = await Services.search.getDefault();
   let engineID = "org.mozilla.testsearchsuggestions";
 
-  // First, get the current counts.
-
-  // telemetry histogram SEARCH_COUNTS
-  let histogramCount = 0;
   let histogramKey = engineID + ".urlbar";
-  let histogram;
-  try {
-    histogram = Services.telemetry.getKeyedHistogramById("SEARCH_COUNTS");
-  } catch (ex) {
-    // No searches performed yet, not a problem.
-  }
-  if (histogram) {
-    let snapshot = histogram.snapshot();
-    if (histogramKey in snapshot) {
-      histogramCount = snapshot[histogramKey].sum;
-    }
-  }
+  let histogram = Services.telemetry.getKeyedHistogramById("SEARCH_COUNTS");
+  histogram.clear();
 
   // FHR -- first make sure the engine has an identifier so that FHR is happy.
   Object.defineProperty(engine.wrappedJSObject, "identifier",
                         { value: engineID });
 
   gURLBar.focus();
   await clickCallback();
 
-  // Now get the new counts and compare them to the old.
-
-  // telemetry histogram SEARCH_COUNTS
-  histogram = Services.telemetry.getKeyedHistogramById("SEARCH_COUNTS");
-  let snapshot = histogram.snapshot();
-  Assert.ok(histogramKey in snapshot, "histogram with key should be recorded");
-  Assert.equal(snapshot[histogramKey].sum, histogramCount + 1,
-               "histogram sum should be incremented");
-}
-
-/**
- * Returns the "action" object at the given index in the urlbar results:
- * { type, params: {}}
- *
- * @param {number} index The index in the urlbar results.
- * @returns {object|null} An action object, or null if index >= number of results.
- */
-function getActionAtIndex(index) {
-  let controller = gURLBar.popup.input.controller;
-  if (controller.matchCount <= index) {
-    return null;
-  }
-  let url = controller.getValueAt(index);
-  let mozActionMatch = url.match(/^moz-action:([^,]+),(.*)$/);
-  if (!mozActionMatch) {
-    let msg = "result at index " + index + " is not a moz-action: " + url;
-    Assert.ok(false, msg);
-    throw new Error(msg);
-  }
-  let [, type, paramStr] = mozActionMatch;
-  return {
-    type,
-    params: JSON.parse(paramStr),
-  };
+  TelemetryTestUtils.assertKeyedHistogramSum(histogram, histogramKey, 1);
 }
 
 /**
  * Returns the index of the first search suggestion in the urlbar results.
  *
  * @returns {number} An index, or -1 if there are no search suggestions.
  */
-function getFirstSuggestionIndex() {
-  let controller = gURLBar.popup.input.controller;
-  let matchCount = controller.matchCount;
+async function getFirstSuggestionIndex() {
+  const matchCount = UrlbarTestUtils.getResultCount(window);
   for (let i = 0; i < matchCount; i++) {
-    let url = controller.getValueAt(i);
-    let mozActionMatch = url.match(/^moz-action:([^,]+),(.*)$/);
-    if (mozActionMatch) {
-      let [, type, paramStr] = mozActionMatch;
-      let params = JSON.parse(paramStr);
-      if (type == "searchengine" && "searchSuggestion" in params) {
-        return i;
-      }
+    let result = await UrlbarTestUtils.getDetailsOfResultAt(window, i);
+    if (result.type == UrlbarUtils.RESULT_TYPE.SEARCH &&
+        result.searchParams.suggestion) {
+      return i;
     }
   }
   return -1;
 }
rename from browser/components/urlbar/tests/legacy/browser_urlbar_stop_pending.js
rename to browser/components/urlbar/tests/browser/browser_stop_pending.js
--- a/browser/components/urlbar/tests/legacy/browser_urlbar_stop_pending.js
+++ b/browser/components/urlbar/tests/browser/browser_stop_pending.js
@@ -1,8 +1,11 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
 /* eslint-disable mozilla/no-arbitrary-setTimeout */
 "use strict";
 
 const SLOW_PAGE = getRootDirectory(gTestPath)
   .replace("chrome://mochitests/content", "http://www.example.com") + "slow-page.sjs";
 const SLOW_PAGE2 = getRootDirectory(gTestPath)
   .replace("chrome://mochitests/content", "http://mochi.test:8888") + "slow-page.sjs?faster";
 
@@ -20,17 +23,17 @@ add_task(async function() {
   let sawChange = false;
   let handler = e => {
     sawChange = true;
     is(gURLBar.value, expectedURLBarChange, "Should not change URL bar value!");
   };
 
   let obs = new MutationObserver(handler);
 
-  obs.observe(gURLBar, {attributes: true});
+  obs.observe(gURLBar.textbox, {attributes: true});
   gURLBar.value = SLOW_PAGE;
   gURLBar.handleCommand();
 
   // If this ever starts going intermittent, we've broken this.
   await new Promise(resolve => setTimeout(resolve, 200));
   expectedURLBarChange = SLOW_PAGE2;
   let pageLoadPromise = BrowserTestUtils.browserLoaded(tab.linkedBrowser);
   gURLBar.value = expectedURLBarChange;
--- a/browser/components/urlbar/tests/browser/head.js
+++ b/browser/components/urlbar/tests/browser/head.js
@@ -8,16 +8,17 @@
 "use strict";
 
 let sandbox;
 
 var {XPCOMUtils} = ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
 XPCOMUtils.defineLazyModuleGetters(this, {
   AppConstants: "resource://gre/modules/AppConstants.jsm",
   PromiseUtils: "resource://gre/modules/PromiseUtils.jsm",
+  TelemetryTestUtils: "resource://testing-common/TelemetryTestUtils.jsm",
   UrlbarController: "resource:///modules/UrlbarController.jsm",
   UrlbarResult: "resource:///modules/UrlbarResult.jsm",
   UrlbarQueryContext: "resource:///modules/UrlbarUtils.jsm",
   UrlbarUtils: "resource:///modules/UrlbarUtils.jsm",
 });
 
 /* import-globals-from head-common.js */
 Services.scriptloader.loadSubScript(
--- a/browser/components/urlbar/tests/legacy/browser.ini
+++ b/browser/components/urlbar/tests/legacy/browser.ini
@@ -13,38 +13,30 @@ support-files =
 # to identify the remaining tests.
 
 # Not porting browser_switchtab_override_keynav.js/browser_switchtab_copy.js
 # to QuantumBar as we no longer have moz-action uris, so they aren't relevant
 # any more.
 [browser_switchtab_copy.js]
 subsuite = clipboard
 [browser_switchtab_override_keynav.js]
-
+# Not porting browser_urlbarAddonIframe.js - we'll be implementing new
+# WebExtension APIs
 [browser_urlbarAddonIframe.js]
 support-files =
   ../browser/Panel.jsm
   ../browser/urlbarAddonIframe.html
   ../browser/urlbarAddonIframe.js
   ../browser/urlbarAddonIframeContentScript.js
-[browser_urlbarKeepStateAcrossTabSwitches.js]
-[browser_urlbarPrivateBrowsingWindowChange.js]
-[browser_urlbarRaceWithTabs.js]
-skip-if = os == "linux" # Bug 1382456
+# Not porting browser_urlbarSearchSuggestions_opt-out.js - search suggestion
+# prompt not in QuantumBar
 [browser_urlbarSearchSuggestions_opt-out.js]
 support-files =
   ../browser/searchSuggestionEngine.xml
   ../browser/searchSuggestionEngine.sjs
-[browser_urlbarSearchTelemetry.js]
-support-files =
-  ../browser/searchSuggestionEngine.xml
-  ../browser/searchSuggestionEngine.sjs
-[browser_urlbar_stop_pending.js]
-support-files =
-  ../browser/slow-page.sjs
 
 
 # These are tests that are already running with QuantumBar, but we want to run them
 # against both the legacy urlbar and the new QuantumBar. The references in this
 # directory will run them against the old urlbar as per the pref above.
 
 [../browser/browser_action_searchengine.js]
 [../browser/browser_action_searchengine_alias.js]
@@ -59,36 +51,47 @@ skip-if = (verify && !debug && (os == 'w
 skip-if = os != "mac" # Mac only feature
 [../browser/browser_autoFill_backspaced.js]
 [../browser/browser_autoFill_canonize.js]
 [../browser/browser_autoFill_preserveCase.js]
 [../browser/browser_autoFill_trimURLs.js]
 [../browser/browser_autocomplete_tag_star_visibility.js]
 [../browser/browser_canonizeURL.js]
 [../browser/browser_dragdropURL.js]
+[../browser/browser_keepStateAcrossTabSwitches.js]
 [../browser/browser_keyword_override.js]
 [../browser/browser_keyword_select_and_type.js]
 [../browser/browser_keyword.js]
 support-files =
   ../browser/print_postdata.sjs
 [../browser/browser_URLBarSetURI.js]
 skip-if = (os == "linux" || os == "mac") && debug # bug 970052, bug 970053
 [../browser/browser_locationBarCommand.js]
 [../browser/browser_locationBarExternalLoad.js]
 [../browser/browser_moz_action_link.js]
 [../browser/browser_new_tab_urlbar_reset.js]
 [../browser/browser_pasteAndGo.js]
 subsuite = clipboard
 [../browser/browser_populateAfterPushState.js]
+[../browser/browser_privateBrowsingWindowChange.js]
+[../browser/browser_raceWithTabs.js]
+skip-if = os == "linux" # Bug 1382456
 [../browser/browser_redirect_error.js]
 support-files = ../browser/redirect_error.sjs
 [../browser/browser_remotetab.js]
 [../browser/browser_removeUnsafeProtocolsFromURLBarPaste.js]
 subsuite = clipboard
 [../browser/browser_search_favicon.js]
+[../browser/browser_searchTelemetry.js]
+support-files =
+  ../browser/searchSuggestionEngine.xml
+  ../browser/searchSuggestionEngine.sjs
+[../browser/browser_stop_pending.js]
+support-files =
+  ../browser/slow-page.sjs
 [../browser/browser_switchTab_closesUrlbarPopup.js]
 [../browser/browser_switchTab_decodeuri.js]
 [../browser/browser_switchTab_override.js]
 skip-if = ((os == 'win') && verify && debug)
 [../browser/browser_switchToTab_closes_newtab.js]
 [../browser/browser_switchToTabHavingURI_aOpenParams.js]
 [../browser/browser_tabMatchesInAwesomebar_perwindowpb.js]
 skip-if = os == 'linux' # Bug 1104755