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
|
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
const testPref = "Foo,FooDupe";
function promiseNewEngine(basename) {
return new Promise((resolve, reject) => {
info("Waiting for engine to be added: " + basename);
Services.search.init({
onInitComplete: function() {
let url = getRootDirectory(gTestPath) + basename;
Services.search.addEngine(url, null, "", false, {
onSuccess: function (engine) {
info("Search engine added: " + basename);
resolve(engine);
},
onError: function (errCode) {
ok(false, "addEngine failed with error code " + errCode);
reject();
}
});
}
});
});
}
add_task(function* test_remove() {
yield promiseNewEngine("testEngine_dupe.xml");
yield promiseNewEngine("testEngine.xml");
Services.prefs.setCharPref("browser.search.hiddenOneOffs", testPref);
info("Removing testEngine_dupe.xml");
Services.search.removeEngine(Services.search.getEngineByName("FooDupe"));
let hiddenOneOffs =
Services.prefs.getCharPref("browser.search.hiddenOneOffs").split(",");
is(hiddenOneOffs.length, 1,
"hiddenOneOffs has the correct engine count post removal.");
is(hiddenOneOffs.some(x => x == "FooDupe"), false,
"Removed Engine is not in hiddenOneOffs after removal");
is(hiddenOneOffs.some(x => x == "Foo"), true,
"Current hidden engine is not affected by removal.");
info("Removing testEngine.xml");
Services.search.removeEngine(Services.search.getEngineByName("Foo"));
is(Services.prefs.getCharPref("browser.search.hiddenOneOffs"), "",
"hiddenOneOffs is empty after removing all hidden engines.");
});
add_task(function* test_add() {
yield promiseNewEngine("testEngine.xml");
info("setting prefs to " + testPref);
Services.prefs.setCharPref("browser.search.hiddenOneOffs", testPref);
yield promiseNewEngine("testEngine_dupe.xml");
let hiddenOneOffs =
Services.prefs.getCharPref("browser.search.hiddenOneOffs").split(",");
is(hiddenOneOffs.length, 1,
"hiddenOneOffs has the correct number of hidden engines present post add.");
is(hiddenOneOffs.some(x => x == "FooDupe"), false,
"Added engine is not present in hidden list.");
is(hiddenOneOffs.some(x => x == "Foo"), true,
"Adding an engine does not remove engines from hidden list.");
});
add_task(function* test_diacritics() {
const diacritic_engine = "Foo \u2661";
let Preferences =
Cu.import("resource://gre/modules/Preferences.jsm", {}).Preferences;
Preferences.set("browser.search.hiddenOneOffs", diacritic_engine);
yield promiseNewEngine("testEngine_diacritics.xml");
let hiddenOneOffs =
Preferences.get("browser.search.hiddenOneOffs").split(",");
is(hiddenOneOffs.some(x => x == diacritic_engine), false,
"Observer cleans up added hidden engines that include a diacritic.");
Preferences.set("browser.search.hiddenOneOffs", diacritic_engine);
info("Removing testEngine_diacritics.xml");
Services.search.removeEngine(Services.search.getEngineByName(diacritic_engine));
hiddenOneOffs =
Preferences.get("browser.search.hiddenOneOffs").split(",");
is(hiddenOneOffs.some(x => x == diacritic_engine), false,
"Observer cleans up removed hidden engines that include a diacritic.");
});
registerCleanupFunction(() => {
info("Removing testEngine.xml");
Services.search.removeEngine(Services.search.getEngineByName("Foo"));
info("Removing testEngine_dupe.xml");
Services.search.removeEngine(Services.search.getEngineByName("FooDupe"));
Services.prefs.clearUserPref("browser.search.hiddenOneOffs");
});
|