Bug 1166174 - Fix MobileConnection.getCellInfoList() and add test case for it. r=hsinyi
authorEdgar Chen <echen@mozilla.com>
Fri, 22 May 2015 18:14:35 +0800
changeset 245970 fc7990f05afa42c8dc4d51cbf9101fb4bc9336b9
parent 245969 4195d8d8fdf080748467a4f9d8679fe5f7c3cc5a
child 245971 1c832596db3ac6a37359487a37ab9b940f25ec04
push id60333
push userryanvm@gmail.com
push dateThu, 28 May 2015 14:20:47 +0000
treeherdermozilla-inbound@8225a3b75df6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewershsinyi
bugs1166174
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 1166174 - Fix MobileConnection.getCellInfoList() and add test case for it. r=hsinyi
dom/mobileconnection/tests/marionette/head_chrome.js
dom/mobileconnection/tests/marionette/manifest.ini
dom/mobileconnection/tests/marionette/test_mobile_cell_Info_list.js
dom/mobileconnection/tests/marionette/test_mobile_neighboring_cell_ids.js
dom/system/gonk/ril_worker.js
new file mode 100644
--- /dev/null
+++ b/dom/mobileconnection/tests/marionette/head_chrome.js
@@ -0,0 +1,144 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+MARIONETTE_CONTEXT = "chrome";
+
+let XPCOMUtils = Cu.import("resource://gre/modules/XPCOMUtils.jsm").XPCOMUtils;
+let Promise = Cu.import("resource://gre/modules/Promise.jsm").Promise;
+
+let mobileConnectionService =
+  Cc["@mozilla.org/mobileconnection/gonkmobileconnectionservice;1"]
+  .getService(Ci.nsIMobileConnectionService);
+ok(mobileConnectionService,
+   "mobileConnectionService.constructor is " + mobileConnectionService.constructor);
+
+let _pendingEmulatorShellCmdCount = 0;
+
+/**
+ * Send emulator shell command with safe guard.
+ *
+ * We should only call |finish()| after all emulator shell command transactions
+ * end, so here comes with the pending counter.  Resolve when the emulator
+ * shell gives response. Never reject.
+ *
+ * Fulfill params:
+ *   result -- an array of emulator shell response lines.
+ *
+ * @param aCommands
+ *        A string array commands to be passed to emulator through adb shell.
+ *
+ * @return A deferred promise.
+ */
+function runEmulatorShellCmdSafe(aCommands) {
+  return new Promise(function(aResolve, aReject) {
+    ++_pendingEmulatorShellCmdCount;
+    runEmulatorShell(aCommands, function(aResult) {
+      --_pendingEmulatorShellCmdCount;
+
+      ok(true, "Emulator shell response: " + JSON.stringify(aResult));
+      aResolve(aResult);
+    });
+  });
+}
+
+/**
+ * Get nsIMobileConnection by clientId
+ *
+ * @param aClient [optional]
+ *        A numeric DSDS client id. Default: 0.
+ *
+ * @return A nsIMobileConnection.
+ */
+function getMobileConnection(aClientId = 0) {
+  let mobileConnection = mobileConnectionService.getItemByServiceId(0);
+  ok(mobileConnection,
+     "mobileConnection.constructor is " + mobileConnection.constructor);
+  return mobileConnection;
+}
+
+/**
+ * Get Neighboring Cell Ids.
+ *
+ * Fulfill params:
+ *   An array of nsINeighboringCellInfo.
+ * Reject params:
+ *   'RadioNotAvailable', 'RequestNotSupported', or 'GenericFailure'
+ *
+ * @param aClient [optional]
+ *        A numeric DSDS client id. Default: 0.
+ *
+ * @return A deferred promise.
+ */
+function getNeighboringCellIds(aClientId = 0) {
+  let mobileConnection = getMobileConnection(aClientId);
+  return new Promise(function(aResolve, aReject) {
+    ok(true, "getNeighboringCellIds");
+    mobileConnection.getNeighboringCellIds({
+      QueryInterface: XPCOMUtils.generateQI([Ci.nsINeighboringCellIdsCallback]),
+      notifyGetNeighboringCellIds: function(aCount, aResults) {
+        aResolve(aResults);
+      },
+      notifyGetNeighboringCellIdsFailed: function(aErrorMsg) {
+        aReject(aErrorMsg);
+      },
+    });
+  });
+}
+
+/**
+ * Get Cell Info List.
+ *
+ * Fulfill params:
+ *   An array of nsICellInfo.
+ * Reject params:
+ *   'RadioNotAvailable', 'RequestNotSupported', or 'GenericFailure'
+ *
+ * @param aClient [optional]
+ *        A numeric DSDS client id. Default: 0.
+ *
+ * @return A deferred promise.
+ */
+function getCellInfoList(aClientId = 0) {
+  let mobileConnection = getMobileConnection(aClientId);
+  return new Promise(function(aResolve, aReject) {
+    ok(true, "getCellInfoList");
+    mobileConnection.getCellInfoList({
+      QueryInterface: XPCOMUtils.generateQI([Ci.nsICellInfoListCallback]),
+      notifyGetCellInfoList: function(aCount, aResults) {
+        aResolve(aResults);
+      },
+      notifyGetCellInfoListFailed: function(aErrorMsg) {
+        aReject(aErrorMsg);
+      },
+    });
+  });
+}
+
+/**
+ * Wait for pending emulator transactions and call |finish()|.
+ */
+function cleanUp() {
+  // Use ok here so that we have at least one test run.
+  ok(true, ":: CLEANING UP ::");
+
+  waitFor(finish, function() {
+    return _pendingEmulatorShellCmdCount === 0;
+  });
+}
+
+/**
+ * Basic test routine helper.
+ *
+ * This helper does nothing but clean-ups.
+ *
+ * @param aTestCaseMain
+ *        A function that takes no parameter.
+ */
+function startTestBase(aTestCaseMain) {
+  return Promise.resolve()
+    .then(aTestCaseMain)
+    .catch((aException) => {
+      ok(false, "promise rejects during test: " + aException);
+    })
+    .then(cleanUp);
+}
--- a/dom/mobileconnection/tests/marionette/manifest.ini
+++ b/dom/mobileconnection/tests/marionette/manifest.ini
@@ -30,8 +30,9 @@ disabled = Bug 979137
 [test_mobile_call_forwarding.js]
 [test_mobile_call_forwarding_set_error.js]
 [test_mobile_call_forwarding_get_error.js]
 [test_mobile_voice_privacy.js]
 [test_dsds_mobile_data_connection.js]
 [test_mobile_clir.js]
 [test_mobile_clir_radio_off.js]
 [test_mobile_neighboring_cell_ids.js]
