tor-browser

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

commit ba74a3b2c4b376b5852faf926b688de0a647ca23
parent 757bcfcd621253ae7767ec6eaf235cb38da7004d
Author: Mark Banner <standard8@mozilla.com>
Date:   Thu,  2 Oct 2025 09:43:17 +0000

Bug 1990778 - Combine the main configuration tests from test_google.js into test_searchconfig.js to save CPU time. r=florian,search-reviewers,scunnane

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

Diffstat:
Mtoolkit/components/search/tests/xpcshell/searchconfigs/head_searchconfig.js | 77+++++++++++++++++++++++++++++------------------------------------------------
Dtoolkit/components/search/tests/xpcshell/searchconfigs/test_google.js | 210-------------------------------------------------------------------------------
Mtoolkit/components/search/tests/xpcshell/searchconfigs/test_searchconfig.js | 68++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Atoolkit/components/search/tests/xpcshell/searchconfigs/test_searchconfig_google_additional.js | 167+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mtoolkit/components/search/tests/xpcshell/searchconfigs/xpcshell.toml | 10++++++++--
5 files changed, 272 insertions(+), 260 deletions(-)

diff --git a/toolkit/components/search/tests/xpcshell/searchconfigs/head_searchconfig.js b/toolkit/components/search/tests/xpcshell/searchconfigs/head_searchconfig.js @@ -127,6 +127,28 @@ async function maybeSetupConfig() { */ /** + * Processes the configuration to get the search engines for the specified + * region/locale. + * + * @param {SearchEngineSelector} engineSelector + * @param {string} region + * @param {string} locale + * @returns {Promise<{engines: AppProvidedConfigEngine[], appDefaultEngineId: string}>} + */ +async function getEngines(engineSelector, region, locale) { + let configs = await engineSelector.fetchEngineConfiguration({ + locale, + region, + channel: SearchUtils.MODIFIED_APP_CHANNEL, + }); + + return { + engines: await SearchTestUtils.searchConfigToEngines(configs.engines), + appDefaultEngineId: configs.appDefaultEngineId, + }; +} + +/** * This class implements the test harness for search configuration tests. * These tests are designed to ensure that the correct search engines are * loaded for the various region/locale configurations. @@ -143,14 +165,11 @@ class SearchConfigTest { #testDetails; /** - * @param {SearchConfigTestDetails|SearchConfigTestDetails[]} testDetails - * The initial configuration for this test, or an array of configurations - * for testing multiple engines efficiently. + * @param {SearchConfigTestDetails[]} testDetails + * An array of configurations for testing multiple engines. */ constructor(testDetails) { - this.#testDetails = Array.isArray(testDetails) - ? testDetails - : [testDetails]; + this.#testDetails = testDetails; } /** @@ -169,20 +188,6 @@ class SearchConfigTest { await maybeSetupConfig(); - // Disable region checks. - Services.prefs.setBoolPref("browser.search.geoSpecificDefaults", false); - - // Enable separatePrivateDefault testing. We test with this on, as we have - // separate tests for ensuring the normal = private when this is off. - Services.prefs.setBoolPref( - SearchUtils.BROWSER_SEARCH_PREF + "separatePrivateDefault.ui.enabled", - true - ); - Services.prefs.setBoolPref( - SearchUtils.BROWSER_SEARCH_PREF + "separatePrivateDefault", - true - ); - this.#engineSelector = new SearchEngineSelector(); } @@ -197,7 +202,8 @@ class SearchConfigTest { // when updating the requested/available locales. for (let region of regions) { for (let locale of locales) { - const { engines, appDefaultEngineId } = await this._getEngines( + const { engines, appDefaultEngineId } = await getEngines( + this.#engineSelector, region, locale ); @@ -226,40 +232,15 @@ class SearchConfigTest { } /** - * Processes the configuration to get the search engines for the specified - * region/locale. - * - * @param {string} region - * @param {string} locale - * @returns {Promise<{engines: AppProvidedConfigEngine[], appDefaultEngineId: string}>} - */ - async _getEngines(region, locale) { - let configs = await this.#engineSelector.fetchEngineConfiguration({ - locale, - region: region || "default", - channel: SearchUtils.MODIFIED_APP_CHANNEL, - }); - - return { - engines: await SearchTestUtils.searchConfigToEngines(configs.engines), - appDefaultEngineId: configs.appDefaultEngineId, - }; - } - - /** * @returns {Set<?string>} the list of regions for the tests to run with. */ get _regions() { - // TODO: The legacy configuration worked with null as an unknown region, - // for the search engine selector, we expect "default" but apply the - // fallback in _getEngines. Once we remove the legacy configuration, we can - // simplify this. if (TEST_DEBUG) { - return new Set(["by", "cn", "kz", "us", "ru", "tr", null]); + return new Set(["by", "cn", "kz", "us", "ru", "tr", "default"]); } return new Set([ ...Services.intl.getAvailableLocaleDisplayNames("region"), - null, + "default", ]); } diff --git a/toolkit/components/search/tests/xpcshell/searchconfigs/test_google.js b/toolkit/components/search/tests/xpcshell/searchconfigs/test_google.js @@ -1,210 +0,0 @@ -/* Any copyright is dedicated to the Public Domain. - http://creativecommons.org/publicdomain/zero/1.0/ */ - -"use strict"; - -ChromeUtils.defineESModuleGetters(this, { - NimbusFeatures: "resource://nimbus/ExperimentAPI.sys.mjs", -}); - -const { EnterprisePolicyTesting } = ChromeUtils.importESModule( - "resource://testing-common/EnterprisePolicyTesting.sys.mjs" -); - -const test = new SearchConfigTest({ - identifier: "google", - aliases: ["@google"], - default: { - // Included everywhere apart from the exclusions below. These are basically - // just excluding what Baidu includes. - excluded: [ - { - regions: ["cn"], - locales: ["zh-CN"], - }, - ], - }, - available: { - excluded: [ - // Should be available everywhere. - ], - }, - details: [ - { - included: [{ regions: ["us"] }], - domain: "google.com", - telemetryId: - SearchUtils.MODIFIED_APP_CHANNEL == "esr" - ? "google-b-1-e" - : "google-b-1-d", - searchUrlCode: - SearchUtils.MODIFIED_APP_CHANNEL == "esr" - ? "client=firefox-b-1-e" - : "client=firefox-b-1-d", - partnerCode: - SearchUtils.MODIFIED_APP_CHANNEL == "esr" - ? "firefox-b-1-e" - : "firefox-b-1-d", - }, - { - excluded: [{ regions: ["us", "by", "kz", "ru", "tr"] }], - included: [{}], - domain: "google.com", - telemetryId: - SearchUtils.MODIFIED_APP_CHANNEL == "esr" ? "google-b-e" : "google-b-d", - searchUrlCode: - SearchUtils.MODIFIED_APP_CHANNEL == "esr" - ? "client=firefox-b-e" - : "client=firefox-b-d", - partnerCode: - SearchUtils.MODIFIED_APP_CHANNEL == "esr" - ? "firefox-b-e" - : "firefox-b-d", - }, - { - included: [{ regions: ["by", "kz", "ru", "tr"] }], - domain: "google.com", - telemetryId: "google-com-nocodes", - partnerCode: "", - searchUrlParamNotInQuery: "client", - }, - ], -}); - -add_setup(async function () { - sinon.spy(NimbusFeatures.searchConfiguration, "onUpdate"); - sinon.stub(NimbusFeatures.searchConfiguration, "ready").resolves(); - await test.setup(); - - // This is needed to make sure the search settings can be loaded - // when the search service is initialized. - do_get_profile(); - - registerCleanupFunction(async () => { - sinon.restore(); - }); -}); - -add_task(async function test_searchConfig_google() { - await test.run(); -}); - -// We skip this test on ESR as on the ESR channel, we don't set up nimbus -// because we are not using any experiments there - the channel pref is used -// for enterprise, rather than the google_channel_* experiment options. -add_task( - { skip_if: () => SearchUtils.MODIFIED_APP_CHANNEL == "esr" }, - async function test_searchConfig_google_with_nimbus() { - let sandbox = sinon.createSandbox(); - // Test a couple of configurations with a preference parameter set up. - const TEST_DATA = [ - { - locale: "en-US", - region: "US", - expected: "nimbus_us_param", - }, - { - locale: "en-US", - region: "GB", - expected: "nimbus_row_param", - }, - ]; - - Assert.ok( - NimbusFeatures.searchConfiguration.onUpdate.called, - "Should register an update listener for Nimbus experiments" - ); - // Stub getVariable to populate the cache with our expected data - sandbox.stub(NimbusFeatures.searchConfiguration, "getVariable").returns([ - { key: "google_channel_us", value: "nimbus_us_param" }, - { key: "google_channel_row", value: "nimbus_row_param" }, - ]); - // Set the pref cache with Nimbus values - NimbusFeatures.searchConfiguration.onUpdate.firstCall.args[0](); - - for (const testData of TEST_DATA) { - info(`Checking region ${testData.region}, locale ${testData.locale}`); - const { engines } = await test._getEngines( - testData.region, - testData.locale - ); - - Assert.equal(engines[0].id, "google", "Should have the correct engine"); - - const submission = engines[0].getSubmission("test", URLTYPE_SEARCH_HTML); - Assert.ok( - NimbusFeatures.searchConfiguration.ready.called, - "Should wait for Nimbus to get ready" - ); - Assert.ok( - NimbusFeatures.searchConfiguration.getVariable, - "Should call NimbusFeatures.searchConfiguration.getVariable to populate the cache" - ); - Assert.ok( - submission.uri.query - .split("&") - .includes("channel=" + testData.expected), - "Should be including the correct preference parameter for the engine" - ); - } - - sandbox.restore(); - } -); - -async function assertEnterpriseParameter(useEmptyPolicy) { - // Test a couple of configurations. - const TEST_DATA = [ - { - locale: "en-US", - region: "US", - }, - { - locale: "en-US", - region: "GB", - }, - ]; - - Services.search.wrappedJSObject.reset(); - await EnterprisePolicyTesting.setupPolicyEngineWithJson( - useEmptyPolicy - ? {} - : { - policies: { - BlockAboutSupport: true, - }, - } - ); - await Services.search.init(); - - for (const testData of TEST_DATA) { - info(`Checking region ${testData.region}, locale ${testData.locale}`); - const { engines } = await test._getEngines( - testData.region, - testData.locale - ); - - Assert.equal(engines[0].id, "google", "Should have the correct engine"); - - const submission = engines[0].getSubmission("test", URLTYPE_SEARCH_HTML); - Assert.ok( - submission.uri.query.split("&").includes("channel=entpr"), - "Should be including the correct preference parameter for the engine" - ); - } -} - -// On ESR the channel parameter should always be `entpr`, regardless of if -// enterprise policies are set up or not. -add_task( - { skip_if: () => SearchUtils.MODIFIED_APP_CHANNEL != "esr" }, - async function test_searchConfig_google_enterprise_on_esr() { - await assertEnterpriseParameter(true); - } -); - -// If there's a policy set, we should also have the channel=entpr parameter -// set. -add_task(async function test_searchConfig_google_enterprise_policy() { - await assertEnterpriseParameter(false); -}); diff --git a/toolkit/components/search/tests/xpcshell/searchconfigs/test_searchconfig.js b/toolkit/components/search/tests/xpcshell/searchconfigs/test_searchconfig.js @@ -3,6 +3,13 @@ "use strict"; +/** + * Tests to ensure the production search configuration is correctly set up for + * the search engines. These are, by default, run against the remote settings + * dumps in this repository. See `maybeSetupConfig` in the head file for testing + * against servers. + */ + // Wikipedia locale-to-domain mapping configuration const WIKIPEDIA_LOCALES_INFO = [ [["af"]], @@ -578,6 +585,67 @@ const test = new SearchConfigTest([ ], }, { + identifier: "google", + aliases: ["@google"], + default: { + // Included everywhere apart from the exclusions below. These are basically + // just excluding what Baidu includes. + excluded: [ + { + regions: ["cn"], + locales: ["zh-CN"], + }, + ], + }, + available: { + excluded: [ + // Should be available everywhere. + ], + }, + details: [ + { + included: [{ regions: ["us"] }], + domain: "google.com", + telemetryId: + SearchUtils.MODIFIED_APP_CHANNEL == "esr" + ? "google-b-1-e" + : "google-b-1-d", + searchUrlCode: + SearchUtils.MODIFIED_APP_CHANNEL == "esr" + ? "client=firefox-b-1-e" + : "client=firefox-b-1-d", + partnerCode: + SearchUtils.MODIFIED_APP_CHANNEL == "esr" + ? "firefox-b-1-e" + : "firefox-b-1-d", + }, + { + excluded: [{ regions: ["us", "by", "kz", "ru", "tr"] }], + included: [{}], + domain: "google.com", + telemetryId: + SearchUtils.MODIFIED_APP_CHANNEL == "esr" + ? "google-b-e" + : "google-b-d", + searchUrlCode: + SearchUtils.MODIFIED_APP_CHANNEL == "esr" + ? "client=firefox-b-e" + : "client=firefox-b-d", + partnerCode: + SearchUtils.MODIFIED_APP_CHANNEL == "esr" + ? "firefox-b-e" + : "firefox-b-d", + }, + { + included: [{ regions: ["by", "kz", "ru", "tr"] }], + domain: "google.com", + telemetryId: "google-com-nocodes", + partnerCode: "", + searchUrlParamNotInQuery: "client", + }, + ], + }, + { identifier: "qwant", aliases: ["@qwant"], default: { diff --git a/toolkit/components/search/tests/xpcshell/searchconfigs/test_searchconfig_google_additional.js b/toolkit/components/search/tests/xpcshell/searchconfigs/test_searchconfig_google_additional.js @@ -0,0 +1,167 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +/** + * Additional tests against the search config for Google related items. + */ + +ChromeUtils.defineESModuleGetters(this, { + NimbusFeatures: "resource://nimbus/ExperimentAPI.sys.mjs", +}); + +const { EnterprisePolicyTesting } = ChromeUtils.importESModule( + "resource://testing-common/EnterprisePolicyTesting.sys.mjs" +); + +let engineSelector; + +add_setup(async function () { + sinon.spy(NimbusFeatures.searchConfiguration, "onUpdate"); + sinon.stub(NimbusFeatures.searchConfiguration, "ready").resolves(); + + updateAppInfo({ + name: "firefox", + ID: "xpcshell@tests.mozilla.org", + version: "42.0", + platformVersion: "42.0", + }); + + await maybeSetupConfig(); + + engineSelector = new SearchEngineSelector(); + + // This is needed to make sure the search settings can be loaded + // when the search service is initialized. + do_get_profile(); + + registerCleanupFunction(async () => { + sinon.restore(); + }); +}); + +// We skip this test on ESR as on the ESR channel, we don't set up nimbus +// because we are not using any experiments there - the channel pref is used +// for enterprise, rather than the google_channel_* experiment options. +add_task( + { skip_if: () => SearchUtils.MODIFIED_APP_CHANNEL == "esr" }, + async function test_searchConfig_google_with_nimbus() { + let sandbox = sinon.createSandbox(); + // Test a couple of configurations with a preference parameter set up. + const TEST_DATA = [ + { + locale: "en-US", + region: "US", + expected: "nimbus_us_param", + }, + { + locale: "en-US", + region: "GB", + expected: "nimbus_row_param", + }, + ]; + + // Call this once to cause ConfigSearchEngine to initialise `ParamPreferenceCache`. + await getEngines(engineSelector, "default", "default"); + + Assert.ok( + NimbusFeatures.searchConfiguration.onUpdate.called, + "Should register an update listener for Nimbus experiments" + ); + // Stub getVariable to populate the cache with our expected data + sandbox.stub(NimbusFeatures.searchConfiguration, "getVariable").returns([ + { key: "google_channel_us", value: "nimbus_us_param" }, + { key: "google_channel_row", value: "nimbus_row_param" }, + ]); + // Set the pref cache with Nimbus values + NimbusFeatures.searchConfiguration.onUpdate.firstCall.args[0](); + + for (const testData of TEST_DATA) { + info(`Checking region ${testData.region}, locale ${testData.locale}`); + const { engines } = await getEngines( + engineSelector, + testData.region, + testData.locale + ); + + Assert.equal(engines[0].id, "google", "Should have the correct engine"); + + const submission = engines[0].getSubmission("test", URLTYPE_SEARCH_HTML); + Assert.ok( + NimbusFeatures.searchConfiguration.ready.called, + "Should wait for Nimbus to get ready" + ); + Assert.ok( + NimbusFeatures.searchConfiguration.getVariable, + "Should call NimbusFeatures.searchConfiguration.getVariable to populate the cache" + ); + Assert.ok( + submission.uri.query + .split("&") + .includes("channel=" + testData.expected), + "Should be including the correct preference parameter for the engine" + ); + } + + sandbox.restore(); + } +); + +async function assertEnterpriseParameter(useEmptyPolicy) { + // Test a couple of configurations. + const TEST_DATA = [ + { + locale: "en-US", + region: "US", + }, + { + locale: "en-US", + region: "GB", + }, + ]; + + Services.search.wrappedJSObject.reset(); + await EnterprisePolicyTesting.setupPolicyEngineWithJson( + useEmptyPolicy + ? {} + : { + policies: { + BlockAboutSupport: true, + }, + } + ); + await Services.search.init(); + + for (const testData of TEST_DATA) { + info(`Checking region ${testData.region}, locale ${testData.locale}`); + const { engines } = await getEngines( + engineSelector, + testData.region, + testData.locale + ); + + Assert.equal(engines[0].id, "google", "Should have the correct engine"); + + const submission = engines[0].getSubmission("test", URLTYPE_SEARCH_HTML); + Assert.ok( + submission.uri.query.split("&").includes("channel=entpr"), + "Should be including the correct preference parameter for the engine" + ); + } +} + +// On ESR the channel parameter should always be `entpr`, regardless of if +// enterprise policies are set up or not. +add_task( + { skip_if: () => SearchUtils.MODIFIED_APP_CHANNEL != "esr" }, + async function test_searchConfig_google_enterprise_on_esr() { + await assertEnterpriseParameter(true); + } +); + +// If there's a policy set, we should also have the channel=entpr parameter +// set. +add_task(async function test_searchConfig_google_enterprise_policy() { + await assertEnterpriseParameter(false); +}); diff --git a/toolkit/components/search/tests/xpcshell/searchconfigs/xpcshell.toml b/toolkit/components/search/tests/xpcshell/searchconfigs/xpcshell.toml @@ -2,6 +2,12 @@ firefox-appdir = "browser" head = "head_searchconfig.js" dupe-manifest = "" +prefs = [ + # Enable separatePrivateDefault testing. We test with this on, as we have + # separate tests for ensuring the normal = private when this is off. + "browser.search.separatePrivateDefault.ui.enabled=true", + "browser.search.separatePrivateDefault=true", +] support-files = ["../../../../../../browser/locales/all-locales"] tags = "searchconfig remote-settings" # These are extensive tests, we don't need to run them on asan/tsan. @@ -20,10 +26,10 @@ requesttimeoutfactor = 2 ["test_distributions.js"] -["test_google.js"] - ["test_searchconfig.js"] +["test_searchconfig_google_additional.js"] + ["test_searchconfig_ui_schemas_valid.js"] support-files = [ "../../../schema/search-config-icons-schema.json",