Bug 963274 - Allow removing contacts by ID. r=gwagner
authorReuben Morais <reuben.morais@gmail.com>
Wed, 29 Jan 2014 08:20:40 -0500
changeset 181829 604c9742ffb487a1cfa4c3a7190a438d50ee310f
parent 181828 e367fd549454e1cd5ed791350624ec07b35a2363
child 181830 d81ec82bda34bdcf1297b091d8ec66ba4e218863
push id3343
push userffxbld
push dateMon, 17 Mar 2014 21:55:32 +0000
treeherdermozilla-beta@2f7d3415f79f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgwagner
bugs963274
milestone29.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 963274 - Allow removing contacts by ID. r=gwagner
dom/contacts/ContactManager.js
dom/contacts/tests/test_contacts_basics2.html
dom/webidl/Contacts.webidl
--- a/dom/contacts/ContactManager.js
+++ b/dom/contacts/ContactManager.js
@@ -386,24 +386,29 @@ ContactManager.prototype = {
         cpmm.sendAsyncMessage("Contacts:GetAll:SendNow", { cursorId: aCursorId });
       }
     } else {
       if (DEBUG) debug("waiting for contact");
       data.waitingForNext = true;
     }
   },
 
-  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);
     this.askPermission("remove", request, allowCallback);
     return request;
   },
 
   clear: function() {
--- a/dom/contacts/tests/test_contacts_basics2.html
+++ b/dom/contacts/tests/test_contacts_basics2.html
@@ -795,16 +795,38 @@ var steps = [
   function() {
     ok(true, "mozContact.init resets properties");
     var c = new mozContact({jobTitle: ["Software Engineer"]});
     c.init({nickname: ["Jobless Johnny"]});
     ise(c.nickname[0], "Jobless Johnny", "Same nickname");
     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();
   }
 ];
 
 function next() {
   ok(true, "Begin!");
--- a/dom/webidl/Contacts.webidl
+++ b/dom/webidl/Contacts.webidl
@@ -113,14 +113,14 @@ dictionary ContactFindOptions : ContactF
 
 [NoInterfaceObject, NavigatorProperty="mozContacts",
  JSImplementation="@mozilla.org/contactManager;1"]
 interface ContactManager : EventTarget {
   DOMRequest find(optional ContactFindOptions options);
   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();
 
   attribute  EventHandler oncontactchange;
 };