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 = "5555557777"; michael@0: let connectedCalls; michael@0: let outgoingCall; michael@0: michael@0: function dial() { michael@0: log("Make an outgoing call."); michael@0: michael@0: telephony.dial(number).then(call => { michael@0: outgoingCall = call; michael@0: ok(outgoingCall); michael@0: is(outgoingCall.number, number); michael@0: is(outgoingCall.state, "dialing"); michael@0: michael@0: is(outgoingCall, telephony.active); michael@0: is(telephony.calls.length, 1); michael@0: is(telephony.calls[0], outgoingCall); michael@0: michael@0: outgoingCall.onalerting = function onalerting(event) { michael@0: log("Received 'onalerting' call event."); michael@0: is(outgoingCall, event.call); michael@0: is(outgoingCall.state, "alerting"); michael@0: michael@0: emulator.run("gsm list", function(result) { michael@0: log("Call list is now: " + result); michael@0: is(result[0], "outbound to " + number + " : ringing"); michael@0: is(result[1], "OK"); michael@0: answer(); michael@0: }); michael@0: }; michael@0: }); michael@0: } michael@0: michael@0: function answer() { michael@0: log("Answering the outgoing call."); michael@0: michael@0: // We get no "connecting" event when the remote party answers the call. michael@0: michael@0: outgoingCall.onconnected = function onconnected(event) { michael@0: log("Received 'connected' call event."); michael@0: is(outgoingCall, event.call); michael@0: is(outgoingCall.state, "connected"); michael@0: michael@0: is(outgoingCall, 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], "outbound to " + number + " : active"); michael@0: is(result[1], "OK"); michael@0: hold(); michael@0: }); michael@0: }; michael@0: emulator.run("gsm accept " + number); 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: outgoingCall.onholding = function onholding(event) { michael@0: log("Received 'holding' call event"); michael@0: is(outgoingCall, event.call); michael@0: is(outgoingCall.state, "holding"); michael@0: gotHolding = true; michael@0: }; michael@0: michael@0: outgoingCall.onheld = function onheld(event) { michael@0: log("Received 'held' call event"); michael@0: is(outgoingCall, event.call); michael@0: is(outgoingCall.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], outgoingCall); michael@0: michael@0: emulator.run("gsm list", function(result) { michael@0: log("Call list is now: " + result); michael@0: is(result[0], "outbound to " + number + " : held"); michael@0: is(result[1], "OK"); michael@0: // Bug 781604: emulator assertion if outgoing call kept on hold 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: resume(); michael@0: }); michael@0: }; michael@0: outgoingCall.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: outgoingCall.onresuming = function onresuming(event) { michael@0: log("Received 'resuming' call event"); michael@0: is(outgoingCall, event.call); michael@0: is(outgoingCall.state, "resuming"); michael@0: gotResuming = true; michael@0: }; michael@0: michael@0: outgoingCall.onconnected = function onconnected(event) { michael@0: log("Received 'connected' call event"); michael@0: is(outgoingCall, event.call); michael@0: is(outgoingCall.state, "connected"); michael@0: ok(gotResuming); michael@0: michael@0: is(outgoingCall, telephony.active); michael@0: is(telephony.calls.length, 1); michael@0: is(telephony.calls[0], outgoingCall); michael@0: michael@0: emulator.run("gsm list", function(result) { michael@0: log("Call list is now: " + result); michael@0: is(result[0], "outbound to " + number + " : active"); michael@0: is(result[1], "OK"); michael@0: hangUp(); michael@0: }); michael@0: }; michael@0: outgoingCall.resume(); michael@0: } michael@0: michael@0: function hangUp() { michael@0: log("Hanging up the outgoing call."); michael@0: michael@0: let gotDisconnecting = false; michael@0: outgoingCall.ondisconnecting = function ondisconnecting(event) { michael@0: log("Received 'disconnecting' call event."); michael@0: is(outgoingCall, event.call); michael@0: is(outgoingCall.state, "disconnecting"); michael@0: gotDisconnecting = true; michael@0: }; michael@0: michael@0: outgoingCall.ondisconnected = function ondisconnected(event) { michael@0: log("Received 'disconnected' call event."); michael@0: is(outgoingCall, event.call); michael@0: is(outgoingCall.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: outgoingCall.hangUp(); michael@0: } michael@0: michael@0: function cleanUp() { michael@0: finish(); michael@0: } michael@0: michael@0: startTest(function() { michael@0: dial(); michael@0: });