Bug 1173156 - Fix typo and add a Marionette test case. r=btseng
authorSamael Wang <freesamael@gmail.com>
Mon, 15 Jun 2015 17:17:56 +0800
changeset 248822 a312bb7e2c14e14a33202896e0c3aca1e08139fe
parent 248821 2de050fb497e7cc7e04274674a76840ea18d21de
child 248823 c449f25d8fd1c8fe38fe89486d6fe3fc10c4e07e
push id28907
push userryanvm@gmail.com
push dateMon, 15 Jun 2015 19:30:53 +0000
treeherdermozilla-central@a975d628ae44 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbtseng
bugs1173156
milestone41.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 1173156 - Fix typo and add a Marionette test case. r=btseng
dom/mobilemessage/gonk/SmsService.js
dom/mobilemessage/tests/marionette/test_outgoing_unstable_voice_connection.js
--- a/dom/mobilemessage/gonk/SmsService.js
+++ b/dom/mobilemessage/gonk/SmsService.js
@@ -71,27 +71,27 @@ XPCOMUtils.defineLazyGetter(this, "gPhon
 });
 
 XPCOMUtils.defineLazyGetter(this, "gWAP", function() {
   let ns = {};
   Cu.import("resource://gre/modules/WapPushManager.js", ns);
   return ns;
 });
 
