summaryrefslogtreecommitdiffstats
path: root/toolkit/components/search/tests/xpcshell/test_settings_persist_diff_locale_same_name.js
blob: 3c0b930bc8683e50bf41e693bc614a61aad1032b (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/ */

"use strict";

const CONFIG = [
  {
    webExtension: { id: "engine@search.mozilla.org" },
    appliesTo: [{ included: { everywhere: true } }],
  },
  {
    // This engine has the same name, but still should be replaced correctly.
    webExtension: {
      id: "engine-same-name@search.mozilla.org",
    },
    appliesTo: [
      {
        included: { everywhere: true },
        excluded: { regions: ["FR"] },
      },
      {
        included: { regions: ["FR"] },
        webExtension: {
          locales: ["gd"],
        },
      },
    ],
  },
];

add_task(async function setup() {
  await SearchTestUtils.useTestEngines("data", null, CONFIG);
  await AddonTestUtils.promiseStartupManager();
  let settingsFileWritten = promiseAfterSettings();
  Region._setHomeRegion("US", false);
  await Services.search.init();
  await settingsFileWritten;
});

add_task(async function test_settings_persist_diff_locale_same_name() {
  let settingsFileWritten = promiseAfterSettings();
  let engine1 = Services.search.getEngineByName("engine-same-name");
  Services.search.moveEngine(engine1, 0);

  let engine2 = Services.search.getEngineByName("Test search engine");
  Services.search.moveEngine(engine2, 1);
  // Ensure we have saved the settings before we restart below.
  await settingsFileWritten;

  Assert.deepEqual(
    (await Services.search.getEngines()).map(e => e.name),
    ["engine-same-name", "Test search engine"],
    "Should have set the engines to the expected order"
  );

  // Setting the region to FR will change the engine id, but use the same name.
  Region._setHomeRegion("FR", false);

  // Pretend we are restarting.
  Services.search.wrappedJSObject.reset();
  await Services.search.init();

  Assert.deepEqual(
    (await Services.search.getEngines()).map(e => e.name),
    ["engine-same-name", "Test search engine"],
    "Should have retained the engines in the expected order"
  );
});