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 | holdCall(); |
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 | function holdCall() { |
michael@0 | 70 | log("Putting the original (outgoing) call on hold."); |
michael@0 | 71 | |
michael@0 | 72 | let gotHolding = false; |
michael@0 | 73 | outgoingCall.onholding = function onholding(event) { |
michael@0 | 74 | log("Received 'holding' call event"); |
michael@0 | 75 | is(outgoingCall, event.call); |
michael@0 | 76 | is(outgoingCall.state, "holding"); |
michael@0 | 77 | gotHolding = true; |
michael@0 | 78 | }; |
michael@0 | 79 | |
michael@0 | 80 | outgoingCall.onheld = function onheld(event) { |
michael@0 | 81 | log("Received 'held' call event"); |
michael@0 | 82 | is(outgoingCall, event.call); |
michael@0 | 83 | is(outgoingCall.state, "held"); |
michael@0 | 84 | ok(gotHolding); |
michael@0 | 85 | |
michael@0 | 86 | is(telephony.active, null); |
michael@0 | 87 | is(telephony.calls.length, 1); |
michael@0 | 88 | is(telephony.calls[0], outgoingCall); |
michael@0 | 89 | |
michael@0 | 90 | emulator.run("gsm list", function(result) { |
michael@0 | 91 | log("Call list is now: " + result); |
michael@0 | 92 | is(result[0], "outbound to " + outNumber + " : held"); |
michael@0 | 93 | is(result[1], "OK"); |
michael@0 | 94 | simulateIncoming(); |
michael@0 | 95 | }); |
michael@0 | 96 | }; |
michael@0 | 97 | outgoingCall.hold(); |
michael@0 | 98 | } |
michael@0 | 99 | |
michael@0 | 100 | // With one call on hold, simulate an incoming call |
michael@0 | 101 | function simulateIncoming() { |
michael@0 | 102 | log("Simulating an incoming call (with one call already held)."); |
michael@0 | 103 | |
michael@0 | 104 | telephony.onincoming = function onincoming(event) { |
michael@0 | 105 | log("Received 'incoming' call event."); |
michael@0 | 106 | incomingCall = event.call; |
michael@0 | 107 | ok(incomingCall); |
michael@0 | 108 | is(incomingCall.number, inNumber); |
michael@0 | 109 | is(incomingCall.state, "incoming"); |
michael@0 | 110 | |
michael@0 | 111 | // Should be two calls now |
michael@0 | 112 | is(telephony.calls.length, 2); |
michael@0 | 113 | is(telephony.calls[0], outgoingCall); |
michael@0 | 114 | is(telephony.calls[1], incomingCall); |
michael@0 | 115 | |
michael@0 | 116 | emulator.run("gsm list", function(result) { |
michael@0 | 117 | log("Call list is now: " + result); |
michael@0 | 118 | is(result[0], "outbound to " + outNumber + " : held"); |
michael@0 | 119 | is(result[1], "inbound from " + inNumber + " : incoming"); |
michael@0 | 120 | is(result[2], "OK"); |
michael@0 | 121 | answerIncoming(); |
michael@0 | 122 | }); |
michael@0 | 123 | }; |
michael@0 | 124 | emulator.run("gsm call " + inNumber); |
michael@0 | 125 | } |
michael@0 | 126 | |
michael@0 | 127 | // Answer incoming call; original outgoing call should be held |
michael@0 | 128 | function answerIncoming() { |
michael@0 | 129 | log("Answering the incoming call."); |
michael@0 | 130 | |
michael@0 | 131 | let gotConnecting = false; |
michael@0 | 132 | incomingCall.onconnecting = function onconnectingIn(event) { |
michael@0 | 133 | log("Received 'connecting' call event for incoming/2nd call."); |
michael@0 | 134 | is(incomingCall, event.call); |
michael@0 | 135 | is(incomingCall.state, "connecting"); |
michael@0 | 136 | gotConnecting = true; |
michael@0 | 137 | }; |
michael@0 | 138 | |
michael@0 | 139 | incomingCall.onconnected = function onconnectedIn(event) { |
michael@0 | 140 | log("Received 'connected' call event for incoming/2nd call."); |
michael@0 | 141 | is(incomingCall, event.call); |
michael@0 | 142 | is(incomingCall.state, "connected"); |
michael@0 | 143 | ok(gotConnecting); |
michael@0 | 144 | |
michael@0 | 145 | is(incomingCall, telephony.active); |
michael@0 | 146 | is(outgoingCall.state, "held"); |
michael@0 | 147 | |
michael@0 | 148 | emulator.run("gsm list", function(result) { |
michael@0 | 149 | log("Call list is now: " + result); |
michael@0 | 150 | is(result[0], "outbound to " + outNumber + " : held"); |
michael@0 | 151 | is(result[1], "inbound from " + inNumber + " : active"); |
michael@0 | 152 | is(result[2], "OK"); |
michael@0 | 153 | hangUpOutgoing(); |
michael@0 | 154 | }); |
michael@0 | 155 | }; |
michael@0 | 156 | incomingCall.answer(); |
michael@0 | 157 | } |
michael@0 | 158 | |
michael@0 | 159 | // Hang-up original outgoing (now held) call |
michael@0 | 160 | function hangUpOutgoing() { |
michael@0 | 161 | log("Hanging up the original outgoing (now held) call."); |
michael@0 | 162 | |
michael@0 | 163 | let gotDisconnecting = false; |
michael@0 | 164 | outgoingCall.ondisconnecting = function ondisconnectingOut(event) { |
michael@0 | 165 | log("Received 'disconnecting' call event for original outgoing call."); |
michael@0 | 166 | is(outgoingCall, event.call); |
michael@0 | 167 | is(outgoingCall.state, "disconnecting"); |
michael@0 | 168 | gotDisconnecting = true; |
michael@0 | 169 | }; |
michael@0 | 170 | |
michael@0 | 171 | outgoingCall.ondisconnected = function ondisconnectedOut(event) { |
michael@0 | 172 | log("Received 'disconnected' call event for original outgoing call."); |
michael@0 | 173 | is(outgoingCall, event.call); |
michael@0 | 174 | is(outgoingCall.state, "disconnected"); |
michael@0 | 175 | ok(gotDisconnecting); |
michael@0 | 176 | |
michael@0 | 177 | // Back to one call now |
michael@0 | 178 | is(telephony.calls.length, 1); |
michael@0 | 179 | is(incomingCall.state, "connected"); |
michael@0 | 180 | |
michael@0 | 181 | emulator.run("gsm list", function(result) { |
michael@0 | 182 | log("Call list is now: " + result); |
michael@0 | 183 | is(result[0], "inbound from " + inNumber + " : active"); |
michael@0 | 184 | is(result[1], "OK"); |
michael@0 | 185 | hangUpIncoming(); |
michael@0 | 186 | }); |
michael@0 | 187 | }; |
michael@0 | 188 | outgoingCall.hangUp(); |
michael@0 | 189 | } |
michael@0 | 190 | |
michael@0 | 191 | // Hang-up remaining (incoming) call |
michael@0 | 192 | function hangUpIncoming() { |
michael@0 | 193 | log("Hanging up the remaining (incoming) call."); |
michael@0 | 194 | |
michael@0 | 195 | let gotDisconnecting = false; |
michael@0 | 196 | incomingCall.ondisconnecting = function ondisconnectingIn(event) { |
michael@0 | 197 | log("Received 'disconnecting' call event for remaining (incoming) call."); |
michael@0 | 198 | is(incomingCall, event.call); |
michael@0 | 199 | is(incomingCall.state, "disconnecting"); |
michael@0 | 200 | gotDisconnecting = true; |
michael@0 | 201 | }; |
michael@0 | 202 | |
michael@0 | 203 | incomingCall.ondisconnected = function ondisconnectedIn(event) { |
michael@0 | 204 | log("Received 'disconnected' call event for remaining (incoming) call."); |
michael@0 | 205 | is(incomingCall, event.call); |
michael@0 | 206 | is(incomingCall.state, "disconnected"); |
michael@0 | 207 | ok(gotDisconnecting); |
michael@0 | 208 | |
michael@0 | 209 | // Zero calls left |
michael@0 | 210 | is(telephony.active, null); |
michael@0 | 211 | is(telephony.calls.length, 0); |
michael@0 | 212 | |
michael@0 | 213 | emulator.run("gsm list", function(result) { |
michael@0 | 214 | log("Call list is now: " + result); |
michael@0 | 215 | is(result[0], "OK"); |
michael@0 | 216 | cleanUp(); |
michael@0 | 217 | }); |
michael@0 | 218 | }; |
michael@0 | 219 | incomingCall.hangUp(); |
michael@0 | 220 | } |
michael@0 | 221 | |
michael@0 | 222 | function cleanUp() { |
michael@0 | 223 | telephony.onincoming = null; |
michael@0 | 224 | finish(); |
michael@0 | 225 | } |
michael@0 | 226 | |
michael@0 | 227 | startTest(function() { |
michael@0 | 228 | dial(); |
michael@0 | 229 | }); |