Bug 896142 - Entries appearing twice in form-fill autocomplete menus. r=mhammond, a=bbajaj
authorNeil Deakin <neil@mozilla.com>
Wed, 04 Sep 2013 16:14:20 -0400
changeset 153949 acc893e11f2ba2770398cd8dc157f3f5d3b02a80
parent 153948 2a70b9450fc1a81a44f93a29e18cebcca512ed0a
child 153950 0618521e6e13377f69fb1b09b71ab7f959a765cc
push id2859
push userakeybl@mozilla.com
push dateMon, 16 Sep 2013 19:14:59 +0000
treeherdermozilla-beta@87d3c51cd2bf [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmhammond, bbajaj
bugs896142
milestone25.0a2
Bug 896142 - Entries appearing twice in form-fill autocomplete menus. r=mhammond, a=bbajaj
toolkit/components/satchel/FormHistory.jsm
toolkit/components/satchel/test/unit/test_history_api.js
--- a/toolkit/components/satchel/FormHistory.jsm
+++ b/toolkit/components/satchel/FormHistory.jsm
@@ -13,17 +13,17 @@
  *     terms - array of terms to return data for
  *     queryData - object that contains the query terms
  *       The query object contains properties for each search criteria to match, where the value
  *       of the property specifies the value that term must have. For example,
  *       { term1: value1, term2: value2 }
  *     callback - callback that is called when results are available or an error occurs.
  *       The callback is passed a result array containing each found entry. Each element in
  *       the array is an object containing a property for each search term specified by 'terms'.
- * count(terms, queryData, callback)
+ * count(queryData, callback)
  *   Find the number of stored entries that match the given criteria.
  *     queryData - array of objects that indicate the query. See the search method for details.
  *     callback - callback that is called when results are available or an error occurs.
  *       The callback is passed the number of found entries.
  * update(changes, callback)
  *    Write data to form history storage.
  *      changes - an array of changes to be made. If only one change is to be made, it
  *                may be passed as an object rather than a one-element array.
@@ -898,16 +898,17 @@ this.FormHistory = {
           break;
         default:
           throw Components.Exception(
             "update does not recognize op='" + change.op + "'",
             Cr.NS_ERROR_ILLEGAL_VALUE);
       }
 
       numSearches++;
+      let changeToUpdate = change;
       FormHistory.search(
         [ "guid" ],
         {
           fieldname : change.fieldname,
           value : change.value
         }, {
           foundResult : false,
           handleResult : function(aResult) {
@@ -921,17 +922,17 @@ this.FormHistory = {
                 });
               }
 
               searchFailed = true;
               return;
             }
 
             this.foundResult = true;
-            change.guid = aResult["guid"];
+            changeToUpdate.guid = aResult["guid"];
           },
 
           handleError : function(aError) {
             if (aCallbacks && aCallbacks.handleError) {
               aCallbacks.handleError(aError);
             }
           },
 
--- a/toolkit/components/satchel/test/unit/test_history_api.js
+++ b/toolkit/components/satchel/test/unit/test_history_api.js
@@ -368,28 +368,48 @@ add_task(function ()
   testnum++;
   yield promiseUpdate({ op : "add", fieldname: "field4", value: "value4",
                         timesUsed: 5, firstUsed: 230, lastUsed: 600 });
   yield promiseCountEntries(null, null, function(num) do_check_eq(num, 4));
 
   // ===== 19 =====
   // Remove an entry by time
   testnum++;
-  results = yield promiseSearchEntries(["timesUsed", "firstUsed", "lastUsed"],
-                                       { fieldname: "field1", value: "modifiedValue" });
-  [timesUsed, firstUsed, lastUsed] = processFirstResult(results);
-
   yield promiseUpdate({ op : "remove", firstUsedStart: 60, firstUsedEnd: 250 });
   yield promiseCountEntries("field1", "modifiedValue", checkExists);
   yield promiseCountEntries("field2", "value2", checkNotExists);
   yield promiseCountEntries("field3", "value3", checkExists);
   yield promiseCountEntries("field4", "value4", checkNotExists);
   yield promiseCountEntries(null, null, function(num) do_check_eq(num, 2));
   yield countDeletedEntries(10);
 
+  // ===== 20 =====
+  // Bump multiple existing entries at once
+  testnum++;
+
+  yield promiseUpdate([{ op : "add", fieldname: "field5", value: "value5",
+                         timesUsed: 5, firstUsed: 230, lastUsed: 600 },
+                       { op : "add", fieldname: "field6", value: "value6",
+                         timesUsed: 12, firstUsed: 430, lastUsed: 700 }]);
+  yield promiseCountEntries(null, null, function(num) do_check_eq(num, 4));
+
+  yield promiseUpdate([
+                       { op : "bump", fieldname: "field5", value: "value5" },
+                       { op : "bump", fieldname: "field6", value: "value6" }]);
+  results = yield promiseSearchEntries(["fieldname", "timesUsed", "firstUsed", "lastUsed"], { });
+  
+  do_check_eq(6, results[2].timesUsed);
+  do_check_eq(13, results[3].timesUsed);
+  do_check_eq(230, results[2].firstUsed);
+  do_check_eq(430, results[3].firstUsed);
+  do_check_true(results[2].lastUsed > 600);
+  do_check_true(results[3].lastUsed > 700);
+
+  yield promiseCountEntries(null, null, function(num) do_check_eq(num, 4));
+
   } catch (e) {
     throw "FAILED in test #" + testnum + " -- " + e;
   }
   finally {
     FormHistory._supportsDeletedTable = oldSupportsDeletedTable;
     dbConnection.asyncClose(do_test_finished);
   }
 });