Bug 1547671 - Hide the one-off buttons generally when the search string is empty. r=adw
authorDão Gottwald <dao@mozilla.com>
Fri, 17 May 2019 18:49:17 +0000
changeset 474385 f5f6979aa22ac36f8caefbed781a6d97788d5f89
parent 474384 02f6bb0dec8a9c95ed4a01235ee684b24fd95251
child 474386 5f5daca84fbeb06f7df1569b18ad49da977b024e
push id113152
push userdluca@mozilla.com
push dateSat, 18 May 2019 10:33:03 +0000
treeherdermozilla-inbound@9b2f851979cb [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersadw
bugs1547671
milestone68.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 1547671 - Hide the one-off buttons generally when the search string is empty. r=adw Differential Revision: https://phabricator.services.mozilla.com/D31594
browser/components/urlbar/UrlbarView.jsm
browser/components/urlbar/tests/browser/browser_urlbarOneOffs.js
browser/components/urlbar/tests/browser/browser_urlbarOneOffs_settings.js
--- a/browser/components/urlbar/UrlbarView.jsm
+++ b/browser/components/urlbar/UrlbarView.jsm
@@ -227,24 +227,25 @@ class UrlbarView {
         this._selectItem(this._rows.firstElementChild, {
           updateInput: false,
           setAccessibleFocus: this.controller._userSelectionBehavior == "arrow",
         });
       } else {
         // Clear the selection when we get a new set of results.
         this._selectItem(null);
       }
-      // Hide the one-off search buttons if the input starts with a potential @
-      // search alias or the search restriction character.
-      let trimmedValue = this.input.textValue.trim();
+      // Hide the one-off search buttons if the search string is empty, or
+      // starts with a potential @ search alias or the search restriction
+      // character.
+      let trimmedValue = queryContext.searchString.trim();
       this._enableOrDisableOneOffSearches(
-        !trimmedValue ||
-        (trimmedValue[0] != "@" &&
-         (trimmedValue[0] != UrlbarTokenizer.RESTRICT.SEARCH ||
-          trimmedValue.length != 1))
+        trimmedValue &&
+        trimmedValue[0] != "@" &&
+        (trimmedValue[0] != UrlbarTokenizer.RESTRICT.SEARCH ||
+         trimmedValue.length != 1)
       );
     }
 
     this._openPanel();
 
     if (isFirstPreselectedResult) {
       // The first, preselected result may be a search alias result, so apply
       // formatting if necessary.  Conversely, the first result of the previous
--- a/browser/components/urlbar/tests/browser/browser_urlbarOneOffs.js
+++ b/browser/components/urlbar/tests/browser/browser_urlbarOneOffs.js
@@ -51,63 +51,73 @@ add_task(async function history() {
 
   // Key down through each result.
   for (let i = 0; i < gMaxResults; i++) {
     EventUtils.synthesizeKey("KEY_ArrowDown");
     assertState(i, -1,
       "example.com/browser_urlbarOneOffs.js/?" + (gMaxResults - i - 1));
   }
 
-  // Key down through each one-off.
-  let numButtons = oneOffSearchButtons.getSelectableButtons(true).length;
-  for (let i = 0; i < numButtons; i++) {
+  if (!UrlbarPrefs.get("quantumbar")) {
+    // Key down through each one-off.
+    let numButtons = oneOffSearchButtons.getSelectableButtons(true).length;
+    for (let i = 0; i < numButtons; i++) {
+      EventUtils.synthesizeKey("KEY_ArrowDown");
+      assertState(-1, i, "");
+    }
+
+    // Key down once more.  Nothing should be selected.
+    EventUtils.synthesizeKey("KEY_ArrowDown");
+    assertState(-1, -1, "");
+
+    // Once more.  The first result should be selected.
     EventUtils.synthesizeKey("KEY_ArrowDown");
-    assertState(-1, i, "");
+    assertState(0, -1,
+      "example.com/browser_urlbarOneOffs.js/?" + (gMaxResults - 1));
+
+    // Now key up.  Nothing should be selected again.
+    EventUtils.synthesizeKey("KEY_ArrowUp");
+    assertState(-1, -1, "");
+
+    // Key up through each one-off.
+    for (let i = numButtons - 1; i >= 0; i--) {
+      EventUtils.synthesizeKey("KEY_ArrowUp");
+      assertState(-1, i, "");
+    }
+
+    // Key right through each one-off.
+    for (let i = 1; i < numButtons; i++) {
+      EventUtils.synthesizeKey("KEY_ArrowRight");
+      assertState(-1, i, "");
+    }
+
+    // Key left through each one-off.
+    for (let i = numButtons - 2; i >= 0; i--) {
+      EventUtils.synthesizeKey("KEY_ArrowLeft");
+      assertState(-1, i, "");
+    }
+
+    // Key up through each result.
+    for (let i = gMaxResults - 1; i >= 0; i--) {
+      EventUtils.synthesizeKey("KEY_ArrowUp");
+      assertState(i, -1,
+        "example.com/browser_urlbarOneOffs.js/?" + (gMaxResults - i - 1));
+    }
+
+    // Key up once more.  Nothing should be selected.
+    EventUtils.synthesizeKey("KEY_ArrowUp");
+    assertState(-1, -1, "");
+
+    await hidePopup();
+    return;
   }
 
-  // Key down once more.  Nothing should be selected.
-  EventUtils.synthesizeKey("KEY_ArrowDown");
-  assertState(-1, -1, "");
-
-  // Once more.  The first result should be selected.
+  // Key down once more.  Nothing should be selected as one-off buttons
+  // should be hidden.
   EventUtils.synthesizeKey("KEY_ArrowDown");
-  assertState(0, -1,
-    "example.com/browser_urlbarOneOffs.js/?" + (gMaxResults - 1));
-
-  // Now key up.  Nothing should be selected again.
-  EventUtils.synthesizeKey("KEY_ArrowUp");
-  assertState(-1, -1, "");
-
-  // Key up through each one-off.
-  for (let i = numButtons - 1; i >= 0; i--) {
-    EventUtils.synthesizeKey("KEY_ArrowUp");
-    assertState(-1, i, "");
-  }
-
-  // Key right through each one-off.
-  for (let i = 1; i < numButtons; i++) {
-    EventUtils.synthesizeKey("KEY_ArrowRight");
-    assertState(-1, i, "");
-  }
-
-  // Key left through each one-off.
-  for (let i = numButtons - 2; i >= 0; i--) {
-    EventUtils.synthesizeKey("KEY_ArrowLeft");
-    assertState(-1, i, "");
-  }
-
-  // Key up through each result.
-  for (let i = gMaxResults - 1; i >= 0; i--) {
-    EventUtils.synthesizeKey("KEY_ArrowUp");
-    assertState(i, -1,
-      "example.com/browser_urlbarOneOffs.js/?" + (gMaxResults - i - 1));
-  }
-
-  // Key up once more.  Nothing should be selected.
-  EventUtils.synthesizeKey("KEY_ArrowUp");
   assertState(-1, -1, "");
 
   await hidePopup();
 });
 
 // Keys up and down through the non-history panel, i.e., the panel that's shown
 // when you type something in the textbox.
 add_task(async function() {
--- a/browser/components/urlbar/tests/browser/browser_urlbarOneOffs_settings.js
+++ b/browser/components/urlbar/tests/browser/browser_urlbarOneOffs_settings.js
@@ -30,20 +30,17 @@ add_task(async function init() {
     });
   }
   await PlacesTestUtils.addVisits(visits);
 });
 
 
 async function selectSettings(activateFn) {
   await BrowserTestUtils.withNewTab({gBrowser, url: "about:blank"}, async browser => {
-    await UrlbarTestUtils.promisePopupOpen(window, () => {
-      gURLBar.focus();
-      EventUtils.synthesizeKey("KEY_ArrowDown");
-    });
+    await promiseAutocompleteResultPopup("example.com");
     await waitForAutocompleteResultAt(gMaxResults - 1);
 
     await UrlbarTestUtils.promisePopupClose(window, async () => {
       let prefPaneLoaded = TestUtils.topicObserved("sync-pane-loaded", () => true);
 
       activateFn();
 
       await prefPaneLoaded;