Bug 1416041 - Collapse one-offs buttons if only the current engine is active and don't select search settings when collapsed. r=florian draft
authorMarco Bonardo <mbonardo@mozilla.com>
Thu, 11 Jan 2018 18:11:34 +0100
changeset 719241 d1cf002e812e1800182701dbe1d5ebad0df8e242
parent 718505 d5f42a23909eb181274731b07e4984bfbd18557d
child 745736 19f7a88c1ec49916206df2ed6c9fd65ab2ed658b
push id95190
push usermak77@bonardo.net
push dateThu, 11 Jan 2018 18:07:04 +0000
reviewersflorian
bugs1416041
milestone59.0a1
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