Bug 1023141 - query ril.ecclist per dial request - part 2 - test case. r=aknow

This commit is contained in:
Hsin-Yi Tsai 2014-06-24 18:47:12 +08:00
parent 2ed0526578
commit 24ceb32986
2 changed files with 83 additions and 8 deletions

View File

@ -14,11 +14,19 @@ let emulator = (function() {
let pendingCmdCount = 0;
let originalRunEmulatorCmd = runEmulatorCmd;
let pendingShellCount = 0;
let originalRunEmulatorShell = runEmulatorShell;
// Overwritten it so people could not call this function directly.
runEmulatorCmd = function() {
throw "Use emulator.runCmdWithCallback(cmd, callback) instead of runEmulatorCmd";
};
// Overwritten it so people could not call this function directly.
runEmulatorShell = function() {
throw "Use emulator.runShellCmd(cmd, callback) instead of runEmulatorShell";
};
function runCmd(cmd) {
let deferred = Promise.defer();
@ -44,6 +52,21 @@ let emulator = (function() {
});
}
/**
* @return Promise
*/
function runShellCmd(aCommands) {
let deferred = Promise.defer();
++pendingShellCount;
originalRunEmulatorShell(aCommands, function(aResult) {
--pendingShellCount;
deferred.resolve(aResult);
});
return deferred.promise;
}
/**
* @return Promise
*/
@ -53,7 +76,7 @@ let emulator = (function() {
waitFor(function() {
deferred.resolve();
}, function() {
return pendingCmdCount === 0;
return pendingCmdCount === 0 && pendingShellCount === 0;
});
return deferred.promise;
@ -62,6 +85,7 @@ let emulator = (function() {
return {
runCmd: runCmd,
runCmdWithCallback: runCmdWithCallback,
runShellCmd: runShellCmd,
waitFinish: waitFinish
};
}());

View File

@ -4,7 +4,43 @@
MARIONETTE_TIMEOUT = 60000;
MARIONETTE_HEAD_JS = 'head.js';
function testEmergencyLabel(number, emergency) {
const DEFAULT_ECC_LIST = "112,911";
function setEccListProperty(list) {
log("Set property ril.ecclist: " + list);
let deferred = Promise.defer();
try {
emulator.runShellCmd(["setprop","ril.ecclist", list]).then(function() {
deferred.resolve(list);
});
} catch (e) {
deferred.reject(e);
}
return deferred.promise;
}
function getEccListProperty() {
log("Get property ril.ecclist.");
let deferred = Promise.defer();
try {
emulator.runShellCmd(["getprop","ril.ecclist"]).then(function(aResult) {
let list = !aResult.length ? "" : aResult[0];
deferred.resolve(list);
});
} catch (e) {
deferred.reject(e);
}
return deferred.promise;
}
function testEmergencyLabel(number, list) {
if (!list) {
list = DEFAULT_ECC_LIST;
}
let index = list.split(",").indexOf(number);
let emergency = index != -1;
log("= testEmergencyLabel = " + number + " should be " +
(emergency ? "emergency" : "normal") + " call");
@ -23,12 +59,27 @@ function testEmergencyLabel(number, emergency) {
}
startTest(function() {
testEmergencyLabel("112", true)
.then(() => testEmergencyLabel("911", true))
.then(() => testEmergencyLabel("0912345678", false))
.then(() => testEmergencyLabel("777", false))
.then(null, () => {
ok(false, 'promise rejects during test.');
let origEccList;
let eccList;
getEccListProperty()
.then(list => {
origEccList = eccList = list;
})
.then(() => testEmergencyLabel("112", eccList))
.then(() => testEmergencyLabel("911", eccList))
.then(() => testEmergencyLabel("0912345678", eccList))
.then(() => testEmergencyLabel("777", eccList))
.then(() => {
eccList = "777,119";
return setEccListProperty(eccList);
})
.then(() => testEmergencyLabel("777", eccList))
.then(() => testEmergencyLabel("119", eccList))
.then(() => testEmergencyLabel("112", eccList))
.then(() => setEccListProperty(origEccList))
.then(null, error => {
ok(false, 'promise rejects during test: ' + error);
})
.then(finish);
});