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 inNumber = "5555551111"; |
michael@0 | 8 | let outNumber = "5555552222"; |
michael@0 | 9 | let incomingCall; |
michael@0 | 10 | let outgoingCall; |
michael@0 | 11 | |
michael@0 | 12 | function simulateIncoming() { |
michael@0 | 13 | log("Simulating an incoming call."); |
michael@0 | 14 | |
michael@0 | 15 | telephony.onincoming = function onincoming(event) { |
michael@0 | 16 | log("Received 'incoming' call event."); |
michael@0 | 17 | incomingCall = event.call; |
michael@0 | 18 | ok(incomingCall); |
michael@0 | 19 | is(incomingCall.number, inNumber); |
michael@0 | 20 | is(incomingCall.state, "incoming"); |
michael@0 | 21 | |
michael@0 | 22 | is(telephony.calls.length, 1); |
michael@0 | 23 | is(telephony.calls[0], incomingCall); |
michael@0 | 24 | |
michael@0 | 25 | emulator.run("gsm list", function(result) { |
michael@0 | 26 | log("Call list is now: " + result); |
michael@0 | 27 | is(result[0], "inbound from " + inNumber + " : incoming"); |
michael@0 | 28 | is(result[1], "OK"); |
michael@0 | 29 | answerIncoming(); |
michael@0 | 30 | }); |
michael@0 | 31 | }; |
michael@0 | 32 | emulator.run("gsm call " + inNumber); |
michael@0 | 33 | } |
michael@0 | 34 | |
michael@0 | 35 | function answerIncoming() { |
michael@0 | 36 | log("Answering the incoming call."); |
michael@0 | 37 | |
michael@0 | 38 | let gotConnecting = false; |
michael@0 | 39 | incomingCall.onconnecting = function onconnectingIn(event) { |
michael@0 | 40 | log("Received 'connecting' call event for original (incoming) call."); |
michael@0 | 41 | is(incomingCall, event.call); |
michael@0 | 42 | is(incomingCall.state, "connecting"); |
michael@0 | 43 | gotConnecting = true; |
michael@0 | 44 | }; |
michael@0 | 45 | |
michael@0 | 46 | incomingCall.onconnected = function onconnectedIn(event) { |
michael@0 | 47 | log("Received 'connected' call event for original (incoming) call."); |
michael@0 | 48 | is(incomingCall, event.call); |
michael@0 | 49 | is(incomingCall.state, "connected"); |
michael@0 | 50 | ok(gotConnecting); |
michael@0 | 51 | is(incomingCall, telephony.active); |
michael@0 | 52 | |
michael@0 | 53 | emulator.run("gsm list", function(result) { |
michael@0 | 54 | log("Call list is now: " + result); |
michael@0 | 55 | is(result[0], "inbound from " + inNumber + " : active"); |
michael@0 | 56 | is(result[1], "OK"); |
michael@0 | 57 | holdCall(); |
michael@0 | 58 | }); |
michael@0 | 59 | }; |
michael@0 | 60 | incomingCall.answer(); |
michael@0 | 61 | } |
michael@0 | 62 | |
michael@0 | 63 | // Put the original (incoming) call on hold |
michael@0 | 64 | function holdCall() { |
michael@0 | 65 | log("Putting the original (incoming) call on hold."); |
michael@0 | 66 | |
michael@0 | 67 | let gotHolding = false; |
michael@0 | 68 | incomingCall.onholding = function onholding(event) { |
michael@0 | 69 | log("Received 'holding' call event"); |
michael@0 | 70 | is(incomingCall, event.call); |
michael@0 | 71 | is(incomingCall.state, "holding"); |
michael@0 | 72 | gotHolding = true; |
michael@0 | 73 | }; |
michael@0 | 74 | |
michael@0 | 75 | incomingCall.onheld = function onheld(event) { |
michael@0 | 76 | log("Received 'held' call event"); |
michael@0 | 77 | is(incomingCall, event.call); |
michael@0 | 78 | is(incomingCall.state, "held"); |
michael@0 | 79 | ok(gotHolding); |
michael@0 | 80 | |
michael@0 | 81 | is(telephony.active, null); |
michael@0 | 82 | is(telephony.calls.length, 1); |
michael@0 | 83 | is(telephony.calls[0], 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], "inbound from " + inNumber + " : held"); |
michael@0 | 88 | is(result[1], "OK"); |
michael@0 | 89 | dial(); |
michael@0 | 90 | }); |
michael@0 | 91 | }; |
michael@0 | 92 | incomingCall.hold(); |
michael@0 | 93 | } |
michael@0 | 94 | |
michael@0 | 95 | // With one call on hold, make outgoing call |
michael@0 | 96 | function dial() { |
michael@0 | 97 | log("Making an outgoing call (while have one call already held)."); |
michael@0 | 98 | |
michael@0 | 99 | telephony.dial(outNumber).then(call => { |
michael@0 | 100 | outgoingCall = call; |
michael@0 | 101 | ok(outgoingCall); |
michael@0 | 102 | is(outgoingCall.number, outNumber); |
michael@0 | 103 | is(outgoingCall.state, "dialing"); |
michael@0 | 104 | is(outgoingCall, telephony.active); |
michael@0 | 105 | is(telephony.calls.length, 2); |
michael@0 | 106 | is(telephony.calls[0], incomingCall); |
michael@0 | 107 | is(telephony.calls[1], outgoingCall); |
michael@0 | 108 | |
michael@0 | 109 | outgoingCall.onalerting = function onalerting(event) { |
michael@0 | 110 | log("Received 'onalerting' call event."); |
michael@0 | 111 | is(outgoingCall, event.call); |
michael@0 | 112 | is(outgoingCall.state, "alerting"); |
michael@0 | 113 | |
michael@0 | 114 | emulator.run("gsm list", function(result) { |
michael@0 | 115 | log("Call list is now: " + result); |
michael@0 | 116 | is(result[0], "inbound from " + inNumber + " : held"); |
michael@0 | 117 | is(result[1], "outbound to " + outNumber + " : ringing"); |
michael@0 | 118 | is(result[2], "OK"); |
michael@0 | 119 | answerOutgoing(); |
michael@0 | 120 | }); |
michael@0 | 121 | }; |
michael@0 | 122 | }); |
michael@0 | 123 | } |
michael@0 | 124 | |
michael@0 | 125 | // Have the outgoing call answered |
michael@0 | 126 | function answerOutgoing() { |
michael@0 | 127 | log("Answering the outgoing/2nd call"); |
michael@0 | 128 | |
michael@0 | 129 | // We get no "connecting" event when the remote party answers the call. |
michael@0 | 130 | outgoingCall.onconnected = function onconnectedOut(event) { |
michael@0 | 131 | log("Received 'connected' call event for outgoing/2nd call."); |
michael@0 | 132 | is(outgoingCall, event.call); |
michael@0 | 133 | is(outgoingCall.state, "connected"); |
michael@0 | 134 | is(outgoingCall, telephony.active); |
michael@0 | 135 | |
michael@0 | 136 | emulator.run("gsm list", function(result) { |
michael@0 | 137 | log("Call list is now: " + result); |
michael@0 | 138 | is(result[0], "inbound from " + inNumber + " : held"); |
michael@0 | 139 | is(result[1], "outbound to " + outNumber + " : active"); |
michael@0 | 140 | is(result[2], "OK"); |
michael@0 | 141 | holdSecondCall(); |
michael@0 | 142 | }); |
michael@0 | 143 | }; |
michael@0 | 144 | emulator.run("gsm accept " + outNumber); |
michael@0 | 145 | } |
michael@0 | 146 | |
michael@0 | 147 | // With one held call and one active, hold the active one; expect the first |
michael@0 | 148 | // (held) call to automatically become active, and the 2nd call to go on hold |
michael@0 | 149 | function holdSecondCall() { |
michael@0 | 150 | let firstCallReconnected = false; |
michael@0 | 151 | let secondCallHeld = false; |
michael@0 | 152 | |
michael@0 | 153 | log("Putting the 2nd (outgoing) call on hold."); |
michael@0 | 154 | |
michael@0 | 155 | // Since first call will become connected again, setup handler |
michael@0 | 156 | incomingCall.onconnected = function onreconnected(event) { |
michael@0 | 157 | log("Received 'connected' call event for original (incoming) call."); |
michael@0 | 158 | is(incomingCall, event.call); |
michael@0 | 159 | is(incomingCall.state, "connected"); |
michael@0 | 160 | is(incomingCall, telephony.active); |
michael@0 | 161 | firstCallReconnected = true; |
michael@0 | 162 | if (firstCallReconnected && secondCallHeld) { |
michael@0 | 163 | verifyCalls(); |
michael@0 | 164 | } |
michael@0 | 165 | }; |
michael@0 | 166 | |
michael@0 | 167 | // Handlers for holding 2nd call |
michael@0 | 168 | let gotHolding = false; |
michael@0 | 169 | outgoingCall.onholding = function onholdingOut(event) { |
michael@0 | 170 | log("Received 'holding' call event for 2nd call."); |
michael@0 | 171 | is(outgoingCall, event.call); |
michael@0 | 172 | is(outgoingCall.state, "holding"); |
michael@0 | 173 | gotHolding = true; |
michael@0 | 174 | }; |
michael@0 | 175 | |
michael@0 | 176 | outgoingCall.onheld = function onheldOut(event) { |
michael@0 | 177 | log("Received 'held' call event for 2nd call."); |
michael@0 | 178 | is(outgoingCall, event.call); |
michael@0 | 179 | is(outgoingCall.state, "held"); |
michael@0 | 180 | ok(gotHolding); |
michael@0 | 181 | secondCallHeld = true; |
michael@0 | 182 | if (firstCallReconnected && secondCallHeld) { |
michael@0 | 183 | verifyCalls(); |
michael@0 | 184 | } |
michael@0 | 185 | }; |
michael@0 | 186 | outgoingCall.hold(); |
michael@0 | 187 | } |
michael@0 | 188 | |
michael@0 | 189 | function verifyCalls() { |
michael@0 | 190 | is(telephony.active, incomingCall); |
michael@0 | 191 | is(telephony.calls.length, 2); |
michael@0 | 192 | is(telephony.calls[0], incomingCall); |
michael@0 | 193 | is(telephony.calls[1], outgoingCall); |
michael@0 | 194 | |
michael@0 | 195 | emulator.run("gsm list", function(result) { |
michael@0 | 196 | log("Call list is now: " + result); |
michael@0 | 197 | is(result[0], "inbound from " + inNumber + " : active"); |
michael@0 | 198 | is(result[1], "outbound to " + outNumber + " : held"); |
michael@0 | 199 | is(result[2], "OK"); |
michael@0 | 200 | hangUpIncoming(); |
michael@0 | 201 | }); |
michael@0 | 202 | } |
michael@0 | 203 | |
michael@0 | 204 | // Hang-up the original incoming call, which is now active |
michael@0 | 205 | function hangUpIncoming() { |
michael@0 | 206 | log("Hanging up the original incoming (now active) call."); |
michael@0 | 207 | |
michael@0 | 208 | let gotDisconnecting = false; |
michael@0 | 209 | incomingCall.ondisconnecting = function ondisconnectingIn(event) { |
michael@0 | 210 | log("Received 'disconnecting' call event for original (incoming) call."); |
michael@0 | 211 | is(incomingCall, event.call); |
michael@0 | 212 | is(incomingCall.state, "disconnecting"); |
michael@0 | 213 | gotDisconnecting = true; |
michael@0 | 214 | }; |
michael@0 | 215 | |
michael@0 | 216 | incomingCall.ondisconnected = function ondisconnectedIn(event) { |
michael@0 | 217 | log("Received 'disconnected' call event for original (incoming) call."); |
michael@0 | 218 | is(incomingCall, event.call); |
michael@0 | 219 | is(incomingCall.state, "disconnected"); |
michael@0 | 220 | ok(gotDisconnecting); |
michael@0 | 221 | |
michael@0 | 222 | // Now back to one call |
michael@0 | 223 | is(telephony.active, null); |
michael@0 | 224 | is(telephony.calls.length, 1); |
michael@0 | 225 | is(telephony.calls[0], outgoingCall); |
michael@0 | 226 | |
michael@0 | 227 | emulator.run("gsm list", function(result) { |
michael@0 | 228 | log("Call list is now: " + result); |
michael@0 | 229 | is(result[0], "outbound to " + outNumber + " : held"); |
michael@0 | 230 | is(result[1], "OK"); |
michael@0 | 231 | hangUpOutgoing(); |
michael@0 | 232 | }); |
michael@0 | 233 | }; |
michael@0 | 234 | incomingCall.hangUp(); |
michael@0 | 235 | } |
michael@0 | 236 | |
michael@0 | 237 | // Hang-up the remaining (outgoing) call, which is held |
michael@0 | 238 | function hangUpOutgoing() { |
michael@0 | 239 | log("Hanging up the remaining (outgoing) held call."); |
michael@0 | 240 | |
michael@0 | 241 | let gotDisconnecting = false; |
michael@0 | 242 | outgoingCall.ondisconnecting = function ondisconnectingOut(event) { |
michael@0 | 243 | log("Received 'disconnecting' call event for remaining (outgoing) call."); |
michael@0 | 244 | is(outgoingCall, event.call); |
michael@0 | 245 | is(outgoingCall.state, "disconnecting"); |
michael@0 | 246 | gotDisconnecting = true; |
michael@0 | 247 | }; |
michael@0 | 248 | |
michael@0 | 249 | outgoingCall.ondisconnected = function ondisconnectedOut(event) { |
michael@0 | 250 | log("Received 'disconnected' call event for remaining (outgoing) call."); |
michael@0 | 251 | is(outgoingCall, event.call); |
michael@0 | 252 | is(outgoingCall.state, "disconnected"); |
michael@0 | 253 | ok(gotDisconnecting); |
michael@0 | 254 | |
michael@0 | 255 | // Now no calls |
michael@0 | 256 | is(telephony.active, null); |
michael@0 | 257 | is(telephony.calls.length, 0); |
michael@0 | 258 | |
michael@0 | 259 | emulator.run("gsm list", function(result) { |
michael@0 | 260 | log("Call list is now: " + result); |
michael@0 | 261 | is(result[0], "OK"); |
michael@0 | 262 | cleanUp(); |
michael@0 | 263 | }); |
michael@0 | 264 | }; |
michael@0 | 265 | outgoingCall.hangUp(); |
michael@0 | 266 | } |
michael@0 | 267 | |
michael@0 | 268 | function cleanUp() { |
michael@0 | 269 | telephony.onincoming = null; |
michael@0 | 270 | finish(); |
michael@0 | 271 | } |
michael@0 | 272 | |
michael@0 | 273 | startTest(function() { |
michael@0 | 274 | simulateIncoming(); |
michael@0 | 275 | }); |