2012-11-21 18:39:42 -08:00
|
|
|
/* Any copyright is dedicated to the Public Domain.
|
|
|
|
* http://creativecommons.org/publicdomain/zero/1.0/ */
|
|
|
|
|
2013-04-09 09:02:51 -07:00
|
|
|
MARIONETTE_TIMEOUT = 60000;
|
2013-10-01 23:27:52 -07:00
|
|
|
MARIONETTE_HEAD_JS = 'head.js';
|
2012-11-21 18:39:42 -08:00
|
|
|
|
|
|
|
SpecialPowers.addPermission("telephony", true, document);
|
|
|
|
|
|
|
|
let telephony = window.navigator.mozTelephony;
|
|
|
|
let outNumber = "5555551111";
|
|
|
|
let outgoingCall;
|
|
|
|
|
2013-04-26 07:44:26 -07:00
|
|
|
function getExistingCalls() {
|
2013-10-01 23:27:52 -07:00
|
|
|
emulator.run("gsm list", function(result) {
|
2013-04-26 07:44:26 -07:00
|
|
|
log("Initial call list: " + result);
|
|
|
|
if (result[0] == "OK") {
|
|
|
|
dial();
|
|
|
|
} else {
|
|
|
|
cancelExistingCalls(result);
|
2013-10-01 23:27:52 -07:00
|
|
|
}
|
2013-04-26 07:44:26 -07:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function cancelExistingCalls(callList) {
|
|
|
|
if (callList.length && callList[0] != "OK") {
|
|
|
|
// Existing calls remain; get rid of the next one in the list
|
2013-09-18 00:44:08 -07:00
|
|
|
nextCall = callList.shift().split(/\s+/)[2].trim();
|
2013-04-26 07:44:26 -07:00
|
|
|
log("Cancelling existing call '" + nextCall +"'");
|
2013-10-01 23:27:52 -07:00
|
|
|
emulator.run("gsm cancel " + nextCall, function(result) {
|
2013-04-26 07:44:26 -07:00
|
|
|
if (result[0] == "OK") {
|
|
|
|
cancelExistingCalls(callList);
|
|
|
|
} else {
|
|
|
|
log("Failed to cancel existing call");
|
|
|
|
cleanUp();
|
2013-10-01 23:27:52 -07:00
|
|
|
}
|
2013-04-26 07:44:26 -07:00
|
|
|
});
|
|
|
|
} else {
|
|
|
|
// No more calls in the list; give time for emulator to catch up
|
|
|
|
waitFor(dial, function() {
|
2013-10-01 23:27:52 -07:00
|
|
|
return (telephony.calls.length === 0);
|
2013-04-26 07:44:26 -07:00
|
|
|
});
|
2013-10-01 23:27:52 -07:00
|
|
|
}
|
2013-04-26 07:44:26 -07:00
|
|
|
}
|
|
|
|
|
2012-11-21 18:39:42 -08:00
|
|
|
function dial() {
|
|
|
|
log("Make an outgoing call.");
|
|
|
|
outgoingCall = telephony.dial(outNumber);
|
|
|
|
|
|
|
|
outgoingCall.onalerting = function onalerting(event) {
|
|
|
|
log("Received 'alerting' call event.");
|
|
|
|
answer();
|
2013-09-18 00:44:08 -07:00
|
|
|
};
|
2012-11-21 18:39:42 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
function answer() {
|
|
|
|
log("Answering the outgoing call.");
|
|
|
|
|
|
|
|
outgoingCall.onconnected = function onconnectedOut(event) {
|
|
|
|
log("Received 'connected' call event for the original outgoing call.");
|
|
|
|
// just some code to keep call active for awhile
|
|
|
|
callStartTime = Date.now();
|
|
|
|
waitFor(cleanUp,function() {
|
|
|
|
callDuration = Date.now() - callStartTime;
|
|
|
|
log("Waiting while call is active, call duration (ms): " + callDuration);
|
|
|
|
return(callDuration >= 2000);
|
|
|
|
});
|
|
|
|
};
|
2013-10-01 23:27:52 -07:00
|
|
|
emulator.run("gsm accept " + outNumber);
|
2012-11-21 18:39:42 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
function cleanUp(){
|
|
|
|
outgoingCall.hangUp();
|
|
|
|
ok("passed");
|
|
|
|
finish();
|
|
|
|
}
|
|
|
|
|
2013-10-01 23:27:52 -07:00
|
|
|
startTest(function() {
|
|
|
|
getExistingCalls();
|
|
|
|
});
|