mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1097942 - add UITour mechanism for selecting an engine, r=Unfocused
This commit is contained in:
parent
d40c85430c
commit
f9a860c734
@ -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 => {
|
||||
|
@ -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() {
|
||||
|
@ -207,4 +207,10 @@ if (typeof Mozilla == 'undefined') {
|
||||
});
|
||||
};
|
||||
|
||||
Mozilla.UITour.setDefaultSearchEngine = function(identifier) {
|
||||
_sendEvent('setDefaultSearchEngine', {
|
||||
identifier: identifier,
|
||||
});
|
||||
};
|
||||
|
||||
})();
|
||||
|
Loading…
Reference in New Issue
Block a user