Bug 864556 - Follow up, land the part of the patch that never landed. r=gwagner a=leo+
authorReuben Morais <reuben.morais@gmail.com>
Mon, 29 Jul 2013 14:18:42 -0400
changeset 119818 44de5fb4e8d0b73c1167945b139fc108fd15cf21
parent 119817 150c3f4ad24b3690cbc76ae462b4ac02d137368b
child 119819 658f625177cae97ae7d3e2cab8f0ea3ffcd8f797
push id1010
push userreuben.morais@gmail.com
push dateMon, 29 Jul 2013 18:24:46 +0000
reviewersgwagner, leo
bugs864556
milestone18.1
Bug 864556 - Follow up, land the part of the patch that never landed. r=gwagner a=leo+
dom/contacts/ContactManager.js
dom/contacts/ContactManager.manifest
dom/contacts/tests/test_contacts_basics.html
dom/interfaces/contacts/nsIDOMContactManager.idl
--- a/dom/contacts/ContactManager.js
+++ b/dom/contacts/ContactManager.js
@@ -504,17 +504,17 @@ Contact.prototype = {
                                      flags: nsIClassInfo.DOM_OBJECT}),
 
   QueryInterface : XPCOMUtils.generateQI([nsIDOMContact, nsIDOMContactProperties])
 }
 
 // ContactManager
 
 const CONTACTMANAGER_CONTRACTID = "@mozilla.org/contactManager;1";
-const CONTACTMANAGER_CID        = Components.ID("{7bfb6481-f946-4254-afc5-d7fe9f5c45a3}");
+const CONTACTMANAGER_CID        = Components.ID("{0a2b72f3-7761-431b-8fa4-df1459316272}");
 const nsIDOMContactManager      = Components.interfaces.nsIDOMContactManager;
 
 function ContactManager()
 {
   if (DEBUG) debug("Constructor");
 }
 
 ContactManager.prototype = {
--- a/dom/contacts/ContactManager.manifest
+++ b/dom/contacts/ContactManager.manifest
@@ -15,11 +15,11 @@ contract @mozilla.org/contactFindSortOpt
 
 component {e13ca4c5-c9cd-40bb-95e9-b636d42f5edf} ContactManager.js
 contract @mozilla.org/contactFindOptions;1 {e13ca4c5-c9cd-40bb-95e9-b636d42f5edf}
 
 component {da0f7040-388b-11e1-b86c-0800200c9a66} ContactManager.js
 contract @mozilla.org/contact;1 {da0f7040-388b-11e1-b86c-0800200c9a66}
 category JavaScript-global-constructor mozContact @mozilla.org/contact;1
 
-component {7bfb6481-f946-4254-afc5-d7fe9f5c45a3} ContactManager.js
-contract @mozilla.org/contactManager;1 {7bfb6481-f946-4254-afc5-d7fe9f5c45a3}
+component {0a2b72f3-7761-431b-8fa4-df1459316272} ContactManager.js
+contract @mozilla.org/contactManager;1 {0a2b72f3-7761-431b-8fa4-df1459316272}
 category JavaScript-navigator-property mozContacts @mozilla.org/contactManager;1
--- a/dom/contacts/tests/test_contacts_basics.html
+++ b/dom/contacts/tests/test_contacts_basics.html
@@ -220,46 +220,65 @@ function checkContacts(contact1, contact
   for (var i in contact1.impp) {
     checkField(contact1.impp[i], contact2.impp[i]);
   }
 }
 
 var req;
 var index = 0;
 
+var initialRev;
+
+function checkRevision(revision, msg, then) {
+  var revReq = mozContacts.getRevision();
+  revReq.onsuccess = function(e) {
+    is(e.target.result, initialRev+revision, msg);
+    then();
+  };
+  revReq.onerror = onFailure;
+}
+
 var mozContacts = window.navigator.mozContacts;
 
 var steps = [
+  function() {
+    mozContacts.getRevision().onsuccess = function(e) {
+      initialRev = e.target.result;
+      next();
+    };
+  },
   function () {
     ok(true, "Deleting database");
-    req = mozContacts.clear();
-    req.onsuccess = function () {
-      ok(true, "Deleted the database");
-      next();
-    };
-    req.onerror = onFailure;
+    checkRevision(0, "Initial revision is 0", function() {
+      req = mozContacts.clear();
+      req.onsuccess = function () {
+        ok(true, "Deleted the database");
+        checkRevision(1, "Revision was incremented on clear", next);
+      };
+      req.onerror = onFailure;
+    });
   },
   function () {
     ok(true, "Retrieving all contacts");
     req = mozContacts.find({});
     req.onsuccess = function () {
       is(req.result.length, 0, "Empty database is empty.");
-      next();
+      checkRevision(1, "Revision was not incremented on find", next);
     };
     req.onerror = onFailure;
   },
   function () {
     ok(true, "Adding empty contact");
     createResult1 = new mozContact();
     createResult1.init({});
     req = navigator.mozContacts.save(createResult1);
     req.onsuccess = function () {
       ok(createResult1.id, "The contact now has an ID.");
       sample_id1 = createResult1.id;
-      next();
+      checkRevision(2, "Revision was incremented on save", next);
     };
     req.onerror = onFailure;
   },
   function () {
     ok(true, "Retrieving all contacts");
     req = mozContacts.find({});
     req.onsuccess = function () {
       is(req.result.length, 1, "One contact.");
@@ -271,17 +290,17 @@ var steps = [
   function () {
     ok(true, "Deleting empty contact");
     req = navigator.mozContacts.remove(findResult1);
     req.onsuccess = function () {
       var req2 = mozContacts.find({});
       req2.onsuccess = function () {
         is(req2.result.length, 0, "Empty Database.");
         clearTemps();
-        next();
+        checkRevision(3, "Revision was incremented on remove", next);
       }
       req2.onerror = onFailure;
     }
     req.onerror = onFailure;
   },
   function () {
     ok(true, "Adding a new contact1");
     createResult1 = new mozContact();
--- a/dom/interfaces/contacts/nsIDOMContactManager.idl
+++ b/dom/interfaces/contacts/nsIDOMContactManager.idl
@@ -18,25 +18,27 @@ interface nsIDOMContact : nsIDOMContactP
 {
   attribute DOMString id;
   readonly attribute jsval     published;
   readonly attribute jsval     updated;
 
   void init(in nsIDOMContactProperties properties);  // Workaround BUG 723206
 };
 
-[scriptable, uuid(1d70322b-f11b-4f19-9586-7bf291f212aa)]
+[scriptable, uuid(0a2b72f3-7761-431b-8fa4-df1459316272)]
 interface nsIDOMContactManager : nsISupports
 {
   nsIDOMDOMRequest find(in nsIDOMContactFindOptions options);
 
   nsIDOMDOMCursor getAll(in nsIDOMContactFindSortOptions options);
 
   nsIDOMDOMRequest clear();
 
   nsIDOMDOMRequest save(in nsIDOMContact contact);
 
   nsIDOMDOMRequest remove(in nsIDOMContact contact);
 
   nsIDOMDOMRequest getSimContacts(in DOMString type);
 
   attribute nsIDOMEventListener oncontactchange;
+
+  nsIDOMDOMRequest getRevision();
 };