Bug 1084384: support importing contacts with phone numbers in a different format r=abr a=lmandel
authorRandell Jesup <rjesup@jesup.org>
Sun, 19 Oct 2014 20:57:32 -0400
changeset 225739 8c42ccaf8aa1
parent 225738 bda95894a692
child 225740 5840764c4312
push id3995
push userrjesup@wgate.com
push date2014-10-20 00:58 +0000
treeherdermozilla-beta@8c42ccaf8aa1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersabr, lmandel
bugs1084384
milestone34.0
Bug 1084384: support importing contacts with phone numbers in a different format r=abr a=lmandel
browser/components/loop/GoogleImporter.jsm
browser/components/loop/test/mochitest/browser_GoogleImporter.js
browser/components/loop/test/mochitest/fixtures/google_contacts.txt
browser/components/loop/test/mochitest/head.js
--- a/browser/components/loop/GoogleImporter.jsm
+++ b/browser/components/loop/GoogleImporter.jsm
@@ -443,20 +443,23 @@ this.GoogleImporter.prototype = {
       }
     }
 
     // Process telephone numbers.
     let phoneNodes = entry.getElementsByTagNameNS(kNS_GD, "phoneNumber");
     if (phoneNodes.length) {
       contact.tel = [];
       for (let [,phoneNode] of Iterator(phoneNodes)) {
+        let phoneNumber = phoneNode.hasAttribute("uri") ?
+          phoneNode.getAttribute("uri").replace("tel:", "") :
+          phoneNode.firstChild.nodeValue;
         contact.tel.push({
           pref: (phoneNode.getAttribute("primary") == "true"),
           type: [getFieldType(phoneNode)],
-          value: phoneNode.getAttribute("uri").replace("tel:", "")
+          value: phoneNumber
         });
       }
     }
 
     let orgNodes = entry.getElementsByTagNameNS(kNS_GD, "organization");
     if (orgNodes.length) {
       contact.org = [];
       contact.jobTitle = [];
--- a/browser/components/loop/test/mochitest/browser_GoogleImporter.js
+++ b/browser/components/loop/test/mochitest/browser_GoogleImporter.js
@@ -12,74 +12,88 @@ function promiseImport() {
         reject(err);
       } else {
         resolve(stats);
       }
     }, mockDb, window);
   });
 }
 
+const kContactsCount = 7;
+
 add_task(function* test_GoogleImport() {
   let stats;
   // An error may throw and the test will fail when that happens.
   stats = yield promiseImport();
 
+  let contactsCount = mockDb.size;
+
   // Assert the world.
-  Assert.equal(stats.total, 6, "Five contacts should get processed");
-  Assert.equal(stats.success, 6, "Five contacts should be imported");
+  Assert.equal(stats.total, contactsCount, "Five contacts should get processed");
+  Assert.equal(stats.success, contactsCount, "Five contacts should be imported");
 
   yield promiseImport();
-  Assert.equal(Object.keys(mockDb._store).length, 6, "Database should contain only five contact after reimport");
+  Assert.equal(Object.keys(mockDb._store).length, contactsCount, "Database should be the same size after reimport");
 
-  let c = mockDb._store[mockDb._next_guid - 6];
+  let currentContact = contactsCount;
+
+  let c = mockDb._store[mockDb._next_guid - currentContact];
   Assert.equal(c.name[0], "John Smith", "Full name should match");
   Assert.equal(c.givenName[0], "John", "Given name should match");
   Assert.equal(c.familyName[0], "Smith", "Family name should match");
   Assert.equal(c.email[0].type, "other", "Email type should match");
   Assert.equal(c.email[0].value, "john.smith@example.com", "Email should match");
   Assert.equal(c.email[0].pref, true, "Pref should match");
   Assert.equal(c.category[0], "google", "Category should match");
   Assert.equal(c.id, "http://www.google.com/m8/feeds/contacts/tester%40mochi.com/base/0", "UID should match and be scoped to provider");
 
-  c = mockDb._store[mockDb._next_guid - 5];
+  c = mockDb._store[mockDb._next_guid - (--currentContact)];
   Assert.equal(c.name[0], "Jane Smith", "Full name should match");
   Assert.equal(c.givenName[0], "Jane", "Given name should match");
   Assert.equal(c.familyName[0], "Smith", "Family name should match");
   Assert.equal(c.email[0].type, "other", "Email type should match");
   Assert.equal(c.email[0].value, "jane.smith@example.com", "Email should match");
   Assert.equal(c.email[0].pref, true, "Pref should match");
   Assert.equal(c.category[0], "google", "Category should match");
   Assert.equal(c.id, "http://www.google.com/m8/feeds/contacts/tester%40mochi.com/base/1", "UID should match and be scoped to provider");
 
-  c = mockDb._store[mockDb._next_guid - 4];
+  c = mockDb._store[mockDb._next_guid - (--currentContact)];
   Assert.equal(c.name[0], "Davy Randall Jones", "Full name should match");
   Assert.equal(c.givenName[0], "Davy Randall", "Given name should match");
   Assert.equal(c.familyName[0], "Jones", "Family name should match");
   Assert.equal(c.email[0].type, "other", "Email type should match");
   Assert.equal(c.email[0].value, "davy.jones@example.com", "Email should match");
   Assert.equal(c.email[0].pref, true, "Pref should match");
   Assert.equal(c.category[0], "google", "Category should match");
   Assert.equal(c.id, "http://www.google.com/m8/feeds/contacts/tester%40mochi.com/base/2", "UID should match and be scoped to provider");
 
-  c = mockDb._store[mockDb._next_guid - 3];
+  c = mockDb._store[mockDb._next_guid - (--currentContact)];
   Assert.equal(c.name[0], "noname@example.com", "Full name should match");
   Assert.equal(c.email[0].type, "other", "Email type should match");
   Assert.equal(c.email[0].value, "noname@example.com", "Email should match");
   Assert.equal(c.email[0].pref, true, "Pref should match");
   Assert.equal(c.category[0], "google", "Category should match");
   Assert.equal(c.id, "http://www.google.com/m8/feeds/contacts/tester%40mochi.com/base/3", "UID should match and be scoped to provider");
 
-  c = mockDb._store[mockDb._next_guid - 2];
+  c = mockDb._store[mockDb._next_guid - (--currentContact)];
   Assert.equal(c.name[0], "lycnix", "Full name should match");
   Assert.equal(c.email[0].type, "other", "Email type should match");
   Assert.equal(c.email[0].value, "lycnix", "Email should match");
   Assert.equal(c.email[0].pref, true, "Pref should match");
   Assert.equal(c.category[0], "google", "Category should match");
   Assert.equal(c.id, "http://www.google.com/m8/feeds/contacts/tester%40mochi.com/base/7", "UID should match and be scoped to provider");
 
-  c = mockDb._store[mockDb._next_guid - 1];
+  c = mockDb._store[mockDb._next_guid - (--currentContact)];
   Assert.equal(c.name[0], "+31-6-12345678", "Full name should match");
-  Assert.equal(c.tel[0].type, "mobile", "Email type should match");
-  Assert.equal(c.tel[0].value, "+31-6-12345678", "Email should match");
+  Assert.equal(c.tel[0].type, "mobile", "Phone type should match");
+  Assert.equal(c.tel[0].value, "+31-6-12345678", "Phone should match");
   Assert.equal(c.tel[0].pref, false, "Pref should match");
   Assert.equal(c.category[0], "google", "Category should match");
   Assert.equal(c.id, "http://www.google.com/m8/feeds/contacts/tester%40mochi.com/base/8", "UID should match and be scoped to provider");
+
+  c = mockDb._store[mockDb._next_guid - (--currentContact)];
+  Assert.equal(c.name[0], "215234523452345", "Full name should match");
+  Assert.equal(c.tel[0].type, "mobile", "Phone type should match");
+  Assert.equal(c.tel[0].value, "215234523452345", "Phone should match");
+  Assert.equal(c.tel[0].pref, false, "Pref should match");
+  Assert.equal(c.category[0], "google", "Category should match");
+  Assert.equal(c.id, "http://www.google.com/m8/feeds/contacts/tester%40mochi.com/base/6", "UID should match and be scoped to provider");
 });
