Bug 836157 - Contacts API: Remove unused indexes. r=bent
authorGregor Wagner <anygregor@gmail.com>
Wed, 30 Jan 2013 17:17:07 -0800
changeset 120419 aba3331a5c543556a49d95c4f8017be6d098475a
parent 120418 774ba579fd394883d42e0db89a44211fbbba785b
child 120420 3867507b94198e409a5efa333c68f2f9bb9b4e16
push id24251
push userryanvm@gmail.com
push dateThu, 31 Jan 2013 20:56:22 +0000
treeherdermozilla-central@683b08dc1afd [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbent
bugs836157
milestone21.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 836157 - Contacts API: Remove unused indexes. r=bent
dom/base/IndexedDBHelper.jsm
dom/contacts/fallback/ContactDB.jsm
dom/contacts/tests/test_contacts_basics.html
dom/contacts/tests/test_contacts_blobs.html
--- a/dom/base/IndexedDBHelper.jsm
+++ b/dom/base/IndexedDBHelper.jsm
@@ -41,54 +41,56 @@ IndexedDBHelper.prototype = {
    * 
    * @param successCb
    *        Success callback to call once database is open.
    * @param failureCb
    *        Error callback to call when an error is encountered.
    */
   open: function open(aSuccessCb, aFailureCb) {
     let self = this;
-    debug("Try to open database:" + self.dbName + " " + self.dbVersion);
+    if (DEBUG) debug("Try to open database:" + self.dbName + " " + self.dbVersion);
     let req = this.dbGlobal.indexedDB.open(this.dbName, this.dbVersion);
     req.onsuccess = function (event) {
-      debug("Opened database:" + self.dbName + " " + self.dbName);
+      if (DEBUG) debug("Opened database:" + self.dbName + " " + self.dbName);
       self._db = event.target.result;
       self._db.onversionchange = function(event) {
-        debug("WARNING: DB modified from a different window.");
+        if (DEBUG) debug("WARNING: DB modified from a different window.");
       }
       aSuccessCb();
     };
 
     req.onupgradeneeded = function (aEvent) {
-      debug("Database needs upgrade:" + self.dbName + aEvent.oldVersion + aEvent.newVersion);
-      debug("Correct new database version:" + aEvent.newVersion == this.dbVersion);
+      if (DEBUG) {
+        debug("Database needs upgrade:" + self.dbName + aEvent.oldVersion + aEvent.newVersion);
+        debug("Correct new database version:" + aEvent.newVersion == this.dbVersion);
+      }
 
       let _db = aEvent.target.result;
       self.upgradeSchema(req.transaction, _db, aEvent.oldVersion, aEvent.newVersion);
     };
     req.onerror = function (aEvent) {
-      debug("Failed to open database:" + self.dbName);
+      if (DEBUG) debug("Failed to open database:" + self.dbName);
       aFailureCb(aEvent.target.errorMessage);
     };
     req.onblocked = function (aEvent) {
-      debug("Opening database request is blocked.");
+      if (DEBUG) debug("Opening database request is blocked.");
     };
   },
 
   /**
    * Use the cached DB or open a new one.
    * 
    * @param successCb
    *        Success callback to call.
    * @param failureCb
    *        Error callback to call when an error is encountered.
    */
   ensureDB: function ensureDB(aSuccessCb, aFailureCb) {
     if (this._db) {
-      debug("ensureDB: already have a database, returning early.");
+      if (DEBUG) debug("ensureDB: already have a database, returning early.");
       aSuccessCb();
       return;
     }
     this.open(aSuccessCb, aFailureCb);
   },
 
   /**
    * Start a new transaction.
@@ -101,28 +103,28 @@ IndexedDBHelper.prototype = {
    * @param successCb
    *        Success callback to call on a successful transaction commit.
    *        The result is stored in txn.result.
    * @param failureCb
    *        Error callback to call when an error is encountered.
    */
   newTxn: function newTxn(txn_type, callback, successCb, failureCb) {
     this.ensureDB(function () {
-      debug("Starting new transaction" + txn_type);
+      if (DEBUG) debug("Starting new transaction" + txn_type);
       let txn = this._db.transaction(this.dbName, txn_type);
-      debug("Retrieving object store", this.dbName);
+      if (DEBUG) debug("Retrieving object store", this.dbName);
       let store = txn.objectStore(this.dbStoreName);
 
       txn.oncomplete = function (event) {
-        debug("Transaction complete. Returning to callback.");
+        if (DEBUG) debug("Transaction complete. Returning to callback.");
         successCb(txn.result);
       };
 
       txn.onabort = function (event) {
-        debug("Caught error on transaction");
+        if (DEBUG) debug("Caught error on transaction");
         /*
          * event.target.error may be null
          * if txn was aborted by calling txn.abort()
          */
         if (event.target.error)
             failureCb(event.target.error.name);
         else
             failureCb("UnknownError");
--- a/dom/contacts/fallback/ContactDB.jsm
+++ b/dom/contacts/fallback/ContactDB.jsm
@@ -13,17 +13,17 @@ const Cu = Components.utils;
 const Cc = Components.classes;
 const Ci = Components.interfaces;
 
 Cu.import("resource://gre/modules/Services.jsm");
 Cu.import("resource://gre/modules/IndexedDBHelper.jsm");
 Cu.import("resource://gre/modules/PhoneNumberUtils.jsm");
 
 const DB_NAME = "contacts";
-const DB_VERSION = 6;
+const DB_VERSION = 7;
 const STORE_NAME = "contacts";
 
 this.ContactDB = function ContactDB(aGlobal) {
   if (DEBUG) debug("Constructor");
   this._global = aGlobal;
 }
 
 ContactDB.prototype = {
@@ -44,35 +44,24 @@ ContactDB.prototype = {
          *  published:     Date(...),   // First published date.
          *  updated:       Date(...),   // Last updated date.
          *  properties:    {...}        // Object holding the ContactProperties
          * }
          */
         if (DEBUG) debug("create schema");
         objectStore = db.createObjectStore(this.dbStoreName, {keyPath: "id"});
 
-        // Metadata indexes
-        objectStore.createIndex("published", "published", { unique: false });
-        objectStore.createIndex("updated",   "updated",   { unique: false });
+        // Properties indexes
+        objectStore.createIndex("familyName", "properties.familyName", { multiEntry: true });
+        objectStore.createIndex("givenName",  "properties.givenName",  { multiEntry: true });
 
-        // Properties indexes
-        objectStore.createIndex("nickname",   "properties.nickname",   { unique: false, multiEntry: true });
-        objectStore.createIndex("name",       "properties.name",       { unique: false, multiEntry: true });
-        objectStore.createIndex("familyName", "properties.familyName", { unique: false, multiEntry: true });
-        objectStore.createIndex("givenName",  "properties.givenName",  { unique: false, multiEntry: true });
-        objectStore.createIndex("email",      "properties.email",      { unique: false, multiEntry: true });
-        objectStore.createIndex("note",       "properties.note",       { unique: false, multiEntry: true });
-
-        objectStore.createIndex("nicknameLowerCase",   "search.nickname",   { unique: false, multiEntry: true });
-        objectStore.createIndex("nameLowerCase",       "search.name",       { unique: false, multiEntry: true });
-        objectStore.createIndex("familyNameLowerCase", "search.familyName", { unique: false, multiEntry: true });
-        objectStore.createIndex("givenNameLowerCase",  "search.givenName",  { unique: false, multiEntry: true });
-        objectStore.createIndex("telLowerCase",        "search.tel",        { unique: false, multiEntry: true });
-        objectStore.createIndex("emailLowerCase",      "search.email",      { unique: false, multiEntry: true });
-        objectStore.createIndex("noteLowerCase",       "search.note",       { unique: false, multiEntry: true });
+        objectStore.createIndex("familyNameLowerCase", "search.familyName", { multiEntry: true });
+        objectStore.createIndex("givenNameLowerCase",  "search.givenName",  { multiEntry: true });
+        objectStore.createIndex("telLowerCase",        "search.tel",        { multiEntry: true });
+        objectStore.createIndex("emailLowerCase",      "search.email",      { multiEntry: true });
       } else if (currVersion == 1) {
         if (DEBUG) debug("upgrade 1");
 
         // Create a new scheme for the tel field. We move from an array of tel-numbers to an array of
         // ContactTelephone.
         if (!objectStore) {
           objectStore = aTransaction.objectStore(STORE_NAME);
         }
@@ -91,27 +80,30 @@ ContactDB.prototype = {
             }
             cursor.update(cursor.value);
             if (DEBUG) debug("upgrade tel2: " + JSON.stringify(cursor.value));
             cursor.continue();
           }
         };
 
         // Create new searchable indexes.
-        objectStore.createIndex("tel", "search.tel", { unique: false, multiEntry: true });
-        objectStore.createIndex("category", "properties.category", { unique: false, multiEntry: true });
+        objectStore.createIndex("tel", "search.tel", { multiEntry: true });
+        objectStore.createIndex("category", "properties.category", { multiEntry: true });
       } else if (currVersion == 2) {
         if (DEBUG) debug("upgrade 2");
         // Create a new scheme for the email field. We move from an array of emailaddresses to an array of 
         // ContactEmail.
         if (!objectStore) {
           objectStore = aTransaction.objectStore(STORE_NAME);
         }
+
         // Delete old email index.
-        objectStore.deleteIndex("email");
+        if (objectStore.indexNames.contains("email")) {
+          objectStore.deleteIndex("email");
+        }
 
         // Upgrade existing email field in the DB.
         objectStore.openCursor().onsuccess = function(event) {
           let cursor = event.target.result;
           if (cursor) {
             if (cursor.value.properties.email) {
               if (DEBUG) debug("upgrade email1: " + JSON.stringify(cursor.value));
               cursor.value.properties.email =
@@ -119,17 +111,17 @@ ContactDB.prototype = {
               cursor.update(cursor.value);
               if (DEBUG) debug("upgrade email2: " + JSON.stringify(cursor.value));
             }
             cursor.continue();
           }
         };
 
         // Create new searchable indexes.
-        objectStore.createIndex("email", "search.email", { unique: false, multiEntry: true });
+        objectStore.createIndex("email", "search.email", { multiEntry: true });
       } else if (currVersion == 3) {
         if (DEBUG) debug("upgrade 3");
 
         if (!objectStore) {
           objectStore = aTransaction.objectStore(STORE_NAME);
         }
 
         // Upgrade existing impp field in the DB.
@@ -170,20 +162,22 @@ ContactDB.prototype = {
           let cursor = event.target.result;
           if (cursor) {
             if (cursor.value.properties.tel) {
               if (DEBUG) debug("upgrade : " + JSON.stringify(cursor.value));
               cursor.value.properties.tel.forEach(
                 function(duple) {
                   let parsedNumber = PhoneNumberUtils.parse(duple.value.toString());
                   if (parsedNumber) {
-                    debug("InternationalFormat: " + parsedNumber.internationalFormat);
-                    debug("InternationalNumber: " + parsedNumber.internationalNumber);
-                    debug("NationalNumber: " + parsedNumber.nationalNumber);
-                    debug("NationalFormat: " + parsedNumber.nationalFormat);
+                    if (DEBUG) {
+                      debug("InternationalFormat: " + parsedNumber.internationalFormat);
+                      debug("InternationalNumber: " + parsedNumber.internationalNumber);
+                      debug("NationalNumber: " + parsedNumber.nationalNumber);
+                      debug("NationalFormat: " + parsedNumber.nationalFormat);
+                    }
                     if (duple.value.toString() !== parsedNumber.internationalNumber) {
                       cursor.value.search.tel.push(parsedNumber.internationalNumber);
                     }
                   } else {
                     dump("Warning: No international number found for " + duple.value + "\n");
                   }
                 }
               )
@@ -200,17 +194,17 @@ ContactDB.prototype = {
         }
 
         // Delete old tel index (not on the right field).
         if (objectStore.indexNames.contains("tel")) {
           objectStore.deleteIndex("tel");
         }
 
         // Create new index for "equals" searches
-        objectStore.createIndex("tel", "search.exactTel", { unique: false, multiEntry: true });
+        objectStore.createIndex("tel", "search.exactTel", { multiEntry: true });
 
         objectStore.openCursor().onsuccess = function(event) {
           let cursor = event.target.result;
           if (cursor) {
             if (cursor.value.properties.tel) {
               if (DEBUG) debug("upgrade : " + JSON.stringify(cursor.value));
               cursor.value.properties.tel.forEach(
                 function(duple) {
@@ -226,16 +220,29 @@ ContactDB.prototype = {
                 }
               )
               cursor.update(cursor.value);
             }
             if (DEBUG) debug("upgrade : " + JSON.stringify(cursor.value));
             cursor.continue();
           }
         };
+      } else if (currVersion == 6) {
+        if (!objectStore) {
+          objectStore = aTransaction.objectStore(STORE_NAME);
+        }
+        let names = objectStore.indexNames;
+        let blackList = ["tel", "familyName", "givenName",  "familyNameLowerCase",
+                         "givenNameLowerCase", "telLowerCase", "category", "email",
+                         "emailLowerCase"];
+        for (var i = 0; i < names.length; i++) {
+          if (blackList.indexOf(names[i]) < 0) {
+            objectStore.deleteIndex(names[i]);
+          }
+        }
       }
     }
   },
 
   makeImport: function makeImport(aContact) {
     let contact = {};
     contact.properties = {
       name:            [],
@@ -257,31 +264,22 @@ ContactDB.prototype = {
       note:            [],
       impp:            [],
       anniversary:     null,
       sex:             null,
       genderIdentity:  null
     };
 
     contact.search = {
-      name:            [],
-      honorificPrefix: [],
       givenName:       [],
-      additionalName:  [],
       familyName:      [],
-      honorificSuffix: [],
-      nickname:        [],
       email:           [],
       category:        [],
       tel:             [],
-      exactTel:        [],
-      org:             [],
-      jobTitle:        [],
-      note:            [],
-      impp:            []
+      exactTel:        []
     };
 
     for (let field in aContact.properties) {
       contact.properties[field] = aContact.properties[field];
       // Add search fields
       if (aContact.properties[field] && contact.search[field]) {
         for (let i = 0; i <= aContact.properties[field].length; i++) {
           if (aContact.properties[field][i]) {
@@ -303,20 +301,22 @@ ContactDB.prototype = {
                   digits = digits.join('');
                   for(let i = 0; i < digits.length; i++) {
                     search[digits.substring(i, digits.length)] = 1;
                   }
                 }
                 if (DEBUG) debug("lookup: " + JSON.stringify(contact.search[field]));
                 let parsedNumber = PhoneNumberUtils.parse(number.toString());
                 if (parsedNumber) {
-                  debug("InternationalFormat: " + parsedNumber.internationalFormat);
-                  debug("InternationalNumber: " + parsedNumber.internationalNumber);
-                  debug("NationalNumber: " + parsedNumber.nationalNumber);
-                  debug("NationalFormat: " + parsedNumber.nationalFormat);
+                  if (DEBUG) {
+                    debug("InternationalFormat: " + parsedNumber.internationalFormat);
+                    debug("InternationalNumber: " + parsedNumber.internationalNumber);
+                    debug("NationalNumber: " + parsedNumber.nationalNumber);
+                    debug("NationalFormat: " + parsedNumber.nationalFormat);
+                  }
                   if (parsedNumber.internationalNumber &&
                       number.toString() !== parsedNumber.internationalNumber) {
                     contact.search.exactTel.push(parsedNumber.internationalNumber);
                     let digits = parsedNumber.internationalNumber.match(/\d/g);
                     if (digits) {
                       digits = digits.join('');
                       for(let i = 0; i < digits.length; i++) {
                         search[digits.substring(i, digits.length)] = 1;
--- a/dom/contacts/tests/test_contacts_basics.html
+++ b/dom/contacts/tests/test_contacts_basics.html
@@ -304,19 +304,19 @@ var steps = [
       sample_id1 = createResult1.id;
       checkContacts(properties1, createResult1);
       next();
     };
     req.onerror = onFailure;
   },
   function () {
     ok(true, "Retrieving by substring");
-    var options = {filterBy: ["name"],
+    var options = {filterBy: ["givenName"],
                    filterOp: "contains",
-                   filterValue: properties1.name.substring(0,3)};
+                   filterValue: properties1.givenName[1].substring(0,3)};
     req = mozContacts.find(options);
     req.onsuccess = function () {
       ok(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
@@ -352,19 +352,19 @@ var steps = [
     req.onerror = onFailure;
   },
   function () {
     ok(true, "Retrieving by substring and update");
     mozContacts.oncontactchange = function(event) {
        is(event.contactID, findResult1.id, "Same contactID");
        is(event.reason, "update", "Same reason");
      }
-    var options = {filterBy: ["name"],
+    var options = {filterBy: ["givenName"],
                    filterOp: "contains",
-                   filterValue: properties1.name.substring(0,3)};
+                   filterValue: properties1.givenName[0].substring(0,3)};
     req = mozContacts.find(options);
     req.onsuccess = function () {
       ok(req.result.length == 1, "Found exactly 1 contact.");
       findResult1 = req.result[0];
       findResult1.jobTitle = ["new Job"];
       ok(findResult1.id == sample_id1, "Same ID");
       checkContacts(createResult1, properties1);
       next();
@@ -383,19 +383,19 @@ var steps = [
     req.onsuccess = function () {
       ok(createResult2.id, "The contact now has an ID.");
       next();
     };
     req.onerror = onFailure;
   },
   function () {
     ok(true, "Retrieving by substring");
-    var options = {filterBy: ["name"],
+    var options = {filterBy: ["givenName"],
                    filterOp: "contains",
-                   filterValue: properties1.name.substring(0,3)};
+                   filterValue: properties1.givenName[0].substring(0,3)};
     req = mozContacts.find(options);
     req.onsuccess = function () {
       ok(req.result.length == 1, "Found exactly 1 contact.");
       findResult1 = req.result[0];
       checkContacts(createResult1, findResult1);
       next();
     };
     req.onerror = onFailure;
@@ -409,19 +409,19 @@ var steps = [
     req = navigator.mozContacts.remove(createResult1);
     req.onsuccess = function () {
       next();
     };
     req.onerror = onFailure;
   },
   function () {
     ok(true, "Retrieving by substring");
-    var options = {filterBy: ["name"],
+    var options = {filterBy: ["givenName"],
                    filterOp: "contains",
-                   filterValue: properties1.name.substring(0,3)};
+                   filterValue: properties1.givenName[1].substring(0,3)};
     req = mozContacts.find(options);
     req.onsuccess = function () {
       ok(req.result.length == 0, "Found no contact.");
       next();
     };
     req.onerror = onFailure;
   },
   function () {
@@ -433,19 +433,19 @@ var steps = [
     req = navigator.mozContacts.remove(createResult2);
     req.onsuccess = function () {
       next();
     };
     req.onerror = onFailure;
   },
   function () {
     ok(true, "Retrieving by substring");
-    var options = {filterBy: ["name"],
+    var options = {filterBy: ["givenName"],
                    filterOp: "contains",
-                   filterValue: properties1.name.substring(0,3)};
+                   filterValue: properties1.givenName[1].substring(0,3)};
     req = mozContacts.find(options);
     req.onsuccess = function () {
       ok(req.result.length == 0, "Found no contact.");
       next();
     };
     req.onerror = onFailure;
   },
   function () {
@@ -532,32 +532,32 @@ var steps = [
       ok(findResult1.id == sample_id1, "Same ID");
       checkContacts(createResult1, properties1);
       next();
     };
     req.onerror = onFailure;
   },
   function () {
     ok(true, "Retrieving by substring3");
-    var options = {filterBy: ["name", "givenName"],
+    var options = {filterBy: ["familyName", "givenName"],
                    filterOp: "contains",
                    filterValue: properties1.givenName[0].substring(0,3)};
     req = mozContacts.find(options);
     req.onsuccess = function () {
       ok(req.result.length == 1, "Found exactly 1 contact.");
       findResult1 = req.result[0];
       ok(findResult1.id == sample_id1, "Same ID");
       checkContacts(createResult1, properties1);
       next();
     };
     req.onerror = onFailure;
   },
   function () {
     ok(true, "Retrieving by substring3, Testing multi entry");
-    var options = {filterBy: ["name", "givenName", "familyName"],
+    var options = {filterBy: ["givenName", "familyName"],
                    filterOp: "contains",
                    filterValue: properties1.familyName[1].substring(0,3).toLowerCase()};
     req = mozContacts.find(options);
     req.onsuccess = function () {
       ok(req.result.length == 1, "Found exactly 1 contact.");
       findResult1 = req.result[0];
       ok(findResult1.id == sample_id1, "Same ID");
       checkContacts(createResult1, properties1);
@@ -648,49 +648,49 @@ var steps = [
         next();
       }
       req2.onerror = onFailure;
     };
     req.onerror = onFailure;
   },
   function () {
     ok(true, "Searching contacts by query");
-    var options = {filterBy: ["name", "email"],
+    var options = {filterBy: ["givenName", "email"],
                    filterOp: "contains",
-                   filterValue: properties1.name[0].substring(0,4)};
+                   filterValue: properties1.givenName[0].substring(0,4)};
     req = mozContacts.find(options);
     req.onsuccess = function () {
       ok(req.result.length == 1, "Found exactly 1 contact.");
       findResult1 = req.result[0];
       ok(findResult1.id == sample_id1, "Same ID");
       checkContacts(findResult1, properties1);
       next();
     };
     req.onerror = onFailure;
   },
   function () {
     ok(true, "Searching contacts by query");
-    var options = {filterBy: ["nickname", "email"],
+    var options = {filterBy: ["givenName", "email"],
                    filterOp: "contains",
-                   filterValue: properties1.nickname};
+                   filterValue: properties1.givenName[0]};
     req = mozContacts.find(options);
     req.onsuccess = function () {
       ok(req.result.length == 1, "Found exactly 1 contact.");
       findResult1 = req.result[0];
       ok(findResult1.id == sample_id1, "Same ID");
       checkContacts(findResult1, properties1);
       next();
     };
     req.onerror = onFailure;
   },
   function () {
     ok(true, "Searching contacts with multiple indices");
-    var options = {filterBy: ["nickname", "email", "name"],
+    var options = {filterBy: ["email", "givenName"],
                    filterOp: "equals",
-                   filterValue: properties1.nickname};
+                   filterValue: properties1.givenName[1]};
     req = mozContacts.find(options);
     req.onsuccess = function () {
       ok(req.result.length == 1, "Found exactly 1 contact.");
       findResult1 = req.result[0];
       ok(findResult1.id == sample_id1, "Same ID");
       checkContacts(findResult1, properties1);
       next();
     };
@@ -699,19 +699,19 @@ var steps = [
   function () {
     ok(true, "Modifying contact3");
     findResult1.email = [{value: properties1.nickname}];
     findResult1.nickname = "TEST";
     var newContact = new mozContact();
     newContact.init(findResult1);
     req = mozContacts.save(newContact);
     req.onsuccess = function () {
-      var options = {filterBy: ["nickname", "email", "name"],
+      var options = {filterBy: ["email", "givenName"],
                      filterOp: "contains",
-                     filterValue: properties1.nickname};
+                     filterValue: properties1.givenName[0]};
       // One contact has it in nickname and the other in email
       var req2 = mozContacts.find(options);
       req2.onsuccess = function () {
         ok(req2.result.length == 2, "Found exactly 2 contacts.");
         ok(req2.result[0].id != req2.result[1].id, "Different ID");
         next();
       }
       req2.onerror = onFailure;
@@ -771,34 +771,34 @@ var steps = [
     req.onsuccess = function () {
       ok(req.result.length == 2, "Found exactly 2 contact.");
       next();
     }
     req.onerror = onFailure;
   },
   function () {
     console.log("Searching contacts by query1");
-    var options = {filterBy: ["name", "email"],
+    var options = {filterBy: ["givenName", "email"],
                    filterOp: "contains",
-                   filterValue: properties1.name[0].substring(0, 4)}
+                   filterValue: properties1.givenName[0].substring(0, 4)}
     req = mozContacts.find(options)
     req.onsuccess = function () {
       ok(req.result.length == 1, "Found exactly 1 contact.");
       findResult1 = req.result[0];
       ok(findResult1.id == sample_id1, "Same ID");
       checkContacts(findResult1, createResult1);
       next();
     }
     req.onerror = onFailure;
   },
   function () {
     ok(true, "Searching contacts by query2");
-    var options = {filterBy: ["name", "email"],
+    var options = {filterBy: ["givenName", "email"],
                    filterOp: "contains",
-                   filterValue: properties2.name[0].substring(0, 4)};
+                   filterValue: properties2.givenName[0].substring(0, 4)};
     req = mozContacts.find(options);
     req.onsuccess = function () {
       ok(req.result.length == 1, "Found exactly 1 contact.");
       findResult1 = req.result[0];
       ok(findResult1.adr.length == 2, "Adr length 2");
       checkContacts(findResult1, createResult2);
       next();
     }
@@ -892,32 +892,32 @@ var steps = [
     req.onsuccess = function () {
       ok(req.result.length == 10, "10 Entries.");
       next();
     }
     req.onerror = onFailure;
   },
   function () {
     ok(true, "Retrieving all contacts2");
-    var options = {filterBy: ["name"],
+    var options = {filterBy: ["givenName"],
                    filterOp: "contains",
-                   filterValue: properties1.name[0].substring(0, 4)};
+                   filterValue: properties1.givenName[0].substring(0, 4)};
     req = mozContacts.find(options);
     req.onsuccess = function () {
       ok(req.result.length == 20, "20 Entries.");
       checkContacts(createResult1, req.result[19]);
       next();
     }
     req.onerror = onFailure;
   },
   function () {
     ok(true, "Retrieving all contacts3");
-    var options = {filterBy: ["name", "givenName", "tel", "email", "note"],
+    var options = {filterBy: ["givenName", "tel", "email"],
                    filterOp: "contains",
-                   filterValue: properties1.name[0].substring(0, 4),
+                   filterValue: properties1.givenName[0].substring(0, 4),
                    filterLimit: 15 };
     req = mozContacts.find(options);
     req.onsuccess = function () {
       ok(req.result.length == 15, "15 Entries.");
       checkContacts(createResult1, req.result[10]);
       next();
     }
     req.onerror = onFailure;
@@ -956,30 +956,30 @@ var steps = [
       ok(createResult1.email != cloned.email, "Clone has different email");
       ok(cloned.givenName == "Tom", "New Name");
       next();
     }
     req.onerror = onFailure;
   },
   function () {
     ok(true, "Retrieving all contacts");
-    var options = {filterBy: ["name"],
+    var options = {filterBy: ["givenName"],
                    filterOp: "contains",
-                   filterValue: properties2.name[0].substring(0, 4)};
+                   filterValue: properties2.givenName[0].substring(0, 4)};
     req = mozContacts.find({});
     req.onsuccess = function () {
       ok(req.result.length == 2, "2 Entries.");
       next();
     }
     req.onerror = onFailure;
   },
   function () {
     ok(true, "Search with redundant fields should only return 1 contact");
     createResult1 = new mozContact();
-    createResult1.init({name: "XXX", nickname: "XXX", email: [{value: "XXX"}], tel: {value: "XXX"}});
+    createResult1.init({name: "XXX", givenName: "XXX", email: [{value: "XXX"}], tel: {value: "XXX"}});
     req = mozContacts.save(createResult1);
     req.onsuccess = function() {
       var options = {filterBy: [],
                      filterOp: "equals",
                      filterValue: "XXX"};
       var req2 = mozContacts.find(options);
       req2.onsuccess = function() {
         ok(req2.result.length == 1, "1 Entry");
@@ -1102,26 +1102,26 @@ var steps = [
       checkContacts(req.result[4], c4);
       next();
     };
     req.onerror = onFailure;
   },
   function () {
     ok(true, "Don't allow to add custom fields");
     createResult1 = new mozContact();
-    createResult1.init({name: "customTest", yyy: "XXX"});
+    createResult1.init({givenName: "customTest", yyy: "XXX"});
     req = mozContacts.save(createResult1);
     req.onsuccess = function() {
       var options = {filterBy: [],
                      filterOp: "equals",
                      filterValue: "customTest"};
       var req2 = mozContacts.find(options);
       req2.onsuccess = function() {
         ok(req2.result.length == 1, "1 Entry");
-        checkStr(req2.result.name, "customTest", "same name");
+        checkStr(req2.result.givenName, "customTest", "same name");
         ok(req2.result.yyy === undefined, "custom property undefined");
         next();
       }
       req2.onerror = onFailure;
     }
     req.onerror = onFailure;
   },
   function () {
--- a/dom/contacts/tests/test_contacts_blobs.html
+++ b/dom/contacts/tests/test_contacts_blobs.html
@@ -83,22 +83,22 @@ function verifyBuffers(buffer1, buffer2,
   if (isLast)
     next();
 }
 
 var randomBlob = getRandomBlob(1024);
 var randomBlob2 = getRandomBlob(1024);
 
 var properties1 = {
-  name: "xTestname1",
+  givenName: "xTestname1",
   photo: [randomBlob]
 };
 
 var properties2 = {
-  name: "yTestname2",
+  givenName: "yTestname2",
   photo: [randomBlob, randomBlob2]
 };
 
 var sample_id1;
 var createResult1;
 var findResult1;
 
 function onUnwantedSuccess() {
@@ -180,19 +180,19 @@ var steps = [
       ok(createResult1.id, "The contact now has an ID.");
       sample_id1 = createResult1.id;
       next();
     };
     req.onerror = onFailure;
   },
   function () {
     ok(true, "Retrieving by substring");
-    var options = {filterBy: ["name"],
+    var options = {filterBy: ["givenName"],
                    filterOp: "contains",
-                   filterValue: properties1.name.substring(0,3)};
+                   filterValue: properties1.givenName.substring(0,3)};
     req = mozContacts.find(options);
     req.onsuccess = function () {
       ok(req.result.length == 1, "Found exactly 1 contact.");
       findResult1 = req.result[0];
       ok(findResult1.id == sample_id1, "Same ID");
       verifyBlobArray(createResult1.photo, properties1.photo);
     };
     req.onerror = onFailure;
@@ -206,56 +206,56 @@ var steps = [
       ok(createResult1.id, "The contact now has an ID.");
       sample_id1 = createResult1.id;
       next();
     };
     req.onerror = onFailure;
   },
   function () {
     ok(true, "Retrieving by substring");
-    var options = {filterBy: ["name"],
+    var options = {filterBy: ["givenName"],
                    filterOp: "contains",
-                   filterValue: properties2.name.substring(0,3)};
+                   filterValue: properties2.givenName.substring(0,3)};
     req = mozContacts.find(options);
     req.onsuccess = function () {
       ok(req.result.length == 1, "Found exactly 1 contact.");
       findResult1 = req.result[0];
       ok(findResult1.id == sample_id1, "Same ID");
       verifyBlobArray(createResult1.photo, properties2.photo);
     };
     req.onerror = onFailure;
   },
   function () {
     ok(true, "Adding photo as String");
     createResult1 = new mozContact();
-    createResult1.init({name: "asdf", photo: ["xyz"]});
+    createResult1.init({givenName: "asdf", photo: ["xyz"]});
     req = navigator.mozContacts.save(createResult1);
     req.onsuccess = function () {
       ok(createResult1.id, "The contact now has an ID.");
       sample_id1 = createResult1.id;
       is(createResult1.photo, null, "No photo")
       next();
     };
     req.onerror = onFailure;
   },
   function () {
     ok(true, "Adding photo as String");
     createResult1 = new mozContact();
-    createResult1.init({name: "jkl", photo: "xyz"});
+    createResult1.init({givenName: "jkl", photo: "xyz"});
     req = navigator.mozContacts.save(createResult1);
     req.onsuccess = function () {
       ok(createResult1.id, "The contact now has an ID.");
       is(createResult1.photo, null, "No photo")
       next();
     };
     req.onerror = onFailure;
   },
   function () {
     ok(true, "Retrieving by substring");
-    var options = {filterBy: ["name"],
+    var options = {filterBy: ["givenName"],
                    filterOp: "contains",
                    filterValue: "asdf"};
     req = mozContacts.find(options);
     req.onsuccess = function () {
       ok(req.result.length == 1, "Found exactly 1 contact.");
       findResult1 = req.result[0];
       ok(findResult1.id == sample_id1, "Same ID");
       is(findResult1.photo, null, "No photo");