tor-browser

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

commit c550000d83525bfe61795bd2c26e2fc901223b60
parent 161c6ab8c0b0fa22465a36f53d160f3b996546ee
Author: Moritz Beier <mbeier@mozilla.com>
Date:   Fri, 14 Nov 2025 15:54:53 +0000

Bug 1998930 - Don't show contextual search for default search engine. r=urlbar-reviewers,Standard8

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

Diffstat:
Mbrowser/components/urlbar/ActionsProviderContextualSearch.sys.mjs | 11+++++++++--
Mbrowser/components/urlbar/tests/browser/browser_contextualsearch.js | 61++++++++++++++++++++++++++++++++++---------------------------
2 files changed, 43 insertions(+), 29 deletions(-)

diff --git a/browser/components/urlbar/ActionsProviderContextualSearch.sys.mjs b/browser/components/urlbar/ActionsProviderContextualSearch.sys.mjs @@ -123,6 +123,11 @@ class ProviderContextualSearch extends ActionsProvider { return engine; } + // Don't match the default engine for non-query-matches. + let defaultEngine = queryContext.isPrivate + ? Services.search.defaultPrivateEngine + : Services.search.defaultEngine; + let browser = lazy.BrowserWindowTracker.getTopWindow()?.gBrowser.selectedBrowser; if (!browser) { @@ -160,12 +165,12 @@ class ProviderContextualSearch extends ActionsProvider { // Cache the result against this host so we do not need to rerun // the same query every keystroke. this.#hostEngines.set(host, hostEngine); - if (hostEngine) { + if (hostEngine && hostEngine.engine.name != defaultEngine.name) { return hostEngine; } } else if (host) { let cachedEngine = this.#hostEngines.get(host); - if (cachedEngine) { + if (cachedEngine && cachedEngine.engine.name != defaultEngine.name) { return cachedEngine; } } @@ -173,6 +178,8 @@ class ProviderContextualSearch extends ActionsProvider { // Lastly match any openSearch if (browser) { let openSearchEngines = lazy.OpenSearchManager.getEngines(browser); + // We don't need to check if the engine has the same name as the + // default engine because OpenSearchManager already handles that. if (openSearchEngines.length) { return { type: OPEN_SEARCH_ENGINE, engine: openSearchEngines[0] }; } diff --git a/browser/components/urlbar/tests/browser/browser_contextualsearch.js b/browser/components/urlbar/tests/browser/browser_contextualsearch.js @@ -51,13 +51,6 @@ let loadUri = async uri => { await loaded; }; -let updateConfig = async config => { - await waitForIdle(); - await SearchTestUtils.setRemoteSettingsConfig(config); - await Services.search.wrappedJSObject.reset(); - await Services.search.init(); -}; - add_setup(async function setup() { await SpecialPowers.pushPrefEnv({ set: [ @@ -67,8 +60,6 @@ add_setup(async function setup() { }); registerCleanupFunction(async () => { - await updateConfig(null); - Services.search.restoreDefaultEngines(); Services.prefs.clearUserPref( "browser.urlbar.quickactions.timesShownOnboardingLabel" ); @@ -95,7 +86,7 @@ add_task(async function test_engine_match() { PlacesTestUtils.waitForNotification("history-cleared"); await PlacesUtils.history.clear(); await promiseClearHistory; - await updateConfig(CONFIG); + await SearchTestUtils.updateRemoteSettingsConfig(CONFIG); await loadUri("https://example.org/"); await UrlbarTestUtils.promiseAutocompleteResultPopup({ @@ -135,12 +126,10 @@ add_task(async function test_engine_match() { EventUtils.synthesizeKey("KEY_Enter"); await onLoad; - await updateConfig(null); }); add_task(async function test_actions() { let testActionCalled = 0; - await updateConfig(CONFIG); await loadUri("https://example.net/"); ActionsProviderQuickActions.addAction("testaction", { @@ -161,7 +150,6 @@ add_task(async function test_actions() { Assert.equal(testActionCalled, 1, "Test action was called"); - await updateConfig(null); ActionsProviderQuickActions.removeAction("testaction"); }); @@ -240,7 +228,7 @@ add_task(async function test_tab_to_search_engine() { }, }, ]); - await updateConfig(newConfig); + await SearchTestUtils.updateRemoteSettingsConfig(newConfig); await UrlbarTestUtils.promiseAutocompleteResultPopup({ window, @@ -267,19 +255,46 @@ add_task(async function test_tab_to_search_engine() { }); await onLoad; - await updateConfig(null); + await SearchTestUtils.updateRemoteSettingsConfig(CONFIG); }); -add_task(async function test_onboarding_default_engine() { +add_task(async function test_dont_suggest_default_engine() { + await UrlbarTestUtils.promiseAutocompleteResultPopup({ + window, + value: "default", + }); + + Assert.ok( + await hasActions(1), + "Default engine is suggested when it matches the query" + ); + + // Load a URI from the host of the default engine. + await loadUri("https://example.com/"); + + await UrlbarTestUtils.promiseAutocompleteResultPopup({ + window, + value: "something", + }); + + Assert.ok( + !(await hasActions(1)), + "Default engine is not suggested based on current host" + ); + + await UrlbarTestUtils.promisePopupClose(window, () => { + EventUtils.synthesizeKey("KEY_Escape"); + }); +}); + +add_task(async function test_onboarding() { await SpecialPowers.pushPrefEnv({ set: [["browser.urlbar.quickactions.timesToShowOnboardingLabel", 3]], }); - await updateConfig(CONFIG); - await UrlbarTestUtils.promiseAutocompleteResultPopup({ window, - value: "default", + value: "non-default", }); Assert.ok( @@ -292,8 +307,6 @@ add_task(async function test_onboarding_default_engine() { await UrlbarTestUtils.promisePopupClose(window, () => { EventUtils.synthesizeKey("KEY_Escape"); }); - - await updateConfig(null); }); async function hasActions(index) { @@ -304,9 +317,3 @@ async function hasActions(index) { .result; return result.providerName == "UrlbarProviderGlobalActions"; } - -async function waitForIdle() { - for (let i = 0; i < 10; i++) { - await new Promise(resolve => Services.tm.idleDispatchToMainThread(resolve)); - } -}