From 52adefe90119611c902c7f57cd6a6f7d1456c34d Mon Sep 17 00:00:00 2001 From: Edgar Chen Date: Fri, 22 May 2015 18:14:35 +0800 Subject: [PATCH] Bug 1166174 - Fix MobileConnection.getCellInfoList() and add test case for it. r=hsinyi --- .../tests/marionette/head_chrome.js | 144 ++++++++++++++++++ .../tests/marionette/manifest.ini | 1 + .../marionette/test_mobile_cell_Info_list.js | 40 +++++ .../test_mobile_neighboring_cell_ids.js | 46 ++---- dom/system/gonk/ril_worker.js | 1 - 5 files changed, 198 insertions(+), 34 deletions(-) create mode 100644 dom/mobileconnection/tests/marionette/head_chrome.js create mode 100644 dom/mobileconnection/tests/marionette/test_mobile_cell_Info_list.js diff --git a/dom/mobileconnection/tests/marionette/head_chrome.js b/dom/mobileconnection/tests/marionette/head_chrome.js new file mode 100644 index 00000000000..412e149f842 --- /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); +} diff --git a/dom/mobileconnection/tests/marionette/manifest.ini b/dom/mobileconnection/tests/marionette/manifest.ini index 2b8b7685bbc..6b21b095be8 100644 --- a/dom/mobileconnection/tests/marionette/manifest.ini +++ b/dom/mobileconnection/tests/marionette/manifest.ini @@ -35,3 +35,4 @@ disabled = Bug 979137 [test_mobile_clir.js] [test_mobile_clir_radio_off.js] [test_mobile_neighboring_cell_ids.js] +[test_mobile_cell_Info_list.js] diff --git a/dom/mobileconnection/tests/marionette/test_mobile_cell_Info_list.js b/dom/mobileconnection/tests/marionette/test_mobile_cell_Info_list.js new file mode 100644 index 00000000000..f845ada4e58 --- /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. + }); + }); +}); diff --git a/dom/mobileconnection/tests/marionette/test_mobile_neighboring_cell_ids.js b/dom/mobileconnection/tests/marionette/test_mobile_neighboring_cell_ids.js index 7904ec68d7f..ec4fbb3e44e 100644 --- a/dom/mobileconnection/tests/marionette/test_mobile_neighboring_cell_ids.js +++ b/dom/mobileconnection/tests/marionette/test_mobile_neighboring_cell_ids.js @@ -2,37 +2,17 @@ * http://creativecommons.org/publicdomain/zero/1.0/ */ MARIONETTE_TIMEOUT = 30000; -// This test must run in chrome context. -MARIONETTE_CONTEXT = "chrome"; +MARIONETTE_HEAD_JS = "head_chrome.js"; -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(); - - 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); + }); +}); diff --git a/dom/system/gonk/ril_worker.js b/dom/system/gonk/ril_worker.js index 9fe72c5322b..19f8be2034e 100644 --- a/dom/system/gonk/ril_worker.js +++ b/dom/system/gonk/ril_worker.js @@ -5616,7 +5616,6 @@ RilObject.prototype[REQUEST_VOICE_RADIO_TECH] = function REQUEST_VOICE_RADIO_TEC 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;