mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-09 11:25:00 +00:00
Bug 1027996 - Part 1: Change emulator.run to promise version. r=hsinyi
This commit is contained in:
parent
2c4e446c07
commit
9e5aae8d3e
@ -16,14 +16,28 @@ let emulator = (function() {
|
||||
|
||||
// Overwritten it so people could not call this function directly.
|
||||
runEmulatorCmd = function() {
|
||||
throw "Use emulator.run(cmd, callback) instead of runEmulatorCmd";
|
||||
throw "Use emulator.runWithCallback(cmd, callback) instead of runEmulatorCmd";
|
||||
};
|
||||
|
||||
function run(cmd, callback) {
|
||||
function run(cmd) {
|
||||
let deferred = Promise.defer();
|
||||
|
||||
pendingCmdCount++;
|
||||
originalRunEmulatorCmd(cmd, function(result) {
|
||||
is(result[result.length - 1], "OK", "emulator command should be OK.");
|
||||
pendingCmdCount--;
|
||||
if (result[result.length - 1] === "OK") {
|
||||
deferred.resolve(result);
|
||||
} else {
|
||||
is(result[result.length - 1], "OK", "emulator command result.");
|
||||
deferred.reject();
|
||||
}
|
||||
});
|
||||
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
function runWithCallback(cmd, callback) {
|
||||
run(cmd).then(result => {
|
||||
if (callback && typeof callback === "function") {
|
||||
callback(result);
|
||||
}
|
||||
@ -47,6 +61,7 @@ let emulator = (function() {
|
||||
|
||||
return {
|
||||
run: run,
|
||||
runWithCallback: runWithCallback,
|
||||
waitFinish: waitFinish
|
||||
};
|
||||
}());
|
||||
@ -75,26 +90,26 @@ let emulator = (function() {
|
||||
/**
|
||||
* @return Promise
|
||||
*/
|
||||
function clearCalls() {
|
||||
function waitForNoCall() {
|
||||
let deferred = Promise.defer();
|
||||
|
||||
log("Clear existing calls.");
|
||||
emulator.run("gsm clear", function(result) {
|
||||
if (result[0] == "OK") {
|
||||
waitFor(function() {
|
||||
deferred.resolve();
|
||||
}, function() {
|
||||
return telephony.calls.length === 0;
|
||||
});
|
||||
} else {
|
||||
log("Failed to clear existing calls.");
|
||||
deferred.reject();
|
||||
}
|
||||
waitFor(function() {
|
||||
deferred.resolve();
|
||||
}, function() {
|
||||
return telephony.calls.length === 0;
|
||||
});
|
||||
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Promise
|
||||
*/
|
||||
function clearCalls() {
|
||||
log("Clear existing calls.");
|
||||
return emulator.run("gsm clear").then(waitForNoCall);
|
||||
}
|
||||
|
||||
/**
|
||||
* Provide a string with format of the emulator call list result.
|
||||
*
|
||||
@ -328,18 +343,12 @@ let emulator = (function() {
|
||||
* @return A deferred promise.
|
||||
*/
|
||||
function checkEmulatorCallList(expectedCallList) {
|
||||
let deferred = Promise.defer();
|
||||
|
||||
emulator.run("gsm list", function(result) {
|
||||
log("Call list is now: " + result);
|
||||
for (let i = 0; i < expectedCallList.length; ++i) {
|
||||
is(result[i], expectedCallList[i], "emulator calllist");
|
||||
}
|
||||
is(result[expectedCallList.length], "OK", "emulator calllist");
|
||||
deferred.resolve();
|
||||
});
|
||||
|
||||
return deferred.promise;
|
||||
return emulator.run("gsm list").then(result => {
|
||||
log("Call list is now: " + result);
|
||||
for (let i = 0; i < expectedCallList.length; ++i) {
|
||||
is(result[i], expectedCallList[i], "emulator calllist");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user