tor-browser

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

commit 16544332ee2e398b7dfe71b31a5e90a1a7f41d55
parent f9d0500cc5e429f99f2126d2d0b9ac628585a4a6
Author: Jens Stutte <jstutte@mozilla.com>
Date:   Wed,  8 Oct 2025 13:08:05 +0000

Bug 1992777 - SearchService.forceInitializationStatusForTests must remove the pre-init observer when needed. r=search-reviewers,Standard8

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

Diffstat:
Mtoolkit/components/search/SearchService.sys.mjs | 17+++++++++++++++--
1 file changed, 15 insertions(+), 2 deletions(-)

diff --git a/toolkit/components/search/SearchService.sys.mjs b/toolkit/components/search/SearchService.sys.mjs @@ -513,8 +513,9 @@ export class SearchService { */ reset() { lazy.logConsole.debug("Resetting search service."); - if (this.#initializationStatus != "not initialized") { + if (this.#earlyObserversAdded) { Services.obs.removeObserver(this, lazy.Region.REGION_TOPIC); + this.#earlyObserversAdded = false; } this.#initializationStatus = "not initialized"; this.#initDeferredPromise = Promise.withResolvers(); @@ -1237,6 +1238,13 @@ export class SearchService { #parseSubmissionMap = null; /** + * Keep track of pre-init observers have been added. + * + * @type {boolean} + */ + #earlyObserversAdded = false; + + /** * Keep track of observers have been added. * * @type {boolean} @@ -1454,7 +1462,10 @@ export class SearchService { #doPreInitWork() { // We need to catch the region being updated during initialization so we // start listening straight away. - Services.obs.addObserver(this, lazy.Region.REGION_TOPIC); + if (!this.#earlyObserversAdded) { + Services.obs.addObserver(this, lazy.Region.REGION_TOPIC); + this.#earlyObserversAdded = true; + } this.#getIgnoreListAndSubscribe().catch(ex => console.error(ex, "Search Service could not get the ignore list.") @@ -3678,6 +3689,8 @@ export class SearchService { Services.obs.removeObserver(this, lazy.SearchUtils.TOPIC_ENGINE_MODIFIED); Services.obs.removeObserver(this, QUIT_APPLICATION_TOPIC); Services.obs.removeObserver(this, TOPIC_LOCALES_CHANGE); + this.#observersAdded = false; + this.#earlyObserversAdded = false; } QueryInterface = ChromeUtils.generateQI([