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
--- 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