diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-15 03:34:42 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-15 03:34:42 +0000 |
commit | da4c7e7ed675c3bf405668739c3012d140856109 (patch) | |
tree | cdd868dba063fecba609a1d819de271f0d51b23e /toolkit/components/search/tests/xpcshell/test_engine_selector_subvariants.js | |
parent | Adding upstream version 125.0.3. (diff) | |
download | firefox-da4c7e7ed675c3bf405668739c3012d140856109.tar.xz firefox-da4c7e7ed675c3bf405668739c3012d140856109.zip |
Adding upstream version 126.0.upstream/126.0
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'toolkit/components/search/tests/xpcshell/test_engine_selector_subvariants.js')
-rw-r--r-- | toolkit/components/search/tests/xpcshell/test_engine_selector_subvariants.js | 142 |
1 files changed, 142 insertions, 0 deletions
diff --git a/toolkit/components/search/tests/xpcshell/test_engine_selector_subvariants.js b/toolkit/components/search/tests/xpcshell/test_engine_selector_subvariants.js new file mode 100644 index 0000000000..ed61362ca6 --- /dev/null +++ b/toolkit/components/search/tests/xpcshell/test_engine_selector_subvariants.js @@ -0,0 +1,142 @@ +/* Any copyright is dedicated to the Public Domain. +https://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +const CONFIG = [ + { + recordType: "engine", + identifier: "engine-1", + base: {}, + variants: [ + { + environment: { + allRegionsAndLocales: true, + }, + partnerCode: "variant-partner-code", + subVariants: [ + { + environment: { regions: ["CA", "FR"] }, + telemetrySuffix: "subvariant-telemetry", + }, + { + environment: { regions: ["GB", "FR"] }, + partnerCode: "subvariant-partner-code", + }, + ], + }, + ], + }, + { + recordType: "defaultEngines", + specificDefaults: [], + }, + { + recordType: "engineOrders", + orders: [], + }, +]; + +const engineSelector = new SearchEngineSelector(); +let settings; +let configStub; + +/** + * This function asserts if the actual engines returned equals the expected + * engines. + * + * @param {object} config + * A fake search config containing engines. + * @param {object} userEnv + * A fake user's environment including locale and region, experiment, etc. + * @param {Array} expectedEngines + * The array of expected engines to be returned from the fake config. + * @param {string} message + * The assertion message. + */ +async function assertActualEnginesEqualsExpected( + config, + userEnv, + expectedEngines, + message +) { + engineSelector._configuration = null; + configStub.returns(config); + let { engines } = await engineSelector.fetchEngineConfiguration(userEnv); + + Assert.deepEqual(engines, expectedEngines, message); +} + +add_setup(async function () { + settings = await RemoteSettings(SearchUtils.NEW_SETTINGS_KEY); + configStub = sinon.stub(settings, "get"); +}); + +add_task(async function test_no_subvariants_match() { + await assertActualEnginesEqualsExpected( + CONFIG, + { + locale: "fi", + region: "FI", + }, + [ + { + identifier: "engine-1", + partnerCode: "variant-partner-code", + }, + ], + "Should match no subvariants." + ); +}); + +add_task(async function test_matching_subvariant_with_properties() { + await assertActualEnginesEqualsExpected( + CONFIG, + { + locale: "en-GB", + region: "GB", + }, + [ + { + identifier: "engine-1", + partnerCode: "subvariant-partner-code", + }, + ], + "Should match subvariant with subvariant properties." + ); +}); + +add_task(async function test_matching_variant_and_subvariant_with_properties() { + await assertActualEnginesEqualsExpected( + CONFIG, + { + locale: "en-CA", + region: "CA", + }, + [ + { + identifier: "engine-1", + partnerCode: "variant-partner-code", + telemetrySuffix: "subvariant-telemetry", + }, + ], + "Should match subvariant with subvariant properties." + ); +}); + +add_task(async function test_matching_two_subvariant_with_properties() { + await assertActualEnginesEqualsExpected( + CONFIG, + { + locale: "fr", + region: "FR", + }, + [ + { + identifier: "engine-1", + partnerCode: "subvariant-partner-code", + }, + ], + "Should match the last subvariant with subvariant properties." + ); +}); |