Bug 1023695 - Part 6: Add Marionette Test Case to Verify ondeleted Event. r=vyang, a=2.0+
authorBevis Tseng <btseng@mozilla.com>
Fri, 27 Jun 2014 15:34:37 +0800
changeset 208925 6dd0fbb7c2e5d2eac8536589de3ba01b6fc35832
parent 208924 775ba85429bc47f991db632694ecd9731de7103c
child 208926 f6670cdc8b9a332b64eab0ea19674d5cc0b636a2
push id494
push userraliiev@mozilla.com
push dateMon, 25 Aug 2014 18:42:16 +0000
treeherdermozilla-release@a3cc3e46b571 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersvyang, 2
bugs1023695
milestone32.0a2
Bug 1023695 - Part 6: Add Marionette Test Case to Verify ondeleted Event. r=vyang, a=2.0+
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
@@ -307,19 +307,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
@@ -45,8 +45,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());
+});