Bug 1023695 - Part 6: Add Marionette Test Case to Verify ondeleted Event. r=vyang.
authorBevis Tseng <btseng@mozilla.com>
Fri, 27 Jun 2014 15:34:37 +0800
changeset 193311 6dceb20498b30dccd8db8685ae804149d7b83375
parent 193310 bd756f5d5cf25d4b468eebaf987cd767db64c288
child 193312 58cdfdba19be2eb7ad621da5aafc723d0f84e4c6
push id27116
push userryanvm@gmail.com
push dateThu, 10 Jul 2014 22:09:47 +0000
treeherdermozilla-central@0a0348d3f0c8 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersvyang
bugs1023695
milestone33.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 1023695 - Part 6: Add Marionette Test Case to Verify ondeleted Event. r=vyang.
dom/mobilemessage/tests/marionette/head.js
dom/mobilemessage/tests/marionette/manifest.ini
dom/mobilemessage/tests/marionette/test_ondeleted_event.js
--- a/dom/mobilemessage/tests/marionette/head.js
+++ b/dom/mobilemessage/tests/marionette/head.js
@@ -356,19 +356,27 @@ function getThreadById(aThreadId) {
  * @return An empty array if nothing to be deleted; otherwise, a deferred promise.
  */
 function deleteMessagesById(aMessageIds) {
   if (!aMessageIds.length) {
     ok(true, "no message to be deleted");
     return [];
   }
 
+  let promises = [];
+  promises.push(waitForManagerEvent("deleted"));
+
   let request = manager.delete(aMessageIds);
-  return wrapDomRequestAsPromise(request)
-      .then((aEvent) => { return aEvent.target.result; });
+  promises.push(wrapDomRequestAsPromise(request));
+
+  return Promise.all(promises)
+    .then((aResults) => {
+      return { deletedInfo: aResults[0],
+               deletedFlags: aResults[1].target.result };
+    });
 }
 
 /**
  * Delete messages specified from database.
  *
  * Fulfill params:
  *   result -- an array of boolean values indicating whether delesion was
  *             actually performed on the message record with corresponding id.
--- a/dom/mobilemessage/tests/marionette/manifest.ini
+++ b/dom/mobilemessage/tests/marionette/manifest.ini
@@ -43,8 +43,9 @@ qemu = true
 [test_mmdb_full_storage.js]
 [test_mmdb_upgradeSchema_current_structure.js]
 [test_mmdb_upgradeSchema_22.js]
 [test_replace_short_message_type.js]
 [test_mt_sms_concatenation.js]
 [test_error_of_mms_manual_retrieval.js]
 [test_error_of_mms_send.js]
 [test_error_of_sms_send.js]
+[test_ondeleted_event.js]
new file mode 100644
--- /dev/null
+++ b/dom/mobilemessage/tests/marionette/test_ondeleted_event.js
@@ -0,0 +1,58 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+MARIONETTE_TIMEOUT = 60000;
+MARIONETTE_HEAD_JS = 'head.js';
+
+const DESTINATING_ADDRESS_1 = "0987654321";
+const DESTINATING_ADDRESS_2 = "1234567890";
+const OUT_TEXT = "Outgoing SMS message!";
+
+function verifyDeletedInfo(aDeletedInfo, aMsgIds, aThreadIds) {
+    is(JSON.stringify(aDeletedInfo.deletedMessageIds),
+       JSON.stringify(aMsgIds), 'Check Msg Id.');
+    is(JSON.stringify(aDeletedInfo.deletedThreadIds),
+       JSON.stringify(aThreadIds), 'Check Thread Id.');
+}
+
+function testDeletingMessagesInOneThreadOneByOne() {
+  let sentMessages = [];
+
+  return Promise.resolve()
+  .then(() => sendSmsWithSuccess(DESTINATING_ADDRESS_1, OUT_TEXT))
+  .then((aMessage) => { sentMessages.push(aMessage); })
+  .then(() => sendSmsWithSuccess(DESTINATING_ADDRESS_1, OUT_TEXT))
+  .then((aMessage) => { sentMessages.push(aMessage); })
+  .then(() => deleteMessagesById([sentMessages[0].id]))
+  .then((aResult) => {
+    verifyDeletedInfo(aResult.deletedInfo,
+                      [sentMessages[0].id],
+                      null);
+  })
+  .then(() => deleteMessagesById([sentMessages[1].id]))
+  .then((aResult) => {
+    verifyDeletedInfo(aResult.deletedInfo,
+                      [sentMessages[1].id],
+                      [sentMessages[1].threadId]);
+  });
+}
+
+function testDeletingMessagesInTwoThreadsAtOnce() {
+  let sentMessages = [];
+  return Promise.resolve()
+  .then(() => sendSmsWithSuccess(DESTINATING_ADDRESS_1, OUT_TEXT))
+  .then((aMessage) => { sentMessages.push(aMessage); })
+  .then(() => sendSmsWithSuccess(DESTINATING_ADDRESS_2, OUT_TEXT))
+  .then((aMessage) => { sentMessages.push(aMessage); })
+  .then(() =>
+    deleteMessagesById(sentMessages.map((aMsg) => { return aMsg.id; })))
+  .then((aResult) =>
+    verifyDeletedInfo(aResult.deletedInfo,
+                      sentMessages.map((aMsg) => { return aMsg.id; }),
+                      sentMessages.map((aMsg) => { return aMsg.threadId; })));
+}
+
+startTestCommon(function testCaseMain() {
+  return testDeletingMessagesInOneThreadOneByOne()
+    .then(() => testDeletingMessagesInTwoThreadsAtOnce());
+});