From 8cb437aed818c00fbfa8848db0af6b033742f018 Mon Sep 17 00:00:00 2001 From: Edouard Oger Date: Fri, 22 Sep 2017 15:19:56 -0400 Subject: [PATCH] Bug 1395427 p2 - Include guid in formhistory-remove notifications. r=markh MozReview-Commit-ID: Je0rV277d7 --HG-- extra : rebase_source : 0557db8a84c98b0fa55b6a4f23fa8001876d559b --- toolkit/components/satchel/FormHistory.jsm | 4 ++- .../components/satchel/FormHistoryStartup.js | 3 +- .../components/satchel/nsFormAutoComplete.js | 9 +++-- .../satchel/test/unit/test_notify.js | 36 ++++++++++++++++--- 4 files changed, 44 insertions(+), 8 deletions(-) diff --git a/toolkit/components/satchel/FormHistory.jsm b/toolkit/components/satchel/FormHistory.jsm index 34b681ba34cb..0c7020bfe0c0 100644 --- a/toolkit/components/satchel/FormHistory.jsm +++ b/toolkit/components/satchel/FormHistory.jsm @@ -1037,7 +1037,7 @@ this.FormHistory = { */ let query = "/* do not warn (bug 496471): can't use an index */ " + - "SELECT value, " + + "SELECT value, guid, " + "ROUND( " + "timesUsed / MAX(1.0, (lastUsed - firstUsed) / :timeGroupingSize) * " + "MAX(1.0, :maxTimeGroupings - (:now - lastUsed) / :timeGroupingSize) * " + @@ -1073,9 +1073,11 @@ this.FormHistory = { handleResult(aResultSet) { for (let row = aResultSet.getNextRow(); row; row = aResultSet.getNextRow()) { let value = row.getResultByName("value"); + let guid = row.getResultByName("guid"); let frecency = row.getResultByName("frecency"); let entry = { text: value, + guid, textLowerCase: value.toLowerCase(), frecency, totalScore: Math.round(frecency * row.getResultByName("boundaryBonuses")), diff --git a/toolkit/components/satchel/FormHistoryStartup.js b/toolkit/components/satchel/FormHistoryStartup.js index 9297c959c628..8c41ace310be 100644 --- a/toolkit/components/satchel/FormHistoryStartup.js +++ b/toolkit/components/satchel/FormHistoryStartup.js @@ -126,11 +126,12 @@ FormHistoryStartup.prototype = { } case "FormHistory:RemoveEntry": { - let { inputName, value } = message.data; + let { inputName, value, guid } = message.data; FormHistory.update({ op: "remove", fieldname: inputName, value, + guid, }); break; } diff --git a/toolkit/components/satchel/nsFormAutoComplete.js b/toolkit/components/satchel/nsFormAutoComplete.js index a7048bc8c23c..b7b4ed0dce7a 100644 --- a/toolkit/components/satchel/nsFormAutoComplete.js +++ b/toolkit/components/satchel/nsFormAutoComplete.js @@ -117,11 +117,16 @@ FormHistoryClient.prototype = { * * The value to remove for this particular * field. + * + * @param {string} guid + * + * The guid for the item being removed. */ - remove(value) { + remove(value, guid) { this.mm.sendAsyncMessage("FormHistory:RemoveEntry", { inputName: this.inputName, value, + guid, }); }, @@ -621,7 +626,7 @@ FormAutoCompleteResult.prototype = { let [removedEntry] = this.entries.splice(index, 1); if (removeFromDB) { - this.client.remove(removedEntry.text); + this.client.remove(removedEntry.text, removedEntry.guid); } }, }; diff --git a/toolkit/components/satchel/test/unit/test_notify.js b/toolkit/components/satchel/test/unit/test_notify.js index c27fe76e7430..0c7da6befc15 100644 --- a/toolkit/components/satchel/test/unit/test_notify.js +++ b/toolkit/components/satchel/test/unit/test_notify.js @@ -7,6 +7,8 @@ let expectedNotification; let expectedData; +let subjectIsGuid = false; +let lastGUID; let TestObserver = { QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver, Ci.nsISupportsWeakReference]), @@ -15,14 +17,23 @@ let TestObserver = { do_check_eq(topic, "satchel-storage-changed"); do_check_eq(data, expectedNotification); + let verifySubjectIsGuid = () => { + do_check_true(subject instanceof Ci.nsISupportsString); + do_check_true(isGUID.test(subject.toString())); + lastGUID = subject.toString(); + }; + switch (data) { case "formhistory-add": case "formhistory-update": - do_check_true(subject instanceof Ci.nsISupportsString); - do_check_true(isGUID.test(subject.toString())); + verifySubjectIsGuid(); break; case "formhistory-remove": - do_check_eq(null, subject); + if (subjectIsGuid) { + verifySubjectIsGuid(); + } else { + do_check_eq(null, subject); + } break; default: do_throw("Unhandled notification: " + data + " / " + topic); @@ -102,7 +113,24 @@ function* run_test_steps() { expectedNotification = "formhistory-remove"; expectedData = entry1; - yield updateEntry("remove", entry1[0], entry1[1], next_test); + + subjectIsGuid = true; + yield FormHistory.update({ + op: "remove", + fieldname: entry1[0], + value: entry1[1], + guid: lastGUID, + }, { + handleError(error) { + do_throw("Error occurred updating form history: " + error); + }, + handleCompletion(reason) { + if (!reason) { + next_test(); + } + }, + }); + subjectIsGuid = false; do_check_eq(expectedNotification, null); yield countEntries(entry1[0], entry1[1], function(num) {