diff --git a/browser/base/content/browser.js b/browser/base/content/browser.js index 07f758286fbe8..dd5bc0be54cc4 100644 --- a/browser/base/content/browser.js +++ b/browser/base/content/browser.js @@ -4135,11 +4135,9 @@ const BrowserSearch = { if (delayUpdate && !gURLBar.value) { // Delays changing the URL Bar placeholder until the user is not going to be // seeing it, e.g. when there is a value entered in the bar, or if there is - // a tab switch to a tab which has a url loaded. We delay the update until - // the user is out of search mode since an alternative placeholder is used - // in search mode. + // a tab switch to a tab which has a url loaded. let placeholderUpdateListener = () => { - if (gURLBar.value && !gURLBar.searchMode) { + if (gURLBar.value) { // By the time the user has switched, they may have changed the engine // again, so we need to call this function again but with the // new engine name. diff --git a/browser/components/urlbar/UrlbarController.jsm b/browser/components/urlbar/UrlbarController.jsm index ece930fd29f3c..8b2dcfb2cd36f 100644 --- a/browser/components/urlbar/UrlbarController.jsm +++ b/browser/components/urlbar/UrlbarController.jsm @@ -377,9 +377,7 @@ class UrlbarController { break; case KeyEvent.DOM_VK_RIGHT: case KeyEvent.DOM_VK_END: - this.input.maybePromoteKeywordToSearchMode({ - entry: "typed", - }); + this.input.maybePromoteKeywordToSearchMode(); // Fall through. case KeyEvent.DOM_VK_LEFT: case KeyEvent.DOM_VK_HOME: diff --git a/browser/components/urlbar/UrlbarInput.jsm b/browser/components/urlbar/UrlbarInput.jsm index 8ceb519fea25b..88fea5bef8c34 100644 --- a/browser/components/urlbar/UrlbarInput.jsm +++ b/browser/components/urlbar/UrlbarInput.jsm @@ -938,15 +938,6 @@ class UrlbarInput { // confusing the user, we always enforce it when a result changes our value. this.setPageProxyState("invalid", true); - // A previous result may have previewed search mode. If we don't expect that - // we might stay in a search mode of some kind, exit it now. - if ( - this.searchMode?.isPreview && - result?.payload.keywordOffer != UrlbarUtils.KEYWORD_OFFER.SHOW - ) { - this.setSearchMode({}); - } - if (!result) { // This happens when there's no selection, for example when moving to the // one-offs search settings button, or to the input field when Top Sites @@ -966,20 +957,6 @@ class UrlbarInput { } else if (result.autofill) { let { value, selectionStart, selectionEnd } = result.autofill; this._autofillValue(value, selectionStart, selectionEnd); - } else if ( - result.payload.keywordOffer == UrlbarUtils.KEYWORD_OFFER.SHOW - ) { - // Enter search mode without starting a query. This will just preview - // search mode. - let enteredSearchMode = this.maybePromoteKeywordToSearchMode({ - result, - checkValue: false, - startQuery: false, - }); - if (!enteredSearchMode) { - this._setValue(this._getValueFromResult(result), true); - this.setSearchMode({}); - } } else { // If the url is trimmed but it's invalid (for example it has an unknown // single word host, or an unknown domain suffix), trimming @@ -1069,11 +1046,7 @@ class UrlbarInput { firstResult.heuristic && firstResult.payload.keyword && !firstResult.payload.keywordOffer && - this.maybePromoteKeywordToSearchMode({ - result: firstResult, - entry: "typed", - checkValue: false, - }) + this.maybePromoteKeywordToSearchMode(firstResult, false) ) { return true; } @@ -1172,18 +1145,6 @@ class UrlbarInput { }; if (this.searchMode) { - // The user started a search from search mode preview so we're now in - // regular search mode. We `delete` instead of setting to null for easier - // testing. If this is our first query for this search mode, we record - // search mode entry in telemetry. - if (this.searchMode.isPreview) { - delete this.searchMode.isPreview; - try { - BrowserUsageTelemetry.recordSearchMode(this.searchMode); - } catch (ex) { - Cu.reportError(ex); - } - } options.searchMode = this.searchMode; if (this.searchMode.source) { options.sources = [this.searchMode.source]; @@ -1384,10 +1345,6 @@ class UrlbarInput { } else { this.searchMode.entry = entry; } - - // We always preview search mode before entering it. We enter full search - // mode once a query is started. - this.searchMode.isPreview = true; this.toggleAttribute("searchmode", true); // Clear autofill. if (this._autofillPlaceholder && this.window.gBrowser.userTypedValue) { @@ -1402,6 +1359,13 @@ class UrlbarInput { this.window.gBrowser.selectedBrowser, this.searchMode ); + + // Record search mode entry in telemetry. + try { + BrowserUsageTelemetry.recordSearchMode(this.searchMode); + } catch (ex) { + Cu.reportError(ex); + } } else { this.removeAttribute("searchmode"); this._searchModesByBrowser.delete(this.window.gBrowser.selectedBrowser); @@ -1607,41 +1571,30 @@ class UrlbarInput { * Enters search mode and starts a new search if appropriate for the given * result. See also _searchModeForResult. * - * @param {string} entry - * The search mode entry point. See setSearchMode documentation for details. - * @param {UrlbarResult} [result] - * The result to promote. Defaults to the currently selected result. - * @param {boolean} [checkValue] + * @param {UrlbarResult} result + * The currently selected urlbar result. + * @param {boolean} checkValue * If true, the trimmed input value must equal the result's keyword in order * to enter search mode. - * @param {boolean} [startQuery] - * If true, start a query after entering search mode. Defaults to true. * @returns {boolean} * True if we entered search mode and false if not. */ - maybePromoteKeywordToSearchMode({ - entry, + maybePromoteKeywordToSearchMode( result = this._resultForCurrentValue, - checkValue = true, - startQuery = true, - }) { - if ( - !result || - (checkValue && this.value.trim() != result.payload.keyword?.trim()) - ) { + checkValue = true + ) { + if (checkValue && this.value.trim() != result.payload.keyword?.trim()) { return false; } - let searchMode = this._searchModeForResult(result, entry); + let searchMode = this._searchModeForResult(result, "typed"); if (!searchMode) { return false; } this.setSearchMode(searchMode); this._setValue(result.payload.query?.trimStart() || "", false); - if (startQuery) { - this.startQuery({ allowAutofill: false }); - } + this.startQuery({ allowAutofill: false }); return true; } @@ -2490,12 +2443,6 @@ class UrlbarInput { } this._focusUntrimmedValue = null; - // We exit previewed search mode on blur since the result previewing it is - // implictly unselected. - if (this.searchMode?.isPreview) { - this.setSearchMode({}); - } - this.formatValue(); this._resetSearchState(); diff --git a/browser/components/urlbar/UrlbarProviderTopSites.jsm b/browser/components/urlbar/UrlbarProviderTopSites.jsm index 807daa33bacd3..485b919ea08da 100644 --- a/browser/components/urlbar/UrlbarProviderTopSites.jsm +++ b/browser/components/urlbar/UrlbarProviderTopSites.jsm @@ -219,7 +219,7 @@ class ProviderTopSites extends UrlbarProvider { ...UrlbarResult.payloadAndSimpleHighlights(queryContext.tokens, { title: site.title, keyword: site.title, - keywordOffer: UrlbarUtils.KEYWORD_OFFER.SHOW, + keywordOffer: UrlbarUtils.KEYWORD_OFFER.HIDE, engine: engine.name, query: "", icon: site.favicon, diff --git a/browser/components/urlbar/UrlbarResult.jsm b/browser/components/urlbar/UrlbarResult.jsm index 0246297377666..3cd14dc36a02d 100644 --- a/browser/components/urlbar/UrlbarResult.jsm +++ b/browser/components/urlbar/UrlbarResult.jsm @@ -124,10 +124,7 @@ class UrlbarResult { case UrlbarUtils.RESULT_TYPE.SEARCH: switch (this.payload.keywordOffer) { case UrlbarUtils.KEYWORD_OFFER.SHOW: - if (!UrlbarPrefs.get("update2")) { - return [this.payload.keyword, this.payloadHighlights.keyword]; - } - // Fall through. + return [this.payload.keyword, this.payloadHighlights.keyword]; case UrlbarUtils.KEYWORD_OFFER.HIDE: return ["", []]; } diff --git a/browser/components/urlbar/UrlbarUtils.jsm b/browser/components/urlbar/UrlbarUtils.jsm index d2ae5d68f2207..ac4a19466dccd 100644 --- a/browser/components/urlbar/UrlbarUtils.jsm +++ b/browser/components/urlbar/UrlbarUtils.jsm @@ -160,9 +160,9 @@ var UrlbarUtils = { // when the user picks them. Depending on the use case, a keyword offer can // visually show or hide the keyword itself in its result. For example, // typing "@" by itself will show keyword offers for all engines with @ - // aliases, and those results will preview their search modes. When a keyword - // offer is a heuristic -- like an autofilled @ alias -- usually it hides - // its keyword since the user is already typing it. + // aliases, and those results will visually show their keywords -- @google, + // @bing, etc. When a keyword offer is a heuristic -- like an autofilled @ + // alias -- usually it hides its keyword since the user is already typing it. KEYWORD_OFFER: { SHOW: 1, HIDE: 2, diff --git a/browser/components/urlbar/tests/UrlbarTestUtils.jsm b/browser/components/urlbar/tests/UrlbarTestUtils.jsm index fca45393bd4ae..dee00adb3dcf5 100644 --- a/browser/components/urlbar/tests/UrlbarTestUtils.jsm +++ b/browser/components/urlbar/tests/UrlbarTestUtils.jsm @@ -481,13 +481,7 @@ var UrlbarTestUtils = { // If this is an engine search mode, check that all results are either // search results with the same engine or have the same host as the engine. - // Search mode preview can show other results since it is not supposed to - // start a query. - if ( - expectedSearchMode.engineName && - !expectedSearchMode.isPreview && - this.isPopupOpen(window) - ) { + if (expectedSearchMode.engineName && this.isPopupOpen(window)) { let resultCount = this.getResultCount(window); for (let i = 0; i < resultCount; i++) { let result = await this.getDetailsOfResultAt(window, i); diff --git a/browser/components/urlbar/tests/browser/browser.ini b/browser/components/urlbar/tests/browser/browser.ini index 8a183d9b56614..32e7c69d87c24 100644 --- a/browser/components/urlbar/tests/browser/browser.ini +++ b/browser/components/urlbar/tests/browser/browser.ini @@ -156,7 +156,6 @@ support-files = [browser_searchMode_engineRemoval.js] [browser_searchMode_no_results.js] [browser_searchMode_pickResult.js] -[browser_searchMode_preview.js] [browser_searchMode_setURI.js] [browser_searchMode_suggestions.js] support-files = diff --git a/browser/components/urlbar/tests/browser/browser_restoreEmptyInput.js b/browser/components/urlbar/tests/browser/browser_restoreEmptyInput.js index 50ac4044e669b..c8aeb00634912 100644 --- a/browser/components/urlbar/tests/browser/browser_restoreEmptyInput.js +++ b/browser/components/urlbar/tests/browser/browser_restoreEmptyInput.js @@ -7,20 +7,7 @@ "use strict"; add_task(async function test() { - for (let i = 0; i < 5; i++) { - await PlacesTestUtils.addVisits("http://example.com/"); - } - // Update Top Sites to make sure the last Top Site is a URL. Otherwise, it - // would be a search shortcut and thus would not fill the Urlbar when - // selected. - await updateTopSites(sites => { - return ( - sites && - sites[sites.length - 1] && - sites[sites.length - 1].url == "http://example.com/" - ); - }); - + await PlacesTestUtils.addVisits("http://example.com/"); registerCleanupFunction(async function() { await PlacesUtils.history.clear(); }); diff --git a/browser/components/urlbar/tests/browser/browser_searchMode_preview.js b/browser/components/urlbar/tests/browser/browser_searchMode_preview.js deleted file mode 100644 index 2f21b1170c8fb..0000000000000 --- a/browser/components/urlbar/tests/browser/browser_searchMode_preview.js +++ /dev/null @@ -1,143 +0,0 @@ -/* Any copyright is dedicated to the Public Domain. - http://creativecommons.org/publicdomain/zero/1.0/ */ - -/** - * Tests search mode preview. - */ - -"use strict"; - -const TEST_ENGINE_NAME = "Test"; - -add_task(async function setup() { - await SpecialPowers.pushPrefEnv({ - set: [["browser.urlbar.update2", true]], - }); - let testEngine = await Services.search.addEngineWithDetails( - TEST_ENGINE_NAME, - { - alias: "@test", - template: "http://example.com/?search={searchTerms}", - } - ); - - registerCleanupFunction(async () => { - await Services.search.removeEngine(testEngine); - }); -}); - -// Tests that cycling through token alias engines enters search mode preview. -add_task(async function tokenAlias() { - await UrlbarTestUtils.promiseAutocompleteResultPopup({ - window, - value: "@", - }); - - let result; - while (gURLBar.searchMode?.engineName != TEST_ENGINE_NAME) { - EventUtils.synthesizeKey("KEY_ArrowDown", {}, window); - let index = UrlbarTestUtils.getSelectedRowIndex(window); - result = await UrlbarTestUtils.getDetailsOfResultAt(window, index); - let expectedSearchMode = { - engineName: result.searchParams.engine, - isPreview: true, - entry: "keywordoffer", - }; - if (UrlbarUtils.WEB_ENGINE_NAMES.has(result.searchParams.engine)) { - expectedSearchMode.source = UrlbarUtils.RESULT_SOURCE.SEARCH; - } - await UrlbarTestUtils.assertSearchMode(window, expectedSearchMode); - } - let searchPromise = UrlbarTestUtils.promiseSearchComplete(window); - EventUtils.synthesizeKey("KEY_Enter"); - await searchPromise; - // Test that we are in non-preview search mode. - await UrlbarTestUtils.assertSearchMode(window, { - engineName: result.searchParams.engine, - entry: "keywordoffer", - }); - await UrlbarTestUtils.exitSearchMode(window); -}); - -// Tests that starting to type a query exits search mode preview in favour of -// full search mode. -add_task(async function startTyping() { - await UrlbarTestUtils.promiseAutocompleteResultPopup({ - window, - value: "@", - }); - while (gURLBar.searchMode?.engineName != TEST_ENGINE_NAME) { - EventUtils.synthesizeKey("KEY_ArrowDown", {}, window); - } - - await UrlbarTestUtils.assertSearchMode(window, { - engineName: TEST_ENGINE_NAME, - isPreview: true, - entry: "keywordoffer", - }); - - let searchPromise = UrlbarTestUtils.promiseSearchComplete(window); - EventUtils.synthesizeKey("M"); - await searchPromise; - await UrlbarTestUtils.assertSearchMode(window, { - engineName: TEST_ENGINE_NAME, - entry: "keywordoffer", - }); - await UrlbarTestUtils.exitSearchMode(window); -}); - -// Tests that highlighting a search shortcut Top Site enters search mode -// preview. -add_task(async function topSites() { - // Enable search shortcut Top Sites. - await updateTopSites( - sites => sites && sites[0] && sites[0].searchTopSite, - true - ); - await UrlbarTestUtils.promiseAutocompleteResultPopup({ - window, - value: "", - fireInputEvent: true, - }); - - // We previously verified that the first Top Site is a search shortcut. - EventUtils.synthesizeKey("KEY_ArrowDown", {}, window); - let searchTopSite = await UrlbarTestUtils.getDetailsOfResultAt(window, 0); - await UrlbarTestUtils.assertSearchMode(window, { - engineName: searchTopSite.searchParams.engine, - isPreview: true, - entry: "topsites_urlbar", - }); - await UrlbarTestUtils.exitSearchMode(window); -}); - -// Tests that search mode preview is exited when the view is closed. -add_task(async function closeView() { - await UrlbarTestUtils.promiseAutocompleteResultPopup({ - window, - value: "@", - }); - - while (gURLBar.searchMode?.engineName != TEST_ENGINE_NAME) { - EventUtils.synthesizeKey("KEY_ArrowDown", {}, window); - } - await UrlbarTestUtils.assertSearchMode(window, { - engineName: TEST_ENGINE_NAME, - isPreview: true, - entry: "keywordoffer", - }); - - // We should close search mode when closing the view. - await UrlbarTestUtils.promisePopupClose(window, () => gURLBar.blur()); - await UrlbarTestUtils.assertSearchMode(window, null); - - // Check search mode isn't re-entered when re-opening the view. - await UrlbarTestUtils.promisePopupOpen(window, () => { - if (gURLBar.getAttribute("pageproxystate") == "invalid") { - gURLBar.handleRevert(); - } - EventUtils.synthesizeMouseAtCenter(gURLBar.inputField, {}); - }); - await UrlbarTestUtils.assertSearchMode(window, null); - await UrlbarTestUtils.promisePopupClose(window); -}); diff --git a/browser/components/urlbar/tests/browser/browser_tokenAlias.js b/browser/components/urlbar/tests/browser/browser_tokenAlias.js index 8010bdc39f403..7c0f3cb3ba9a8 100644 --- a/browser/components/urlbar/tests/browser/browser_tokenAlias.js +++ b/browser/components/urlbar/tests/browser/browser_tokenAlias.js @@ -349,22 +349,12 @@ add_task(async function nonHeuristicAliases() { window, tokenEngines.length - 1 ); - // Key down to select each result in turn. The urlbar should preview search - // mode for each engine. + // Key down to select each result in turn. The urlbar value should be set to + // each alias, and each should be highlighted. for (let { tokenAliases } of tokenEngines) { let alias = tokenAliases[0]; - let engineName = (await UrlbarSearchUtils.engineForAlias(alias)).name; EventUtils.synthesizeKey("KEY_ArrowDown"); - let expectedSearchMode = { - engineName, - entry: "keywordoffer", - isPreview: true, - }; - if (UrlbarUtils.WEB_ENGINE_NAMES.has(engineName)) { - expectedSearchMode.source = UrlbarUtils.RESULT_SOURCE.SEARCH; - } - await UrlbarTestUtils.assertSearchMode(window, expectedSearchMode); - Assert.ok(!gURLBar.value, "The Urlbar should be empty."); + assertHighlighted(true, alias); } await UrlbarTestUtils.promisePopupClose(window, () => diff --git a/browser/components/urlbar/tests/browser/browser_urlbar_event_telemetry.js b/browser/components/urlbar/tests/browser/browser_urlbar_event_telemetry.js index 419cbec20f1d0..9e8ae742c9da9 100644 --- a/browser/components/urlbar/tests/browser/browser_urlbar_event_telemetry.js +++ b/browser/components/urlbar/tests/browser/browser_urlbar_event_telemetry.js @@ -600,7 +600,7 @@ const tests = [ fireInputEvent: true, }); - while (win.gURLBar.searchMode?.engineName != "Test") { + while (win.gURLBar.untrimmedValue != "@test") { EventUtils.synthesizeKey("KEY_ArrowDown", {}, win); } EventUtils.synthesizeKey("VK_RETURN", {}, win); @@ -1241,7 +1241,7 @@ const tests = [ await UrlbarTestUtils.promisePopupOpen(win, () => { EventUtils.synthesizeKey("KEY_ArrowDown", {}, win); }); - while (win.gURLBar.searchMode?.engineName != "Google") { + while (win.gURLBar.untrimmedValue != "@google") { EventUtils.synthesizeKey("KEY_ArrowDown", {}, win); } let element = UrlbarTestUtils.getSelectedRow(win); diff --git a/browser/modules/BrowserUsageTelemetry.jsm b/browser/modules/BrowserUsageTelemetry.jsm index 5ea77ae08656e..9a62392c31569 100644 --- a/browser/modules/BrowserUsageTelemetry.jsm +++ b/browser/modules/BrowserUsageTelemetry.jsm @@ -644,11 +644,6 @@ let BrowserUsageTelemetry = { * details. */ recordSearchMode(searchMode) { - // Search mode preview is not search mode. Recording it would just create - // noise. - if (searchMode.isPreview) { - return; - } let scalarKey; if (searchMode.engineName) { let engine = Services.search.getEngineByName(searchMode.engineName);