-XPCOMUtils.defineLazyGetter(this, "gSmsSendingSchedulars", function() {
+XPCOMUtils.defineLazyGetter(this, "gSmsSendingSchedulers", function() {
   return {
-    _schedulars: [],
-    getSchedularByServiceId: function(aServiceId) {
-      let schedular = this._schedulars[aServiceId];
-      if (!schedular) {
-        schedular = this._schedulars[aServiceId] =
-          new SmsSendingSchedular(aServiceId);
+    _schedulers: [],
+    getSchedulerByServiceId: function(aServiceId) {
+      let scheduler = this._schedulers[aServiceId];
+      if (!scheduler) {
+        scheduler = this._schedulers[aServiceId] =
+          new SmsSendingScheduler(aServiceId);
       }
 
-      return schedular;
+      return scheduler;
     }
   };
 });
 
 XPCOMUtils.defineLazyServiceGetter(this, "gCellBroadcastService",
                                    "@mozilla.org/cellbroadcast/cellbroadcastservice;1",
                                    "nsIGonkCellBroadcastService");
 
@@ -329,21 +329,24 @@ SmsService.prototype = {
       Services.obs.notifyObservers(aDomMessage, kSmsFailedObserverTopic, null);
     });
   },
 
   /**
    * Schedule the sending request.
    */
   _scheduleSending: function(aServiceId, aDomMessage, aSilent, aOptions, aRequest) {
-    gSmsSendingSchedulars.getSchedularByServiceId(aServiceId)
+    gSmsSendingSchedulers.getSchedulerByServiceId(aServiceId)
       .schedule({
         messageId: aDomMessage.id,
         onSend: () => {
-          if (DEBUG) debug("onSend: " + aDomMessage.id);
+          if (DEBUG) {
+            debug("onSend: messageId=" + aDomMessage.id +
+                  ", serviceId=" + aServiceId);
+          }
           this._sendToTheAir(aServiceId,
                              aDomMessage,
                              aSilent,
                              aOptions,
                              aRequest);
         },
         onCancel: (aErrorCode) => {
           if (DEBUG) debug("onCancel: " + aErrorCode);
@@ -1188,24 +1191,24 @@ function getEnabledGsmTableTuplesFromMcc
   let extraTuples = RIL.PDU_MCC_NL_TABLE_TUPLES_MAPPING[mcc];
   if (extraTuples) {
     tuples = tuples.concat(extraTuples);
   }
 
   return tuples;
 };
 
-function SmsSendingSchedular(aServiceId) {
+function SmsSendingScheduler(aServiceId) {
   this._serviceId = aServiceId;
   this._queue = [];
 
   Services.obs.addObserver(this, kSmsDeletedObserverTopic, false);
   Services.obs.addObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID, false);
 }
-SmsSendingSchedular.prototype = {
+SmsSendingScheduler.prototype = {
   QueryInterface: XPCOMUtils.generateQI([Ci.nsIMobileConnectionListener]),
 
   _serviceId: 0,
   _isObservingMoboConn: false,
   _queue: null,
 
   /**
    * Ensure the handler is listening on MobileConnection events.
@@ -1245,16 +1248,20 @@ SmsSendingSchedular.prototype = {
    *        - onSend
    *          The callback to invoke to trigger a sending or retry.
    *        - onCancel
    *          The callback to invoke when the request is canceled and won't
    *          retry.
    */
   schedule: function(aSendingRequest) {
     if (aSendingRequest) {
+      if (DEBUG) {
+        debug("scheduling message: messageId=" + aSendingRequest.messageId +
+              ", serviceId=" + this._serviceId);
+      }
       this._ensureMoboConnObserverRegistration();
       this._queue.push(aSendingRequest)
 
       // Keep the queue in order to guarantee the sending order matches user
       // expectation.
       this._queue.sort(function(a, b) {
         return a.messageId - b.messageId;
       });
@@ -1263,17 +1270,17 @@ SmsSendingSchedular.prototype = {
     this.send();
   },
 
   /**
    * Send all requests in the queue if voice connection is available.
    */
   send: function() {
     let connection =
-      gMobileConnectionService.getItemByServiceId(this._servicdeId);
+      gMobileConnectionService.getItemByServiceId(this._serviceId);
 
     // If the voice connection is temporarily unavailable, pend the request.
     let voiceInfo = connection && connection.voice;
     let voiceConnected = voiceInfo && voiceInfo.connected;
     if (!voiceConnected) {
       if (DEBUG) {
         debug("Voice connection is temporarily unavailable. Skip sending.");
       }
--- a/dom/mobilemessage/tests/marionette/test_outgoing_unstable_voice_connection.js
+++ b/dom/mobilemessage/tests/marionette/test_outgoing_unstable_voice_connection.js
@@ -122,17 +122,63 @@ function turnOnVoiceDeleteMessagesAndVer
   // wait for 3 seconds and turn on voice connection.
   promises.push(new Promise(function(resolve, reject) {
       setTimeout(() => resolve(), 3000);
     }).then(() => setEmulatorVoiceStateAndWait("on")));
 
   return Promise.all(promises);
 }
 
+/**
+ * Send messages on the second SIM and verify success while voice connection
+ * on first SIM is disabled.
+ *
+ * @return an array of message IDs.
+ */
+function sendMessagesOnSecondSIM() {
+  return new Promise(function(resolve, reject) {
+    try {
+      let eventCount = 0;
+      let now = Date.now();
+      let messageIds = [];
+      manager.addEventListener("sent", function onevent(aEvent) {
+        log("onsent event received.");
+
+        let message = aEvent.message;
+        let expectedBody = MESSAGES[eventCount++];
+        messageIds.push(message.id);
+        is(message.delivery, "sent", "message.delivery");
+        is(message.receiver, RECEIVER, "message.receiver");
+        is(message.body, expectedBody, "message.body: expected '" + expectedBody
+          + "'' but got '" + message.body + "'");
+
+        // timestamp is in seconds.
+        ok(Math.floor(message.timestamp / 1000) >= Math.floor(now / 1000),
+           "expected " + message.timestamp + " >= " + now);
+
+        // resolve when all messages are appeared "sent"
+        if (eventCount == MESSAGES.length) {
+          manager.removeEventListener("sent", onevent);
+          resolve(messageIds);
+        }
+      });
+
+      // send messages
+      for (let body of MESSAGES) {
+        manager.send(RECEIVER, body, { serviceId: 1 });
+      }
+    } catch (err) {
+      log("Error: " + err);
+      reject(err);
+    }
+  });
+}
+
 startTestCommon(function testCaseMain() {
   return pushPrefEnv({ set: [['dom.sms.requestStatusReport', true]] })
     .then(() => ensureMobileConnection())
     .then(() => setEmulatorVoiceStateAndWait("unregistered"))
+    .then(() => runIfMultiSIM(() => sendMessagesOnSecondSIM()))
     .then(() => sendMessagesAndVerifySending())
     // Delete the first message and wait for result.
     .then((aMessageIds) => turnOnVoiceDeleteMessagesAndVerify([aMessageIds[0]],
       MESSAGES.slice().splice(1, MESSAGES.length - 1), 1));
 });