commit 7bfedfcd97c61067034be540203fae9440b6508c parent 46c3cc6e87b745698d8aba3762959cd723954095 Author: Florian Quèze <florian@queze.net> Date: Tue, 30 Sep 2025 20:41:00 +0000 Bug 1991615 - merge simple searchconfig xpcshell tests into a single test_searchconfigs.js test to reduce the total CPU time, r=Standard8. Differential Revision: https://phabricator.services.mozilla.com/D266779 Diffstat:
10 files changed, 251 insertions(+), 343 deletions(-)
diff --git a/toolkit/components/search/tests/xpcshell/searchconfigs/head_searchconfig.js b/toolkit/components/search/tests/xpcshell/searchconfigs/head_searchconfig.js @@ -138,16 +138,19 @@ class SearchConfigTest { #engineSelector; /** - * @type {SearchConfigTestDetails} + * @type {SearchConfigTestDetails[]} */ #testDetails; /** - * @param {SearchConfigTestDetails} testDetails - * The initial configuration for this test. + * @param {SearchConfigTestDetails|SearchConfigTestDetails[]} testDetails + * The initial configuration for this test, or an array of configurations + * for testing multiple engines efficiently. */ constructor(testDetails) { - this.#testDetails = testDetails; + this.#testDetails = Array.isArray(testDetails) + ? testDetails + : [testDetails]; } /** @@ -198,15 +201,25 @@ class SearchConfigTest { region, locale ); - this._assertEngineRules( - engines.filter(e => e.id == appDefaultEngineId), - region, - locale, - "default" - ); - const isPresent = this._assertAvailableEngines(region, locale, engines); - if (isPresent) { - this._assertEngineDetails(region, locale, engines); + + // Test each configuration in this single iteration + for (let testDetails of this.#testDetails) { + this._assertEngineRules( + engines.filter(e => e.id == appDefaultEngineId), + region, + locale, + "default", + testDetails + ); + const isPresent = this._assertAvailableEngines( + region, + locale, + engines, + testDetails + ); + if (isPresent) { + this._assertEngineDetails(region, locale, engines, testDetails); + } } } } @@ -327,21 +340,23 @@ class SearchConfigTest { * The two-letter locale code. * @param {"default" | "available"} section * The section of the test to check. + * @param {SearchConfigTestDetails} testDetails + * The test details to use. * @returns {boolean} * Returns true if the engine is expected to be present, false otherwise. */ - _assertEngineRules(engines, region, locale, section) { + _assertEngineRules(engines, region, locale, section, testDetails) { const infoString = `region: "${region}" locale: "${locale}"`; - const testSection = this.#testDetails[section]; + const testSection = testDetails[section]; const hasIncluded = "included" in testSection; const hasExcluded = "excluded" in testSection; - const identifierIncluded = !!this._findEngine(engines, this.#testDetails); + const identifierIncluded = !!this._findEngine(engines, testDetails); // If there's not included/excluded, then this shouldn't be the default anywhere. if (section == "default" && !hasIncluded && !hasExcluded) { this.assertOk( !identifierIncluded, - `Should not be ${section} for any locale/region, + `${testDetails.identifier} should not be ${section} for any locale/region, currently set for ${infoString}` ); return false; @@ -364,51 +379,18 @@ class SearchConfigTest { ) { this.assertOk( identifierIncluded, - `Should be ${section} for ${infoString}` + `${testDetails.identifier} should be ${section} for ${infoString}` ); return true; } this.assertOk( !identifierIncluded, - `Should not be ${section} for ${infoString}` + `${testDetails.identifier} should not be ${section} for ${infoString}` ); return false; } /** - * Asserts whether the engine is correctly set as default or not. - * - * @param {string} region - * The two-letter region code. - * @param {string} locale - * The two-letter locale code. - */ - _assertDefaultEngines(region, locale) { - this._assertEngineRules( - [ - /** @type {AppProvidedConfigEngine} */ ( - Services.search.appDefaultEngine - ), - ], - region, - locale, - "default" - ); - // At the moment, this uses the same section as the normal default, as - // we don't set this differently for any region/locale. - this._assertEngineRules( - [ - /** @type {AppProvidedConfigEngine} */ ( - Services.search.appPrivateDefaultEngine - ), - ], - region, - locale, - "default" - ); - } - - /** * Asserts whether the engine is correctly available or not. * * @param {string} region @@ -417,11 +399,19 @@ class SearchConfigTest { * The two-letter locale code. * @param {AppProvidedConfigEngine[]} engines * The current visible engines. + * @param {SearchConfigTestDetails} testDetails + * The test details to use. * @returns {boolean} * Returns true if the engine is expected to be present, false otherwise. */ - _assertAvailableEngines(region, locale, engines) { - return this._assertEngineRules(engines, region, locale, "available"); + _assertAvailableEngines(region, locale, engines, testDetails) { + return this._assertEngineRules( + engines, + region, + locale, + "available", + testDetails + ); } /** @@ -433,9 +423,11 @@ class SearchConfigTest { * The two-letter locale code. * @param {AppProvidedConfigEngine[]} engines * The current visible engines. + * @param {SearchConfigTestDetails} testDetails + * The test details to use. */ - _assertEngineDetails(region, locale, engines) { - const details = this.#testDetails.details.filter(value => { + _assertEngineDetails(region, locale, engines, testDetails) { + const details = testDetails.details.filter(value => { const included = this._localeRegionInSection( value.included, region, @@ -449,16 +441,19 @@ class SearchConfigTest { this.assertEqual( details.length, 1, - `Should have just one details section for region: ${region} locale: ${locale}` + `${testDetails.identifier} should have just one details section for region: ${region} locale: ${locale}` ); - const engine = this._findEngine(engines, this.#testDetails); - this.assertOk(engine, "Should have an engine present"); + const engine = this._findEngine(engines, testDetails); + this.assertOk( + engine, + "${testDetails.identifier} should have an engine present" + ); - if (this.#testDetails.aliases) { + if (testDetails.aliases) { this.assertDeepEqual( engine.aliases, - this.#testDetails.aliases, + testDetails.aliases, "Should have the correct aliases for the engine" ); } @@ -466,7 +461,7 @@ class SearchConfigTest { const location = `in region:${region}, locale:${locale}`; for (const rule of details) { - this._assertCorrectDomains(location, engine, rule); + this._assertCorrectDomains(location, engine, rule, testDetails); this._assertCorrectUrlCode(location, engine, rule); if ("aliases" in rule) { this.assertDeepEqual( @@ -507,11 +502,13 @@ class SearchConfigTest { * The engine being tested. * @param {EngineRuleDetails & DeploymentDetails} rules * Rules to test. + * @param {SearchConfigTestDetails} testDetails + * The test details to use. */ - _assertCorrectDomains(location, engine, rules) { + _assertCorrectDomains(location, engine, rules, testDetails) { this.assertOk( rules.domain, - `Should have an expectedDomain for the engine ${location}` + `${testDetails.identifier} should have an expectedDomain for the engine ${location}` ); let submission = engine.getSubmission("test", URLTYPE_SEARCH_HTML); @@ -523,12 +520,12 @@ class SearchConfigTest { ); submission = engine.getSubmission("test", URLTYPE_SUGGEST_JSON); - if (this.#testDetails.noSuggestionsURL || rules.noSuggestionsURL) { + if (testDetails.noSuggestionsURL || rules.noSuggestionsURL) { this.assertOk(!submission, "Should not have a submission url"); - } else if (this.#testDetails.suggestionUrlBase) { + } else if (testDetails.suggestionUrlBase) { this.assertEqual( submission.uri.prePath + submission.uri.filePath, - this.#testDetails.suggestionUrlBase, + testDetails.suggestionUrlBase, `Should have the correct domain for type: ${URLTYPE_SUGGEST_JSON} ${location}.` ); this.assertOk( diff --git a/toolkit/components/search/tests/xpcshell/searchconfigs/test_amazon.js b/toolkit/components/search/tests/xpcshell/searchconfigs/test_amazon.js @@ -1,41 +0,0 @@ -/* Any copyright is dedicated to the Public Domain. - http://creativecommons.org/publicdomain/zero/1.0/ */ - -"use strict"; - -const test = new SearchConfigTest({ - identifier: "amazondotcom-us", - default: { - // Not default anywhere. - }, - available: { - included: [ - { - // The main regions we ship Amazon to. Below this are special cases. - regions: ["us"], - }, - ], - }, - details: [ - { - domain: "amazon.com", - telemetryId: "amazondotcom-us-adm", - aliases: ["@amazon"], - included: [ - { - regions: ["us"], - }, - ], - noSuggestionsURL: true, - searchUrlCode: "tag=admarketus-20", - }, - ], -}); - -add_setup(async function () { - await test.setup(); -}); - -add_task(async function test_searchConfig_amazon() { - await test.run(); -}); diff --git a/toolkit/components/search/tests/xpcshell/searchconfigs/test_baidu.js b/toolkit/components/search/tests/xpcshell/searchconfigs/test_baidu.js @@ -1,39 +0,0 @@ -/* Any copyright is dedicated to the Public Domain. - http://creativecommons.org/publicdomain/zero/1.0/ */ - -"use strict"; - -const test = new SearchConfigTest({ - identifier: "baidu", - aliases: ["@\u767E\u5EA6", "@baidu"], - default: { - included: [ - { - regions: ["cn"], - locales: ["zh-CN"], - }, - ], - }, - available: { - included: [ - { - locales: ["zh-CN"], - }, - ], - }, - details: [ - { - included: [{}], - domain: "baidu.com", - telemetryId: "baidu", - }, - ], -}); - -add_setup(async function () { - await test.setup(); -}); - -add_task(async function test_searchConfig_baidu() { - await test.run(); -}); diff --git a/toolkit/components/search/tests/xpcshell/searchconfigs/test_bing.js b/toolkit/components/search/tests/xpcshell/searchconfigs/test_bing.js @@ -1,35 +0,0 @@ -/* Any copyright is dedicated to the Public Domain. - http://creativecommons.org/publicdomain/zero/1.0/ */ - -"use strict"; - -const test = new SearchConfigTest({ - identifier: "bing", - aliases: ["@bing"], - default: { - // Not included anywhere. - }, - available: { - excluded: [ - // Should be available everywhere. - ], - }, - details: [ - { - included: [{}], - domain: "bing.com", - telemetryId: - SearchUtils.MODIFIED_APP_CHANNEL == "esr" ? "bing-esr" : "bing", - searchUrlCode: - SearchUtils.MODIFIED_APP_CHANNEL == "esr" ? "pc=MOZR" : "pc=MOZI", - }, - ], -}); - -add_setup(async function () { - await test.setup(); -}); - -add_task(async function test_searchConfig_bing() { - await test.run(); -}); diff --git a/toolkit/components/search/tests/xpcshell/searchconfigs/test_duckduckgo.js b/toolkit/components/search/tests/xpcshell/searchconfigs/test_duckduckgo.js @@ -1,35 +0,0 @@ -/* Any copyright is dedicated to the Public Domain. - http://creativecommons.org/publicdomain/zero/1.0/ */ - -"use strict"; - -const test = new SearchConfigTest({ - identifier: "ddg", - aliases: ["@duckduckgo", "@ddg"], - default: { - // Not included anywhere. - }, - available: { - excluded: [ - // Should be available everywhere. - ], - }, - details: [ - { - included: [{}], - domain: "duckduckgo.com", - telemetryId: - SearchUtils.MODIFIED_APP_CHANNEL == "esr" ? "ddg-esr" : "ddg", - searchUrlCode: - SearchUtils.MODIFIED_APP_CHANNEL == "esr" ? "t=ftsa" : "t=ffab", - }, - ], -}); - -add_setup(async function () { - await test.setup(); -}); - -add_task(async function test_searchConfig_duckduckgo() { - await test.run(); -}); diff --git a/toolkit/components/search/tests/xpcshell/searchconfigs/test_ecosia.js b/toolkit/components/search/tests/xpcshell/searchconfigs/test_ecosia.js @@ -1,38 +0,0 @@ -/* Any copyright is dedicated to the Public Domain. - http://creativecommons.org/publicdomain/zero/1.0/ */ - -"use strict"; - -const test = new SearchConfigTest({ - identifier: "ecosia", - aliases: [], - default: { - // Not default anywhere. - }, - available: { - included: [ - { - locales: ["de"], - }, - { - regions: ["at", "be", "ch", "de", "es", "it", "nl", "se"], - }, - ], - }, - details: [ - { - included: [{}], - domain: "www.ecosia.org", - telemetryId: "ecosia", - searchUrlCode: "tt=mzl", - }, - ], -}); - -add_setup(async function () { - await test.setup(); -}); - -add_task(async function test_searchConfig_ecosia() { - await test.run(); -}); diff --git a/toolkit/components/search/tests/xpcshell/searchconfigs/test_qwant.js b/toolkit/components/search/tests/xpcshell/searchconfigs/test_qwant.js @@ -1,39 +0,0 @@ -/* Any copyright is dedicated to the Public Domain. - http://creativecommons.org/publicdomain/zero/1.0/ */ - -"use strict"; - -const test = new SearchConfigTest({ - identifier: "qwant", - aliases: ["@qwant"], - default: { - // Not default anywhere. - }, - available: { - included: [ - { - locales: ["fr"], - }, - { - regions: ["be", "ch", "es", "fr", "it", "nl"], - }, - ], - }, - details: [ - { - included: [{}], - domain: "www.qwant.com", - telemetryId: "qwant", - searchUrlCode: "client=brz-moz", - suggestUrlCode: "client=opensearch", - }, - ], -}); - -add_setup(async function () { - await test.setup(); -}); - -add_task(async function test_searchConfig_qwant() { - await test.run(); -}); diff --git a/toolkit/components/search/tests/xpcshell/searchconfigs/test_searchconfig.js b/toolkit/components/search/tests/xpcshell/searchconfigs/test_searchconfig.js @@ -0,0 +1,186 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +const test = new SearchConfigTest([ + { + identifier: "amazondotcom-us", + default: { + // Not default anywhere. + }, + available: { + included: [ + { + // The main regions we ship Amazon to. Below this are special cases. + regions: ["us"], + }, + ], + }, + details: [ + { + domain: "amazon.com", + telemetryId: "amazondotcom-us-adm", + aliases: ["@amazon"], + included: [ + { + regions: ["us"], + }, + ], + noSuggestionsURL: true, + searchUrlCode: "tag=admarketus-20", + }, + ], + }, + { + identifier: "baidu", + aliases: ["@百度", "@baidu"], + default: { + included: [ + { + regions: ["cn"], + locales: ["zh-CN"], + }, + ], + }, + available: { + included: [ + { + locales: ["zh-CN"], + }, + ], + }, + details: [ + { + included: [{}], + domain: "baidu.com", + telemetryId: "baidu", + }, + ], + }, + { + identifier: "bing", + aliases: ["@bing"], + default: { + // Not included anywhere. + }, + available: { + excluded: [ + // Should be available everywhere. + ], + }, + details: [ + { + included: [{}], + domain: "bing.com", + telemetryId: + SearchUtils.MODIFIED_APP_CHANNEL == "esr" ? "bing-esr" : "bing", + searchUrlCode: + SearchUtils.MODIFIED_APP_CHANNEL == "esr" ? "pc=MOZR" : "pc=MOZI", + }, + ], + }, + { + identifier: "ddg", + aliases: ["@duckduckgo", "@ddg"], + default: { + // Not included anywhere. + }, + available: { + excluded: [ + // Should be available everywhere. + ], + }, + details: [ + { + included: [{}], + domain: "duckduckgo.com", + telemetryId: + SearchUtils.MODIFIED_APP_CHANNEL == "esr" ? "ddg-esr" : "ddg", + searchUrlCode: + SearchUtils.MODIFIED_APP_CHANNEL == "esr" ? "t=ftsa" : "t=ffab", + }, + ], + }, + { + identifier: "ecosia", + aliases: [], + default: { + // Not default anywhere. + }, + available: { + included: [ + { + locales: ["de"], + }, + { + regions: ["at", "be", "ch", "de", "es", "it", "nl", "se"], + }, + ], + }, + details: [ + { + included: [{}], + domain: "www.ecosia.org", + telemetryId: "ecosia", + searchUrlCode: "tt=mzl", + }, + ], + }, + { + identifier: "qwant", + aliases: ["@qwant"], + default: { + // Not default anywhere. + }, + available: { + included: [ + { + locales: ["fr"], + }, + { + regions: ["be", "ch", "es", "fr", "it", "nl"], + }, + ], + }, + details: [ + { + included: [{}], + domain: "www.qwant.com", + telemetryId: "qwant", + searchUrlCode: "client=brz-moz", + suggestUrlCode: "client=opensearch", + }, + ], + }, + { + identifier: "yahoo-jp", + aliases: [], + default: { + // Not default anywhere. + }, + available: { + included: [ + { + locales: ["ja", "ja-JP-macos"], + }, + ], + }, + details: [ + { + included: [{}], + domain: "search.yahoo.co.jp", + telemetryId: "yahoo-jp", + searchUrlCode: "fr=mozff", + }, + ], + }, +]); + +add_setup(async function () { + await test.setup(); +}); + +add_task(async function test_searchConfigs() { + await test.run(); +}); diff --git a/toolkit/components/search/tests/xpcshell/searchconfigs/test_yahoojp.js b/toolkit/components/search/tests/xpcshell/searchconfigs/test_yahoojp.js @@ -1,36 +0,0 @@ -/* Any copyright is dedicated to the Public Domain. - http://creativecommons.org/publicdomain/zero/1.0/ */ - -"use strict"; - -const test = new SearchConfigTest({ - identifier: "yahoo-jp", - identifierExactMatch: true, - aliases: [], - default: { - // Not default anywhere. - }, - available: { - included: [ - { - locales: ["ja", "ja-JP-macos"], - }, - ], - }, - details: [ - { - included: [{}], - domain: "search.yahoo.co.jp", - telemetryId: "yahoo-jp", - searchUrlCode: "fr=mozff", - }, - ], -}); - -add_setup(async function () { - await test.setup(); -}); - -add_task(async function test_searchConfig_yahoojp() { - await test.run(); -}); diff --git a/toolkit/components/search/tests/xpcshell/searchconfigs/xpcshell.toml b/toolkit/components/search/tests/xpcshell/searchconfigs/xpcshell.toml @@ -18,16 +18,8 @@ skip-if = [ # These tests do take a little longer on Linux ccov, so allow that here. requesttimeoutfactor = 2 -["test_amazon.js"] - -["test_baidu.js"] - -["test_bing.js"] - ["test_distributions.js"] -["test_duckduckgo.js"] - # The test_ebay needs newSearchConfig.enabled=true because there # are changes to ebay and locale pl for search-config-v2. # We have rolled out search-config-v2 100% to Beta 126 and the next Beta 127 @@ -38,11 +30,9 @@ requesttimeoutfactor = 2 ["test_ebay.js"] prefs = ["browser.search.newSearchConfig.enabled=true"] -["test_ecosia.js"] - ["test_google.js"] -["test_qwant.js"] +["test_searchconfig.js"] ["test_searchconfig_ui_schemas_valid.js"] support-files = [ @@ -67,5 +57,3 @@ support-files = [ ["test_selector_db_out_of_date.js"] ["test_wikipedia.js"] - -["test_yahoojp.js"]