From 659a01fbc0d6b53a79da0de217007430f5ca501c Mon Sep 17 00:00:00 2001 From: Gavin Sharp Date: Mon, 17 Jun 2013 14:00:11 -0400 Subject: [PATCH] Bug 867108: hiding and then restoring the default search engine leads to the wrong engine being returned from searchService.defaultEngine until a restart, r=mikedeboer --HG-- rename : toolkit/components/search/tests/xpcshell/test_engineselect.js => toolkit/components/search/tests/xpcshell/test_defaultEngine.js extra : transplant_source : %2C%EE2%EF%EA%8Ak%D8%18%21%BB%98%18%14%BE%E9t%82%7C%BF --- toolkit/components/search/nsSearchService.js | 6 +++-- ..._engineselect.js => test_defaultEngine.js} | 23 ++++++++++++------- .../search/tests/xpcshell/xpcshell.ini | 2 +- 3 files changed, 20 insertions(+), 11 deletions(-) rename toolkit/components/search/tests/xpcshell/{test_engineselect.js => test_defaultEngine.js} (79%) diff --git a/toolkit/components/search/nsSearchService.js b/toolkit/components/search/nsSearchService.js index c6586c6efad3..8a154c15a86e 100644 --- a/toolkit/components/search/nsSearchService.js +++ b/toolkit/components/search/nsSearchService.js @@ -3505,13 +3505,15 @@ SearchService.prototype = { get defaultEngine() { this._ensureInitialized(); - if (!this._defaultEngine || this._defaultEngine.hidden) { + if (!this._defaultEngine) { let defPref = BROWSER_SEARCH_PREF + "defaultenginename"; let defaultEngine = this.getEngineByName(getLocalizedPref(defPref, "")) - if (!defaultEngine || defaultEngine.hidden) + if (!defaultEngine) defaultEngine = this._getSortedEngines(false)[0] || null; this._defaultEngine = defaultEngine; } + if (this._defaultEngine.hidden) + return this._getSortedEngines(false)[0]; return this._defaultEngine; }, diff --git a/toolkit/components/search/tests/xpcshell/test_engineselect.js b/toolkit/components/search/tests/xpcshell/test_defaultEngine.js similarity index 79% rename from toolkit/components/search/tests/xpcshell/test_engineselect.js rename to toolkit/components/search/tests/xpcshell/test_defaultEngine.js index 86796ba393d9..7c35e8fcb662 100644 --- a/toolkit/components/search/tests/xpcshell/test_engineselect.js +++ b/toolkit/components/search/tests/xpcshell/test_defaultEngine.js @@ -44,22 +44,29 @@ function search_observer(aSubject, aTopic, aData) { search.defaultEngine = engine1; do_check_eq(search.defaultEngine, engine1); - - // Tests search defaultEngine when it changes search.defaultEngine = engine2 do_check_eq(search.defaultEngine, engine2); - - // Test search defaultEngine again when we change back search.defaultEngine = engine1; do_check_eq(search.defaultEngine, engine1); - // Test search defaultEngine when the current default is hidden + // Test that hiding the currently-default engine affects the defaultEngine getter + // (when the default is hidden, we fall back to the first in the list, so move + // our second engine to that position) search.moveEngine(engine2, 0); engine1.hidden = true; do_check_eq(search.defaultEngine, engine2); - - // Test search defaultEngine when it is set to a hidden engine - search.defaultEngine = engine1; + + // Test that the default engine is restored when it is unhidden + engine1.hidden = false; + do_check_eq(search.defaultEngine, engine1); + + // Test that setting defaultEngine to an already-hidden engine works, but + // doesn't change the return value of the getter + engine2.hidden = true; + search.moveEngine(engine1, 0) + search.defaultEngine = engine2; + do_check_eq(search.defaultEngine, engine1); + engine2.hidden = false; do_check_eq(search.defaultEngine, engine2); do_test_finished(); diff --git a/toolkit/components/search/tests/xpcshell/xpcshell.ini b/toolkit/components/search/tests/xpcshell/xpcshell.ini index 0284535f3738..282d2ba9a068 100644 --- a/toolkit/components/search/tests/xpcshell/xpcshell.ini +++ b/toolkit/components/search/tests/xpcshell/xpcshell.ini @@ -16,7 +16,7 @@ skip-if = debug && os == "linux" [test_nodb_pluschanges.js] [test_save_sorted_engines.js] [test_purpose.js] -[test_engineselect.js] +[test_defaultEngine.js] [test_prefSync.js] [test_notifications.js] [test_addEngine_callback.js]