mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
ac9532722d
--HG-- extra : rebase_source : f4f501e6246bc9515792890a4229078185b07464
77 lines
2.9 KiB
JavaScript
77 lines
2.9 KiB
JavaScript
/* 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 cachedPref = Services.prefs.getCharPref("browser.search.hiddenOneOffs");
|
|
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, Ci.nsISearchEngine.TYPE_MOZSEARCH, "", 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.includes("FooDupe"), false,
|
|
"Removed Engine is not in hiddenOneOffs after removal");
|
|
is(hiddenOneOffs.includes("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.includes("FooDupe"), false,
|
|
"Added engine is not present in hidden list.");
|
|
is(hiddenOneOffs.includes("Foo"), true,
|
|
"Adding an engine does not remove engines from hidden list.");
|
|
});
|
|
|
|
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.setCharPref("browser.search.hiddenOneOffs", cachedPref);
|
|
});
|