Bug 1466484 - Added remove to SearchEngines Policy r=Felipe

MozReview-Commit-ID: 6g3qp6q605i

--HG--
extra : rebase_source : 139d1d894b0df19eb394ace421c9bea58a86aa27
This commit is contained in:
Kanika Saini 2018-06-11 21:36:15 +05:30
parent 4a109a3f01
commit e22513785d
3 changed files with 59 additions and 0 deletions

View File

@ -646,6 +646,23 @@ var Policies = {
},
onAllWindowsRestored(manager, param) {
Services.search.init(() => {
if (param.Remove) {
// Only rerun if the list of engine names has changed.
runOncePerModification("removeSearchEngines",
JSON.stringify(param.Remove),
() => {
for (let engineName of param.Remove) {
let engine = Services.search.getEngineByName(engineName);
if (engine) {
try {
Services.search.removeEngine(engine);
} catch (ex) {
log.error("Unable to remove the search engine", ex);
}
}
}
});
}
if (param.Add) {
// Only rerun if the list of engine names has changed.
let engineNameList = param.Add.map(engine => engine.Name);

View File

@ -601,6 +601,12 @@
},
"PreventInstalls": {
"type": "boolean"
},
"Remove": {
"type": "array",
"items": {
"type": "string"
}
}
}
},

View File

@ -192,3 +192,39 @@ add_task(async function test_AddSearchProvider() {
is(mockPrompter.promptCount, 1,
"Should have alerted the user of an error when installing new search engine");
});
add_task(async function test_install_and_remove() {
is(Services.search.getEngineByName("Foo"), null,
"Engine \"Foo\" should not be present when test starts");
await setupPolicyEngineWithJson({
"policies": {
"SearchEngines": {
"Add": [
{
"Name": "Foo",
"URLTemplate": "http://example.com/?q={searchTerms}"
}
]
}
}
});
// If this passes, it means that the new search engine was properly installed
isnot(Services.search.getEngineByName("Foo"), null,
"Specified search engine should be installed");
await setupPolicyEngineWithJson({
"policies": {
"SearchEngines": {
"Remove": ["Foo"]
}
}
});
// If this passes, it means that the specified engine was properly removed
is(Services.search.getEngineByName("Foo"), null,
"Specified search engine should not be installed");
EnterprisePolicyTesting.resetRunOnceState();
});