Bug 739751 - Don't inline autocomplete results shorter than the searcString to avoid confusing in-the-middle autocomplete.
authorMarco Bonardo <mbonardo@mozilla.com>
Sat, 07 Apr 2012 00:40:01 +0200
changeset 94516 a6527fdc59f4a7f40a54c943389a4ac46d5f4ec2
parent 94515 fcd6861385da970ea2cdd7c2d4700b57571e57ba
child 94517 8e494b6b36ef52abac5245c2e5a4b382579c75ec
push id886
push userlsblakk@mozilla.com
push dateMon, 04 Jun 2012 19:57:52 +0000
treeherdermozilla-beta@bbd8d5efd6d1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs739751
milestone14.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 739751 - Don't inline autocomplete results shorter than the searcString to avoid confusing in-the-middle autocomplete. r=gavin
toolkit/components/places/nsPlacesAutoComplete.js
toolkit/components/places/tests/inline/test_do_not_trim.js
toolkit/components/places/tests/inline/xpcshell.ini
--- a/toolkit/components/places/nsPlacesAutoComplete.js
+++ b/toolkit/components/places/nsPlacesAutoComplete.js
@@ -1384,16 +1384,25 @@ urlInlineComplete.prototype = {
     // hashed on first use, so while the first query may delay a little bit,
     // next ones will just hit the memory hash.
     if (this._currentSearchString.length == 0 || !this._db ||
         PlacesUtils.bookmarks.getURIForKeyword(this._currentSearchString)) {
       this._finishSearch();
       return;
     }
 
+    // Don't try to autofill if the search term includes any whitespace.
+    // This may confuse completeDefaultIndex cause the AUTOCOMPLETE_MATCH
+    // tokenizer ends up trimming the search string and returning a value
+    // that doesn't match it, or is even shorter.
+    if (/\s/.test(this._currentSearchString)) {
+      this._finishSearch();
+      return;
+    }
+
     // Do a synchronous search on the table of domains.
     let query = this._syncQuery;
     query.params.search_string = this._currentSearchString.toLowerCase();
 
     // Domains have no "/" in them.
     let lastSlashIndex = this._currentSearchString.lastIndexOf("/");
     if (lastSlashIndex == -1) {
       var hasDomainResult = false;
new file mode 100644
--- /dev/null
+++ b/toolkit/components/places/tests/inline/test_do_not_trim.js
@@ -0,0 +1,67 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this file,
+ * You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+// Inline should never return matches shorter than the search string, since
+// that largely confuses completeDefaultIndex
+
+add_autocomplete_test([
+  "Do not autofill whitespaced entry 1",
+  "mozilla.org ",
+  "mozilla.org ",
+  function () {
+    addVisits({ uri: NetUtil.newURI("http://mozilla.org/link/"),
+                transition: TRANSITION_TYPED });
+  }
+]);
+
+add_autocomplete_test([
+  "Do not autofill whitespaced entry 2",
+  "mozilla.org/ ",
+  "mozilla.org/ ",
+  function () {
+    addVisits({ uri: NetUtil.newURI("http://mozilla.org/link/"),
+                transition: TRANSITION_TYPED });
+  }
+]);
+
+add_autocomplete_test([
+  "Do not autofill whitespaced entry 3",
+  "mozilla.org/link ",
+  "mozilla.org/link ",
+  function () {
+    addVisits({ uri: NetUtil.newURI("http://mozilla.org/link/"),
+                transition: TRANSITION_TYPED });
+  }
+]);
+
+add_autocomplete_test([
+  "Do not autofill whitespaced entry 4",
+  "mozilla.org/link/ ",
+  "mozilla.org/link/ ",
+  function () {
+    addVisits({ uri: NetUtil.newURI("http://mozilla.org/link/"),
+                transition: TRANSITION_TYPED });
+  }
+]);
+
+
+add_autocomplete_test([
+  "Do not autofill whitespaced entry 5",
+  "moz illa ",
+  "moz illa ",
+  function () {
+    addVisits({ uri: NetUtil.newURI("http://mozilla.org/link/"),
+                transition: TRANSITION_TYPED });
+  }
+]);
+
+add_autocomplete_test([
+  "Do not autofill whitespaced entry 6",
+  " mozilla",
+  " mozilla",
+  function () {
+    addVisits({ uri: NetUtil.newURI("http://mozilla.org/link/"),
+                transition: TRANSITION_TYPED });
+  }
+]);
--- a/toolkit/components/places/tests/inline/xpcshell.ini
+++ b/toolkit/components/places/tests/inline/xpcshell.ini
@@ -1,8 +1,9 @@
 [DEFAULT]
 head = head_autocomplete.js
 tail = 
 
 [test_autocomplete_functional.js]
 [test_casing.js]
+[test_do_not_trim.js]
 [test_keywords.js]
 [test_typed.js]