Bug 438599 - the currentEngine attribute of nsIBrowserSearchService should never be null, r=Mossop.
authorFlorian Quèze <florian@queze.net>
Fri, 04 Sep 2015 11:39:08 +0200
changeset 260856 3a6613c338c2
parent 260855 d3d166232d2d
child 260857 6bde454912d5
push id29328
push userkwierso@gmail.com
push dateFri, 04 Sep 2015 22:13:38 +0000
treeherdermozilla-central@d41fa6f2f1da [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersMossop
bugs438599
milestone43.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
Bug 438599 - the currentEngine attribute of nsIBrowserSearchService should never be null, r=Mossop.
toolkit/components/search/nsSearchService.js
toolkit/components/search/tests/xpcshell/test_currentEngine_fallback.js
toolkit/components/search/tests/xpcshell/xpcshell.ini
--- a/toolkit/components/search/nsSearchService.js
+++ b/toolkit/components/search/nsSearchService.js
@@ -4911,16 +4911,24 @@ SearchService.prototype = {
         this._currentEngine = this.getEngineByName(name);
       }
     }
 
     if (!this._currentEngine || this._currentEngine.hidden)
       this._currentEngine = this._originalDefaultEngine;
     if (!this._currentEngine || this._currentEngine.hidden)
       this._currentEngine = this._getSortedEngines(false)[0];
+
+    if (!this._currentEngine) {
+      // Last resort fallback: unhide the original default engine.
+      this._currentEngine = this._originalDefaultEngine;
+      if (this._currentEngine)
+        this._currentEngine.hidden = false;
+    }
+
     return this._currentEngine;
   },
 
   set currentEngine(val) {
     this._ensureInitialized();
     // Sometimes we get wrapped nsISearchEngine objects (external XPCOM callers),
     // and sometimes we get raw Engine JS objects (callers in this file), so
     // handle both.
new file mode 100644
--- /dev/null
+++ b/toolkit/components/search/tests/xpcshell/test_currentEngine_fallback.js
@@ -0,0 +1,25 @@
+/* Any copyright is dedicated to the Public Domain.
+   http://creativecommons.org/publicdomain/zero/1.0/ */
+
+function run_test() {
+  do_check_true(Services.search.getVisibleEngines().length > 1);
+  do_check_true(Services.search.isInitialized);
+
+  // Remove the current engine...
+  let currentEngine = Services.search.currentEngine;
+  Services.search.removeEngine(currentEngine);
+
+  // ... and verify a new current engine has been set.
+  do_check_neq(Services.search.currentEngine.name, currentEngine.name);
+  do_check_true(currentEngine.hidden);
+
+  // Remove all the other engines.
+  Services.search.getVisibleEngines().forEach(Services.search.removeEngine);
+  do_check_eq(Services.search.getVisibleEngines().length, 0);
+
+  // Verify the original default engine is used as a fallback and no
+  // longer hidden.
+  do_check_eq(Services.search.currentEngine.name, currentEngine.name);
+  do_check_false(currentEngine.hidden);
+  do_check_eq(Services.search.getVisibleEngines().length, 1);
+}
--- a/toolkit/components/search/tests/xpcshell/xpcshell.ini
+++ b/toolkit/components/search/tests/xpcshell/xpcshell.ini
@@ -77,8 +77,9 @@ tags = addons
 [test_sync_distribution.js]
 [test_sync_fallback.js]
 [test_sync_delay_fallback.js]
 [test_sync_profile_engine.js]
 [test_rel_searchform.js]
 [test_selectedEngine.js]
 [test_geodefaults.js]
 [test_hidden.js]
+[test_currentEngine_fallback.js]