Bug 1416041 - Collapse one-offs buttons if only the current engine is active and don't select search settings when collapsed. r=florian
authorMarco Bonardo <mbonardo@mozilla.com>
Thu, 11 Jan 2018 18:11:34 +0100
changeset 453291 69408f067a9ccde6041ca26449eae32a4011499b
parent 453290 189a02700a27311b5a62def8fa27e1aabd5eca4f
child 453292 a3e930a4edfd0a1913cfa7d41ee59a0e0aa79ea8
push id1648
push usermtabara@mozilla.com
push dateThu, 01 Mar 2018 12:45:47 +0000
treeherdermozilla-release@cbb9688c2eeb [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersflorian
bugs1416041
milestone59.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 1416041 - Collapse one-offs buttons if only the current engine is active and don't select search settings when collapsed. r=florian MozReview-Commit-ID: 9aOM19NPRzt
browser/base/content/test/urlbar/browser_urlbarOneOffs.js
browser/components/search/content/search.xml
--- a/browser/base/content/test/urlbar/browser_urlbarOneOffs.js
+++ b/browser/base/content/test/urlbar/browser_urlbarOneOffs.js
@@ -223,16 +223,35 @@ add_task(async function oneOffReturn() {
     BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser, false,
                                    "http://mochi.test:8888/?terms=foo.bar");
   EventUtils.synthesizeKey("VK_RETURN", {});
   await resultsPromise;
 
   gBrowser.removeTab(gBrowser.selectedTab);
 });
 
+add_task(async function collapsedOneOffs() {
+  // Disable all the engines but the current one, check the oneoffs are
+  // collapsed and that moving up selects the last match.
+  let engines = Services.search.getVisibleEngines()
+                               .filter(e => e.name != Services.search.currentEngine.name);
+  await SpecialPowers.pushPrefEnv({"set": [
+    [ "browser.search.hiddenOneOffs", engines.map(e => e.name).join(",") ]
+  ]});
+
+  let typedValue = "foo";
+  await promiseAutocompleteResultPopup(typedValue, window, true);
+  await waitForAutocompleteResultAt(0);
+  assertState(0, -1);
+  Assert.ok(gURLBar.popup.oneOffSearchButtons.buttons.collapsed,
+    "The one-off buttons should be collapsed");
+  EventUtils.synthesizeKey("VK_UP", {});
+  assertState(1, -1);
+  await hidePopup();
+});
 
 function assertState(result, oneOff, textValue = undefined) {
   Assert.equal(gURLBar.popup.selectedIndex, result,
                "Expected result should be selected");
   Assert.equal(gURLBar.popup.oneOffSearchButtons.selectedButtonIndex, oneOff,
                "Expected one-off should be selected");
   if (textValue !== undefined) {
     Assert.equal(gURLBar.textValue, textValue, "Expected textValue");
--- a/browser/components/search/content/search.xml
+++ b/browser/components/search/content/search.xml
@@ -1553,21 +1553,23 @@
             this.buttons.firstChild.remove();
           // Remove the trailing empty text node introduced by the binding's
           // content markup above.
           if (this.settingsButtonCompact.nextSibling)
             this.settingsButtonCompact.nextSibling.remove();
 
           let engines = this.engines;
           let oneOffCount = engines.length;
+          let collapsed = !oneOffCount ||
+                          (oneOffCount == 1 && engines[0].name == Services.search.currentEngine.name);
 
           // header is a xul:deck so collapsed doesn't work on it, see bug 589569.
-          this.header.hidden = this.buttons.collapsed = !oneOffCount;
+          this.header.hidden = this.buttons.collapsed = collapsed;
 
-          if (!oneOffCount)
+          if (collapsed)
             return;
 
           let panelWidth = parseInt(this.popup.clientWidth);
 
           // There's one weird thing to guard against: when layout pixels
           // aren't an integral multiple of device pixels, the last button
           // of each row sometimes gets pushed to the next row, depending on the
           // panel and button widths.
@@ -1986,16 +1988,18 @@
       </method>
 
       <method name="_handleKeyPress">
         <parameter name="event"/>
         <parameter name="numListItems"/>
         <parameter name="allowEmptySelection"/>
         <parameter name="textboxUserValue"/>
         <body><![CDATA[
+          if (this.compact && this.buttons.collapsed)
+            return false;
           if (event.keyCode == KeyEvent.DOM_VK_RIGHT &&
               this.selectedButton &&
               this.selectedButton.getAttribute("anonid") ==
                 "addengine-menu-button") {
             // If the add-engine overflow menu item is selected and the user
             // presses the right arrow key, open the submenu.  Unfortunately
             // handling the left arrow key -- to close the popup -- isn't
             // straightforward.  Once the popup is open, it consumes all key