diff --git a/toolkit/components/search/SearchService.jsm b/toolkit/components/search/SearchService.jsm index e5e609fd6905..3e92ab9486ca 100644 --- a/toolkit/components/search/SearchService.jsm +++ b/toolkit/components/search/SearchService.jsm @@ -1041,23 +1041,26 @@ SearchService.prototype = { }, async _fetchEngineSelectorEngines() { - let locale = Services.locale.appLocaleAsBCP47; - let region = Region.home || "default"; + let searchEngineSelectorProperties = { + locale: Services.locale.appLocaleAsBCP47, + region: Region.home || "default", + channel: AppConstants.MOZ_APP_VERSION_DISPLAY.endsWith("esr") + ? "esr" + : AppConstants.MOZ_UPDATE_CHANNEL, + experiment: NimbusFeatures.search.getVariable("experiment") ?? "", + distroID: SearchUtils.distroID ?? "", + }; - let channel = AppConstants.MOZ_APP_VERSION_DISPLAY.endsWith("esr") - ? "esr" - : AppConstants.MOZ_UPDATE_CHANNEL; + for (let [key, value] of Object.entries(searchEngineSelectorProperties)) { + this._settings.setAttribute(key, value); + } let { engines, privateDefault, - } = await this._engineSelector.fetchEngineConfiguration({ - locale, - region, - channel, - experiment: NimbusFeatures.search.getVariable("experiment"), - distroID: SearchUtils.distroID, - }); + } = await this._engineSelector.fetchEngineConfiguration( + searchEngineSelectorProperties + ); for (let e of engines) { if (!e.webExtension) { diff --git a/toolkit/components/search/tests/xpcshell/test_settings.js b/toolkit/components/search/tests/xpcshell/test_settings.js index c1840a3cfa24..32e0d521c771 100644 --- a/toolkit/components/search/tests/xpcshell/test_settings.js +++ b/toolkit/components/search/tests/xpcshell/test_settings.js @@ -122,6 +122,39 @@ add_task(async function test_current_setting_engine_properties() { await checkLoadSettingProperties("data/search.json", true, false); }); +add_task(async function test_settings_metadata_properties() { + info("init search service"); + await loadSettingsFile("data/search.json"); + + const settingsFileWritten = promiseAfterSettings(); + let ss = new SearchService(); + let result = await ss.init(); + + info("init'd search service"); + Assert.ok(Components.isSuccessCode(result)); + + await settingsFileWritten; + + let metaDataProperties = [ + "locale", + "region", + "channel", + "experiment", + "distroID", + ]; + + for (let name of metaDataProperties) { + Assert.notEqual( + ss._settings.getAttribute(`${name}`), + undefined, + `Search settings should have ${name} property defined.` + ); + } + + removeSettingsFile(); + ss._removeObservers(); +}); + /** * Test that the JSON settings written in the profile is correct. */