+[test_mobile_cell_Info_list.js]
new file mode 100644
--- /dev/null
+++ b/dom/mobileconnection/tests/marionette/test_mobile_cell_Info_list.js
@@ -0,0 +1,40 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+MARIONETTE_TIMEOUT = 60000;
+MARIONETTE_HEAD_JS = "head_chrome.js";
+
+function getAndroidVersion() {
+  return runEmulatorShellCmdSafe(["getprop", "ro.build.version.sdk"])
+    .then(aResults => aResults[0]);
+}
+
+// Start test.
+startTestBase(function() {
+  return getAndroidVersion().
+    then((aVersion) => {
+      if (aVersion < "19") {
+        // Only emulator-kk supports REQUEST_GET_CELL_INFO_LIST, so we skip this
+        // test if in older android version.
+        log("Skip test: AndroidVersion: " + aVersion);
+        return;
+      }
+
+      return getCellInfoList()
+        .then((aResults) => {
+          // Cell Info are hard-coded in hardware/ril/reference-ril/reference-ril.c.
+          is(aResults.length, 1, "Check number of cell Info");
+
+          let cell = aResults[0];
+          is(cell.type, Ci.nsICellInfo.CELL_INFO_TYPE_GSM, "Check cell.type");
+          is(cell.registered, true, "Check cell.registered");
+
+          ok(cell instanceof Ci.nsIGsmCellInfo,
+             "cell.constructor is " + cell.constructor);
+
+          // The data hard-coded in hardware/ril/reference-ril/reference-ril.c
+          // isn't correct (missing timeStampType), so we skip to check other
+          // attributes first until we fix it.
+        });
+    });
+});
--- a/dom/mobileconnection/tests/marionette/test_mobile_neighboring_cell_ids.js
+++ b/dom/mobileconnection/tests/marionette/test_mobile_neighboring_cell_ids.js
@@ -1,38 +1,18 @@
 /* Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/ */
 
 MARIONETTE_TIMEOUT = 30000;
