tor-browser

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

commit 5ee186d60228c2d8747b00454cce6e402ed7ecb6
parent 126b864d44986f1aaf357daa800d1389e616b70b
Author: James Teow <jteow@mozilla.com>
Date:   Mon,  1 Dec 2025 19:23:46 +0000

Bug 1987895 - Change SearchSuggestionController to allow passing maxLocalResults/maxRemoteResults to fetch and make formHistoryParam a constant - r=Standard8,urlbar-reviewers

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

Diffstat:
Mbrowser/actors/ContentSearchParent.sys.mjs | 13++++++++-----
Mbrowser/components/urlbar/UrlbarProviderRecentSearches.sys.mjs | 8+++++---
Mbrowser/components/urlbar/UrlbarProviderSearchSuggestions.sys.mjs | 26+++++++++++---------------
Mbrowser/components/urlbar/UrlbarUtils.sys.mjs | 13+++----------
Mbrowser/components/urlbar/content/UrlbarInput.mjs | 4----
Mbrowser/components/urlbar/tests/UrlbarTestUtils.sys.mjs | 52+++++++++++++++++++---------------------------------
Mbrowser/components/urlbar/tests/unit/test_providerRecentSearches.js | 1-
Mtoolkit/components/search/SearchSuggestionController.sys.mjs | 61+++++++++++++++++++------------------------------------------
Mtoolkit/components/search/SearchSuggestions.sys.mjs | 6++++--
Mtoolkit/components/search/tests/xpcshell/test_searchSuggest.js | 47+++++++++++++++++++++++------------------------
Mtoolkit/components/search/tests/xpcshell/test_searchSuggest_private.js | 8++++----
11 files changed, 96 insertions(+), 143 deletions(-)

