Bug 1097942 - add UITour mechanism for selecting an engine, r=Unfocused

This commit is contained in:
Gavin Sharp 2014-11-12 12:53:15 -08:00
parent d40c85430c
commit f9a860c734
3 changed files with 63 additions and 0 deletions

View File

@ -521,6 +521,12 @@ this.UITour = {
}).catch(log.error);
break;
}
case "setDefaultSearchEngine": {
let enginePromise = this.selectSearchEngine(data.identifier);
enginePromise.catch(Cu.reportError);
break;
}
}
if (!window.gMultiProcessBrowser) { // Non-e10s. See bug 1089000.
@ -1397,6 +1403,26 @@ this.UITour = {
}
},
selectSearchEngine(aID) {
return new Promise((resolve, reject) => {
Services.search.init((rv) => {
if (!Components.isSuccessCode(rv)) {
reject("selectSearchEngine: search service init failed: " + rv);
return;
}
let engines = Services.search.getVisibleEngines();
for (let engine of engines) {
if (engine.identifier == aID) {
Services.search.defaultEngine = engine;
return resolve();
}
}
reject("selectSearchEngine could not find engine with given ID");
});
});
},
getAvailableSearchEngineTargets(aWindow) {
return new Promise(resolve => {
this.getTarget(aWindow, "search").then(searchTarget => {

View File

@ -369,6 +369,37 @@ let tests = [
});
});
},
function test_select_search_engine(done) {
Services.search.init(rv => {
if (!Components.isSuccessCode(rv)) {
ok(false, "search service init failed: " + rv);
done();
return;
}
let defaultEngine = Services.search.defaultEngine;
gContentAPI.getConfiguration("availableTargets", data => {
let searchEngines = data.targets.filter(t => t.startsWith("searchEngine-"));
let someOtherEngineID = searchEngines.filter(t => t != "searchEngine-" + defaultEngine.identifier)[0];
someOtherEngineID = someOtherEngineID.replace(/^searchEngine-/, "");
let observe = function (subject, topic, verb) {
info("browser-search-engine-modified: " + verb);
if (verb == "engine-current") {
is(Services.search.defaultEngine.identifier, someOtherEngineID, "correct engine was switched to");
done();
}
};
Services.obs.addObserver(observe, "browser-search-engine-modified", false);
registerCleanupFunction(() => {
// Clean up
Services.obs.removeObserver(observe, "browser-search-engine-modified");
Services.search.defaultEngine = defaultEngine;
});
gContentAPI.setDefaultSearchEngine(someOtherEngineID);
});
});
},
// Make sure this test is last in the file so the appMenu gets left open and done will confirm it got tore down.
taskify(function* cleanupMenus() {

View File

@ -207,4 +207,10 @@ if (typeof Mozilla == 'undefined') {
});
};
Mozilla.UITour.setDefaultSearchEngine = function(identifier) {
_sendEvent('setDefaultSearchEngine', {
identifier: identifier,
});
};
})();