Bug 786782 - Part 2/2: Test case. r=marshall_law, a=blocking-basecamp
authorVicamo Yang <vyang@mozilla.com>
Thu, 11 Oct 2012 19:01:55 +0800
changeset 113341 c0b49817915dfc5f65f40f43b83bc55a6d066d1d
parent 113340 e9e79d0ed99550eeb2e190f87d70676bfb888cf1
child 113342 34a039c14957d4a2a0f87e355df7c754b0c06709
push id2292
push userryanvm@gmail.com
push dateSat, 13 Oct 2012 19:19:53 +0000
treeherdermozilla-aurora@c0b49817915d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmarshall_law, blocking-basecamp
bugs786782
milestone18.0a2
Bug 786782 - Part 2/2: Test case. r=marshall_law, a=blocking-basecamp
dom/sms/tests/marionette/test_outgoing.js
--- a/dom/sms/tests/marionette/test_outgoing.js
+++ b/dom/sms/tests/marionette/test_outgoing.js
@@ -5,19 +5,33 @@ MARIONETTE_TIMEOUT = 20000;
 
 SpecialPowers.setBoolPref("dom.sms.enabled", true);
 SpecialPowers.setBoolPref("dom.sms.strict7BitEncoding", false);
 SpecialPowers.addPermission("sms", true, document);
 SpecialPowers.addPermission("mobileconnection", true, document);
 
 let sms = window.navigator.mozSms;
 let receiver = "5555552368";
-let body = "Hello SMS world!";
+const SHORT_BODY = "Hello SMS world!";
+const LONG_BODY = "Let me not to the marriage of true minds\n"
+                + "Admit impediments. Love is not love\n"
+                + "Which alters when it alteration finds,\n"
+                + "Or bends with the remover to remove:\n\n"
+                + "O, no! it is an ever-fix`ed mark,\n"
+                + "That looks on tempests and is never shaken;\n"
+                + "It is the star to every wand'ring bark,\n"
+                + "Whose worth's unknown, although his heighth be taken.\n\n"
+                + "Love's not Time's fool, though rosy lips and cheeks\n"
+                + "Within his bending sickle's compass come;\n"
+                + "Love alters not with his brief hours and weeks,\n"
+                + "But bears it out even to the edge of doom:\n\n"
+                + "If this be error and upon me proved,\n"
+                + "I never writ, nor no man ever loved. ";
 
-function checkSentMessage(message, sentDate) {
+function checkSentMessage(message, body, sentDate) {
   ok(message, "message is valid");
   ok(message instanceof MozSmsMessage,
      "message is instanceof " + message.constructor);
 
   ok(message.id, "message.id is valid");
   is(message.delivery, "sent", "message.delivery");
   is(message.sender, null, "message.sender");
   is(message.receiver, receiver, "message.receiver");
@@ -26,33 +40,33 @@ function checkSentMessage(message, sentD
      "message.timestamp is instanceof " + message.timestamp.constructor);
   // SMSC timestamp is in seconds.
   ok(Math.floor(message.timestamp.getTime() / 1000) >= Math.floor(sentDate / 1000),
      "sent timestamp is valid");
   is(message.read, true, "message.read");
 }
 
 let sentMessages = null;
-function checkSameSentMessage(message, now) {
-  checkSentMessage(message, now);
+function checkSameSentMessage(message, body, now) {
+  checkSentMessage(message, body, now);
 
   let sentMessage = sentMessages[message.id];
   if (!sentMessage) {
     sentMessages[message.id] = message;
     return;
   }
 
   // The two message instance should be exactly the same, but since we had
   // already checked most attributes of them, we only compare their
   // timestamps here.
   ok(sentMessage.timestamp.getTime() == message.timestamp.getTime(),
      "the messages got from onsent event and request result must be the same");
 }
 
-function doSendMessageAndCheckSuccess(receivers, callback) {
+function doSendMessageAndCheckSuccess(receivers, body, callback) {
   sentMessages = [];
 
   let now = Date.now();
   let count;
 
   function done() {
     if (--count > 0) {
       return;
@@ -64,29 +78,29 @@ function doSendMessageAndCheckSuccess(re
 
   function onSmsSent(event) {
     log("SmsManager.onsent event received.");
 
     ok(event instanceof MozSmsEvent,
        "event is instanceof " + event.constructor);
     // Event listener is removed in done().
 
-    checkSameSentMessage(event.message, now);
+    checkSameSentMessage(event.message, body, now);
 
     done();
   }
 
   function onRequestSuccess(event) {
     log("SmsRequest.onsuccess event received.");
 
     ok(event.target instanceof MozSmsRequest,
        "event.target is instanceof " + event.target.constructor);
     event.target.removeEventListener("success", onRequestSuccess);
 
-    checkSameSentMessage(event.target.result, now);
+    checkSameSentMessage(event.target.result, body, now);
 
     done();
   }
 
   sms.addEventListener("sent", onSmsSent);
 
   let result = sms.send(receivers, body);
   if (Array.isArray(receivers)) {
@@ -114,23 +128,29 @@ function doSendMessageAndCheckSuccess(re
   let request = result;
   ok(request instanceof MozSmsRequest,
      "request is instanceof " + request.constructor);
   request.addEventListener("success", onRequestSuccess);
 }
 
 function testSendMessage() {
   log("Testing sending message to one receiver:");
-  doSendMessageAndCheckSuccess(receiver, testSendMessageToMultipleRecipients);
+  doSendMessageAndCheckSuccess(receiver, SHORT_BODY, testSendMultipartMessage);
+}
+
+function testSendMultipartMessage() {
+  log("Testing sending message to one receiver:");
+  doSendMessageAndCheckSuccess(receiver, LONG_BODY,
+                               testSendMessageToMultipleRecipients);
 }
 
 function testSendMessageToMultipleRecipients() {
   log("Testing sending message to multiple receivers:");
   // TODO: bug 788928 - add test cases for nsIDOMSmsManager.ondelivered event
-  doSendMessageAndCheckSuccess([receiver, receiver], cleanUp);
+  doSendMessageAndCheckSuccess([receiver, receiver], SHORT_BODY, cleanUp);
 }
 
 function cleanUp() {
   SpecialPowers.removePermission("sms", document);
   SpecialPowers.removePermission("mobileconnection", document);
   SpecialPowers.clearUserPref("dom.sms.enabled");
   SpecialPowers.clearUserPref("dom.sms.strict7BitEncoding");
   finish();