Bug 1060812 - Stop processing when contact is not found r=Standard8
authorAdam Roach [:abr] <adam@nostrum.com>
Mon, 01 Sep 2014 15:44:51 -0500
changeset 224413 727bbb84051d21dd4778c62844f18362090f443e
parent 224412 48e03a88b6a80479e53ef7e16693d4ed54fdbc21
child 224414 dd158b25ffc212b7a7455c499e8ad3a0a4ad6b27
push id3979
push userraliiev@mozilla.com
push dateMon, 13 Oct 2014 16:35:44 +0000
treeherdermozilla-beta@30f2cc610691 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersStandard8
bugs1060812
milestone34.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 1060812 - Stop processing when contact is not found r=Standard8
browser/components/loop/LoopContacts.jsm
browser/components/loop/test/mochitest/browser_LoopContacts.js
--- a/browser/components/loop/LoopContacts.jsm
+++ b/browser/components/loop/LoopContacts.jsm
@@ -431,17 +431,19 @@ let LoopContactsInternal = Object.freeze
         try {
           request = store.delete(guid);
         } catch (ex) {
           callback(ex);
           return;
         }
 
         request.onsuccess = event => {
-          eventEmitter.emit("remove", contact);
+          if (contact) {
+            eventEmitter.emit("remove", contact);
+          }
           callback(null, event.target.result);
         };
         request.onerror = event => callback(event.target.error);
       }, "readwrite");
     });
   },
 
   /**
@@ -669,16 +671,17 @@ let LoopContactsInternal = Object.freeze
       if (err) {
         callback(err);
         return;
       }
 
       if (!contact) {
         callback(new Error("Contact with " + kKeyPath + " '" +
                            guid + "' could not be found"));
+        return;
       }
 
       LoopStorage.getStore(kObjectStoreName, (err, store) => {
         if (err) {
           callback(err);
           return;
         }
 
@@ -718,16 +721,17 @@ let LoopContactsInternal = Object.freeze
       if (err) {
         callback(err);
         return;
       }
 
       if (!contact) {
         callback(new Error("Contact with " + kKeyPath + " '" +
                            guid + "' could not be found"));
+        return;
       }
 
       contact.blocked = true;
       this.update(contact, callback);
     });
   },
 
   /**
@@ -744,16 +748,17 @@ let LoopContactsInternal = Object.freeze
       if (err) {
         callback(err);
         return;
       }
 
       if (!contact) {
         callback(new Error("Contact with " + kKeyPath + " '" +
                            guid + "' could not be found"));
+        return;
       }
 
       contact.blocked = false;
       this.update(contact, callback);
     });
   },
 
   /**
--- a/browser/components/loop/test/mochitest/browser_LoopContacts.js
+++ b/browser/components/loop/test/mochitest/browser_LoopContacts.js
@@ -141,35 +141,35 @@ registerCleanupFunction(function () {
 
 // Test adding a contact.
 add_task(function* () {
   let contacts = yield promiseLoadContacts();
   for (let i = 0, l = contacts.length; i < l; ++i) {
     compareContacts(contacts[i], kContacts[i]);
   }
 
-  // Add a contact.
+  info("Add a contact.");
   let deferred = Promise.defer();
   gExpectedAdds.push(kDanglingContact);
   LoopContacts.add(kDanglingContact, (err, contact) => {
     Assert.ok(!err, "There shouldn't be an error");
     compareContacts(contact, kDanglingContact);
 
-    // Check if it's persisted.
+    info("Check if it's persisted.");
     LoopContacts.get(contact._guid, (err, contact) => {
       Assert.ok(!err, "There shouldn't be an error");
       compareContacts(contact, kDanglingContact);
       deferred.resolve();
     });
   });
   yield deferred.promise;
 });
 
-// Test removing all contacts.
 add_task(function* () {
+  info("Test removing all contacts.");
   let contacts = yield promiseLoadContacts();
 
   let deferred = Promise.defer();
   LoopContacts.removeAll(function(err) {
     Assert.ok(!err, "There shouldn't be an error");
     LoopContacts.getAll(function(err, found) {
       Assert.ok(!err, "There shouldn't be an error");
       Assert.equal(found.length, 0, "There shouldn't be any contacts left");
@@ -178,100 +178,100 @@ add_task(function* () {
   });
   yield deferred.promise;
 });
 
 // Test retrieving a contact.
 add_task(function* () {
   let contacts = yield promiseLoadContacts();
 
-  // Get a single contact.
+  info("Get a single contact.");
   let deferred = Promise.defer();
   LoopContacts.get(contacts[1]._guid, (err, contact) => {
     Assert.ok(!err, "There shouldn't be an error");
     compareContacts(contact, kContacts[1]);
     deferred.resolve();
   });
   yield deferred.promise;
 
-  // Get a single contact by id.
+  info("Get a single contact by id.");
   let deferred = Promise.defer();
   LoopContacts.getByServiceId(2, (err, contact) => {
     Assert.ok(!err, "There shouldn't be an error");
     compareContacts(contact, kContacts[1]);
     deferred.resolve();
   });
   yield deferred.promise;
 
-  // Get a couple of contacts.
+  info("Get a couple of contacts.");
   let deferred = Promise.defer();
   let toRetrieve = [contacts[0], contacts[2], contacts[3]];
   LoopContacts.getMany(toRetrieve.map(contact => contact._guid), (err, result) => {
     Assert.ok(!err, "There shouldn't be an error");
     Assert.equal(result.length, toRetrieve.length, "Result list should be the same " +
                  "size as the list of items to retrieve");
     for (let contact of toRetrieve) {
       let found = result.filter(c => c._guid == contact._guid);
       Assert.ok(found.length, "Contact " + contact._guid + " should be in the list");
       compareContacts(found[0], contact);
     }
     deferred.resolve();
   });
   yield deferred.promise;
 
-  // Get all contacts.
+  info("Get all contacts.");
   deferred = Promise.defer();
   LoopContacts.getAll((err, contacts) => {
     Assert.ok(!err, "There shouldn't be an error");
     for (let i = 0, l = contacts.length; i < l; ++i) {
       compareContacts(contacts[i], kContacts[i]);
     }
     deferred.resolve();
   });
   yield deferred.promise;
 
-  // Get a non-existent contact.
+  info("Get a non-existent contact.");
   deferred = Promise.defer();
   LoopContacts.get(1000, (err, contact) => {
     Assert.ok(!err, "There shouldn't be an error");
     Assert.ok(!contact, "There shouldn't be a contact");
     deferred.resolve();
   });
   yield deferred.promise;
 });
 
 // Test removing a contact.
 add_task(function* () {
   let contacts = yield promiseLoadContacts();
 
-  // Remove a single contact.
+  info("Remove a single contact.");
   let deferred = Promise.defer();
   let toRemove = contacts[2]._guid;
   gExpectedRemovals.push(toRemove);
   LoopContacts.remove(toRemove, err => {
     Assert.ok(!err, "There shouldn't be an error");
 
     LoopContacts.get(toRemove, (err, contact) => {
       Assert.ok(!err, "There shouldn't be an error");
       Assert.ok(!contact, "There shouldn't be a contact");
       deferred.resolve();
     });
   });
   yield deferred.promise;
 
-  // Remove a non-existing contact.
+  info("Remove a non-existing contact.");
   deferred = Promise.defer();
   LoopContacts.remove(1000, (err, contact) => {
     Assert.ok(!err, "There shouldn't be an error");
     Assert.ok(!contact, "There shouldn't be a contact");
     deferred.resolve();
   });
   yield deferred.promise;
 
-  // Remove multiple contacts.
+  info("Remove multiple contacts.");
   deferred = Promise.defer();
   toRemove = [contacts[0]._guid, contacts[1]._guid];
   gExpectedRemovals.push(...toRemove);
   LoopContacts.removeMany(toRemove, err => {
     Assert.ok(!err, "There shouldn't be an error");
 
     LoopContacts.getAll((err, contacts) => {
       Assert.ok(!err, "There shouldn't be an error");
@@ -287,39 +287,39 @@ add_task(function* () {
 });
 
 // Test updating a contact.
 add_task(function* () {
   let contacts = yield promiseLoadContacts();
 
   const newBday = (new Date(403920000000)).toISOString();
 
-  // Update a single contact.
+  info("Update a single contact.");
   let deferred = Promise.defer();
   let toUpdate = {
     _guid: contacts[2]._guid,
     bday: newBday
   };
   gExpectedUpdates.push(contacts[2]._guid);
   LoopContacts.update(toUpdate, (err, result) => {
     Assert.ok(!err, "There shouldn't be an error");
     Assert.equal(result, toUpdate._guid, "Result should be the same as the contact ID");
 
     LoopContacts.get(toUpdate._guid, (err, contact) => {
       Assert.ok(!err, "There shouldn't be an error");
       Assert.equal(contact.bday, newBday, "Birthday should be the same");
-      // Check that all other properties were left intact.
+      info("Check that all other properties were left intact.");
       contacts[2].bday = newBday;
       compareContacts(contact, contacts[2]);
       deferred.resolve();
     });
   });
   yield deferred.promise;
 
-  // Update a non-existing contact.
+  info("Update a non-existing contact.");
   deferred = Promise.defer();
   toUpdate = {
     _guid: 1000,
     bday: newBday
   };
   LoopContacts.update(toUpdate, (err, contact) => {
     Assert.ok(err, "There should be an error");
     Assert.equal(err.message, "Contact with _guid '1000' could not be found",
@@ -328,65 +328,65 @@ add_task(function* () {
   });
   yield deferred.promise;
 });
 
 // Test blocking and unblocking a contact.
 add_task(function* () {
   let contacts = yield promiseLoadContacts();
 
-  // Block contact.
+  info("Block contact.");
   let deferred = Promise.defer();
   let toBlock = contacts[1]._guid;
   gExpectedUpdates.push(toBlock);
   LoopContacts.block(toBlock, (err, result) => {
     Assert.ok(!err, "There shouldn't be an error");
     Assert.equal(result, toBlock, "Result should be the same as the contact ID");
 
     LoopContacts.get(toBlock, (err, contact) => {
       Assert.ok(!err, "There shouldn't be an error");
       Assert.strictEqual(contact.blocked, true, "Blocked status should be set");
-      // Check that all other properties were left intact.
+      info("Check that all other properties were left intact.");
       delete contact.blocked;
       compareContacts(contact, contacts[1]);
       deferred.resolve();
     });
   });
   yield deferred.promise;
 
-  // Block a non-existing contact.
+  info("Block a non-existing contact.");
   deferred = Promise.defer();
   LoopContacts.block(1000, err => {
     Assert.ok(err, "There should be an error");
     Assert.equal(err.message, "Contact with _guid '1000' could not be found",
                  "Error message should be correct");
     deferred.resolve();
   });
   yield deferred.promise;
 
-  // Unblock a contact.
+  info("Unblock a contact.");
   deferred = Promise.defer();
   let toUnblock = contacts[1]._guid;
   gExpectedUpdates.push(toUnblock);
   LoopContacts.unblock(toUnblock, (err, result) => {
     Assert.ok(!err, "There shouldn't be an error");
     Assert.equal(result, toUnblock, "Result should be the same as the contact ID");
 
     LoopContacts.get(toUnblock, (err, contact) => {
       Assert.ok(!err, "There shouldn't be an error");
       Assert.strictEqual(contact.blocked, false, "Blocked status should be set");
-      // Check that all other properties were left intact.
+      info("Check that all other properties were left intact.");
       delete contact.blocked;
       compareContacts(contact, contacts[1]);
       deferred.resolve();
     });
   });
   yield deferred.promise;
 
-  // Unblock a non-existing contact.
+  info("Unblock a non-existing contact.");
   deferred = Promise.defer();
   LoopContacts.unblock(1000, err => {
     Assert.ok(err, "There should be an error");
     Assert.equal(err.message, "Contact with _guid '1000' could not be found",
                  "Error message should be correct");
     deferred.resolve();
   });
   yield deferred.promise;