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 = "5555551234"; michael@0: let connectedCalls; 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, number); 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 " + number + " : incoming"); michael@0: is(result[1], "OK"); michael@0: answer(); 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: 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: gotConnecting = true; michael@0: }; michael@0: michael@0: incomingCall.onconnected = function onconnected(event) { michael@0: log("Received 'connected' call event."); michael@0: is(incomingCall, event.call); michael@0: is(incomingCall.state, "connected"); michael@0: ok(gotConnecting); michael@0: michael@0: is(incomingCall, 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: hold(); michael@0: }); michael@0: }; michael@0: incomingCall.answer(); michael@0: } michael@0: michael@0: function hold() { michael@0: log("Putting the call on hold."); michael@0: michael@0: let gotHolding = false; michael@0: incomingCall.onholding = function onholding(event) { michael@0: log("Received 'holding' call event"); michael@0: is(incomingCall, event.call); michael@0: is(incomingCall.state, "holding"); michael@0: gotHolding = true; michael@0: }; michael@0: michael@0: incomingCall.onheld = function onheld(event) { michael@0: log("Received 'held' call event"); michael@0: is(incomingCall, event.call); michael@0: is(incomingCall.state, "held"); michael@0: ok(gotHolding); michael@0: michael@0: is(telephony.active, null); 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 " + number + " : held"); michael@0: is(result[1], "OK"); michael@0: // Wait on hold for a couple of seconds michael@0: log("Pausing 2 seconds while on hold"); michael@0: setTimeout(resume, 2000); michael@0: }); michael@0: }; michael@0: incomingCall.hold(); michael@0: } michael@0: michael@0: function resume() { michael@0: log("Resuming the held call."); michael@0: michael@0: let gotResuming = false; michael@0: incomingCall.onresuming = function onresuming(event) { michael@0: log("Received 'resuming' call event"); michael@0: is(incomingCall, event.call); michael@0: is(incomingCall.state, "resuming"); michael@0: gotResuming = true; michael@0: }; michael@0: michael@0: incomingCall.onconnected = function onconnected(event) { michael@0: log("Received 'connected' call event"); michael@0: is(incomingCall, event.call); michael@0: is(incomingCall.state, "connected"); michael@0: ok(gotResuming); michael@0: michael@0: is(incomingCall, telephony.active); 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 " + number + " : active"); michael@0: is(result[1], "OK"); michael@0: hangUp(); michael@0: }); michael@0: }; michael@0: incomingCall.resume(); michael@0: } michael@0: michael@0: function hangUp() { michael@0: log("Hanging up the incoming call."); 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: });