diff --git a/browser/actors/ContentSearchParent.sys.mjs b/browser/actors/ContentSearchParent.sys.mjs @@ -8,6 +8,8 @@ ChromeUtils.defineESModuleGetters(lazy, { BrowserSearchTelemetry: "moz-src:///browser/components/search/BrowserSearchTelemetry.sys.mjs", BrowserUtils: "resource://gre/modules/BrowserUtils.sys.mjs", + DEFAULT_FORM_HISTORY_PARAM: + "moz-src:///toolkit/components/search/SearchSuggestionController.sys.mjs", FormHistory: "resource://gre/modules/FormHistory.sys.mjs", PrivateBrowsingUtils: "resource://gre/modules/PrivateBrowsingUtils.sys.mjs", SearchSuggestionController: @@ -191,7 +193,7 @@ export let ContentSearch = { ); lazy.FormHistory.update({ op: "remove", - fieldname: browserData.controller.formHistoryParam, + fieldname: lazy.DEFAULT_FORM_HISTORY_PARAM, value: entry, guid: result.guid, }).catch(err => @@ -262,8 +264,8 @@ export let ContentSearch = { let browserData = this._suggestionDataForBrowser(browser, true); let { controller } = browserData; let ok = lazy.SearchSuggestionController.engineOffersSuggestions(engine); - controller.maxLocalResults = ok ? MAX_LOCAL_SUGGESTIONS : MAX_SUGGESTIONS; - controller.maxRemoteResults = ok ? MAX_SUGGESTIONS : 0; + let maxLocalResults = ok ? MAX_LOCAL_SUGGESTIONS : MAX_SUGGESTIONS; + let maxRemoteResults = ok ? MAX_SUGGESTIONS : 0; // fetch() rejects its promise if there's a pending request, but since we // process our event queue serially, there's never a pending request. this._currentSuggestion = { controller, browser }; @@ -271,6 +273,8 @@ export let ContentSearch = { searchString, inPrivateBrowsing: lazy.PrivateBrowsingUtils.isBrowserPrivate(browser), engine, + maxLocalResults, + maxRemoteResults, }); // Simplify results since we do not support rich results in this component. @@ -322,10 +326,9 @@ export let ContentSearch = { ) { return false; } - let browserData = this._suggestionDataForBrowser(browser, true); lazy.FormHistory.update({ op: "bump", - fieldname: browserData.controller.formHistoryParam, + fieldname: lazy.DEFAULT_FORM_HISTORY_PARAM, value: entry.value, source: entry.engineName, }).catch(err => console.error("Error adding form history entry: ", err)); diff --git a/browser/components/urlbar/UrlbarProviderRecentSearches.sys.mjs b/browser/components/urlbar/UrlbarProviderRecentSearches.sys.mjs @@ -13,6 +13,8 @@ import { const lazy = {}; ChromeUtils.defineESModuleGetters(lazy, { + DEFAULT_FORM_HISTORY_PARAM: + "moz-src:///toolkit/components/search/SearchSuggestionController.sys.mjs", FormHistory: "resource://gre/modules/FormHistory.sys.mjs", SearchUtils: "moz-src:///toolkit/components/search/SearchUtils.sys.mjs", UrlbarPrefs: "moz-src:///browser/components/urlbar/UrlbarPrefs.sys.mjs", @@ -69,10 +71,10 @@ export class UrlbarProviderRecentSearches extends UrlbarProvider { queryContext.isPrivate ); - if (details.selType == "dismiss" && queryContext.formHistoryName) { + if (details.selType == "dismiss") { lazy.FormHistory.update({ op: "remove", - fieldname: "searchbar-history", + fieldname: lazy.DEFAULT_FORM_HISTORY_PARAM, value: result.payload.suggestion, source: engine.name, }).catch(error => @@ -97,7 +99,7 @@ export class UrlbarProviderRecentSearches extends UrlbarProvider { return; } let results = await lazy.FormHistory.search(["value", "lastUsed"], { - fieldname: "searchbar-history", + fieldname: lazy.DEFAULT_FORM_HISTORY_PARAM, source: engine.name, }); diff --git a/browser/components/urlbar/UrlbarProviderSearchSuggestions.sys.mjs b/browser/components/urlbar/UrlbarProviderSearchSuggestions.sys.mjs @@ -15,6 +15,8 @@ import { const lazy = {}; ChromeUtils.defineESModuleGetters(lazy, { + DEFAULT_FORM_HISTORY_PARAM: + "moz-src:///toolkit/components/search/SearchSuggestionController.sys.mjs", FormHistory: "resource://gre/modules/FormHistory.sys.mjs", SearchSuggestionController: "moz-src:///toolkit/components/search/SearchSuggestionController.sys.mjs", @@ -348,10 +350,11 @@ export class UrlbarProviderSearchSuggestions extends UrlbarProvider { onEngagement(queryContext, controller, details) { let { result } = details; - if (details.selType == "dismiss" && queryContext.formHistoryName) { + + if (details.selType == "dismiss") { lazy.FormHistory.update({ op: "remove", - fieldname: queryContext.formHistoryName, + fieldname: lazy.DEFAULT_FORM_HISTORY_PARAM, value: result.payload.suggestion, }).catch(error => console.error(`Removing form history failed: ${error}`) @@ -386,13 +389,6 @@ export class UrlbarProviderSearchSuggestions extends UrlbarProvider { this.#suggestionsController = new lazy.SearchSuggestionController(); } - // TODO (Bug 1987895): Change Search Suggestions Controller to allow passing - // formHistoryParam and other fields as options on the fetch() call. - if (queryContext.formHistoryName) { - this.#suggestionsController.formHistoryParam = - queryContext.formHistoryName; - } - // If there's a form history entry that equals the search string, the search // suggestions controller will include it, and we'll make a result for it. // If the heuristic result ends up being a search result, the muxer will @@ -400,28 +396,26 @@ export class UrlbarProviderSearchSuggestions extends UrlbarProvider { // final list of results would be left with `count` - 1 form history results // instead of `count`. Therefore we request `count` + 1 entries. The muxer // will dedupe and limit the final form history count as appropriate. - this.#suggestionsController.maxLocalResults = queryContext.maxResults + 1; + let maxLocalResults = queryContext.maxResults + 1; // Request maxResults + 1 remote suggestions for the same reason we request // maxResults + 1 form history entries. let allowRemote = this._allowRemoteSuggestions(queryContext, searchString); - this.#suggestionsController.maxRemoteResults = allowRemote - ? queryContext.maxResults + 1 - : 0; + let maxRemoteResults = allowRemote ? queryContext.maxResults + 1 : 0; if (allowRemote && this.#shouldFetchTrending(queryContext)) { if ( queryContext.searchMode && lazy.UrlbarPrefs.get("trending.maxResultsSearchMode") != -1 ) { - this.#suggestionsController.maxRemoteResults = lazy.UrlbarPrefs.get( + maxRemoteResults = lazy.UrlbarPrefs.get( "trending.maxResultsSearchMode" ); } else if ( !queryContext.searchMode && lazy.UrlbarPrefs.get("trending.maxResultsNoSearchMode") != -1 ) { - this.#suggestionsController.maxRemoteResults = lazy.UrlbarPrefs.get( + maxRemoteResults = lazy.UrlbarPrefs.get( "trending.maxResultsNoSearchMode" ); } @@ -437,6 +431,8 @@ export class UrlbarProviderSearchSuggestions extends UrlbarProvider { restrictToEngine: this._isTokenOrRestrictionPresent(queryContext), dedupeRemoteAndLocal: false, fetchTrending: this.#shouldFetchTrending(queryContext), + maxLocalResults, + maxRemoteResults, }); // The fetch was canceled. diff --git a/browser/components/urlbar/UrlbarUtils.sys.mjs b/browser/components/urlbar/UrlbarUtils.sys.mjs @@ -19,6 +19,8 @@ const lazy = {}; ChromeUtils.defineESModuleGetters(lazy, { ContextualIdentityService: "resource://gre/modules/ContextualIdentityService.sys.mjs", + DEFAULT_FORM_HISTORY_PARAM: + "moz-src:///toolkit/components/search/SearchSuggestionController.sys.mjs", FormHistory: "resource://gre/modules/FormHistory.sys.mjs", KeywordUtils: "resource://gre/modules/KeywordUtils.sys.mjs", PlacesUIUtils: "moz-src:///browser/components/places/PlacesUIUtils.sys.mjs", @@ -1159,7 +1161,7 @@ export var UrlbarUtils = { } return lazy.FormHistory.update({ op: "bump", - fieldname: input.formHistoryName, + fieldname: lazy.DEFAULT_FORM_HISTORY_PARAM, value, source, }); @@ -2343,8 +2345,6 @@ export class UrlbarQueryContext { * If it's false, then `allowRemoteResults` will do its usual checks to * determine whether remote results are allowed. If it's true, then * `allowRemoteResults` will immediately return false. Defaults to false. - * @param {string} [options.formHistoryName] - * The name under which the local form history is registered. */ constructor(options) { // Clone to make sure all properties belong to the system realm. @@ -2373,7 +2373,6 @@ export class UrlbarQueryContext { */ const optionalProperties = [ ["currentPage", v => typeof v == "string" && !!v.length], - ["formHistoryName", v => typeof v == "string" && !!v.length], ["prohibitRemoteResults", () => true, false], ["providers", v => Array.isArray(v) && !!v.length], ["searchMode", v => v && typeof v == "object"], @@ -2443,12 +2442,6 @@ export class UrlbarQueryContext { firstResultChanged = false; /** - * @type {string} - * The form history name to use when saving search history. - */ - formHistoryName; - - /** * @type {UrlbarResult} * The heuristic result associated with the context. */ diff --git a/browser/components/urlbar/content/UrlbarInput.mjs b/browser/components/urlbar/content/UrlbarInput.mjs @@ -70,8 +70,6 @@ const lazy = XPCOMUtils.declareLazy({ logger: () => lazy.UrlbarUtils.getLogger({ prefix: "Input" }), }); -const DEFAULT_FORM_HISTORY_NAME = "searchbar-history"; - const UNLIMITED_MAX_RESULTS = 99; let getBoundsWithoutFlushing = element => @@ -218,7 +216,6 @@ export class UrlbarInput extends HTMLElement { #compositionClosedPopup = false; valueIsTyped = false; - formHistoryName = DEFAULT_FORM_HISTORY_NAME; // Properties accessed in tests. lastQueryContextPromise = Promise.resolve(); @@ -5182,7 +5179,6 @@ export class UrlbarInput extends HTMLElement { ), tabGroup: this.window.gBrowser.selectedTab.group?.id ?? null, currentPage: this.window.gBrowser.currentURI.spec, - formHistoryName: this.formHistoryName, prohibitRemoteResults: event && lazy.UrlbarUtils.isPasteEvent(event) && diff --git a/browser/components/urlbar/tests/UrlbarTestUtils.sys.mjs b/browser/components/urlbar/tests/UrlbarTestUtils.sys.mjs @@ -13,7 +13,8 @@ const lazy = {}; ChromeUtils.defineESModuleGetters(lazy, { BrowserTestUtils: "resource://testing-common/BrowserTestUtils.sys.mjs", BrowserUIUtils: "resource:///modules/BrowserUIUtils.sys.mjs", - BrowserWindowTracker: "resource:///modules/BrowserWindowTracker.sys.mjs", + DEFAULT_FORM_HISTORY_PARAM: + "moz-src:///toolkit/components/search/SearchSuggestionController.sys.mjs", ExperimentAPI: "resource://nimbus/ExperimentAPI.sys.mjs", FormHistoryTestUtils: "resource://testing-common/FormHistoryTestUtils.sys.mjs", @@ -1484,13 +1485,13 @@ UrlbarTestUtils.formHistory = { * * @param {Array} values * The form history entries to remove. - * @param {object} window - * The window containing the urlbar. * @returns {Promise} resolved once the operation is complete. */ - add(values = [], window = lazy.BrowserWindowTracker.getTopWindow()) { - let fieldname = this.getFormHistoryName(window); - return lazy.FormHistoryTestUtils.add(fieldname, values); + add(values = []) { + return lazy.FormHistoryTestUtils.add( + lazy.DEFAULT_FORM_HISTORY_PARAM, + values + ); }, /** @@ -1499,26 +1500,23 @@ UrlbarTestUtils.formHistory = { * * @param {Array} values * The form history entries to remove. - * @param {object} window - * The window containing the urlbar. * @returns {Promise} resolved once the operation is complete. */ - remove(values = [], window = lazy.BrowserWindowTracker.getTopWindow()) { - let fieldname = this.getFormHistoryName(window); - return lazy.FormHistoryTestUtils.remove(fieldname, values); + remove(values = []) { + return lazy.FormHistoryTestUtils.remove( + lazy.DEFAULT_FORM_HISTORY_PARAM, + values + ); }, /** * Removes all values from the urlbar's form history. If you want to remove * individual values, use removeFormHistory. * - * @param {object} window - * The window containing the urlbar. * @returns {Promise} resolved once the operation is complete. */ - clear(window = lazy.BrowserWindowTracker.getTopWindow()) { - let fieldname = this.getFormHistoryName(window); - return lazy.FormHistoryTestUtils.clear(fieldname); + clear() { + return lazy.FormHistoryTestUtils.clear(lazy.DEFAULT_FORM_HISTORY_PARAM); }, /** @@ -1526,14 +1524,14 @@ UrlbarTestUtils.formHistory = { * * @param {object} criteria * Criteria to narrow the search. See FormHistory.search. - * @param {object} window - * The window containing the urlbar. * @returns {Promise} * A promise resolved with an array of found form history entries. */ - search(criteria = {}, window = lazy.BrowserWindowTracker.getTopWindow()) { - let fieldname = this.getFormHistoryName(window); - return lazy.FormHistoryTestUtils.search(fieldname, criteria); + search(criteria = {}) { + return lazy.FormHistoryTestUtils.search( + lazy.DEFAULT_FORM_HISTORY_PARAM, + criteria + ); }, /** @@ -1550,18 +1548,6 @@ UrlbarTestUtils.formHistory = { (subject, data) => !change || data == "formhistory-" + change ); }, - - /** - * Returns the form history name for the urlbar in a window. - * - * @param {object} window - * The window. - * @returns {string} - * The form history name of the urlbar in the window. - */ - getFormHistoryName(window = lazy.BrowserWindowTracker.getTopWindow()) { - return window ? window.gURLBar.formHistoryName : "searchbar-history"; - }, }; /** diff --git a/browser/components/urlbar/tests/unit/test_providerRecentSearches.js b/browser/components/urlbar/tests/unit/test_providerRecentSearches.js @@ -118,7 +118,6 @@ add_task(async function test_per_engine() { let context = createContext("", { isPrivate: false, - formHistoryName: "test", }); await check_results({ context, diff --git a/toolkit/components/search/SearchSuggestionController.sys.mjs b/toolkit/components/search/SearchSuggestionController.sys.mjs @@ -4,7 +4,7 @@ import { XPCOMUtils } from "resource://gre/modules/XPCOMUtils.sys.mjs"; -const DEFAULT_FORM_HISTORY_PARAM = "searchbar-history"; +export const DEFAULT_FORM_HISTORY_PARAM = "searchbar-history"; const HTTP_OK = 200; const REMOTE_TIMEOUT_DEFAULT = 500; @@ -53,6 +53,13 @@ const lazy = XPCOMUtils.declareLazy({ * Whether the request is being made in the context of private browsing. * @property {nsISearchEngine} engine * The search engine to use for suggestions. + * @property {number} [maxLocalResults] + * The maximum number of local form history results to return. This limit is + * only enforced if remote results are also returned. + * @property {number} [maxRemoteResults] + * The maximum number of remote search engine results to return. + * We'll actually only display at most ``maxRemoteResults - + * <displayed local results count>`` remote results. * @property {number} [userContextId] * The userContextId of the selected tab. * @property {boolean} [restrictToEngine] @@ -201,16 +208,6 @@ class SearchSuggestionEntry { */ export class SearchSuggestionController { /** - * Constructor - * - * @param {string} [formHistoryParam] - * The form history type to use with this controller. - */ - constructor(formHistoryParam = DEFAULT_FORM_HISTORY_PARAM) { - this.formHistoryParam = formHistoryParam; - } - - /** * The maximum length of a value to be stored in search history. * * @type {number} @@ -240,30 +237,6 @@ export class SearchSuggestionController { } /** - * The maximum number of local form history results to return. This limit is - * only enforced if remote results are also returned. - * - * @type {number} - */ - maxLocalResults = 5; - - /** - * The maximum number of remote search engine results to return. - * We'll actually only display at most - * maxRemoteResults - <displayed local results count> remote results. - * - * @type {number} - */ - maxRemoteResults = 10; - - /** - * The additional parameter used when searching form history. - * - * @type {string} - */ - formHistoryParam = DEFAULT_FORM_HISTORY_PARAM; - - /** * The last form history result used to improve the performance of * subsequent searches. This shouldn't be used for any other purpose as it * is never cleared and therefore could be stale. @@ -295,6 +268,8 @@ export class SearchSuggestionController { searchString, inPrivateBrowsing, engine, + maxLocalResults = 5, + maxRemoteResults = 10, userContextId = 0, restrictToEngine = false, dedupeRemoteAndLocal = true, @@ -322,10 +297,10 @@ export class SearchSuggestionController { if (!engine.getSubmission) { throw new Error("Invalid search engine"); } - if (!this.maxLocalResults && !this.maxRemoteResults) { + if (!maxLocalResults && !maxRemoteResults) { throw new Error("Zero results expected, what are you trying to do?"); } - if (this.maxLocalResults < 0 || this.maxRemoteResults < 0) { + if (maxLocalResults < 0 || maxRemoteResults < 0) { throw new Error("Number of requested results must be positive"); } @@ -335,6 +310,8 @@ export class SearchSuggestionController { awaitingLocalResults: false, dedupeRemoteAndLocal, engine, + maxLocalResults, + maxRemoteResults, fetchTrending, inPrivateBrowsing, restrictToEngine, @@ -345,7 +322,7 @@ export class SearchSuggestionController { }; // Fetch local results from Form History, if requested. - if (this.maxLocalResults && !fetchTrending) { + if (maxLocalResults && !fetchTrending) { this.#context.awaitingLocalResults = true; promises.push(this.#fetchFormHistory(this.#context)); } @@ -354,7 +331,7 @@ export class SearchSuggestionController { (searchString || fetchTrending) && lazy.suggestionsEnabled && (!inPrivateBrowsing || lazy.suggestionsInPrivateBrowsingEnabled) && - this.maxRemoteResults && + maxRemoteResults && SearchSuggestionController.engineOffersSuggestions(engine, fetchTrending) ) { promises.push(this.#fetchRemote(this.#context)); @@ -416,7 +393,7 @@ export class SearchSuggestionController { // We don't cache these results as we assume that the in-memory SQL cache is // good enough in performance. let params = { - fieldname: this.formHistoryParam, + fieldname: DEFAULT_FORM_HISTORY_PARAM, }; if (context.restrictToEngine) { @@ -681,7 +658,7 @@ export class SearchSuggestionController { // If we have remote results, cap the number of local results if (results.remote.length) { - results.local = results.local.slice(0, this.maxLocalResults); + results.local = results.local.slice(0, context.maxLocalResults); } // We don't want things to appear in both history and suggestions so remove @@ -702,7 +679,7 @@ export class SearchSuggestionController { } // Trim the number of results to the maximum requested (now that we've pruned dupes). - let maxRemoteCount = this.maxRemoteResults; + let maxRemoteCount = context.maxRemoteResults; if (context.dedupeRemoteAndLocal) { maxRemoteCount -= results.local.length; } diff --git a/toolkit/components/search/SearchSuggestions.sys.mjs b/toolkit/components/search/SearchSuggestions.sys.mjs @@ -5,6 +5,8 @@ import { XPCOMUtils } from "resource://gre/modules/XPCOMUtils.sys.mjs"; const lazy = XPCOMUtils.declareLazy({ + DEFAULT_FORM_HISTORY_PARAM: + "moz-src:///toolkit/components/search/SearchSuggestionController.sys.mjs", FormHistory: "resource://gre/modules/FormHistory.sys.mjs", SearchSuggestionController: "moz-src:///toolkit/components/search/SearchSuggestionController.sys.mjs", @@ -296,7 +298,6 @@ class SearchHistoryResult { class SuggestAutoComplete { constructor() { this.#suggestionController = new lazy.SearchSuggestionController(); - this.#suggestionController.maxLocalResults = this.#historyLimit; } /** @@ -423,6 +424,7 @@ class SuggestAutoComplete { searchString, inPrivateBrowsing, engine: Services.search.defaultEngine, + maxLocalResults: this.#historyLimit, }); let formHistoryEntries = (results?.formHistoryResults ?? []).map( @@ -435,7 +437,7 @@ class SuggestAutoComplete { }) ); let autoCompleteResult = new SearchHistoryResult( - this.#suggestionController.formHistoryParam, + lazy.DEFAULT_FORM_HISTORY_PARAM, searchString, formHistoryEntries ); diff --git a/toolkit/components/search/tests/xpcshell/test_searchSuggest.js b/toolkit/components/search/tests/xpcshell/test_searchSuggest.js @@ -463,16 +463,16 @@ add_task(async function both_identical_with_more_than_max_results() { } let controller = new SearchSuggestionController(); - controller.maxLocalResults = 7; - controller.maxRemoteResults = 10; let result = await controller.fetch({ searchString: "letter ", inPrivateBrowsing: false, engine: getEngine, + maxLocalResults: 7, + maxRemoteResults: 10, }); Assert.equal(result.term, "letter "); Assert.equal(result.local.length, 7); - for (let i = 0; i < controller.maxLocalResults; i++) { + for (let i = 0; i < 7; i++) { Assert.equal( result.local[i].value, "letter " + String.fromCharCode("A".charCodeAt() + i) @@ -482,8 +482,7 @@ add_task(async function both_identical_with_more_than_max_results() { for (let i = 0; i < result.remote.length; i++) { Assert.equal( result.remote[i].value, - "letter " + - String.fromCharCode("A".charCodeAt() + controller.maxLocalResults + i) + "letter " + String.fromCharCode("A".charCodeAt() + 7 + i) ); } }); @@ -494,12 +493,12 @@ add_task(async function noremote_maxLocal() { Services.fog.testResetFOG(); let controller = new SearchSuggestionController(); - controller.maxLocalResults = 2; // (should be ignored because no remote results) - controller.maxRemoteResults = 0; let result = await controller.fetch({ searchString: "letter ", inPrivateBrowsing: false, engine: getEngine, + maxLocalResults: 2, // (should be ignored because no remote results) + maxRemoteResults: 0, }); Assert.equal(result.term, "letter "); Assert.equal(result.local.length, 26); @@ -516,12 +515,12 @@ add_task(async function noremote_maxLocal() { add_task(async function someremote_maxLocal() { let controller = new SearchSuggestionController(); - controller.maxLocalResults = 2; - controller.maxRemoteResults = 4; let result = await controller.fetch({ searchString: "letter ", inPrivateBrowsing: false, engine: getEngine, + maxLocalResults: 2, + maxRemoteResults: 4, }); Assert.equal(result.term, "letter "); Assert.equal(result.local.length, 2); @@ -545,12 +544,12 @@ add_task(async function someremote_maxLocal() { add_task(async function one_of_each() { let controller = new SearchSuggestionController(); - controller.maxLocalResults = 1; - controller.maxRemoteResults = 2; let result = await controller.fetch({ searchString: "letter ", inPrivateBrowsing: false, engine: getEngine, + maxLocalResults: 1, + maxRemoteResults: 2, }); Assert.equal(result.term, "letter "); Assert.equal(result.local.length, 1); @@ -566,12 +565,12 @@ add_task(async function local_result_returned_remote_result_disabled() { Services.prefs.setBoolPref("browser.search.suggest.enabled", false); let controller = new SearchSuggestionController(); - controller.maxLocalResults = 1; - controller.maxRemoteResults = 1; let result = await controller.fetch({ searchString: "letter ", inPrivateBrowsing: false, engine: getEngine, + maxLocalResults: 1, + maxRemoteResults: 1, }); Assert.equal(result.term, "letter "); Assert.equal(result.local.length, 26); @@ -589,13 +588,13 @@ add_task(async function local_result_returned_remote_result_disabled() { add_task( async function local_result_returned_remote_result_disabled_after_creation_of_controller() { let controller = new SearchSuggestionController(); - controller.maxLocalResults = 1; - controller.maxRemoteResults = 1; Services.prefs.setBoolPref("browser.search.suggest.enabled", false); let result = await controller.fetch({ searchString: "letter ", inPrivateBrowsing: false, engine: getEngine, + maxLocalResults: 1, + maxRemoteResults: 1, }); Assert.equal(result.term, "letter "); Assert.equal(result.local.length, 26); @@ -615,13 +614,13 @@ add_task( async function one_of_each_disabled_before_creation_enabled_after_creation_of_controller() { Services.prefs.setBoolPref("browser.search.suggest.enabled", false); let controller = new SearchSuggestionController(); - controller.maxLocalResults = 1; - controller.maxRemoteResults = 2; Services.prefs.setBoolPref("browser.search.suggest.enabled", true); let result = await controller.fetch({ searchString: "letter ", inPrivateBrowsing: false, engine: getEngine, + maxLocalResults: 1, + maxRemoteResults: 2, }); Assert.equal(result.term, "letter "); Assert.equal(result.local.length, 1); @@ -637,12 +636,12 @@ add_task( add_task(async function one_local_zero_remote() { let controller = new SearchSuggestionController(); - controller.maxLocalResults = 1; - controller.maxRemoteResults = 0; let result = await controller.fetch({ searchString: "letter ", inPrivateBrowsing: false, engine: getEngine, + maxLocalResults: 1, + maxRemoteResults: 0, }); Assert.equal(result.term, "letter "); Assert.equal(result.local.length, 26); @@ -658,12 +657,12 @@ add_task(async function one_local_zero_remote() { add_task(async function zero_local_one_remote() { let controller = new SearchSuggestionController(); - controller.maxLocalResults = 0; - controller.maxRemoteResults = 1; let result = await controller.fetch({ searchString: "letter ", inPrivateBrowsing: false, engine: getEngine, + maxLocalResults: 0, + maxRemoteResults: 1, }); Assert.equal(result.term, "letter "); Assert.equal(result.local.length, 0); @@ -935,12 +934,12 @@ add_task(async function invalid_engine() { add_task(async function no_results_requested() { Assert.throws(() => { let controller = new SearchSuggestionController(); - controller.maxLocalResults = 0; - controller.maxRemoteResults = 0; controller.fetch({ searchString: "No results requested", inPrivateBrowsing: false, engine: getEngine, + maxLocalResults: 0, + maxRemoteResults: 0, }); }, /result/i); }); @@ -948,11 +947,11 @@ add_task(async function no_results_requested() { add_task(async function minus_one_results_requested() { Assert.throws(() => { let controller = new SearchSuggestionController(); - controller.maxLocalResults = -1; controller.fetch({ searchString: "-1 results requested", inPrivateBrowsing: false, engine: getEngine, + maxLocalResults: -1, }); }, /result/i); }); diff --git a/toolkit/components/search/tests/xpcshell/test_searchSuggest_private.js b/toolkit/components/search/tests/xpcshell/test_searchSuggest_private.js @@ -35,12 +35,12 @@ add_task(async function test_suggestions_in_private_mode_enabled() { Services.prefs.setBoolPref("browser.search.suggest.enabled.private", true); let controller = new SearchSuggestionController(); - controller.maxLocalResults = 0; - controller.maxRemoteResults = 1; let result = await controller.fetch({ searchString: "mo", inPrivateBrowsing: true, engine, + maxLocalResults: 0, + maxRemoteResults: 1, }); Assert.equal(result.remote.length, 1); }); @@ -49,12 +49,12 @@ add_task(async function test_suggestions_in_private_mode_disabled() { Services.prefs.setBoolPref("browser.search.suggest.enabled.private", false); let controller = new SearchSuggestionController(); - controller.maxLocalResults = 0; - controller.maxRemoteResults = 1; let result = await controller.fetch({ searchString: "mo", inPrivateBrowsing: true, engine, + maxLocalResults: 0, + maxRemoteResults: 1, }); Assert.equal(result.remote.length, 0); });