commit dac09b7cc7026d7ddc3b1f9f50d017c0177c3e94
parent f0a2798907e418d00b5fcae95f7c5a72ac1590c1
Author: Moritz Beier <mbeier@mozilla.com>
Date: Tue, 16 Dec 2025 10:43:55 +0000
Bug 2004321 - Fix tooltip of unified search button in new searchbar when keyword.enabled=false. r=dao,urlbar-reviewers
Differential Revision: https://phabricator.services.mozilla.com/D276460
Diffstat:
7 files changed, 90 insertions(+), 24 deletions(-)
diff --git a/browser/components/urlbar/SearchModeSwitcher.sys.mjs b/browser/components/urlbar/SearchModeSwitcher.sys.mjs
@@ -338,8 +338,10 @@ export class SearchModeSwitcher {
labelEl.textContent = label;
}
- // If keyword.enabled is true, then the tooltip is already set.
- if (!lazy.UrlbarPrefs.get("keyword.enabled")) {
+ if (
+ !lazy.UrlbarPrefs.get("keyword.enabled") &&
+ this.#input.sapName != "searchbar"
+ ) {
this.#input.document.l10n.setAttributes(
this.#toolbarbutton,
"urlbar-searchmode-no-keyword"
diff --git a/browser/components/urlbar/tests/UrlbarTestUtils.sys.mjs b/browser/components/urlbar/tests/UrlbarTestUtils.sys.mjs
@@ -1463,6 +1463,23 @@ class UrlbarInputTestUtils {
);
}
+ /**
+ * Gets the icon url of the search mode switcher icon.
+ *
+ * @param {ChromeWindow} win
+ * @returns {?string}
+ */
+ getSearchModeSwitcherIcon(win) {
+ let searchModeSwitcherButton = this.#urlbar(win).querySelector(
+ ".searchmode-switcher-icon"
+ );
+
+ // match and capture the URL inside `url("...")`
+ let re = /url\("([^"]+)"\)/;
+ let { listStyleImage } = win.getComputedStyle(searchModeSwitcherButton);
+ return listStyleImage.match(re)?.[1] ?? null;
+ }
+
async openTrustPanel(win) {
let btn = win.document.getElementById("trust-icon");
let popupShown = lazy.BrowserTestUtils.waitForEvent(
diff --git a/browser/components/urlbar/tests/browser/browser_searchModeSwitcher_basic.js b/browser/components/urlbar/tests/browser/browser_searchModeSwitcher_basic.js
@@ -273,7 +273,7 @@ add_task(async function test_icon_new_window() {
let expectedIcon = await Services.search.defaultEngine.getIconURL();
Assert.equal(
- await getSearchModeSwitcherIcon(newWin),
+ UrlbarTestUtils.getSearchModeSwitcherIcon(newWin),
expectedIcon,
"The search mode switcher should already have the engine favicon."
);
@@ -290,7 +290,7 @@ add_task(async function test_search_icon_change() {
const globeIconUrl = UrlbarUtils.ICON.GLOBE;
Assert.equal(
- await getSearchModeSwitcherIcon(newWin),
+ UrlbarTestUtils.getSearchModeSwitcherIcon(newWin),
globeIconUrl,
"The search mode switcher should have the globe icon url since keyword.enabled is false"
);
@@ -313,7 +313,7 @@ add_task(async function test_search_icon_change() {
.getIconURL();
Assert.equal(
- await getSearchModeSwitcherIcon(newWin),
+ UrlbarTestUtils.getSearchModeSwitcherIcon(newWin),
bingSearchEngineIconUrl,
"The search mode switcher should have the bing icon url since we are in \
search mode"
@@ -329,7 +329,7 @@ add_task(async function test_search_icon_change() {
await UrlbarTestUtils.assertSearchMode(newWin, null);
let searchModeSwitcherIconUrl = await BrowserTestUtils.waitForCondition(
- () => getSearchModeSwitcherIcon(newWin),
+ () => UrlbarTestUtils.getSearchModeSwitcherIcon(newWin),
"Waiting for the search mode switcher icon to update after exiting search mode."
);
@@ -734,7 +734,7 @@ add_task(async function test_search_service_fail() {
});
let searchModeSwitcherIconUrl = await BrowserTestUtils.waitForCondition(
- () => getSearchModeSwitcherIcon(newWin),
+ () => UrlbarTestUtils.getSearchModeSwitcherIcon(newWin),
"Waiting for the search mode switcher icon to update after exiting search mode."
);
@@ -788,7 +788,7 @@ add_task(async function test_search_mode_switcher_engine_no_icon() {
await popupHidden;
Assert.equal(
- await getSearchModeSwitcherIcon(window),
+ UrlbarTestUtils.getSearchModeSwitcherIcon(window),
UrlbarUtils.ICON.SEARCH_GLASS,
"The search mode switcher should display the default search glass icon when the engine has no icon."
);
@@ -844,7 +844,7 @@ add_task(async function test_search_mode_switcher_private_engine_icon() {
);
Assert.equal(
- await getSearchModeSwitcherIcon(window),
+ UrlbarTestUtils.getSearchModeSwitcherIcon(window),
defaultEngineIcon,
"Is the icon of the default engine."
);
@@ -861,7 +861,7 @@ add_task(async function test_search_mode_switcher_private_engine_icon() {
});
Assert.equal(
- await getSearchModeSwitcherIcon(privateWin),
+ UrlbarTestUtils.getSearchModeSwitcherIcon(privateWin),
defaultPrivateEngineIcon,
"Is the icon of the default private engine."
);
@@ -874,7 +874,8 @@ add_task(async function test_search_mode_switcher_private_engine_icon() {
info("Waiting for the icon to be updated.");
await TestUtils.waitForCondition(
- () => getSearchModeSwitcherIcon(privateWin) == defaultEngineIcon
+ () =>
+ UrlbarTestUtils.getSearchModeSwitcherIcon(privateWin) == defaultEngineIcon
);
Assert.ok(true, "The icon was updated.");
@@ -901,14 +902,3 @@ add_task(async function open_with_option() {
EventUtils.synthesizeKey("KEY_Escape");
await popupHidden;
});
-
-function getSearchModeSwitcherIcon(window) {
- let searchModeSwitcherButton = window.gURLBar.querySelector(
- ".searchmode-switcher-icon"
- );
-
- // match and capture the URL inside `url("...")`
- let re = /url\("([^"]+)"\)/;
- let { listStyleImage } = window.getComputedStyle(searchModeSwitcherButton);
- return listStyleImage.match(re)?.[1] ?? null;
-}
diff --git a/browser/components/urlbar/tests/browser/head-common.js b/browser/components/urlbar/tests/browser/head-common.js
@@ -38,6 +38,14 @@ ChromeUtils.defineLazyGetter(this, "UrlbarTestUtils", () => {
return module;
});
+ChromeUtils.defineLazyGetter(this, "SearchbarTestUtils", () => {
+ const { SearchbarTestUtils: module } = ChromeUtils.importESModule(
+ "resource://testing-common/UrlbarTestUtils.sys.mjs"
+ );
+ module.init(this);
+ return module;
+});
+
ChromeUtils.defineLazyGetter(this, "SearchTestUtils", () => {
const { SearchTestUtils: module } = ChromeUtils.importESModule(
"resource://testing-common/SearchTestUtils.sys.mjs"
diff --git a/browser/components/urlbar/tests/browser/searchbar/browser.toml b/browser/components/urlbar/tests/browser/searchbar/browser.toml
@@ -11,4 +11,6 @@ prefs = [
["browser_search.js"]
+["browser_searchModeSwitcher.js"]
+
["browser_searchmode.js"]
diff --git a/browser/components/urlbar/tests/browser/searchbar/browser_searchModeSwitcher.js b/browser/components/urlbar/tests/browser/searchbar/browser_searchModeSwitcher.js
@@ -0,0 +1,49 @@
+/* Any copyright is dedicated to the Public Domain.
+ https://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+add_setup(async function setup() {
+ // Wait for the search service to make sure icons are available immediately.
+ await Services.search.init();
+});
+
+// keyword.enabled=false should have no effect on icon and label.
+add_task(async function test_keyword_disabled() {
+ await SpecialPowers.pushPrefEnv({
+ set: [["keyword.enabled", false]],
+ });
+ let win = await BrowserTestUtils.openNewBrowserWindow();
+
+ // Getting the icon is async, so wait until the icon is set.
+ await BrowserTestUtils.waitForCondition(
+ async () =>
+ SearchbarTestUtils.getSearchModeSwitcherIcon(win) ==
+ (await Services.search.defaultEngine.getIconURL())
+ );
+
+ Assert.ok(
+ true,
+ "The search mode switcher should have the default icon " +
+ "despite keyword.enabled being false"
+ );
+
+ Assert.equal(
+ document
+ .querySelector("#searchbar-new .searchmode-switcher")
+ .getAttribute("data-l10n-id"),
+ "urlbar-searchmode-button2",
+ "Searchbar has regular l10n id"
+ );
+
+ Assert.equal(
+ win.document
+ .querySelector("#urlbar .searchmode-switcher")
+ .getAttribute("data-l10n-id"),
+ "urlbar-searchmode-no-keyword",
+ "Urlbar has l10n id for keyword disabled"
+ );
+
+ await BrowserTestUtils.closeWindow(win);
+ await SpecialPowers.popPrefEnv();
+});
diff --git a/browser/components/urlbar/tests/browser/searchbar/head.js b/browser/components/urlbar/tests/browser/searchbar/head.js
@@ -6,7 +6,6 @@
ChromeUtils.defineESModuleGetters(this, {
CustomizableUITestUtils:
"resource://testing-common/CustomizableUITestUtils.sys.mjs",
- SearchbarTestUtils: "resource://testing-common/UrlbarTestUtils.sys.mjs",
SearchUITestUtils: "resource://testing-common/SearchUITestUtils.sys.mjs",
SearchUtils: "moz-src:///toolkit/components/search/SearchUtils.sys.mjs",
TelemetryTestUtils: "resource://testing-common/TelemetryTestUtils.sys.mjs",
@@ -24,7 +23,6 @@ Services.scriptloader.loadSubScript(
let gCUITestUtils = new CustomizableUITestUtils(window);
gCUITestUtils.addSearchBar();
-SearchbarTestUtils.init(this);
registerCleanupFunction(async () => {
gCUITestUtils.removeSearchBar();