michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: * http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: MARIONETTE_TIMEOUT = 60000; michael@0: MARIONETTE_HEAD_JS = 'head.js'; michael@0: michael@0: let number = "5555552368"; michael@0: let incoming; michael@0: michael@0: function simulateIncoming() { michael@0: log("Simulating an incoming call."); michael@0: michael@0: telephony.oncallschanged = function oncallschanged(event) { michael@0: log("Received 'callschanged' event."); michael@0: michael@0: if (!event.call) { michael@0: log("Notifying calls array is loaded. No call information accompanies."); michael@0: return; michael@0: } michael@0: michael@0: telephony.oncallschanged = null; michael@0: michael@0: incoming = event.call; michael@0: ok(incoming); michael@0: is(incoming.number, number); michael@0: is(incoming.state, "incoming"); michael@0: michael@0: is(telephony.calls.length, 1); michael@0: is(telephony.calls[0], incoming); michael@0: michael@0: emulator.run("gsm list", function(result) { michael@0: log("Call list is now: " + result); michael@0: is(result[0], "inbound from " + number + " : incoming"); michael@0: is(result[1], "OK"); michael@0: answer(); michael@0: }); michael@0: }; michael@0: michael@0: emulator.run("gsm call " + number); michael@0: } michael@0: michael@0: function answer() { michael@0: log("Answering the incoming call."); michael@0: michael@0: let gotConnecting = false; michael@0: incoming.onconnecting = function onconnecting(event) { michael@0: log("Received 'connecting' call event."); michael@0: is(incoming, event.call); michael@0: is(incoming.state, "connecting"); michael@0: michael@0: // Incoming call is not 'active' until its state becomes 'connected'. michael@0: isnot(incoming, telephony.active); michael@0: gotConnecting = true; michael@0: }; michael@0: michael@0: incoming.onconnected = function onconnected(event) { michael@0: log("Received 'connected' call event."); michael@0: is(incoming, event.call); michael@0: is(incoming.state, "connected"); michael@0: ok(gotConnecting); michael@0: michael@0: is(incoming, telephony.active); michael@0: michael@0: emulator.run("gsm list", function(result) { michael@0: log("Call list is now: " + result); michael@0: is(result[0], "inbound from " + number + " : active"); michael@0: is(result[1], "OK"); michael@0: hangUp(); michael@0: }); michael@0: }; michael@0: incoming.answer(); michael@0: } michael@0: michael@0: function hangUp() { michael@0: log("Hanging up the incoming call."); michael@0: michael@0: // Should received 'diconnecting', 'callschanged', 'disconnected' events in michael@0: // order. michael@0: let gotDisconnecting = false; michael@0: let gotCallschanged = false; michael@0: michael@0: incoming.ondisconnecting = function ondisconnecting(event) { michael@0: log("Received 'disconnecting' call event."); michael@0: is(incoming, event.call); michael@0: is(incoming.state, "disconnecting"); michael@0: gotDisconnecting = true; michael@0: }; michael@0: michael@0: telephony.oncallschanged = function oncallschanged(event) { michael@0: log("Received 'callschanged' event."); michael@0: michael@0: if (!event.call) { michael@0: log("Notifying calls array is loaded. No call information accompanies."); michael@0: return; michael@0: } michael@0: michael@0: is(incoming, event.call); michael@0: is(incoming.state, "disconnected"); michael@0: is(telephony.active, null); michael@0: is(telephony.calls.length, 0); michael@0: gotCallschanged = true; michael@0: }; michael@0: michael@0: incoming.ondisconnected = function ondisconnected(event) { michael@0: log("Received 'disconnected' call event."); michael@0: is(incoming, event.call); michael@0: is(incoming.state, "disconnected"); michael@0: ok(gotDisconnecting); michael@0: ok(gotCallschanged); michael@0: michael@0: is(telephony.active, null); michael@0: is(telephony.calls.length, 0); michael@0: michael@0: emulator.run("gsm list", function(result) { michael@0: log("Call list is now: " + result); michael@0: is(result[0], "OK"); michael@0: cleanUp(); michael@0: }); michael@0: }; michael@0: michael@0: incoming.hangUp(); michael@0: } michael@0: michael@0: function cleanUp() { michael@0: telephony.oncallschanged = null; michael@0: finish(); michael@0: } michael@0: michael@0: startTest(function() { michael@0: simulateIncoming(); michael@0: });