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 | MARIONETTE_HEAD_JS = 'head.js'; |
michael@0 | 6 | |
michael@0 | 7 | let outNumber = "5555551111"; |
michael@0 | 8 | let inNumber = "5555552222"; |
michael@0 | 9 | let outgoingCall; |
michael@0 | 10 | let incomingCall; |
michael@0 | 11 | let gotOriginalConnected = false; |
michael@0 | 12 | |
michael@0 | 13 | function dial() { |
michael@0 | 14 | log("Make an outgoing call."); |
michael@0 | 15 | telephony.dial(outNumber).then(call => { |
michael@0 | 16 | outgoingCall = call; |
michael@0 | 17 | ok(outgoingCall); |
michael@0 | 18 | is(outgoingCall.number, outNumber); |
michael@0 | 19 | is(outgoingCall.state, "dialing"); |
michael@0 | 20 | |
michael@0 | 21 | is(outgoingCall, telephony.active); |
michael@0 | 22 | is(telephony.calls.length, 1); |
michael@0 | 23 | is(telephony.calls[0], outgoingCall); |
michael@0 | 24 | |
michael@0 | 25 | outgoingCall.onalerting = function onalerting(event) { |
michael@0 | 26 | log("Received 'onalerting' call event."); |
michael@0 | 27 | is(outgoingCall, event.call); |
michael@0 | 28 | is(outgoingCall.state, "alerting"); |
michael@0 | 29 | |
michael@0 | 30 | emulator.run("gsm list", function(result) { |
michael@0 | 31 | log("Call list is now: " + result); |
michael@0 | 32 | is(result[0], "outbound to " + outNumber + " : ringing"); |
michael@0 | 33 | is(result[1], "OK"); |
michael@0 | 34 | answer(); |
michael@0 | 35 | }); |
michael@0 | 36 | }; |
michael@0 | 37 | }); |
michael@0 | 38 | } |
michael@0 | 39 | |
michael@0 | 40 | function answer() { |
michael@0 | 41 | log("Answering the outgoing call."); |
michael@0 | 42 | |
michael@0 | 43 | // We get no "connecting" event when the remote party answers the call. |
michael@0 | 44 | outgoingCall.onconnected = function onconnectedOut(event) { |
michael@0 | 45 | log("Received 'connected' call event for the original outgoing call."); |
michael@0 | 46 | |
michael@0 | 47 | is(outgoingCall, event.call); |
michael@0 | 48 | is(outgoingCall.state, "connected"); |
michael@0 | 49 | is(outgoingCall, telephony.active); |
michael@0 | 50 | |
michael@0 | 51 | emulator.run("gsm list", function(result) { |
michael@0 | 52 | log("Call list is now: " + result); |
michael@0 | 53 | is(result[0], "outbound to " + outNumber + " : active"); |
michael@0 | 54 | is(result[1], "OK"); |
michael@0 | 55 | |
michael@0 | 56 | if(!gotOriginalConnected){ |
michael@0 | 57 | gotOriginalConnected = true; |
michael@0 | 58 | simulateIncoming(); |
michael@0 | 59 | } else { |
michael@0 | 60 | // Received connected event for original call multiple times (fail) |
michael@0 | 61 | ok(false, |
michael@0 | 62 | "Received 'connected' event for original call multiple times"); |
michael@0 | 63 | } |
michael@0 | 64 | }); |
michael@0 | 65 | }; |
michael@0 | 66 | emulator.run("gsm accept " + outNumber); |
michael@0 | 67 | } |
michael@0 | 68 | |
michael@0 | 69 | // With one connected call already, simulate an incoming call |
michael@0 | 70 | function simulateIncoming() { |
michael@0 | 71 | log("Simulating an incoming call (with one call already connected)."); |
michael@0 | 72 | |
michael@0 | 73 | telephony.onincoming = function onincoming(event) { |
michael@0 | 74 | log("Received 'incoming' call event."); |
michael@0 | 75 | incomingCall = event.call; |
michael@0 | 76 | ok(incomingCall); |
michael@0 | 77 | is(incomingCall.number, inNumber); |
michael@0 | 78 | is(incomingCall.state, "incoming"); |
michael@0 | 79 | |
michael@0 | 80 | // Should be two calls now |
michael@0 | 81 | is(telephony.calls.length, 2); |
michael@0 | 82 | is(telephony.calls[0], outgoingCall); |
michael@0 | 83 | is(telephony.calls[1], incomingCall); |
michael@0 | 84 | |
michael@0 | 85 | emulator.run("gsm list", function(result) { |
michael@0 | 86 | log("Call list is now: " + result); |
michael@0 | 87 | is(result[0], "outbound to " + outNumber + " : active"); |
michael@0 | 88 | is(result[1], "inbound from " + inNumber + " : incoming"); |
michael@0 | 89 | is(result[2], "OK"); |
michael@0 | 90 | answerIncoming(); |
michael@0 | 91 | }); |
michael@0 | 92 | }; |
michael@0 | 93 | emulator.run("gsm call " + inNumber); |
michael@0 | 94 | } |
michael@0 | 95 | |
michael@0 | 96 | // Answer incoming call; original outgoing call should be held |
michael@0 | 97 | function answerIncoming() { |
michael@0 | 98 | log("Answering the incoming call."); |
michael@0 | 99 | |
michael@0 | 100 | let gotConnecting = false; |
michael@0 | 101 | incomingCall.onconnecting = function onconnectingIn(event) { |
michael@0 | 102 | log("Received 'connecting' call event for incoming/2nd call."); |
michael@0 | 103 | is(incomingCall, event.call); |
michael@0 | 104 | is(incomingCall.state, "connecting"); |
michael@0 | 105 | gotConnecting = true; |
michael@0 | 106 | }; |
michael@0 | 107 | |
michael@0 | 108 | incomingCall.onconnected = function onconnectedIn(event) { |
michael@0 | 109 | log("Received 'connected' call event for incoming/2nd call."); |
michael@0 | 110 | is(incomingCall, event.call); |
michael@0 | 111 | is(incomingCall.state, "connected"); |
michael@0 | 112 | ok(gotConnecting); |
michael@0 | 113 | |
michael@0 | 114 | is(incomingCall, telephony.active); |
michael@0 | 115 | is(outgoingCall.state, "held"); |
michael@0 | 116 | |
michael@0 | 117 | emulator.run("gsm list", function(result) { |
michael@0 | 118 | log("Call list is now: " + result); |
michael@0 | 119 | is(result[0], "outbound to " + outNumber + " : held"); |
michael@0 | 120 | is(result[1], "inbound from " + inNumber + " : active"); |
michael@0 | 121 | is(result[2], "OK"); |
michael@0 | 122 | hangUpOutgoing(); |
michael@0 | 123 | }); |
michael@0 | 124 | }; |
michael@0 | 125 | incomingCall.answer(); |
michael@0 | 126 | } |
michael@0 | 127 | |
michael@0 | 128 | // Hang-up original outgoing (now held) call |
michael@0 | 129 | function hangUpOutgoing() { |
michael@0 | 130 | log("Hanging up the original outgoing (now held) call."); |
michael@0 | 131 | |
michael@0 | 132 | let gotDisconnecting = false; |
michael@0 | 133 | outgoingCall.ondisconnecting = function ondisconnectingOut(event) { |
michael@0 | 134 | log("Received 'disconnecting' call event for original outgoing call."); |
michael@0 | 135 | is(outgoingCall, event.call); |
michael@0 | 136 | is(outgoingCall.state, "disconnecting"); |
michael@0 | 137 | gotDisconnecting = true; |
michael@0 | 138 | }; |
michael@0 | 139 | |
michael@0 | 140 | outgoingCall.ondisconnected = function ondisconnectedOut(event) { |
michael@0 | 141 | log("Received 'disconnected' call event for original outgoing call."); |
michael@0 | 142 | is(outgoingCall, event.call); |
michael@0 | 143 | is(outgoingCall.state, "disconnected"); |
michael@0 | 144 | ok(gotDisconnecting); |
michael@0 | 145 | |
michael@0 | 146 | // Back to one call now |
michael@0 | 147 | is(telephony.calls.length, 1); |
michael@0 | 148 | is(incomingCall.state, "connected"); |
michael@0 | 149 | |
michael@0 | 150 | emulator.run("gsm list", function(result) { |
michael@0 | 151 | log("Call list is now: " + result); |
michael@0 | 152 | is(result[0], "inbound from " + inNumber + " : active"); |
michael@0 | 153 | is(result[1], "OK"); |
michael@0 | 154 | hangUpIncoming(); |
michael@0 | 155 | }); |
michael@0 | 156 | }; |
michael@0 | 157 | outgoingCall.hangUp(); |
michael@0 | 158 | } |
michael@0 | 159 | |
michael@0 | 160 | // Hang-up remaining (incoming) call |
michael@0 | 161 | function hangUpIncoming() { |
michael@0 | 162 | log("Hanging up the remaining (incoming) call."); |
michael@0 | 163 | |
michael@0 | 164 | let gotDisconnecting = false; |
michael@0 | 165 | incomingCall.ondisconnecting = function ondisconnectingIn(event) { |
michael@0 | 166 | log("Received 'disconnecting' call event for remaining (incoming) call."); |
michael@0 | 167 | is(incomingCall, event.call); |
michael@0 | 168 | is(incomingCall.state, "disconnecting"); |
michael@0 | 169 | gotDisconnecting = true; |
michael@0 | 170 | }; |
michael@0 | 171 | |
michael@0 | 172 | incomingCall.ondisconnected = function ondisconnectedIn(event) { |
michael@0 | 173 | log("Received 'disconnected' call event for remaining (incoming) call."); |
michael@0 | 174 | is(incomingCall, event.call); |
michael@0 | 175 | is(incomingCall.state, "disconnected"); |
michael@0 | 176 | ok(gotDisconnecting); |
michael@0 | 177 | |
michael@0 | 178 | // Zero calls left |
michael@0 | 179 | is(telephony.active, null); |
michael@0 | 180 | is(telephony.calls.length, 0); |
michael@0 | 181 | |
michael@0 | 182 | emulator.run("gsm list", function(result) { |
michael@0 | 183 | log("Call list is now: " + result); |
michael@0 | 184 | is(result[0], "OK"); |
michael@0 | 185 | cleanUp(); |
michael@0 | 186 | }); |
michael@0 | 187 | }; |
michael@0 | 188 | incomingCall.hangUp(); |
michael@0 | 189 | } |
michael@0 | 190 | |
michael@0 | 191 | function cleanUp() { |
michael@0 | 192 | telephony.onincoming = null; |
michael@0 | 193 | finish(); |
michael@0 | 194 | } |
michael@0 | 195 | |
michael@0 | 196 | startTest(function() { |
michael@0 | 197 | dial(); |
michael@0 | 198 | }); |