summaryrefslogtreecommitdiffstats
path: root/toolkit/components/search/tests/xpcshell/test_engine_selector_application.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 17:32:43 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 17:32:43 +0000
commit6bf0a5cb5034a7e684dcc3500e841785237ce2dd (patch)
treea68f146d7fa01f0134297619fbe7e33db084e0aa /toolkit/components/search/tests/xpcshell/test_engine_selector_application.js
parentInitial commit. (diff)
downloadthunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.tar.xz
thunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.zip
Adding upstream version 1:115.7.0.upstream/1%115.7.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'toolkit/components/search/tests/xpcshell/test_engine_selector_application.js')
-rw-r--r--toolkit/components/search/tests/xpcshell/test_engine_selector_application.js115
1 files changed, 115 insertions, 0 deletions
diff --git a/toolkit/components/search/tests/xpcshell/test_engine_selector_application.js b/toolkit/components/search/tests/xpcshell/test_engine_selector_application.js
new file mode 100644
index 0000000000..ef54b763af
--- /dev/null
+++ b/toolkit/components/search/tests/xpcshell/test_engine_selector_application.js
@@ -0,0 +1,115 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+ChromeUtils.defineESModuleGetters(this, {
+ SearchEngineSelector: "resource://gre/modules/SearchEngineSelector.sys.mjs",
+});
+
+const TEST_CONFIG = [
+ {
+ webExtension: {
+ id: "aol@example.com",
+ },
+ appliesTo: [
+ {
+ included: { everywhere: true },
+ },
+ ],
+ default: "yes-if-no-other",
+ },
+ {
+ webExtension: {
+ id: "lycos@example.com",
+ },
+ appliesTo: [
+ {
+ included: { everywhere: true },
+ application: {
+ channel: ["nightly"],
+ },
+ },
+ ],
+ default: "yes",
+ },
+ {
+ webExtension: {
+ id: "altavista@example.com",
+ },
+ appliesTo: [
+ {
+ included: { everywhere: true },
+ application: {
+ channel: ["nightly", "esr"],
+ },
+ },
+ ],
+ },
+ {
+ webExtension: {
+ id: "excite@example.com",
+ },
+ appliesTo: [
+ {
+ included: { everywhere: true },
+ },
+ {
+ included: { everywhere: true },
+ application: {
+ channel: ["release"],
+ },
+ default: "yes",
+ },
+ ],
+ },
+];
+
+const expectedEnginesPerChannel = {
+ default: ["aol@example.com", "excite@example.com"],
+ nightly: [
+ "lycos@example.com",
+ "aol@example.com",
+ "altavista@example.com",
+ "excite@example.com",
+ ],
+ beta: ["aol@example.com", "excite@example.com"],
+ release: ["excite@example.com", "aol@example.com"],
+ esr: ["aol@example.com", "altavista@example.com", "excite@example.com"],
+};
+
+const expectedDefaultEngine = {
+ default: "aol@example.com",
+ nightly: "lycos@example.com",
+ beta: "aol@example.com",
+ release: "excite@example.com",
+ esr: "aol@example.com",
+};
+
+const engineSelector = new SearchEngineSelector();
+
+add_task(async function test_engine_selector_channels() {
+ const settings = await RemoteSettings(SearchUtils.SETTINGS_KEY);
+ sinon.stub(settings, "get").returns(TEST_CONFIG);
+
+ for (let [channel, expected] of Object.entries(expectedEnginesPerChannel)) {
+ const { engines } = await engineSelector.fetchEngineConfiguration({
+ locale: "en-US",
+ region: "us",
+ channel,
+ });
+
+ const engineIds = engines.map(obj => obj.webExtension.id);
+ Assert.deepEqual(
+ engineIds,
+ expected,
+ `Should have the expected engines for channel "${channel}"`
+ );
+
+ Assert.equal(
+ engineIds[0],
+ expectedDefaultEngine[channel],
+ `Should have the correct default for channel "${channel}"`
+ );
+ }
+});