Bug 1496743 - Stop logging telemetry when pressing enter on the one-off search settings button in the urlbar. r=adw
authorMark Banner <standard8@mozilla.com>
Wed, 10 Oct 2018 07:21:23 +0000
changeset 488807 107392a74e8a7a8d39e66a9b176eb5060ff00924
parent 488806 e8e4080d11009e7e05871301f252a593e913e497
child 488808 a79effc68816dc508ca25b07cfb61bcb2282e230
push id246
push userfmarier@mozilla.com
push dateSat, 13 Oct 2018 00:15:40 +0000
reviewersadw
bugs1496743
milestone64.0a1
Bug 1496743 - Stop logging telemetry when pressing enter on the one-off search settings button in the urlbar. r=adw Also add tests for the search settings button in the urlbar. Differential Revision: https://phabricator.services.mozilla.com/D8146
browser/base/content/test/urlbar/browser.ini
browser/base/content/test/urlbar/browser_urlbarOneOffs_settings.js
browser/base/content/urlbarBindings.xml
--- a/browser/base/content/test/urlbar/browser.ini
+++ b/browser/base/content/test/urlbar/browser.ini
@@ -94,16 +94,20 @@ skip-if = os == "linux" # Bug 1073339 - 
 [browser_urlbarOneOffs.js]
 support-files =
   searchSuggestionEngine.xml
   searchSuggestionEngine.sjs
 [browser_urlbarOneOffs_searchSuggestions.js]
 support-files =
   searchSuggestionEngine.xml
   searchSuggestionEngine.sjs
+[browser_urlbarOneOffs_settings.js]
+support-files =
+  searchSuggestionEngine.xml
+  searchSuggestionEngine.sjs
 [browser_urlbarPlaceholder.js]
 support-files =
   searchSuggestionEngine.xml
   searchSuggestionEngine.sjs
 [browser_urlbarPrivateBrowsingWindowChange.js]
 [browser_urlbarRaceWithTabs.js]
 [browser_urlbarRevert.js]
 [browser_urlbarSearchFunction.js]
new file mode 100644
--- /dev/null
+++ b/browser/base/content/test/urlbar/browser_urlbarOneOffs_settings.js
@@ -0,0 +1,78 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+const TEST_ENGINE_BASENAME = "searchSuggestionEngine.xml";
+
+let gMaxResults;
+
+add_task(async function init() {
+  Services.prefs.setBoolPref("browser.urlbar.oneOffSearches", true);
+  gMaxResults = Services.prefs.getIntPref("browser.urlbar.maxRichResults");
+
+  // Add a search suggestion engine and move it to the front so that it appears
+  // as the first one-off.
+  let engine = await SearchTestUtils.promiseNewSearchEngine(
+    getRootDirectory(gTestPath) + TEST_ENGINE_BASENAME);
+  Services.search.moveEngine(engine, 0);
+
+  registerCleanupFunction(async function() {
+    await hidePopup();
+    await PlacesUtils.history.clear();
+  });
+
+  await PlacesUtils.history.clear();
+
+  let visits = [];
+  for (let i = 0; i < gMaxResults; i++) {
+    visits.push({
+      uri: makeURI("http://example.com/browser_urlbarOneOffs.js/?" + i),
+      // TYPED so that the visit shows up when the urlbar's drop-down arrow is
+      // pressed.
+      transition: Ci.nsINavHistoryService.TRANSITION_TYPED,
+    });
+  }
+  await PlacesTestUtils.addVisits(visits);
+});
+
+
+async function selectSettings(activateFn) {
+  await BrowserTestUtils.withNewTab({gBrowser, url: "about:blank"}, async browser => {
+    gURLBar.focus();
+    EventUtils.synthesizeKey("KEY_ArrowDown");
+    await promisePopupShown(gURLBar.popup);
+    await waitForAutocompleteResultAt(gMaxResults - 1);
+
+    let promiseHidden = promisePopupHidden(gURLBar.popup);
+    let prefPaneLoaded = TestUtils.topicObserved("sync-pane-loaded", () => true);
+
+    activateFn();
+
+    await prefPaneLoaded;
+    await promiseHidden;
+
+    Assert.equal(gBrowser.contentWindow.history.state, "paneSearch",
+      "Should have opened the search preferences pane");
+  });
+}
+
+add_task(async function test_open_settings_with_enter() {
+  await selectSettings(() => {
+    EventUtils.synthesizeKey("KEY_ArrowUp");
+
+    Assert.equal(gURLBar.popup.oneOffSearchButtons.selectedButton.getAttribute("anonid"),
+      "search-settings-compact", "Should have selected the settings button");
+
+    EventUtils.synthesizeKey("KEY_Enter");
+  });
+});
+
+add_task(async function test_open_settings_with_click() {
+  await selectSettings(() => {
+    gURLBar.popup.oneOffSearchButtons.settingsButton.click();
+  });
+});
+
+async function hidePopup() {
+  EventUtils.synthesizeKey("KEY_Escape");
+  await promisePopupHidden(gURLBar.popup);
+}
--- a/browser/base/content/urlbarBindings.xml
+++ b/browser/base/content/urlbarBindings.xml
@@ -647,19 +647,16 @@ file, You can obtain one at http://mozil
         <parameter name="triggeringPrincipal"/>
         <body><![CDATA[
           let isMouseEvent = event instanceof MouseEvent;
           if (isMouseEvent && event.button == 2) {
             // Do nothing for right clicks.
             return;
           }
 
-          BrowserUsageTelemetry.recordUrlbarSelectedResultMethod(
-            event, this.userSelectionBehavior);
-
           // Determine whether to use the selected one-off search button.  In
           // one-off search buttons parlance, "selected" means that the button
           // has been navigated to via the keyboard.  So we want to use it if
           // the triggering event is not a mouse click -- i.e., it's a Return
           // key -- or if the one-off was mouse-clicked.
           let selectedOneOff = this.popup.oneOffSearchButtons.selectedButton;
           if (selectedOneOff &&
               isMouseEvent &&
@@ -668,16 +665,19 @@ file, You can obtain one at http://mozil
           }
 
           // Do the command of the selected one-off if it's not an engine.
           if (selectedOneOff && !selectedOneOff.engine) {
             selectedOneOff.doCommand();
             return;
           }
 
+          BrowserUsageTelemetry.recordUrlbarSelectedResultMethod(
+            event, this.userSelectionBehavior);
+
           let where = openUILinkWhere || this._whereToOpen(event);
 
           let url = this.value;
           if (!url) {
             return;
           }
 
           let mayInheritPrincipal = false;