Bug 1395427 p2 - Include guid in formhistory-remove notifications. r=markh

MozReview-Commit-ID: Je0rV277d7

--HG--
extra : rebase_source : 0557db8a84c98b0fa55b6a4f23fa8001876d559b
This commit is contained in:
Edouard Oger 2017-09-22 15:19:56 -04:00
Родитель 56ecdf96b5
Коммит 8cb437aed8
4 изменённых файлов: 44 добавлений и 8 удалений

Просмотреть файл

@ -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")),

Просмотреть файл

@ -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;
}

Просмотреть файл

@ -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);
}
},
};

Просмотреть файл

@ -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) {