Bug 882777 - Contacts API: Fix Date and pref properties. r=reuben
authorGregor Wagner <anygregor@gmail.com>
Thu, 13 Jun 2013 15:43:30 -0700
changeset 146518 c3fef5de1868d1c38b83a03c32326d0b2d962bb4
parent 146517 ab100d18b1002b569d7233dc534801e85103fc09
child 146519 dcec1d40d201bbf47af7d19eb4f60edfb8194256
push id2697
push userbbajaj@mozilla.com
push dateMon, 05 Aug 2013 18:49:53 +0000
treeherdermozilla-beta@dfec938c7b63 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersreuben
bugs882777
milestone24.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 882777 - Contacts API: Fix Date and pref properties. r=reuben
dom/contacts/ContactManager.js
dom/contacts/tests/test_contacts_basics.html
--- a/dom/contacts/ContactManager.js
+++ b/dom/contacts/ContactManager.js
@@ -83,17 +83,18 @@ function ContactAddress(aType, aStreetAd
 
 ContactAddress.prototype = {
   __exposedProps__: {
                       type: 'rw',
                       streetAddress: 'rw',
                       locality: 'rw',
                       region: 'rw',
                       postalCode: 'rw',
-                      countryName: 'rw'
+                      countryName: 'rw',
+                      pref: 'rw'
                      },
 
   classID : CONTACTADDRESS_CID,
   classInfo : XPCOMUtils.generateCI({classID: CONTACTADDRESS_CID,
                                      contractID: CONTACTADDRESS_CONTRACTID,
                                      classDescription: "ContactAddress",
                                      interfaces: [nsIContactAddress],
                                      flags: nsIClassInfo.DOM_OBJECT}),
@@ -111,17 +112,18 @@ function ContactField(aType, aValue, aPr
   this.type = sanitizeStringArray(aType);
   this.value = stringOrBust(aValue);
   this.pref = aPref;
 };
 
 ContactField.prototype = {
   __exposedProps__: {
                       type: 'rw',
-                      value: 'rw'
+                      value: 'rw',
+                      pref: 'rw'
                      },
 
   classID : CONTACTFIELD_CID,
   classInfo : XPCOMUtils.generateCI({classID: CONTACTFIELD_CID,
                                      contractID: CONTACTFIELD_CONTRACTID,
                                      classDescription: "ContactField",
                                      interfaces: [nsIContactField],
                                      flags: nsIClassInfo.DOM_OBJECT}),
@@ -141,17 +143,18 @@ function ContactTelField(aType, aValue, 
   this.carrier = stringOrBust(aCarrier);
   this.pref = aPref;
 };
 
 ContactTelField.prototype = {
   __exposedProps__: {
                       type: 'rw',
                       value: 'rw',
-                      carrier: 'rw'
+                      carrier: 'rw',
+                      pref: 'rw'
                      },
 
   classID : CONTACTTELFIELD_CID,
   classInfo : XPCOMUtils.generateCI({classID: CONTACTTELFIELD_CID,
                                      contractID: CONTACTTELFIELD_CONTRACTID,
                                      classDescription: "ContactTelField",
                                      interfaces: [nsIContactTelField],
                                      flags: nsIClassInfo.DOM_OBJECT}),
@@ -412,29 +415,29 @@ Contact.prototype = {
     this._note = sanitizeStringArray(aNote);
   },
 
   get note() {
     return this._note;
   },
 
   set bday(aBday) {
-    if (aBday instanceof Date) {
+    if (aBday && aBday.constructor.name === "Date") {
       this._bday = aBday;
     } else if (typeof aBday === "string" || typeof aBday === "number") {
       this._bday = new Date(aBday);
     }
   },
 
   get bday() {
     return this._bday;
   },
 
   set anniversary(aAnniversary) {
-    if (aAnniversary instanceof Date) {
+    if (aAnniversary && aAnniversary.constructor.name === "Date") {
       this._anniversary = aAnniversary;
     } else if (typeof aAnniversary === "string" || typeof aAnniversary === "number") {
       this._anniversary = new Date(aAnniversary);
     }
   },
 
   get anniversary() {
     return this._anniversary;
--- a/dom/contacts/tests/test_contacts_basics.html
+++ b/dom/contacts/tests/test_contacts_basics.html
@@ -157,17 +157,16 @@ function checkStrArray(str1, str2, msg) 
   }
 }
 
 function checkAddress(adr1, adr2) {
   if (adr1 ^ adr2) {
     ok(false, "Expected both adrs to be either present or absent");
     return;
   }
-  dump("adr1: " + adr1 + ", adr2: " + adr2 + "\n");
   checkStrArray(adr1.type, adr2.type, "Same type");
   checkStrArray(adr1.streetAddress, adr2.streetAddress, "Same streetAddress");
   checkStrArray(adr1.locality, adr2.locality, "Same locality");
   checkStrArray(adr1.region, adr2.region, "Same region");
   checkStrArray(adr1.postalCode, adr2.postalCode, "Same postalCode");
   checkStrArray(adr1.countryName, adr2.countryName, "Same countryName");
   is(adr1.pref, adr2.pref, "Same pref");
 }
@@ -345,17 +344,16 @@ var steps = [
                    filterOp: "startsWith",
                    filterValue: properties1.givenName[1].substring(0,3)};
     req = mozContacts.find(options);
     req.onsuccess = function () {
       is(req.result.length, 1, "Found exactly 1 contact.");
       findResult1 = req.result[0];
       ok(findResult1.id == sample_id1, "Same ID");
       checkContacts(createResult1, properties1);
-      dump("findResult: " + JSON.stringify(findResult1) + "\n");
       // Some manual testing. Testint the testfunctions
       // tel: [{type: ["work"], value: "123456", carrier: "testCarrier"} , {type: ["home", "fax"], value: "+55 (31) 9876-3456"}],
       is(findResult1.tel[0].carrier, "testCarrier", "Same Carrier");
       is(findResult1.tel[0].type, "work", "Same type");
       is(findResult1.tel[0].value, "123456", "Same Value");
       is(findResult1.tel[1].type[1], "fax", "Same type");
       is(findResult1.tel[1].value, "+55 (31) 9876-3456", "Same Value");
 
@@ -905,19 +903,20 @@ var steps = [
       ok(createResult2.id, "The contact now has an ID.");
       sample_id2 = createResult2.id;
       next();
     };
     req.onerror = onFailure;
   },
   function () {
     ok(true, "Retrieving all contacts");
-    req = mozContacts.find({})
+    req = mozContacts.find({sortBy: 'FamilyName',})
     req.onsuccess = function () {
       is(req.result.length, 2, "Found exactly 2 contact.");
+      checkContacts(properties2, req.result[1]);
       next();
     }
     req.onerror = onFailure;
   },
   function () {
     console.log("Searching contacts by query1");
     var options = {filterBy: ["givenName", "email"],
                    filterOp: "startsWith",