Bug 891707 - Part 1: Wait for |UNSOLICITED_RESPONSE_VOICE_NETWORK_STATE_CHANGED| when changing modem tech. r=aknow
authorBen Hsu <driftersprt@gmail.com>
Sun, 14 Jun 2015 19:51:00 -0400
changeset 287768 664df831252b1badd3a040b8bfc512a60c84d1a9
parent 287767 105d5ff7b72c8c4b8e47f13cb85434f1af418672
child 287769 bbaf3960224b1fce073984151a200fb99570c46d
push id5067
push userraliiev@mozilla.com
push dateMon, 21 Sep 2015 14:04:52 +0000
treeherdermozilla-beta@14221ffe5b2f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersaknow
bugs891707
milestone42.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 891707 - Part 1: Wait for |UNSOLICITED_RESPONSE_VOICE_NETWORK_STATE_CHANGED| when changing modem tech. r=aknow
dom/telephony/test/marionette/head.js
--- a/dom/telephony/test/marionette/head.js
+++ b/dom/telephony/test/marionette/head.js
@@ -272,25 +272,77 @@ let emulator = (function() {
         resolve();
       }, function() {
         return telephony.calls.length === 0;
       });
     });
   }
 
   /**
+   * @param aVoiceType
+   *        The voice type of a mobileConnection, which can be obtained from
+   *        |<mobileConnection>.voice.type|.
+   * @return A string with format of the emulator voice tech.
+   */
+  function voiceTypeToTech(aVoiceType) {
+    switch(aVoiceType) {
+        case "gsm":
+        case "gprs":
+        case "edge":
+          return "gsm";
+
+        case "umts":
+        case "hsdpa":
+        case "hsupa":
+        case "hspa":
+        case "hspa+":
+          return "wcdma";
+
+        case "is95a":
+        case "is95b":
+        case "1xrtt":
+          return "cdma";
+
+        case "evdo0":
+        case "evdoa":
+        case "evdob":
+          return "evdo";
+
+        case "ehrpd":
+        case "lte":
+          return "lte";
+
+        default:
+          return null;
+      }
+  }
+
+  /**
    * @return Promise
    */
   function changeModemTech(aTech, aPreferredMask) {
-    return Promise.resolve()
+    let mobileConn = navigator.mozMobileConnections[0];
+
+    function isTechMatched() {
+      return aTech === voiceTypeToTech(mobileConn.voice.type);
+    }
+
+    let promise1 = isTechMatched() ? Promise.resolve()
+                                   : waitForEvent(mobileConn,
+                                                  "voicechange",
+                                                  isTechMatched);
+
+    let promise2 = Promise.resolve()
       .then(() => emulator.runCmd("modem tech " + aTech + " " + aPreferredMask))
       .then(() => emulator.runCmd("modem tech"))
       .then(result => is(result[0],
                          aTech + " " + aPreferredMask,
                          "Check modem 'tech/preferred mask'"));
+
+    return Promise.all([promise1, promise2]);
   }
 
   /**
    * @return Promise
    */
   function clearCalls() {
     log("Clear existing calls.");