1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/telephony/test/marionette/test_outgoing_already_held.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,245 @@ 1.4 +/* Any copyright is dedicated to the Public Domain. 1.5 + * http://creativecommons.org/publicdomain/zero/1.0/ */ 1.6 + 1.7 +MARIONETTE_TIMEOUT = 60000; 1.8 +MARIONETTE_HEAD_JS = 'head.js'; 1.9 + 1.10 +let inNumber = "5555551111"; 1.11 +let outNumber = "5555552222"; 1.12 +let incomingCall; 1.13 +let outgoingCall; 1.14 + 1.15 +function simulateIncoming() { 1.16 + log("Simulating an incoming call."); 1.17 + 1.18 + telephony.onincoming = function onincoming(event) { 1.19 + log("Received 'incoming' call event."); 1.20 + incomingCall = event.call; 1.21 + ok(incomingCall); 1.22 + is(incomingCall.number, inNumber); 1.23 + is(incomingCall.state, "incoming"); 1.24 + 1.25 + is(telephony.calls.length, 1); 1.26 + is(telephony.calls[0], incomingCall); 1.27 + 1.28 + // Wait for emulator to catch up before continuing 1.29 + waitFor(verifyCallList,function() { 1.30 + return(rcvdEmulatorCallback); 1.31 + }); 1.32 + }; 1.33 + 1.34 + let rcvdEmulatorCallback = false; 1.35 + emulator.run("gsm call " + inNumber, function(result) { 1.36 + is(result[0], "OK", "emulator callback"); 1.37 + rcvdEmulatorCallback = true; 1.38 + }); 1.39 +} 1.40 + 1.41 +function verifyCallList(){ 1.42 + emulator.run("gsm list", function(result) { 1.43 + log("Call list is now: " + result); 1.44 + is(result[0], "inbound from " + inNumber + " : incoming"); 1.45 + is(result[1], "OK"); 1.46 + answerIncoming(); 1.47 + }); 1.48 +} 1.49 + 1.50 +function answerIncoming() { 1.51 + log("Answering the incoming call."); 1.52 + 1.53 + let gotConnecting = false; 1.54 + incomingCall.onconnecting = function onconnectingIn(event) { 1.55 + log("Received 'connecting' call event for original (incoming) call."); 1.56 + is(incomingCall, event.call); 1.57 + is(incomingCall.state, "connecting"); 1.58 + gotConnecting = true; 1.59 + }; 1.60 + 1.61 + incomingCall.onconnected = function onconnectedIn(event) { 1.62 + log("Received 'connected' call event for original (incoming) call."); 1.63 + is(incomingCall, event.call); 1.64 + is(incomingCall.state, "connected"); 1.65 + ok(gotConnecting); 1.66 + 1.67 + is(incomingCall, telephony.active); 1.68 + 1.69 + emulator.run("gsm list", function(result) { 1.70 + log("Call list is now: " + result); 1.71 + is(result[0], "inbound from " + inNumber + " : active"); 1.72 + is(result[1], "OK"); 1.73 + holdCall(); 1.74 + }); 1.75 + }; 1.76 + incomingCall.answer(); 1.77 +} 1.78 + 1.79 +// Put the original (incoming) call on hold 1.80 +function holdCall(){ 1.81 + log("Putting the original (incoming) call on hold."); 1.82 + 1.83 + let gotHolding = false; 1.84 + incomingCall.onholding = function onholding(event) { 1.85 + log("Received 'holding' call event"); 1.86 + is(incomingCall, event.call); 1.87 + is(incomingCall.state, "holding"); 1.88 + gotHolding = true; 1.89 + }; 1.90 + 1.91 + incomingCall.onheld = function onheld(event) { 1.92 + log("Received 'held' call event"); 1.93 + is(incomingCall, event.call); 1.94 + is(incomingCall.state, "held"); 1.95 + ok(gotHolding); 1.96 + 1.97 + is(telephony.active, null); 1.98 + is(telephony.calls.length, 1); 1.99 + is(telephony.calls[0], incomingCall); 1.100 + 1.101 + emulator.run("gsm list", function(result) { 1.102 + log("Call list is now: " + result); 1.103 + is(result[0], "inbound from " + inNumber + " : held"); 1.104 + is(result[1], "OK"); 1.105 + dial(); 1.106 + }); 1.107 + }; 1.108 + incomingCall.hold(); 1.109 +} 1.110 + 1.111 +// With one call on hold, make outgoing call 1.112 +function dial() { 1.113 + log("Making an outgoing call (while have one call already held)."); 1.114 + 1.115 + telephony.dial(outNumber).then(call => { 1.116 + outgoingCall = call; 1.117 + ok(outgoingCall); 1.118 + is(outgoingCall.number, outNumber); 1.119 + is(outgoingCall.state, "dialing"); 1.120 + 1.121 + is(outgoingCall, telephony.active); 1.122 + is(telephony.calls.length, 2); 1.123 + is(telephony.calls[0], incomingCall); 1.124 + is(telephony.calls[1], outgoingCall); 1.125 + 1.126 + outgoingCall.onalerting = function onalerting(event) { 1.127 + log("Received 'onalerting' call event."); 1.128 + is(outgoingCall, event.call); 1.129 + is(outgoingCall.state, "alerting"); 1.130 + 1.131 + emulator.run("gsm list", function(result) { 1.132 + log("Call list is now: " + result); 1.133 + is(result[0], "inbound from " + inNumber + " : held"); 1.134 + is(result[1], "outbound to " + outNumber + " : ringing"); 1.135 + is(result[2], "OK"); 1.136 + answerOutgoing(); 1.137 + }); 1.138 + }; 1.139 + }); 1.140 +} 1.141 + 1.142 +// Have the outgoing call answered 1.143 +function answerOutgoing() { 1.144 + log("Answering the outgoing/2nd call"); 1.145 + 1.146 + // We get no "connecting" event when the remote party answers the call. 1.147 + outgoingCall.onconnected = function onconnectedOut(event) { 1.148 + log("Received 'connected' call event for outgoing/2nd call."); 1.149 + is(outgoingCall, event.call); 1.150 + is(outgoingCall.state, "connected"); 1.151 + 1.152 + is(outgoingCall, telephony.active); 1.153 + 1.154 + // Wait for emulator to catch up before continuing 1.155 + waitFor(checkCallList,function() { 1.156 + return(rcvdEmulatorCallback); 1.157 + }); 1.158 + }; 1.159 + 1.160 + let rcvdEmulatorCallback = false; 1.161 + emulator.run("gsm accept " + outNumber, function(result) { 1.162 + is(result[0], "OK", "emulator callback"); 1.163 + rcvdEmulatorCallback = true; 1.164 + }); 1.165 +} 1.166 + 1.167 +function checkCallList(){ 1.168 + emulator.run("gsm list", function(result) { 1.169 + log("Call list is now: " + result); 1.170 + is(result[0], "inbound from " + inNumber + " : held"); 1.171 + is(result[1], "outbound to " + outNumber + " : active"); 1.172 + is(result[2], "OK"); 1.173 + hangUpIncoming(); 1.174 + }); 1.175 +} 1.176 + 1.177 +// Hang-up the original incoming call, which is now held 1.178 +function hangUpIncoming() { 1.179 + log("Hanging up the original incoming (now held) call."); 1.180 + 1.181 + let gotDisconnecting = false; 1.182 + incomingCall.ondisconnecting = function ondisconnectingIn(event) { 1.183 + log("Received 'disconnecting' call event for original (incoming) call."); 1.184 + is(incomingCall, event.call); 1.185 + is(incomingCall.state, "disconnecting"); 1.186 + gotDisconnecting = true; 1.187 + }; 1.188 + 1.189 + incomingCall.ondisconnected = function ondisconnectedIn(event) { 1.190 + log("Received 'disconnected' call event for original (incoming) call."); 1.191 + is(incomingCall, event.call); 1.192 + is(incomingCall.state, "disconnected"); 1.193 + ok(gotDisconnecting); 1.194 + 1.195 + // Now back to one call 1.196 + is(telephony.active, outgoingCall); 1.197 + is(telephony.calls.length, 1); 1.198 + is(telephony.calls[0], outgoingCall); 1.199 + 1.200 + emulator.run("gsm list", function(result) { 1.201 + log("Call list is now: " + result); 1.202 + is(result[0], "outbound to " + outNumber + " : active"); 1.203 + is(result[1], "OK"); 1.204 + hangUpOutgoing(); 1.205 + }); 1.206 + }; 1.207 + incomingCall.hangUp(); 1.208 +} 1.209 + 1.210 +// Hang-up the remaining (outgoing) call 1.211 +function hangUpOutgoing() { 1.212 + log("Hanging up the remaining (outgoing) call."); 1.213 + 1.214 + let gotDisconnecting = false; 1.215 + outgoingCall.ondisconnecting = function ondisconnectingOut(event) { 1.216 + log("Received 'disconnecting' call event for remaining (outgoing) call."); 1.217 + is(outgoingCall, event.call); 1.218 + is(outgoingCall.state, "disconnecting"); 1.219 + gotDisconnecting = true; 1.220 + }; 1.221 + 1.222 + outgoingCall.ondisconnected = function ondisconnectedOut(event) { 1.223 + log("Received 'disconnected' call event for remaining (outgoing) call."); 1.224 + is(outgoingCall, event.call); 1.225 + is(outgoingCall.state, "disconnected"); 1.226 + ok(gotDisconnecting); 1.227 + 1.228 + // Now no calls 1.229 + is(telephony.active, null); 1.230 + is(telephony.calls.length, 0); 1.231 + 1.232 + emulator.run("gsm list", function(result) { 1.233 + log("Call list is now: " + result); 1.234 + is(result[0], "OK"); 1.235 + cleanUp(); 1.236 + }); 1.237 + }; 1.238 + outgoingCall.hangUp(); 1.239 +} 1.240 + 1.241 +function cleanUp() { 1.242 + telephony.onincoming = null; 1.243 + finish(); 1.244 +} 1.245 + 1.246 +startTest(function() { 1.247 + simulateIncoming(); 1.248 +});