-// This test must run in chrome context.
-MARIONETTE_CONTEXT = "chrome";
-
-let Promise = Cu.import("resource://gre/modules/Promise.jsm").Promise;
-
-let service = Cc["@mozilla.org/mobileconnection/mobileconnectionservice;1"]
-              .getService(Ci.nsIMobileConnectionService);
-ok(service, "service.constructor is " + service.constructor);
-
-let mobileConnection = service.getItemByServiceId(0);
-ok(mobileConnection, "mobileConnection.constructor is " + mobileConnection.constrctor);
-
-function testGetNeighboringCellIds() {
-  log("Test getting mobile neighboring cell ids");
-  let deferred = Promise.defer();
+MARIONETTE_HEAD_JS = "head_chrome.js";
 
-  mobileConnection.getNeighboringCellIds({
-    notifyGetNeighboringCellIds: function(aResult) {
-      deferred.resolve(aResult);
-    },
-    notifyGetNeighboringCellIdsFailed: function(aError) {
-      deferred.reject(aError);
-    }
-  });
-  return deferred.promise;
-}
-
-// Start tests
-testGetNeighboringCellIds()
-  .then(function resolve(aResult) {
-    ok(false, "getNeighboringCellIds should not success");
-  }, function reject(aError) {
-    is(aError, "RequestNotSupported", "failed to getNeighboringCellIds");
-  }).then(finish);
\ No newline at end of file
+// Start test.
+startTestBase(function() {
+  // Emulator doesn't support REQUEST_GET_NEIGHBORING_CELL_IDS, so we expect to
+  // get an 'RequestNotSupported' error here.
+  return getNeighboringCellIds()
+    .then(() => {
+      ok(false, "should not success");
+    }, (aErrorMsg) => {
+      is(aErrorMsg, "RequestNotSupported",
+         "Failed to getNeighboringCellIds: " + aErrorMsg);
+    });
+});
--- a/dom/system/gonk/ril_worker.js
+++ b/dom/system/gonk/ril_worker.js
@@ -5611,17 +5611,16 @@ RilObject.prototype[REQUEST_VOICE_RADIO_
       this.context.debug("Error when getting voice radio tech: " +
                          options.errorMsg);
     }
     return;
   }
   let radioTech = this.context.Buf.readInt32List();
   this._processRadioTech(radioTech[0]);
 };
-RilObject.prototype[REQUEST_GET_CELL_INFO_LIST] = null;
 RilObject.prototype[REQUEST_SET_UNSOL_CELL_INFO_LIST_RATE] = null;
 RilObject.prototype[REQUEST_SET_INITIAL_ATTACH_APN] = null;
 RilObject.prototype[REQUEST_IMS_REGISTRATION_STATE] = null;
 RilObject.prototype[REQUEST_IMS_SEND_SMS] = null;
 RilObject.prototype[REQUEST_SIM_TRANSMIT_APDU_BASIC] = null;
 RilObject.prototype[REQUEST_SIM_OPEN_CHANNEL] = function REQUEST_SIM_OPEN_CHANNEL(length, options) {
   if (options.errorMsg) {
     this.sendChromeMessage(options);