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