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 inNumber = "5555551111"; michael@0: let incomingCall; michael@0: michael@0: function simulateIncoming() { michael@0: log("Simulating an incoming call."); michael@0: michael@0: telephony.onincoming = function onincoming(event) { michael@0: log("Received 'incoming' call event."); michael@0: incomingCall = event.call; michael@0: ok(incomingCall); michael@0: is(incomingCall.number, inNumber); michael@0: is(incomingCall.state, "incoming"); michael@0: michael@0: is(telephony.calls.length, 1); michael@0: is(telephony.calls[0], incomingCall); 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 " + inNumber + " : incoming"); michael@0: is(result[1], "OK"); michael@0: answerIncoming(); michael@0: }); michael@0: }; michael@0: emulator.run("gsm call " + inNumber); michael@0: } michael@0: michael@0: function answerIncoming() { michael@0: log("Answering the incoming call."); michael@0: michael@0: incomingCall.onconnecting = function onconnecting(event) { michael@0: log("Received 'connecting' call event."); michael@0: is(incomingCall, event.call); michael@0: is(incomingCall.state, "connecting"); michael@0: // Now have the remote party hang-up the call before it is fully connected michael@0: remoteHangUp(); michael@0: }; michael@0: michael@0: incomingCall.onconnected = function onconnected(event) { michael@0: log("Received 'connected' call event."); michael@0: }; michael@0: incomingCall.answer(); michael@0: } michael@0: michael@0: function remoteHangUp() { michael@0: log("Hanging up the incoming call (remotely) before fully connected."); michael@0: michael@0: // We get no 'disconnecting' event when remote party hangs-up the call michael@0: michael@0: incomingCall.ondisconnected = function ondisconnected(event) { michael@0: log("Received 'disconnected' call event."); michael@0: is(incomingCall, event.call); michael@0: is(incomingCall.state, "disconnected"); 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: emulator.run("gsm cancel " + inNumber); michael@0: } michael@0: michael@0: function cleanUp() { michael@0: telephony.onincoming = null; michael@0: finish(); michael@0: } michael@0: michael@0: startTest(function() { michael@0: simulateIncoming(); michael@0: });