Bug 1180827 - Fix reuse of previous search results. r=MattN, a=ritu
authorBlake Kaplan <mrbkap@gmail.com>
Thu, 16 Jul 2015 13:34:40 -0700
changeset 281738 e936bc5444ad1d5b0abd6c45c7eb9cd1c3f52e86
parent 281737 619f2707ec0de0dcc6924e7437a44ddb4b927bc4
child 281739 16c7bedeca10bb48e4e0a5d6f9b16d5868e83bbb
push id4932
push userjlund@mozilla.com
push dateMon, 10 Aug 2015 18:23:06 +0000
treeherdermozilla-beta@6dd5a4f5f745 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersMattN, ritu
bugs1180827
milestone41.0a2
Bug 1180827 - Fix reuse of previous search results. r=MattN, a=ritu
toolkit/components/satchel/nsFormAutoComplete.js
toolkit/components/satchel/test/test_form_autocomplete_with_list.html
--- a/toolkit/components/satchel/nsFormAutoComplete.js
+++ b/toolkit/components/satchel/nsFormAutoComplete.js
@@ -211,31 +211,31 @@ FormAutoComplete.prototype = {
             // the way we abuse the formfill autocomplete API in e10s, we have
             // to deal with the <datalist> results here as well (and down below
             // in mergeResults).
             // If there were datalist results result is a FormAutoCompleteResult
             // as defined in nsFormAutoCompleteResult.jsm with the entire list
             // of results in wrappedResult._values and only the results from
             // form history in wrappedResults.entries.
             // First, grab the entire list of old results.
-            let allResults = wrappedResult._values;
+            let allResults = wrappedResult._labels;
             let datalistResults, datalistLabels;
             if (allResults) {
                 // We have datalist results, extract them from the values array.
-                datalistResults = allResults.slice(wrappedResult.entries.length);
+                datalistLabels = allResults.slice(wrappedResult.entries.length);
                 let filtered = [];
-                datalistLabels = [];
-                for (let i = datalistResults.length; i > 0; --i) {
-                    if (datalistResults[i - 1].contains(searchString)) {
-                        filtered.push(datalistResults[i - 1]);
-                        datalistLabels.push(wrappedResult._labels[i - 1]);
+                datalistResults = [];
+                for (let i = 0; i < datalistLabels.length; ++i) {
+                    if (datalistLabels[i].toLowerCase().includes(searchString)) {
+                        filtered.push(datalistLabels[i]);
+                        datalistResults.push(wrappedResult._values[i]);
                     }
                 }
 
-                datalistResults = filtered;
+                datalistLabels = filtered;
             }
 
             let searchTokens = searchString.split(/\s+/);
             // We have a list of results for a shorter search string, so just
             // filter them further based on the new search string and add to a new array.
             let entries = wrappedResult.entries;
             let filteredEntries = [];
             for (let i = 0; i < entries.length; i++) {
--- a/toolkit/components/satchel/test/test_form_autocomplete_with_list.html
+++ b/toolkit/components/satchel/test/test_form_autocomplete_with_list.html
@@ -198,16 +198,38 @@ function runTest() {
     case 9:
         //Test deletion
         checkMenuEntries(["PASS1", "PASS2", "final"], testNum);
         // Check the new first entry (of 3)
         doKey("down");
         doKey("return");
         checkForm("Google");
 
+        expectPopup();
+        restoreForm();
+        doKey("down");
+        break;
+
+    case 10:
+        // Test autocompletion of datalists with cached results.
+        sendString("PAS");
+        waitForMenuChange(2);
+        break;
+
+    case 11:
+        // Continuation of test 10
+        sendString("S1");
+        waitForMenuChange(1);
+        break;
+
+    case 12:
+        doKey("down");
+        doKey("return");
+        checkForm("Google");
+
         // Trigger autocomplete popup
         // Look at form 3, try to trigger autocomplete popup
         input.value = "";
         input = $_(3, "field2");
         testNum = 99;
         expectPopup();
         restoreForm();
         doKey("down");