summaryrefslogtreecommitdiffstats
path: root/toolkit/components/search/tests/xpcshell/test_validate_engines.js
blob: d311253183e514c3c9f6d5f56e35529606a56bdc (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
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */

// Ensure all the engines defined in the configuration are valid by
// creating a refined configuration that includes all the engines everywhere.

"use strict";

const { SearchService } = ChromeUtils.importESModule(
  "resource://gre/modules/SearchService.sys.mjs"
);

const ss = new SearchService();

add_task(async function test_validate_engines() {
  let settings = RemoteSettings(SearchUtils.SETTINGS_KEY);
  let config = await settings.get();

  if (SearchUtils.newSearchConfigEnabled) {
    // We do not load engines with the same name. However, in search-config-v2
    // we have multiple engines named eBay, so we error out.
    // We never deploy more than one eBay in each environment so this issue
    // won't be a problem.
    // Ignore the error and test the configs can be created to engine objects.
    consoleAllowList.push("Could not load engine");
    config = config.map(obj => {
      if (obj.recordType == "engine") {
        return {
          recordType: "engine",
          identifier: obj.identifier,
          base: {
            name: obj.base.name,
            urls: {
              search: {
                base: obj.base.urls.search.base || "",
                searchTermParamName: "q",
              },
            },
          },
          variants: [
            {
              environment: { allRegionsAndLocales: true },
            },
          ],
        };
      }

      return obj;
    });
  } else {
    config = config.map(e => {
      return {
        appliesTo: [
          {
            included: {
              everywhere: true,
            },
          },
        ],
        webExtension: e.webExtension,
      };
    });
  }

  sinon.stub(settings, "get").returns(config);
  await AddonTestUtils.promiseStartupManager();
  await ss.init();
});