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

/* Check default search engine is picked from list.json searchDefault */

"use strict";

add_task(async function setup() {
  await SearchTestUtils.useTestEngines();

  Services.locale.availableLocales = [
    ...Services.locale.availableLocales,
    "de",
    "fr",
  ];

  Services.prefs.setBoolPref(
    SearchUtils.BROWSER_SEARCH_PREF + "separatePrivateDefault.ui.enabled",
    true
  );
  Services.prefs.setBoolPref(
    SearchUtils.BROWSER_SEARCH_PREF + "separatePrivateDefault",
    true
  );
  Region._setHomeRegion("US", false);
});

add_task(async function test_listJSONlocale() {
  Services.locale.requestedLocales = ["de"];

  await AddonTestUtils.promiseStartupManager();
  await Services.search.init();

  Assert.ok(Services.search.isInitialized, "search initialized");

  let sortedEngines = await Services.search.getEngines();
  Assert.equal(sortedEngines.length, 1, "Should have only one engine");

  Assert.equal(
    Services.search.defaultEngine.name,
    "Test search engine",
    "Should have the correct default engine"
  );
  Assert.equal(
    Services.search.defaultPrivateEngine.name,
    // 'de' only displays google, so we'll be using the same engine as the
    // normal default.
    "Test search engine",
    "Should have the correct private default engine"
  );
});

// Check that switching locale switches search engines
add_task(async function test_listJSONlocaleSwitch() {
  let defaultBranch = Services.prefs.getDefaultBranch(
    SearchUtils.BROWSER_SEARCH_PREF
  );
  defaultBranch.setCharPref("param.code", "good&id=unique");

  await promiseSetLocale("fr");

  Assert.ok(Services.search.isInitialized, "search initialized");

  let sortedEngines = await Services.search.getEngines();
  Assert.deepEqual(
    sortedEngines.map(e => e.name),
    ["Test search engine", "engine-pref", "engine-resourceicon"],
    "Should have the correct engine list"
  );

  Assert.equal(
    Services.search.defaultEngine.name,
    "Test search engine",
    "Should have the correct default engine"
  );
  Assert.equal(
    Services.search.defaultPrivateEngine.name,
    "engine-pref",
    "Should have the correct private default engine"
  );
});

// Check that region overrides apply
add_task(async function test_listJSONRegionOverride() {
  await promiseSetHomeRegion("RU");

  Assert.ok(Services.search.isInitialized, "search initialized");

  let sortedEngines = await Services.search.getEngines();
  Assert.deepEqual(
    sortedEngines.map(e => e.name),
    ["Test search engine", "engine-pref", "engine-chromeicon"],
    "Should have the correct engine list"
  );

  Assert.equal(
    Services.search.defaultEngine.name,
    "Test search engine",
    "Should have the correct default engine"
  );
  Assert.equal(
    Services.search.defaultPrivateEngine.name,
    "engine-pref",
    "Should have the correct private default engine"
  );
});