-
Notifications
You must be signed in to change notification settings - Fork 54
/
test_getDefaultEngines.js
123 lines (109 loc) · 3.55 KB
/
test_getDefaultEngines.js
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
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
/* Check the correct default engines are picked from the configuration list. */
"use strict";
const modernConfig = Services.prefs.getBoolPref(
SearchUtils.BROWSER_SEARCH_PREF + "modernConfig",
false
);
// With modern configuration, we have a slightly different order, since the
// default engines will get place first, regardless of the specified orders
// of the other engines.
const EXPECTED_ORDER = modernConfig
? [
// Default engines
"Test search engine",
"engine-pref",
// Two engines listed in searchOrder.
"engine-resourceicon",
"engine-chromeicon",
// Rest of the engines in order.
"engine-rel-searchform-purpose",
"Test search engine (Reordered)",
]
: [
// Two engines listed in searchOrder.
"engine-resourceicon",
"engine-chromeicon",
// Rest of the engines in alphabetical order.
"engine-pref",
"engine-rel-searchform-purpose",
"Test search engine",
"Test search engine (Reordered)",
];
add_task(async function setup() {
await AddonTestUtils.promiseStartupManager();
await useTestEngines();
Services.prefs.setBoolPref(
SearchUtils.BROWSER_SEARCH_PREF + "separatePrivateDefault",
true
);
});
async function checkOrder(expectedOrder) {
const sortedEngines = await Services.search.getDefaultEngines();
Assert.deepEqual(
sortedEngines.map(s => s.name),
expectedOrder,
"Should have the expected engine order"
);
}
add_task(async function test_getDefaultEngines_no_others() {
await checkOrder(EXPECTED_ORDER);
}).skip();
add_task(async function test_getDefaultEngines_with_non_builtins() {
await Services.search.addEngineWithDetails("nonbuiltin1", {
method: "get",
template: "http://example.com/?search={searchTerms}",
});
// We should still have the same built-in engines listed.
await checkOrder(EXPECTED_ORDER);
}).skip();
add_task(async function test_getDefaultEngines_with_distro() {
Services.prefs.getDefaultBranch("distribution.").setCharPref("id", "test");
Services.prefs.setCharPref(
SearchUtils.BROWSER_SEARCH_PREF + "order.extra.bar",
"engine-pref"
);
Services.prefs.setCharPref(
SearchUtils.BROWSER_SEARCH_PREF + "order.extra.foo",
"engine-resourceicon"
);
let localizedStr = Cc["@mozilla.org/pref-localizedstring;1"].createInstance(
Ci.nsIPrefLocalizedString
);
localizedStr.data = "engine-rel-searchform-purpose";
Services.prefs.setComplexValue(
SearchUtils.BROWSER_SEARCH_PREF + "order.1",
Ci.nsIPrefLocalizedString,
localizedStr
);
localizedStr = Cc["@mozilla.org/pref-localizedstring;1"].createInstance(
Ci.nsIPrefLocalizedString
);
localizedStr.data = "engine-chromeicon";
Services.prefs.setComplexValue(
SearchUtils.BROWSER_SEARCH_PREF + "order.2",
Ci.nsIPrefLocalizedString,
localizedStr
);
// TODO: Bug 1590860. The order of the lists is wrong - the order prefs should
// be overriding it, but they don't because the code doesn't work right.
const expected = modernConfig
? [
"Test search engine",
"engine-pref",
"engine-resourceicon",
"engine-chromeicon",
"engine-rel-searchform-purpose",
"Test search engine (Reordered)",
]
: [
"engine-pref",
"engine-rel-searchform-purpose",
"engine-resourceicon",
"engine-chromeicon",
"Test search engine",
"Test search engine (Reordered)",
];
await checkOrder(expected);
});