diff --git a/dom/contacts/ContactManager.js b/dom/contacts/ContactManager.js index 8a5416923251..19a636ff2e4a 100644 --- a/dom/contacts/ContactManager.js +++ b/dom/contacts/ContactManager.js @@ -391,14 +391,19 @@ ContactManager.prototype = { } }, - remove: function removeContact(aRecord) { + remove: function removeContact(aRecordOrId) { let request = this.createRequest(); - if (!aRecord || !aRecord.id) { + let id; + if (typeof aRecordOrId === "string") { + id = aRecordOrId; + } else if (!aRecordOrId || !aRecordOrId.id) { Services.DOMRequest.fireErrorAsync(request, true); return request; + } else { + id = aRecordOrId.id; } - let options = { id: aRecord.id }; + let options = { id: id }; let allowCallback = function() { cpmm.sendAsyncMessage("Contact:Remove", {requestID: this.getRequestId({request: request, reason: "remove"}), options: options}); }.bind(this); diff --git a/dom/contacts/tests/test_contacts_basics2.html b/dom/contacts/tests/test_contacts_basics2.html index e2ec474f57c7..43353cb2c1c4 100644 --- a/dom/contacts/tests/test_contacts_basics2.html +++ b/dom/contacts/tests/test_contacts_basics2.html @@ -800,6 +800,28 @@ var steps = [ ok(!c.jobTitle, "jobTitle is not set"); next(); }, + function() { + ok(true, "mozContacts.remove with an ID works"); + var c = new mozContact({name: ["Ephemeral Jimmy"]}); + req = navigator.mozContacts.save(c); + req.onsuccess = function() { + req = navigator.mozContacts.remove(c.id); + req.onsuccess = function() { + req = navigator.mozContacts.find({ + filterBy: ["id"], + filterOp: "equals", + filterValue: c.id + }); + req.onsuccess = function() { + ise(req.result.length, 0, "Successfully removed contact by ID"); + next(); + }; + req.onerror = onFailure; + }; + req.onerror = onFailure; + }; + req.onerror = onFailure; + }, function () { ok(true, "all done!\n"); SimpleTest.finish(); diff --git a/dom/webidl/Contacts.webidl b/dom/webidl/Contacts.webidl index 70c004883fed..2512ecf819bc 100644 --- a/dom/webidl/Contacts.webidl +++ b/dom/webidl/Contacts.webidl @@ -118,7 +118,7 @@ interface ContactManager : EventTarget { DOMCursor getAll(optional ContactFindSortOptions options); DOMRequest clear(); DOMRequest save(mozContact contact); - DOMRequest remove(mozContact contact); + DOMRequest remove((mozContact or DOMString) contactOrId); DOMRequest getRevision(); DOMRequest getCount();