author | Mark Banner <standard8@mozilla.com> |
Mon, 24 Jun 2019 14:42:58 +0000 | |
changeset 479967 | 7877de0a1529873bca86c012608249e7bf4cae2d |
parent 479966 | 49799d8989589e9efc34091979ab77a5d2ff53c1 |
child 479968 | 21826fb830de97ce71635ad784acf5a0b0bf237c |
push id | 36197 |
push user | aciure@mozilla.com |
push date | Tue, 25 Jun 2019 09:39:03 +0000 |
treeherder | mozilla-central@5bfd0011c6e3 [default view] [failures only] |
perfherder | [talos] [build metrics] [platform microbench] (compared to previous push) |
reviewers | daleharvey |
bugs | 1560424 |
milestone | 69.0a1 |
first release with | nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
|
last release without | nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
|
--- a/toolkit/components/search/SearchService.jsm +++ b/toolkit/components/search/SearchService.jsm @@ -2243,16 +2243,34 @@ SearchService.prototype = { return this.defaultEngine; }, async setDefault(engine) { await this.init(true); return this.defaultEngine = engine; }, + get defaultPrivateEngine() { + return this.defaultEngine; + }, + + set defaultPrivateEngine(engine) { + return this.defaultEngine = engine; + }, + + async getDefaultPrivate() { + await this.init(true); + return this.defaultEngine; + }, + + async setDefaultPrivate(engine) { + await this.init(true); + return this.defaultEngine = engine; + }, + async getDefaultEngineInfo() { let result = {}; let engine; try { engine = await this.getDefault(); } catch (e) { // The defaultEngine getter will throw if there's no engine at all,
--- a/toolkit/components/search/nsISearchService.idl +++ b/toolkit/components/search/nsISearchService.idl @@ -295,17 +295,17 @@ interface nsISearchService : nsISupports * * @param name * The search engine's name. Must be unique. Must not be null. * * @param details * An object that can contain the following fields: * * {iconURL} Optional: A URL string pointing to the icon to be used to - * represent the engine. + * represent the engine. * * {alias} Optional: A unique shortcut that can be used to retrieve the * search engine. * * {description} Optional: A description of the search engine. * * {method} Optional: The HTTP request method used when submitting a * search query. Case insensitive value of either "get" or "post". @@ -443,16 +443,25 @@ interface nsISearchService : nsISupports * default engine. */ attribute nsISearchEngine defaultEngine; Promise getDefault(); Promise setDefault(in nsISearchEngine engine); /** + * The currently active search engine for private browsing mode. + * @see defaultEngine. + */ + attribute nsISearchEngine defaultPrivateEngine; + + Promise getDefaultPrivate(); + Promise setDefaultPrivate(in nsISearchEngine engine); + + /** * Gets a representation of the default engine in an anonymized JSON * string suitable for recording in the Telemetry environment. * * @return an object containing anonymized info about the default engine: * name, loadPath, submissionURL (for default engines). */ Promise getDefaultEngineInfo();
new file mode 100644 --- /dev/null +++ b/toolkit/components/search/tests/xpcshell/test_defaultPrivateEngine.js @@ -0,0 +1,49 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ */ + +/* + * Test that defaultEngine property can be set and yields the proper events and\ + * behavior (search results) + */ + +"use strict"; + +add_task(async function setup() { + useHttpServer(); + await AddonTestUtils.promiseStartupManager(); +}); + +add_task(async function test_defaultPrivateEngine() { + let search = Services.search; + await search.init(); + + let originalDefault = search.defaultPrivateEngine; + + let [engine1, engine2] = await addTestEngines([ + { name: "Test search engine", xmlFileName: "engine.xml" }, + { name: "A second test engine", xmlFileName: "engine2.xml" }, + ]); + + search.defaultPrivateEngine = engine1; + Assert.equal(search.defaultPrivateEngine, engine1); + search.defaultPrivateEngine = engine2; + Assert.equal(search.defaultPrivateEngine, engine2); + search.defaultPrivateEngine = engine1; + Assert.equal(search.defaultPrivateEngine, engine1); + + // Test that hiding the currently-default engine affects the defaultEngine getter + // We fallback first to the original default... + engine1.hidden = true; + Assert.equal(search.defaultPrivateEngine, originalDefault); + + // ... and then to the first visible engine in the list, so move our second + // engine to that position. + await search.moveEngine(engine2, 0); + originalDefault.hidden = true; + Assert.equal(search.defaultPrivateEngine, engine2); + + // Test that setting defaultEngine to an already-hidden engine works, but + // doesn't change the return value of the getter + search.defaultPrivateEngine = engine1; + Assert.equal(search.defaultPrivateEngine, engine2); +});
--- a/toolkit/components/search/tests/xpcshell/xpcshell.ini +++ b/toolkit/components/search/tests/xpcshell/xpcshell.ini @@ -73,16 +73,17 @@ support-files = data/search_ignorelist.j [test_location_error.js] [test_location_malformed_json.js] [test_location_timeout.js] [test_location_timeout_xhr.js] [test_nodb_pluschanges.js] [test_save_sorted_engines.js] [test_pref.js] [test_defaultEngine.js] +[test_defaultPrivateEngine.js] [test_notifications.js] [test_parseSubmissionURL.js] [test_SearchStaticData.js] [test_addEngine_callback.js] [test_multipleIcons.js] [test_resultDomain.js] [test_searchSuggest.js] [test_searchSuggest_cookies.js]