Bug 508102 - Warning: reference to undefined property this._pendingQuery / Location bar autocomplete doesn't work anymore
authorShawn Wilsher <sdwilsh@shawnwilsher.com>
Thu, 10 Sep 2009 10:55:33 -0700
changeset 32362 a1d8b365bc51644385689d22e8b0530ad72068f3
parent 32361 94b823431cc060e1aac0c495b3181851ef5c34be
child 32363 3075967d091a05616f8daa4d95809630aef7117b
push id9031
push usersdwilsh@shawnwilsher.com
push dateThu, 10 Sep 2009 18:23:48 +0000
treeherdermozilla-central@a1d8b365bc51 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs508102
milestone1.9.3a1pre
Bug 508102 - Warning: reference to undefined property this._pendingQuery / Location bar autocomplete doesn't work anymore Stop throwing if stopSearch is called without a call to startSearch. r=dietrich
toolkit/components/places/src/nsPlacesAutoComplete.js
toolkit/components/places/tests/unit/test_autocomplete_stopSearch_no_throw.js
--- a/toolkit/components/places/src/nsPlacesAutoComplete.js
+++ b/toolkit/components/places/src/nsPlacesAutoComplete.js
@@ -420,17 +420,20 @@ nsPlacesAutoComplete.prototype = {
     // Set up our persistent state for the duration of the search.
     this._searchTokens = tokens;
     this._usedPlaceIds = {};
   },
 
   stopSearch: function PAC_stopSearch()
   {
     // We need to cancel our searches so we do not get any [more] results.
-    this._stopActiveQuery();
+    // However, it's possible we haven't actually started any searches, so this
+    // method may throw because this._pendingQuery may be undefined.
+    if (this._pendingQuery)
+      this._stopActiveQuery();
 
     this._finishSearch(false);
   },
 
   //////////////////////////////////////////////////////////////////////////////
   //// nsIAutoCompleteSimpleResultListener
 
   onValueRemoved: function PAC_onValueRemoved(aResult, aURISpec, aRemoveFromDB)
new file mode 100644
--- /dev/null
+++ b/toolkit/components/places/tests/unit/test_autocomplete_stopSearch_no_throw.js
@@ -0,0 +1,73 @@
+/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim:set ts=2 sw=2 sts=2 et: */
+/* ***** BEGIN LICENSE BLOCK *****
+ * Version: MPL 1.1/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Original Code is mozilla.org code.
+ *
+ * The Initial Developer of the Original Code is
+ * Mozilla Corporation.
+ * Portions created by the Initial Developer are Copyright (C) 2009
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *   Shawn Wilsher <me@shawnwilsher.com> (Original Author)
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 2 or later (the "GPL"), or
+ * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * use your version of this file under the terms of the MPL, indicate your
+ * decision by deleting the provisions above and replace them with the notice
+ * and other provisions required by the GPL or the LGPL. If you do not delete
+ * the provisions above, a recipient may use your version of this file under
+ * the terms of any one of the MPL, the GPL or the LGPL.
+ *
+ * ***** END LICENSE BLOCK ***** */
+
+/**
+ * Added with bug 508102 to make sure that calling stopSearch on our
+ * AutoComplete implementation does not throw.
+ */
+
+////////////////////////////////////////////////////////////////////////////////
+//// Globals and Constants
+
+let ac = Cc["@mozilla.org/autocomplete/search;1?name=history"].
+         getService(Ci.nsIAutoCompleteSearch);
+
+////////////////////////////////////////////////////////////////////////////////
+//// Test Functions
+
+function test_stopSearch()
+{
+  try {
+    ac.stopSearch();
+  }
+  catch (e) {
+    do_throw("we should not have caught anything!");
+  }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+//// Test Runner
+
+let tests = [
+  test_stopSearch,
+];
+function run_test()
+{
+  tests.forEach(function(test) test());
+}