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 hang-up the call before it is fully connected michael@0: michael@0: // Bug 784429: Hang-up while connecting, call is not terminated michael@0: // If hang-up between 'connecting' and 'connected' states, receive the michael@0: // 'disconnecting' event but then a 'connected' event, and the call is michael@0: // never terminated; this test times out waiting for 'disconnected', and michael@0: // will leave the emulator in a bad state (with an active incoming call). michael@0: // For now, hangUp after the 'connected' event so this test doesn't michael@0: // timeout; once the bug is fixed then update and remove the setTimeout michael@0: michael@0: //hangUp(); michael@0: log("==> Waiting one second, remove wait once bug 784429 is fixed <=="); michael@0: setTimeout(hangUp, 1000); 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 hangUp() { michael@0: log("Hanging up the incoming call before fully connected."); michael@0: michael@0: let gotDisconnecting = false; michael@0: incomingCall.ondisconnecting = function ondisconnecting(event) { michael@0: log("Received 'disconnecting' call event."); michael@0: is(incomingCall, event.call); michael@0: is(incomingCall.state, "disconnecting"); michael@0: gotDisconnecting = true; michael@0: }; 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: ok(gotDisconnecting); 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: incomingCall.hangUp(); 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: });