summaryrefslogtreecommitdiffstats
path: root/toolkit/components/search/tests/xpcshell/test_engine_selector_application_name.js
blob: fef03c47be75b2d492c50c32bfb9feb8cc64aba2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/* 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 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: {
          name: ["firefox"],
        },
      },
    ],
    default: "yes",
  },
  {
    webExtension: {
      id: "altavista@example.com",
    },
    appliesTo: [
      {
        included: { everywhere: true },
        application: {
          name: ["fenix"],
        },
      },
    ],
  },
  {
    webExtension: {
      id: "excite@example.com",
    },
    appliesTo: [
      {
        included: { everywhere: true },
        application: {
          name: ["firefox"],
          minVersion: "10",
          maxVersion: "30",
        },
        default: "yes",
      },
    ],
  },
];

const engineSelector = new SearchEngineSelector();

const tests = [
  {
    name: "Firefox",
    version: "1",
    expected: ["lycos@example.com", "aol@example.com"],
  },
  {
    name: "Firefox",
    version: "20",
    expected: ["lycos@example.com", "aol@example.com", "excite@example.com"],
  },
  {
    name: "Fenix",
    version: "20",
    expected: ["aol@example.com", "altavista@example.com"],
  },
  {
    name: "Firefox",
    version: "31",
    expected: ["lycos@example.com", "aol@example.com"],
  },
  {
    name: "Firefox",
    version: "30",
    expected: ["lycos@example.com", "aol@example.com", "excite@example.com"],
  },
  {
    name: "Firefox",
    version: "10",
    expected: ["lycos@example.com", "aol@example.com", "excite@example.com"],
  },
];

add_task(async function setup() {
  await SearchTestUtils.useTestEngines("data", null, CONFIG);
  await AddonTestUtils.promiseStartupManager();

  let confUrl = `data:application/json,${JSON.stringify(CONFIG)}`;
  Services.prefs.setStringPref("search.config.url", confUrl);
});

add_task(async function test_application_name() {
  for (const { name, version, expected } of tests) {
    let { engines } = await engineSelector.fetchEngineConfiguration({
      locale: "default",
      region: "default",
      name,
      version,
    });
    const engineIds = engines.map(obj => obj.webExtension.id);
    Assert.deepEqual(
      engineIds,
      expected,
      `Should have the expected engines for app: "${name}"
      and version: "${version}"`
    );
  }
});