Bug 997584 - part 2 - test clir on radio off. r=vicamo
☠☠ backed out by f752e0359a8d ☠ ☠
authorHsin-Yi Tsai <htsai@mozilla.com>
Mon, 21 Apr 2014 11:17:26 +0800
changeset 198051 8304d89d43008a6217d6d1ffa2cd12090ca1e4e5
parent 198050 d050c422919ae6c4ba75663a3ce1fbe237556f76
child 198052 c5f0b2c282acc437a3ce9752eb357abe187be68f
push id3624
push userasasaki@mozilla.com
push dateMon, 09 Jun 2014 21:49:01 +0000
treeherdermozilla-beta@b1a5da15899a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersvicamo
bugs997584
milestone31.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 997584 - part 2 - test clir on radio off. r=vicamo
dom/mobileconnection/tests/marionette/head.js
dom/mobileconnection/tests/marionette/manifest.ini
dom/mobileconnection/tests/marionette/test_mobile_clir_radio_off.js
--- a/dom/mobileconnection/tests/marionette/head.js
+++ b/dom/mobileconnection/tests/marionette/head.js
@@ -261,16 +261,34 @@ function ensureMobileConnection(aAdditio
 
     document.body.appendChild(workingFrame);
   });
 
   return deferred.promise;
 }
 
 /**
+ * Get MozMobileConnection by ServiceId
+ *
+ * @param aServiceId [optional]
+ *        A numeric DSDS service id. Default: the one indicated in
+ *        start*TestCommon() or 0 if not indicated.
+ *
+ * @return A MozMobileConnection.
+ */
+function getMozMobileConnectionByServiceId(aServiceId) {
+  let mobileConn = mobileConnection;
+  if (aServiceId !== undefined) {
+    mobileConn =
+      workingFrame.contentWindow.navigator.mozMobileConnections[aServiceId];
+  }
+  return mobileConn;
+}
+
+/**
  * Wait for one named MobileConnection event.
  *
  * Resolve if that named event occurs.  Never reject.
  *
  * Fulfill params: the DOMEvent passed.
  *
  * @param aEventName
  *        A string event name.
@@ -278,21 +296,17 @@ function ensureMobileConnection(aAdditio
  *        A numeric DSDS service id. Default: the one indicated in
  *        start*TestCommon() or 0 if not indicated.
  *
  * @return A deferred promise.
  */
 function waitForManagerEvent(aEventName, aServiceId) {
   let deferred = Promise.defer();
 
-  let mobileConn = mobileConnection;
-  if (aServiceId !== undefined) {
-    mobileConn =
-      workingFrame.contentWindow.navigator.mozMobileConnections[aServiceId];
-  }
+  let mobileConn = getMozMobileConnectionByServiceId(aServiceId);
 
   mobileConn.addEventListener(aEventName, function onevent(aEvent) {
     mobileConn.removeEventListener(aEventName, onevent);
 
     ok(true, "MobileConnection event '" + aEventName + "' got.");
     deferred.resolve(aEvent);
   });
 
@@ -404,36 +418,140 @@ function selectNetworkAutomaticallyAndWa
  */
 function setDataEnabledAndWait(aEnabled, aServiceId) {
   let deferred = Promise.defer();
 
   let promises = [];
   promises.push(waitForManagerEvent("datachange", aServiceId));
   promises.push(setDataEnabled(aEnabled));
   Promise.all(promises).then(function keepWaiting() {
-    let mobileConn = mobileConnection;
-    if (aServiceId !== undefined) {
-      mobileConn =
-        workingFrame.contentWindow.navigator.mozMobileConnections[aServiceId];
-    }
+    let mobileConn = getMozMobileConnectionByServiceId(aServiceId);
     // To ignore some transient states, we only resolve that deferred promise
     // when the |connected| state equals to the expected one and never rejects.
     let connected = mobileConn.data.connected;
     if (connected == aEnabled) {
       deferred.resolve();
       return;
     }
 
     return waitForManagerEvent("datachange", aServiceId).then(keepWaiting);
   });
 
   return deferred.promise;
 }
 
 /**
+ * Set radio enabling state.
+ *
+ * Resolve no matter the request succeeds or fails. Never reject.
+ *
+ * Fulfill params: (none)
+ *
+ * @param aEnabled
+ *        A boolean state.
+ * @param aServiceId [optional]
+ *        A numeric DSDS service id. Default: the one indicated in
+ *        start*TestCommon() or 0 if not indicated.
+ *
+ * @return A deferred promise.
+ */
+function setRadioEnabled(aEnabled, aServiceId) {
+  let mobileConn = getMozMobileConnectionByServiceId(aServiceId);
+  let request = mobileConn.setRadioEnabled(aEnabled);
+  return wrapDomRequestAsPromise(request)
+    .then(function onsuccess() {
+      ok(true, "setRadioEnabled " + aEnabled + " on " + aServiceId + " success.");
+    }, function onerror() {
+      ok(false, "setRadioEnabled " + aEnabled + " on " + aServiceId + " " +
+         request.error.name);
+    });
+}
+
+/**
+ * Set radio enabling state and wait for "radiostatechange" event.
+ *
+ * Resolve if radio state changed to the expected one. Never reject.
+ *
+ * Fulfill params: (none)
+ *
+ * @param aEnabled
+ *        A boolean state.
+ * @param aServiceId [optional]
+ *        A numeric DSDS service id. Default: the one indicated in
+ *        start*TestCommon() or 0 if not indicated.
+ *
+ * @return A deferred promise.
+ */
+function setRadioEnabledAndWait(aEnabled, aServiceId) {
+  let deferred = Promise.defer();
+
+  let promises = [];
+  promises.push(waitForManagerEvent("radiostatechange", aServiceId));
+  promises.push(setRadioEnabled(aEnabled, aServiceId));
+  Promise.all(promises).then(function keepWaiting() {
+    let mobileConn = getMozMobileConnectionByServiceId(aServiceId);
+    // To ignore some transient states, we only resolve that deferred promise
+    // when |radioState| equals to the expected one and never rejects.
+    let state = mobileConn.radioState;
+    aEnabled = aEnabled ? "enabled" : "disabled";
+    if (state == aEnabled) {
+      deferred.resolve();
+      return;
+    }
+
+    return waitForManagerEvent("radiostatechange", aServiceId).then(keepWaiting);
+  });
+
+  return deferred.promise;
+}
+
+/**
+ * Set CLIR (calling line id restriction).
+ *
+ * Fulfill params: (none)
+ * Reject params:
+ *   'RadioNotAvailable', 'RequestNotSupported', or 'GenericFailure'
+ *
+ * @param aMode
+ *        A short number.
+ * @param aServiceId [optional]
+ *        A numeric DSDS service id. Default: the one indicated in
+ *        start*TestCommon() or 0 if not indicated.
+ *
+ * @return A deferred promise.
+ */
+function setClir(aMode, aServiceId) {
+  ok(true, "setClir(" + aMode + ", " + aServiceId + ")");
+  let mobileConn = getMozMobileConnectionByServiceId(aServiceId);
+  let request = mobileConn.setCallingLineIdRestriction(aMode);
+  return wrapDomRequestAsPromise(request);
+}
+
+/**
+ * Get CLIR (calling line id restriction).
+ *
+ * Fulfill params:
+ *   CLIR mode.
+ * Reject params:
+ *   'RadioNotAvailable', 'RequestNotSupported', or 'GenericFailure'
+ *
+ * @param aServiceId [optional]
+ *        A numeric DSDS service id. Default: the one indicated in
+ *        start*TestCommon() or 0 if not indicated.
+ *
+ * @return A deferred promise.
+ */
+function getClir(aServiceId) {
+  ok(true, "getClir(" + aServiceId + ")");
+  let mobileConn = getMozMobileConnectionByServiceId(aServiceId);
+  let request = mobileConn.getCallingLineIdRestriction();
+  return wrapDomRequestAsPromise(request);
+}
+
+/**
  * Set voice/data state and wait for state change.
  *
  * Fulfill params: (none)
  *
  * @param aWhich
  *        "voice" or "data".
  * @param aState
  *        "unregistered", "searching", "denied", "roaming", or "home".
@@ -465,21 +583,17 @@ function setEmulatorVoiceDataStateAndWai
  *
  * @return A deferred promise.
  */
 function setEmulatorRoamingAndWait(aRoaming, aServiceId) {
   function doSetAndWait(aWhich, aRoaming, aServiceId) {
     let state = (aRoaming ? "roaming" : "home");
     return setEmulatorVoiceDataStateAndWait(aWhich, state, aServiceId)
       .then(() => {
-        let mobileConn = mobileConnection;
-        if (aServiceId !== undefined) {
-          mobileConn =
-            workingFrame.contentWindow.navigator.mozMobileConnections[aServiceId];
-        }
+        let mobileConn = getMozMobileConnectionByServiceId(aServiceId);
         is(mobileConn[aWhich].roaming, aRoaming,
                      aWhich + ".roaming")
       });
   }
 
   // Set voice registration state first and then data registration state.
   return doSetAndWait("voice", aRoaming, aServiceId)
     .then(() => doSetAndWait("data", aRoaming, aServiceId));
--- a/dom/mobileconnection/tests/marionette/manifest.ini
+++ b/dom/mobileconnection/tests/marionette/manifest.ini
@@ -20,9 +20,10 @@ qemu = true
 [test_call_barring_change_password.js]
 [test_mobile_set_radio.js]
 [test_mobile_last_known_network.js]
 [test_mobile_icc_change.js]
 [test_mobile_connections_array_uninitialized.js]
 [test_mobile_signal_strength.js]
 [test_mobile_data_ipv6.js]
 disabled = Bug 979137
-[test_dsds_mobile_data_connection.js]
\ No newline at end of file
+[test_dsds_mobile_data_connection.js]
+[test_mobile_clir_radio_off.js]
new file mode 100644
--- /dev/null
+++ b/dom/mobileconnection/tests/marionette/test_mobile_clir_radio_off.js
@@ -0,0 +1,36 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+MARIONETTE_TIMEOUT = 60000;
+MARIONETTE_HEAD_JS = "head.js";
+
+function testSetClirOnRadioOff(aMode) {
+  log("testSetClirOnRadioOff (set to mode: " + aMode + ")");
+  return Promise.resolve()
+    .then(() => setClir(aMode))
+    .then(() => {
+      ok(false, "shouldn't resolve");
+    }, (evt) => {
+      is(evt.target.error.name, "RadioNotAvailable");
+    });
+}
+
+function testGetClirOnRadioOff() {
+  log("testGetClirOnRadioOff");
+  return Promise.resolve()
+    .then(() => getClir())
+    .then(() => {
+      ok(false, "shouldn't resolve");
+    }, (evt) => {
+      is(evt.target.error.name, "RadioNotAvailable");
+    });
+}
+
+startTestCommon(function() {
+  return setRadioEnabledAndWait(false)
+    .then(() => testSetClirOnRadioOff(0))
+    .then(() => testGetClirOnRadioOff())
+    // Restore radio state.
+    .then(() => setRadioEnabledAndWait(true),
+          () => setRadioEnabledAnWait(true));
+});