--- a/browser/components/loop/test/mochitest/fixtures/google_contacts.txt
+++ b/browser/components/loop/test/mochitest/fixtures/google_contacts.txt
@@ -97,9 +97,21 @@
     <app:edited xmlns:app="http://www.w3.org/2007/app">2014-10-10T14:55:44.786Z</app:edited>
     <category scheme="http://schemas.google.com/g/2005#kind" term="http://schemas.google.com/contact/2008#contact"/>
     <title/>
     <link href="https://www.google.com/m8/feeds/photos/media/tester%40mochi.com/8" rel="http://schemas.google.com/contacts/2008/rel#photo" type="image/*"/>
     <link href="https://www.google.com/m8/feeds/contacts/tester%40mochi.com/full/8" rel="self" type="application/atom+xml"/>
     <link href="https://www.google.com/m8/feeds/contacts/tester%40mochi.com/full/8" rel="edit" type="application/atom+xml"/>
     <gd:phoneNumber rel="http://schemas.google.com/g/2005#mobile" uri="tel:+31-6-12345678">0612345678</gd:phoneNumber>
   </entry>
+  <entry gd:etag="&quot;SX8-ejVSLit7I2A9XRdQFUkDRgY.&quot;">
+    <id>http://www.google.com/m8/feeds/contacts/tester%40mochi.com/base/6</id>
+    <updated>2014-10-17T12:32:08.152Z</updated>
+    <app:edited xmlns:app="http://www.w3.org/2007/app">2014-10-17T12:32:08.152Z</app:edited>
+    <category scheme="http://schemas.google.com/g/2005#kind" term="http://schemas.google.com/contact/2008#contact"/>
+    <title/>
+    <link href="https://www.google.com/m8/feeds/photos/media/tester%40mochi.com/6" rel="http://schemas.google.com/contacts/2008/rel#photo" type="image/*"/>
+    <link href="https://www.google.com/m8/feeds/contacts/tester%40mochi.com/full/6" rel="self" type="application/atom+xml"/>
+    <link href="https://www.google.com/m8/feeds/contacts/tester%40mochi.com/full/6" rel="edit" type="application/atom+xml"/>
+    <gd:phoneNumber rel="http://schemas.google.com/g/2005#mobile">215234523452345</gd:phoneNumber>
+    <gContact:groupMembershipInfo deleted="false" href="http://www.google.com/m8/feeds/groups/tester%40mochi.com/base/6"/>
+  </entry>
 </feed>
--- a/browser/components/loop/test/mochitest/head.js
+++ b/browser/components/loop/test/mochitest/head.js
@@ -220,16 +220,20 @@ CustomizableUI.addWidgetToArea("loop-cal
 registerCleanupFunction(function() {
   CustomizableUI.reset();
 });
 
 const mockDb = {
   _store: { },
   _next_guid: 1,
 
+  get size() {
+    return Object.getOwnPropertyNames(this._store).length;
+  },
+
   add: function(details, callback) {
     if (!("id" in details)) {
       callback(new Error("No 'id' field present"));
       return;
     }
     details._guid = this._next_guid++;
     this._store[details._guid] = details;
     callback(null, details);