2012-06-08 00:09:15 -07: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-06-08 00:09:15 -07:00
|
|
|
|
|
|
|
let number = "5555552368";
|
|
|
|
let incoming;
|
|
|
|
|
|
|
|
function simulateIncoming() {
|
|
|
|
log("Simulating an incoming call.");
|
|
|
|
|
|
|
|
telephony.oncallschanged = function oncallschanged(event) {
|
|
|
|
log("Received 'callschanged' event.");
|
|
|
|
|
2013-05-30 19:05:39 -07:00
|
|
|
if (!event.call) {
|
|
|
|
log("Notifying calls array is loaded. No call information accompanies.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-10-01 23:27:52 -07:00
|
|
|
telephony.oncallschanged = null;
|
2012-06-08 00:09:15 -07:00
|
|
|
|
2013-10-01 23:27:52 -07:00
|
|
|
incoming = event.call;
|
|
|
|
ok(incoming);
|
2014-05-14 23:37:19 -07:00
|
|
|
is(incoming.id.number, number);
|
2013-10-01 23:27:52 -07:00
|
|
|
is(incoming.state, "incoming");
|
|
|
|
|
|
|
|
is(telephony.calls.length, 1);
|
|
|
|
is(telephony.calls[0], incoming);
|
|
|
|
|
2014-06-24 03:36:59 -07:00
|
|
|
emulator.runCmdWithCallback("gsm list", function(result) {
|
2013-10-01 23:27:52 -07:00
|
|
|
log("Call list is now: " + result);
|
|
|
|
is(result[0], "inbound from " + number + " : incoming");
|
|
|
|
answer();
|
|
|
|
});
|
2012-06-08 00:09:15 -07:00
|
|
|
};
|
|
|
|
|
2014-06-24 03:36:59 -07:00
|
|
|
emulator.runCmdWithCallback("gsm call " + number);
|
2012-06-08 00:09:15 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
function answer() {
|
|
|
|
log("Answering the incoming call.");
|
|
|
|
|
|
|
|
let gotConnecting = false;
|
|
|
|
incoming.onconnecting = function onconnecting(event) {
|
|
|
|
log("Received 'connecting' call event.");
|
|
|
|
is(incoming, event.call);
|
|
|
|
is(incoming.state, "connecting");
|
|
|
|
|
|
|
|
// Incoming call is not 'active' until its state becomes 'connected'.
|
|
|
|
isnot(incoming, telephony.active);
|
|
|
|
gotConnecting = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
incoming.onconnected = function onconnected(event) {
|
|
|
|
log("Received 'connected' call event.");
|
|
|
|
is(incoming, event.call);
|
|
|
|
is(incoming.state, "connected");
|
|
|
|
ok(gotConnecting);
|
|
|
|
|
|
|
|
is(incoming, telephony.active);
|
|
|
|
|
2014-06-24 03:36:59 -07:00
|
|
|
emulator.runCmdWithCallback("gsm list", function(result) {
|
2012-06-08 00:09:15 -07:00
|
|
|
log("Call list is now: " + result);
|
|
|
|
is(result[0], "inbound from " + number + " : active");
|
|
|
|
hangUp();
|
|
|
|
});
|
|
|
|
};
|
|
|
|
incoming.answer();
|
2013-10-01 23:27:52 -07:00
|
|
|
}
|
2012-06-08 00:09:15 -07:00
|
|
|
|
|
|
|
function hangUp() {
|
|
|
|
log("Hanging up the incoming call.");
|
|
|
|
|
2013-10-01 23:27:52 -07:00
|
|
|
// Should received 'diconnecting', 'callschanged', 'disconnected' events in
|
|
|
|
// order.
|
2012-06-08 00:09:15 -07:00
|
|
|
let gotDisconnecting = false;
|
2013-10-01 23:27:52 -07:00
|
|
|
let gotCallschanged = false;
|
|
|
|
|
2012-06-08 00:09:15 -07:00
|
|
|
incoming.ondisconnecting = function ondisconnecting(event) {
|
|
|
|
log("Received 'disconnecting' call event.");
|
|
|
|
is(incoming, event.call);
|
|
|
|
is(incoming.state, "disconnecting");
|
|
|
|
gotDisconnecting = true;
|
|
|
|
};
|
|
|
|
|
2013-10-01 23:27:52 -07:00
|
|
|
telephony.oncallschanged = function oncallschanged(event) {
|
|
|
|
log("Received 'callschanged' event.");
|
|
|
|
|
|
|
|
if (!event.call) {
|
|
|
|
log("Notifying calls array is loaded. No call information accompanies.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
is(incoming, event.call);
|
|
|
|
is(incoming.state, "disconnected");
|
|
|
|
is(telephony.active, null);
|
|
|
|
is(telephony.calls.length, 0);
|
|
|
|
gotCallschanged = true;
|
|
|
|
};
|
|
|
|
|
2012-06-08 00:09:15 -07:00
|
|
|
incoming.ondisconnected = function ondisconnected(event) {
|
|
|
|
log("Received 'disconnected' call event.");
|
|
|
|
is(incoming, event.call);
|
|
|
|
is(incoming.state, "disconnected");
|
|
|
|
ok(gotDisconnecting);
|
2013-10-01 23:27:52 -07:00
|
|
|
ok(gotCallschanged);
|
2012-06-08 00:09:15 -07:00
|
|
|
|
|
|
|
is(telephony.active, null);
|
|
|
|
is(telephony.calls.length, 0);
|
|
|
|
|
2014-06-24 03:36:59 -07:00
|
|
|
emulator.runCmdWithCallback("gsm list", function(result) {
|
2012-06-08 00:09:15 -07:00
|
|
|
log("Call list is now: " + result);
|
2013-10-01 23:27:52 -07:00
|
|
|
cleanUp();
|
2012-06-08 00:09:15 -07:00
|
|
|
});
|
|
|
|
};
|
2013-10-01 23:27:52 -07:00
|
|
|
|
2012-06-08 00:09:15 -07:00
|
|
|
incoming.hangUp();
|
|
|
|
}
|
|
|
|
|
|
|
|
function cleanUp() {
|
2012-11-13 14:05:27 -08:00
|
|
|
telephony.oncallschanged = null;
|
2012-06-08 00:09:15 -07:00
|
|
|
finish();
|
|
|
|
}
|
|
|
|
|
2013-10-01 23:27:52 -07:00
|
|
|
startTest(function() {
|
2013-10-28 02:22:44 -07:00
|
|
|
simulateIncoming();
|
2013-10-01 23:27:52 -07:00
|
|
|
});
|