mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-18 07:45:30 +00:00
Bug 975778 - Part 1: Modify some helper functions (head.js). r=btseng
This commit is contained in:
parent
40544946e0
commit
82a40c4afd
@ -536,6 +536,11 @@ var Modem = Modems[0];
|
||||
function checkEmulatorCallList(expectedCallList) {
|
||||
return emulator.runCmd("telephony list").then(result => {
|
||||
log("Call list is now: " + result);
|
||||
// The last element of the result is "OK"
|
||||
is(result.length - 1,
|
||||
expectedCallList.length,
|
||||
"Emulator call list length");
|
||||
|
||||
for (let i = 0; i < expectedCallList.length; ++i) {
|
||||
is(result[i], expectedCallList[i], "emulator calllist");
|
||||
}
|
||||
@ -628,14 +633,21 @@ var Modem = Modems[0];
|
||||
*/
|
||||
function checkActive(aExpectedCalls, aExpectedCallsInConference) {
|
||||
// Get the active call
|
||||
let calls = aExpectedCalls && aExpectedCalls.filter(aExpectedCall => {
|
||||
return aExpectedCall.state === "connected" ||
|
||||
aExpectedCall.state === "alerting" ||
|
||||
aExpectedCall.state === "dialing";
|
||||
let activeCalls = aExpectedCalls && aExpectedCalls.map(aExpectedCall => {
|
||||
let isActive = aExpectedCall.state === "connected" ||
|
||||
aExpectedCall.state === "alerting" ||
|
||||
aExpectedCall.state === "dialing";
|
||||
return isActive ? aExpectedCall.reference : null;
|
||||
});
|
||||
|
||||
ok(calls.length < 2, "Too many actives call in telephony.calls");
|
||||
let activeCall = calls.length ? calls[0].reference : null;
|
||||
// Since a CDMA active call and a CDMA waiting call refer to the same
|
||||
// telephony call object, we remove duplicated elememts in activeCalls
|
||||
activeCalls = new Set(activeCalls);
|
||||
activeCalls.delete(null);
|
||||
activeCalls = [...activeCalls];
|
||||
|
||||
ok(activeCalls.length < 2, "Too many active calls in telephony.calls");
|
||||
let activeCall = activeCalls.length ? activeCalls[0] : null;
|
||||
|
||||
// Get the active conference
|
||||
let callsInConference = aExpectedCallsInConference || [];
|
||||
@ -690,20 +702,22 @@ var Modem = Modems[0];
|
||||
}
|
||||
|
||||
callsInTelephony.push(aCall);
|
||||
ok(!aCall.secondId, "For a telephony call, the secondId must be null");
|
||||
});
|
||||
|
||||
// Check the active connection
|
||||
checkActive(callsInTelephony, CallsInConference);
|
||||
|
||||
// Check telephony.calls
|
||||
is(telephony.calls.length,
|
||||
callsInTelephony.length,
|
||||
"Check telephony.calls.length");
|
||||
let references = callsInTelephony.map(aCall => aCall.reference);
|
||||
references = new Set(references);
|
||||
is(telephony.calls.length, references.size, "Check telephony.calls.length");
|
||||
|
||||
callsInTelephony.forEach(aExpectedCall => {
|
||||
let number = aExpectedCall.number;
|
||||
let call = telephony.calls.find(aCall => aCall.id.number === number);
|
||||
let call = telephony.calls.find(aCall => {
|
||||
return (aCall.id.number === number) ||
|
||||
(Modem.isCDMA() ? (aCall.secondId && aCall.secondId.number === number) : false);
|
||||
});
|
||||
if (!call) {
|
||||
ok(false, "telephony.calls lost the call(number: " + number + ")");
|
||||
return;
|
||||
@ -971,22 +985,36 @@ var Modem = Modems[0];
|
||||
function remoteDial(number, numberPresentation, name, namePresentation) {
|
||||
log("Simulating an incoming call.");
|
||||
|
||||
// Register listeners
|
||||
let promises = [waitForEvent(telephony, "callschanged")];
|
||||
if (Modem.isGSM() ||
|
||||
Modem.isCDMA() && telephony.calls.length == 0) {
|
||||
promises.push(waitForEvent(telephony, "incoming"));
|
||||
}
|
||||
|
||||
// Make an incoming call
|
||||
numberPresentation = numberPresentation || "";
|
||||
name = name || "";
|
||||
namePresentation = namePresentation || "";
|
||||
emulator.runCmd("telephony call " + number +
|
||||
"," + numberPresentation +
|
||||
"," + name +
|
||||
"," + namePresentation);
|
||||
|
||||
return waitForEvent(telephony, "incoming")
|
||||
.then(event => {
|
||||
let call = event.call;
|
||||
promises.push(emulator.runCmd("telephony call " + number +
|
||||
"," + numberPresentation +
|
||||
"," + name +
|
||||
"," + namePresentation));
|
||||
|
||||
// Return the promise and check
|
||||
return Promise.all(promises)
|
||||
.then(aResult => {
|
||||
let call = aResult[0].call;
|
||||
ok(call);
|
||||
is(call.state, "incoming");
|
||||
checkCallId(number, numberPresentation, name, namePresentation,
|
||||
call.id.number, call.id.name);
|
||||
|
||||
let isCdmaSecondCall = Modem.isCDMA() &&
|
||||
navigator.mozTelephony.calls[0].secondId;
|
||||
|
||||
is(call.state, isCdmaSecondCall ? "connected" : "incoming");
|
||||
checkCallId(number, numberPresentation,
|
||||
name, namePresentation,
|
||||
isCdmaSecondCall ? call.secondId.number : call.id.number,
|
||||
isCdmaSecondCall ? call.secondId.name : call.id.name);
|
||||
|
||||
return call;
|
||||
});
|
||||
@ -1015,16 +1043,33 @@ var Modem = Modems[0];
|
||||
/**
|
||||
* Remote party hangs up the call.
|
||||
*
|
||||
* @param call
|
||||
* A TelephonyCall object.
|
||||
* @param aIdentifier
|
||||
* <A TelephonyCall object or a number string>
|
||||
* @return Promise<TelephonyCall>
|
||||
*/
|
||||
function remoteHangUp(call) {
|
||||
log("Remote hanging up the call: " + call.id.number);
|
||||
function remoteHangUp(aIdentifier, aWaitForEvent = true) {
|
||||
let call;
|
||||
let number;
|
||||
if (typeof aIdentifier === "string") { // A number is passed in.
|
||||
number = aIdentifier;
|
||||
call = navigator.mozTelephony.calls.find(aCall => {
|
||||
return aCall.id.number === number ||
|
||||
aCall.secondId && aCall.secondId.number === number;
|
||||
});
|
||||
} else { // A Telephony call object is passed in.
|
||||
call = aIdentifier;
|
||||
number = aIdentifier.id.number;
|
||||
}
|
||||
|
||||
emulator.runCmd("telephony cancel " + call.id.number);
|
||||
log("Remote hanging up the call: " + number);
|
||||
|
||||
return waitForNamedStateEvent(call, "disconnected");
|
||||
let promises = [];
|
||||
if (aWaitForEvent) {
|
||||
promises.push(waitForNamedStateEvent(call, "disconnected"));
|
||||
}
|
||||
|
||||
promises.push(emulator.runCmd("telephony cancel " + number));
|
||||
return Promise.all(promises);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user