Bug 1166174 - Fix MobileConnection.getCellInfoList() and add test case for it. r=hsinyi

This commit is contained in:
Edgar Chen 2015-05-22 18:14:35 +08:00
parent 53210db408
commit 52adefe901
5 changed files with 198 additions and 34 deletions

View File

@ -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);
}

View File

@ -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]

View File

@ -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.
});
});
});

View File

@ -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);
// 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);
});
});

View File

@ -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;