tor-browser

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

commit c691e4fa5f90bb2bf166c950255ea1e6dcde8806
parent ee63c6e0f3627af3cf8bc34cb88f99556f8e5a01
Author: Daisuke Akatsuka <daisuke@birchill.co.jp>
Date:   Thu,  2 Oct 2025 12:31:59 +0000

Bug 1979826: Set focused element when popuphiding to avoid focusing processing upon popupshowing r=daleharvey

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

Diffstat:
Mbrowser/components/urlbar/SearchModeSwitcher.sys.mjs | 9+++------
Mbrowser/components/urlbar/tests/browser/browser_searchModeSwitcher_keyNavigation.js | 37+++++++++++++++++++++++++++++++++++--
2 files changed, 38 insertions(+), 8 deletions(-)

diff --git a/browser/components/urlbar/SearchModeSwitcher.sys.mjs b/browser/components/urlbar/SearchModeSwitcher.sys.mjs @@ -65,13 +65,7 @@ export class SearchModeSwitcher { async #onPopupShowing() { await this.#buildSearchModeList(); - this.#input.view.close({ showFocusBorder: false }); - - // This moves the focus to the urlbar when the popup is closed. - this.#input.document.commandDispatcher.focusedElement = - this.#input.inputField; - Glean.urlbarUnifiedsearchbutton.opened.add(1); } @@ -145,6 +139,9 @@ export class SearchModeSwitcher { return; } if (event.type == "popuphiding") { + // This moves the focus to the urlbar when the popup is closed. + this.#input.document.commandDispatcher.focusedElement = + this.#input.inputField; this.#toolbarbutton.setAttribute("aria-expanded", "false"); return; } diff --git a/browser/components/urlbar/tests/browser/browser_searchModeSwitcher_keyNavigation.js b/browser/components/urlbar/tests/browser/browser_searchModeSwitcher_keyNavigation.js @@ -234,6 +234,39 @@ add_task(async function test_keyboard_nav() { await test_navigate_switcher("KEY_ArrowDown", 3, bingSearchMode); }); +add_task(async function test_open_switcher_with_page() { + info("Open a page"); + await BrowserTestUtils.withNewTab( + { + gBrowser, + url: "https://example.com/", + }, + async function () { + info("Click on the urlbar to select all text"); + await focusOnURLbar(() => + EventUtils.synthesizeMouseAtCenter(gURLBar.inputField, {}) + ); + info("Input a char to show the Unified Search Button"); + EventUtils.synthesizeKey("a"); + + info("Move the focus to the button"); + EventUtils.synthesizeKey("KEY_Tab", { shiftKey: true }); + await TestUtils.waitForCondition( + () => document.activeElement.id == "urlbar-searchmode-switcher" + ); + + info("Do the focus test"); + let popup = UrlbarTestUtils.searchModeSwitcherPopup(window); + let promiseHidden = BrowserTestUtils.waitForEvent(popup, "popuphidden"); + await test_open_switcher(" "); + + info("Close the Unified Search popup"); + EventUtils.synthesizeKey("KEY_Escape"); + await promiseHidden; + } + ); +}); + add_task(async function test_focus_on_switcher_by_tab() { const input = "abc"; info(`Open urlbar view with query [${input}]`); @@ -258,10 +291,10 @@ add_task(async function test_focus_on_switcher_by_tab() { let promiseMenuOpen = BrowserTestUtils.waitForEvent(popup, "popupshown"); EventUtils.synthesizeKey("KEY_Enter"); await promiseMenuOpen; - Assert.notEqual( + Assert.equal( document.activeElement.id, "urlbar-searchmode-switcher", - "Dedicated Search button loses the focus" + "Dedicated Search button still has focus" ); Assert.equal(gURLBar.view.isOpen, false, "Urlbar view panel is closed"); Assert.equal(gURLBar.value, input, "Inputted value still be on urlbar");