tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

commit af5ba32615853b5417d96c2cbadcbfde92350c9b
parent e1df4d5c51b83a64ba0c7008f3d0673255c0e7ac
Author: Moritz Beier <mbeier@mozilla.com>
Date:   Mon,  1 Dec 2025 10:07:26 +0000

Bug 2002503 - Ensure the unified search button in new windows starts with the default engine favicon. r=urlbar-reviewers,dao

Differential Revision: https://phabricator.services.mozilla.com/D274111

Diffstat:
Mbrowser/components/urlbar/content/UrlbarInput.mjs | 19+++++++++++++------
Mbrowser/components/urlbar/tests/browser/browser_placeholder.js | 11+++++++++++
Mbrowser/components/urlbar/tests/browser/browser_searchModeSwitcher_basic.js | 18+++++++++++++++---
3 files changed, 39 insertions(+), 9 deletions(-)

diff --git a/browser/components/urlbar/content/UrlbarInput.mjs b/browser/components/urlbar/content/UrlbarInput.mjs @@ -420,13 +420,16 @@ export class UrlbarInput extends HTMLElement { // On startup, this will be called again by browser-init.js // once gBrowser has been initialized. this.addGBrowserListeners(); + } - // If gBrowser or the search service is not initialized yet, - // the placeholder and icon will be updated in delayedStartupInit. - if (Services.search.isInitialized) { - this.searchModeSwitcher.updateSearchIcon(); - this._updatePlaceholderFromDefaultEngine(); - } + // If the search service is not initialized yet, the placeholder + // and icon will be updated in delayedStartupInit. + if ( + Cu.isESModuleLoaded("resource://gre/modules/SearchService.sys.mjs") && + Services.search.isInitialized + ) { + this.searchModeSwitcher.updateSearchIcon(); + this._updatePlaceholderFromDefaultEngine(); } // Expanding requires a parent toolbar, and us not being read-only. @@ -2498,6 +2501,10 @@ export class UrlbarInput extends HTMLElement { } get searchMode() { + if (!this.window.gBrowser) { + // This only happens before DOMContentLoaded. + return null; + } return this.getSearchMode(this.window.gBrowser.selectedBrowser); } diff --git a/browser/components/urlbar/tests/browser/browser_placeholder.js b/browser/components/urlbar/tests/browser/browser_placeholder.js @@ -8,6 +8,10 @@ "use strict"; +const { sinon } = ChromeUtils.importESModule( + "resource://testing-common/Sinon.sys.mjs" +); + const CONFIG = [ { identifier: "defaultEngine", @@ -142,6 +146,10 @@ async function doDelayedUpdatePlaceholderTest({ defaultEngine }) { info("Clear placeholder cache"); Services.prefs.clearUserPref("browser.urlbar.placeholderName"); + info("Pretend we're on startup and the search service hasn't started yet."); + let stub = sinon.stub(Services.search.wrappedJSObject, "isInitialized"); + stub.get(() => false); + info("Open a new window"); let newWin = await BrowserTestUtils.openNewBrowserWindow(); @@ -156,6 +164,9 @@ async function doDelayedUpdatePlaceholderTest({ defaultEngine }) { "Placeholder data should be unchanged." ); + info("Pretend the search service has finished initializing."); + stub.restore(); + info("Simulate user interaction"); let urlTab = BrowserTestUtils.addTab(newWin.gBrowser, "about:mozilla"); await BrowserTestUtils.switchTab(newWin.gBrowser, urlTab); diff --git a/browser/components/urlbar/tests/browser/browser_searchModeSwitcher_basic.js b/browser/components/urlbar/tests/browser/browser_searchModeSwitcher_basic.js @@ -268,6 +268,19 @@ async function setDefaultEngine(name) { ); } +add_task(async function test_icon_new_window() { + let newWin = await BrowserTestUtils.openNewBrowserWindow(); + let expectedIcon = await Services.search.defaultEngine.getIconURL(); + + Assert.equal( + await getSearchModeSwitcherIcon(newWin), + expectedIcon, + "The search mode switcher should already have the engine favicon." + ); + + await BrowserTestUtils.closeWindow(newWin); +}); + add_task(async function test_search_icon_change() { await SpecialPowers.pushPrefEnv({ set: [["keyword.enabled", false]], @@ -275,12 +288,11 @@ add_task(async function test_search_icon_change() { let newWin = await BrowserTestUtils.openNewBrowserWindow(); const globeIconUrl = UrlbarUtils.ICON.GLOBE; - const searchIconUrl = UrlbarUtils.ICON.SEARCH_GLASS; Assert.equal( await getSearchModeSwitcherIcon(newWin), - searchIconUrl, - "The search mode switcher should have the default (search icon) url since we are not in search mode." + globeIconUrl, + "The search mode switcher should have the globe icon url since keyword.enabled is false" ); let popup = UrlbarTestUtils.searchModeSwitcherPopup(newWin);