Bug 979134: convert test_mobile_voice_location.js to Promise. r=hsinyi

This commit is contained in:
Vicamo Yang 2014-04-09 13:16:07 +08:00
parent 96b5b064f2
commit 88c31c7917
2 changed files with 74 additions and 67 deletions

View File

@ -36,7 +36,8 @@ function runEmulatorCmdSafe(aCommand) {
--_pendingEmulatorCmdCount;
ok(true, "Emulator response: " + JSON.stringify(aResult));
if (Array.isArray(aResult) && aResult[0] === "OK") {
if (Array.isArray(aResult) &&
aResult[aResult.length - 1] === "OK") {
deferred.resolve(aResult);
} else {
deferred.reject(aResult);
@ -450,6 +451,51 @@ function setEmulatorRoamingAndWait(aRoaming) {
.then(() => doSetAndWait("data", aRoaming));
}
/**
* Get GSM location emulation.
*
* Fulfill params:
* { lac: <lac>, cid: <cid> }
* Reject params:
* result -- an array of emulator response lines.
*
* @return A deferred promise.
*/
function getEmulatorGsmLocation() {
let cmd = "gsm location";
return runEmulatorCmdSafe(cmd)
.then(function(aResults) {
// lac: <lac>
// ci: <cid>
// OK
is(aResults[0].substring(0,3), "lac", "lac output");
is(aResults[1].substring(0,2), "ci", "ci output");
let lac = parseInt(aResults[0].substring(5));
lac = (lac < 0 ? 65535 : lac);
let cid = parseInt(aResults[1].substring(4));
cid = (cid < 0 ? 268435455 : cid);
return { lac: lac, cid: cid };
});
}
/**
* Set GSM location emulation.
*
* Fulfill params: (none)
* Reject params: (none)
*
* @param aLac
* @param aCid
*
* @return A deferred promise.
*/
function setEmulatorGsmLocation(aLac, aCid) {
let cmd = "gsm location " + aLac + " " + aCid;
return runEmulatorCmdSafe(cmd);
}
let _networkManager;
/**

View File

@ -1,33 +1,17 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
MARIONETTE_TIMEOUT = 20000;
MARIONETTE_HEAD_JS = "mobile_header.js";
function setEmulatorGsmLocation(lac, cid) {
emulatorHelper.sendCommand("gsm location " + lac + " " + cid);
}
function waitForVoiceChangeEvent(callback) {
mobileConnection.addEventListener("voicechange", function onvoicechange() {
mobileConnection.removeEventListener("voicechange", onvoicechange);
if (callback && typeof callback === "function") {
callback();
}
});
}
/* Test Initial Voice Cell Location Info */
taskHelper.push(function testInitialVoiceCellLocationInfo() {
log("Test initial voice location info");
MARIONETTE_TIMEOUT = 60000;
MARIONETTE_HEAD_JS = "head.js";
function verifyVoiceCellLocationInfo(aLac, aCid) {
let cell = mobileConnection.voice.cell;
ok(cell, "location available");
// Initial LAC/CID. Android emulator initializes both value to
// 0xffff/0xffffffff.
is(cell.gsmLocationAreaCode, 65535, "check voice.cell.gsmLocationAreaCode");
is(cell.gsmCellId, 268435455, "check voice.cell.gsmCellId");
is(cell.gsmLocationAreaCode, aLac, "check voice.cell.gsmLocationAreaCode");
is(cell.gsmCellId, aCid, "check voice.cell.gsmCellId");
is(cell.cdmaBaseStationId, -1, "check voice.cell.cdmaBaseStationId");
is(cell.cdmaBaseStationLatitude, -2147483648,
"check voice.cell.cdmaBaseStationLatitude");
@ -35,54 +19,31 @@ taskHelper.push(function testInitialVoiceCellLocationInfo() {
"check voice.cell.cdmaBaseStationLongitude");
is(cell.cdmaSystemId, -1, "check voice.cell.cdmaSystemId");
is(cell.cdmaNetworkId, -1, "check voice.cell.cdmaNetworkId");
taskHelper.runNext();
});
}
/* Test Voice Cell Location Info Change */
taskHelper.push(function testVoiceCellLocationUpdate() {
function testVoiceCellLocationUpdate(aLac, aCid) {
// Set emulator's lac/cid and wait for 'onvoicechange' event.
function doTestVoiceCellLocation(lac, cid, callback) {
log("Test cell location with lac=" + lac + " and cid=" + cid);
log("Test cell location with lac=" + aLac + " and cid=" + aCid);
waitForVoiceChangeEvent(function() {
let cell = mobileConnection.voice.cell;
is(cell.gsmLocationAreaCode, lac, "check voice.cell.gsmLocationAreaCode");
is(cell.gsmCellId, cid, "check voice.cell.gsmCellId");
// cdma information won't change.
is(cell.cdmaBaseStationId, -1, "check voice.cell.cdmaBaseStationId");
is(cell.cdmaBaseStationLatitude, -2147483648,
"check voice.cell.cdmaBaseStationLatitude");
is(cell.cdmaBaseStationLongitude, -2147483648,
"check voice.cell.cdmaBaseStationLongitude");
is(cell.cdmaSystemId, -1, "check voice.cell.cdmaSystemId");
is(cell.cdmaNetworkId, -1, "check voice.cell.cdmaNetworkId");
let promises = [];
promises.push(waitForManagerEvent("voicechange"));
promises.push(setEmulatorGsmLocation(aLac, aCid));
return Promise.all(promises)
.then(() => verifyVoiceCellLocationInfo(aLac, aCid));
}
if (callback && typeof callback === "function") {
callback();
}
startTestCommon(function() {
return getEmulatorGsmLocation()
.then(function(aResult) {
log("Test initial voice location info");
verifyVoiceCellLocationInfo(aResult.lac, aResult.cid);
return Promise.resolve()
.then(() => testVoiceCellLocationUpdate(100, 100))
.then(() => testVoiceCellLocationUpdate(2000, 2000))
// Reset back to initial values.
.then(() => testVoiceCellLocationUpdate(aResult.lac, aResult.cid));
});
setEmulatorGsmLocation(lac, cid);
}
let testData = [
{lac: 100, cid: 100},
{lac: 2000, cid: 2000},
// Reset lac/cid to default value.
{lac: 65535, cid: 268435455}
];
// Run all test data.
(function do_call() {
let next = testData.shift();
if (!next) {
taskHelper.runNext();
return;
}
doTestVoiceCellLocation(next.lac, next.cid, do_call);
})();
});
// Start test
taskHelper.runNext();