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: let gotConnecting = false; michael@0: incomingCall.onconnecting = function onconnectingIn(event) { michael@0: log("Received 'connecting' call event for incoming call."); 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 onconnectedIn(event) { michael@0: log("Received 'connected' call event for incoming call."); 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 " + inNumber + " : active"); michael@0: is(result[1], "OK"); michael@0: answerAlreadyConnected(); michael@0: }); michael@0: }; michael@0: incomingCall.answer(); michael@0: } michael@0: michael@0: function answerAlreadyConnected() { michael@0: log("Attempting to answer already connected call, should be ignored."); michael@0: michael@0: incomingCall.onconnecting = function onconnectingErr(event) { michael@0: log("Received 'connecting' call event, but should not have."); michael@0: ok(false, "Received 'connecting' event when answered already active call"); michael@0: }; michael@0: michael@0: incomingCall.onconnected = function onconnectedErr(event) { michael@0: log("Received 'connected' call event, but should not have."); michael@0: ok(false, "Received 'connected' event when answered already active call"); michael@0: }; michael@0: michael@0: incomingCall.answer(); michael@0: michael@0: is(incomingCall.state, "connected"); michael@0: is(telephony.calls.length, 1); michael@0: is(telephony.calls[0], incomingCall); michael@0: is(incomingCall, telephony.active); michael@0: hold(); 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 " + inNumber + " : held"); michael@0: is(result[1], "OK"); michael@0: holdAlreadyHeld(); michael@0: }); michael@0: }; michael@0: incomingCall.hold(); michael@0: } michael@0: michael@0: function holdAlreadyHeld() { michael@0: log("Attempting to hold an already held call, should be ignored."); michael@0: michael@0: incomingCall.onholding = function onholding(event) { michael@0: log("Received 'holding' call event, but should not have."); michael@0: ok(false, "Received 'holding' event when held an already held call"); michael@0: }; michael@0: michael@0: incomingCall.onheld = function onheldErr(event) { michael@0: log("Received 'held' call event, but should not have."); michael@0: ok(false, "Received 'held' event when held an already held call"); michael@0: }; michael@0: michael@0: incomingCall.hold(); michael@0: michael@0: is(incomingCall.state, "held"); michael@0: is(telephony.active, null); michael@0: is(telephony.calls.length, 1); michael@0: is(telephony.calls[0], incomingCall); michael@0: michael@0: answerHeld(); michael@0: } michael@0: michael@0: function answerHeld() { michael@0: log("Attempting to answer a held call, should be ignored."); michael@0: michael@0: incomingCall.onconnecting = function onconnectingErr(event) { michael@0: log("Received 'connecting' call event, but should not have."); michael@0: ok(false, "Received 'connecting' event when answered a held call"); michael@0: }; michael@0: michael@0: incomingCall.onconnected = function onconnectedErr(event) { michael@0: log("Received 'connected' call event, but should not have."); michael@0: ok(false, "Received 'connected' event when answered a held call"); michael@0: }; michael@0: michael@0: incomingCall.answer(); michael@0: michael@0: is(incomingCall.state, "held"); michael@0: is(telephony.active, null); michael@0: is(telephony.calls.length, 1); michael@0: is(telephony.calls[0], incomingCall); michael@0: michael@0: resume(); 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 " + inNumber + " : active"); michael@0: is(result[1], "OK"); michael@0: resumeNonHeld(); michael@0: }); michael@0: }; michael@0: incomingCall.resume(); michael@0: } michael@0: michael@0: function resumeNonHeld() { michael@0: log("Attempting to resume non-held call, should be ignored."); michael@0: michael@0: incomingCall.onresuming = function onresumingErr(event) { michael@0: log("Received 'resuming' call event, but should not have."); michael@0: ok(false, "Received 'resuming' event when resumed non-held call"); michael@0: }; michael@0: michael@0: incomingCall.onconnected = function onconnectedErr(event) { michael@0: log("Received 'connected' call event, but should not have."); michael@0: ok(false, "Received 'connected' event when resumed non-held call"); michael@0: }; michael@0: michael@0: incomingCall.resume(); michael@0: michael@0: is(incomingCall.state, "connected"); michael@0: is(telephony.calls.length, 1); michael@0: is(telephony.calls[0], incomingCall); michael@0: is(incomingCall, telephony.active); michael@0: hangUp(); michael@0: } michael@0: michael@0: function hangUp() { michael@0: log("Hanging up the call (local hang-up)."); 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 ondisconnectedOut(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: answerDisconnected(); michael@0: }); michael@0: }; michael@0: incomingCall.hangUp(); michael@0: } michael@0: michael@0: function answerDisconnected() { michael@0: log("Attempting to answer disconnected call, should be ignored."); michael@0: michael@0: incomingCall.onconnecting = function onconnectingErr(event) { michael@0: log("Received 'connecting' call event, but should not have."); michael@0: ok(false, "Received 'connecting' event when answered disconnected call"); michael@0: }; michael@0: michael@0: incomingCall.onconnected = function onconnectedErr(event) { michael@0: log("Received 'connected' call event, but should not have."); michael@0: ok(false, "Received 'connected' event when answered disconnected call"); michael@0: }; michael@0: michael@0: incomingCall.answer(); michael@0: michael@0: is(telephony.active, null); michael@0: is(telephony.calls.length, 0); michael@0: holdDisconnected(); michael@0: } michael@0: michael@0: function holdDisconnected() { michael@0: log("Attempting to hold disconnected call, should be ignored."); michael@0: michael@0: incomingCall.onholding = function onholdingErr(event) { michael@0: log("Received 'holding' call event, but should not have."); michael@0: ok(false, "Received 'holding' event when held a disconnected call"); michael@0: }; michael@0: michael@0: incomingCall.onheld = function onheldErr(event) { michael@0: log("Received 'held' call event, but should not have."); michael@0: ok(false, "Received 'held' event when held a disconnected call"); michael@0: }; michael@0: michael@0: incomingCall.hold(); michael@0: michael@0: is(telephony.active, null); michael@0: is(telephony.calls.length, 0); michael@0: resumeDisconnected(); michael@0: } michael@0: michael@0: function resumeDisconnected() { michael@0: log("Attempting to resume disconnected call, should be ignored."); michael@0: michael@0: incomingCall.onresuming = function onresumingErr(event) { michael@0: log("Received 'resuming' call event, but should not have."); michael@0: ok(false, "Received 'resuming' event when resumed disconnected call"); michael@0: }; michael@0: michael@0: incomingCall.onconnected = function onconnectedErr(event) { michael@0: log("Received 'connected' call event, but should not have."); michael@0: ok(false, "Received 'connected' event when resumed disconnected call"); michael@0: }; michael@0: michael@0: incomingCall.resume(); michael@0: michael@0: is(telephony.active, null); michael@0: is(telephony.calls.length, 0); michael@0: hangUpNonConnected(); michael@0: } michael@0: michael@0: function hangUpNonConnected() { michael@0: log("Attempting to hang-up disconnected call, should be ignored."); michael@0: michael@0: incomingCall.ondisconnecting = function ondisconnectingErr(event) { michael@0: log("Received 'disconnecting' call event, but should not have."); michael@0: ok(false, "Received 'disconnecting' event when hung-up non-active call"); michael@0: }; michael@0: michael@0: incomingCall.ondisconnected = function ondisconnectedErr(event) { michael@0: log("Received 'disconnected' call event, but should not have."); michael@0: ok(false, "Received 'disconnected' event when hung-up non-active call"); michael@0: }; michael@0: michael@0: incomingCall.hangUp(); michael@0: michael@0: is(telephony.active, null); michael@0: is(telephony.calls.length, 0); michael@0: cleanUp(); 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: });