Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | /* Any copyright is dedicated to the Public Domain. |
michael@0 | 2 | * http://creativecommons.org/publicdomain/zero/1.0/ */ |
michael@0 | 3 | |
michael@0 | 4 | MARIONETTE_TIMEOUT = 60000; |
michael@0 | 5 | |
michael@0 | 6 | let outNumber = "5555551111"; |
michael@0 | 7 | let outgoingCall; |
michael@0 | 8 | |
michael@0 | 9 | function dial() { |
michael@0 | 10 | log("Make an outgoing call."); |
michael@0 | 11 | |
michael@0 | 12 | telephony.dial(outNumber).then(call => { |
michael@0 | 13 | outgoingCall = call; |
michael@0 | 14 | ok(outgoingCall); |
michael@0 | 15 | is(outgoingCall.number, outNumber); |
michael@0 | 16 | is(outgoingCall.state, "dialing"); |
michael@0 | 17 | |
michael@0 | 18 | is(outgoingCall, telephony.active); |
michael@0 | 19 | is(telephony.calls.length, 1); |
michael@0 | 20 | is(telephony.calls[0], outgoingCall); |
michael@0 | 21 | |
michael@0 | 22 | outgoingCall.onalerting = function onalerting(event) { |
michael@0 | 23 | log("Received 'alerting' call event."); |
michael@0 | 24 | |
michael@0 | 25 | is(outgoingCall, event.call); |
michael@0 | 26 | is(outgoingCall.state, "alerting"); |
michael@0 | 27 | |
michael@0 | 28 | emulator.run("gsm list", function(result) { |
michael@0 | 29 | log("Call list is now: " + result); |
michael@0 | 30 | is(result[0], "outbound to " + outNumber + " : ringing"); |
michael@0 | 31 | is(result[1], "OK"); |
michael@0 | 32 | answer(); |
michael@0 | 33 | }); |
michael@0 | 34 | }; |
michael@0 | 35 | }); |
michael@0 | 36 | } |
michael@0 | 37 | |
michael@0 | 38 | function answer() { |
michael@0 | 39 | log("Answering the outgoing call."); |
michael@0 | 40 | |
michael@0 | 41 | // We get no "connecting" event when the remote party answers the call. |
michael@0 | 42 | |
michael@0 | 43 | outgoingCall.onconnected = function onconnected(event) { |
michael@0 | 44 | log("Received 'connected' call event."); |
michael@0 | 45 | is(outgoingCall, event.call); |
michael@0 | 46 | is(outgoingCall.state, "connected"); |
michael@0 | 47 | |
michael@0 | 48 | is(outgoingCall, telephony.active); |
michael@0 | 49 | |
michael@0 | 50 | emulator.run("gsm list", function(result) { |
michael@0 | 51 | log("Call list is now: " + result); |
michael@0 | 52 | is(result[0], "outbound to " + outNumber + " : active"); |
michael@0 | 53 | is(result[1], "OK"); |
michael@0 | 54 | hold(); |
michael@0 | 55 | }); |
michael@0 | 56 | }; |
michael@0 | 57 | emulator.run("gsm accept " + outNumber); |
michael@0 | 58 | } |
michael@0 | 59 | |
michael@0 | 60 | function hold() { |
michael@0 | 61 | log("Holding the outgoing call."); |
michael@0 | 62 | |
michael@0 | 63 | outgoingCall.onholding = function onholding(event) { |
michael@0 | 64 | log("Received 'holding' call event."); |
michael@0 | 65 | is(outgoingCall, event.call); |
michael@0 | 66 | is(outgoingCall.state, "holding"); |
michael@0 | 67 | |
michael@0 | 68 | is(outgoingCall, telephony.active); |
michael@0 | 69 | }; |
michael@0 | 70 | |
michael@0 | 71 | outgoingCall.onheld = function onheld(event) { |
michael@0 | 72 | log("Received 'held' call event."); |
michael@0 | 73 | is(outgoingCall, event.call); |
michael@0 | 74 | is(outgoingCall.state, "held"); |
michael@0 | 75 | |
michael@0 | 76 | is(telephony.active, null); |
michael@0 | 77 | is(telephony.calls.length, 1); |
michael@0 | 78 | is(telephony.calls[0], outgoingCall); |
michael@0 | 79 | |
michael@0 | 80 | emulator.run("gsm list", function(result) { |
michael@0 | 81 | log("Call list is now: " + result); |
michael@0 | 82 | is(result[0], "outbound to " + outNumber + " : held"); |
michael@0 | 83 | is(result[1], "OK"); |
michael@0 | 84 | hangUp(); |
michael@0 | 85 | }); |
michael@0 | 86 | }; |
michael@0 | 87 | outgoingCall.hold(); |
michael@0 | 88 | } |
michael@0 | 89 | |
michael@0 | 90 | function hangUp() { |
michael@0 | 91 | log("Hanging up the outgoing call (remotely)."); |
michael@0 | 92 | |
michael@0 | 93 | // We get no 'disconnecting' event when remote party hangs-up the call |
michael@0 | 94 | |
michael@0 | 95 | outgoingCall.ondisconnected = function ondisconnected(event) { |
michael@0 | 96 | log("Received 'disconnected' call event."); |
michael@0 | 97 | is(outgoingCall, event.call); |
michael@0 | 98 | is(outgoingCall.state, "disconnected"); |
michael@0 | 99 | |
michael@0 | 100 | is(telephony.active, null); |
michael@0 | 101 | is(telephony.calls.length, 0); |
michael@0 | 102 | |
michael@0 | 103 | emulator.run("gsm list", function(result) { |
michael@0 | 104 | log("Call list is now: " + result); |
michael@0 | 105 | is(result[0], "OK"); |
michael@0 | 106 | cleanUp(); |
michael@0 | 107 | }); |
michael@0 | 108 | }; |
michael@0 | 109 | emulator.run("gsm cancel " + outNumber); |
michael@0 | 110 | } |
michael@0 | 111 | |
michael@0 | 112 | function cleanUp() { |
michael@0 | 113 | finish(); |
michael@0 | 114 | } |
michael@0 | 115 | |
michael@0 | 116 | startTest(function() { |
michael@0 | 117 | dial(); |
michael@0 | 118 | }); |