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
This commit is contained in:
Gavin Sharp 2013-06-17 14:00:11 -04:00
parent 72bebb943c
commit 659a01fbc0
3 changed files with 20 additions and 11 deletions

View File

@ -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;
},

View File

@ -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();

View File

@ -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]