1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/telephony/test/marionette/test_incoming_already_connected.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,198 @@ 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 + simulateIncoming(); 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 +// With one connected call already, simulate an incoming call 1.73 +function simulateIncoming() { 1.74 + log("Simulating an incoming call (with one call already connected)."); 1.75 + 1.76 + telephony.onincoming = function onincoming(event) { 1.77 + log("Received 'incoming' call event."); 1.78 + incomingCall = event.call; 1.79 + ok(incomingCall); 1.80 + is(incomingCall.number, inNumber); 1.81 + is(incomingCall.state, "incoming"); 1.82 + 1.83 + // Should be two calls now 1.84 + is(telephony.calls.length, 2); 1.85 + is(telephony.calls[0], outgoingCall); 1.86 + is(telephony.calls[1], incomingCall); 1.87 + 1.88 + emulator.run("gsm list", function(result) { 1.89 + log("Call list is now: " + result); 1.90 + is(result[0], "outbound to " + outNumber + " : active"); 1.91 + is(result[1], "inbound from " + inNumber + " : incoming"); 1.92 + is(result[2], "OK"); 1.93 + answerIncoming(); 1.94 + }); 1.95 + }; 1.96 + emulator.run("gsm call " + inNumber); 1.97 +} 1.98 + 1.99 +// Answer incoming call; original outgoing call should be held 1.100 +function answerIncoming() { 1.101 + log("Answering the incoming call."); 1.102 + 1.103 + let gotConnecting = false; 1.104 + incomingCall.onconnecting = function onconnectingIn(event) { 1.105 + log("Received 'connecting' call event for incoming/2nd call."); 1.106 + is(incomingCall, event.call); 1.107 + is(incomingCall.state, "connecting"); 1.108 + gotConnecting = true; 1.109 + }; 1.110 + 1.111 + incomingCall.onconnected = function onconnectedIn(event) { 1.112 + log("Received 'connected' call event for incoming/2nd call."); 1.113 + is(incomingCall, event.call); 1.114 + is(incomingCall.state, "connected"); 1.115 + ok(gotConnecting); 1.116 + 1.117 + is(incomingCall, telephony.active); 1.118 + is(outgoingCall.state, "held"); 1.119 + 1.120 + emulator.run("gsm list", function(result) { 1.121 + log("Call list is now: " + result); 1.122 + is(result[0], "outbound to " + outNumber + " : held"); 1.123 + is(result[1], "inbound from " + inNumber + " : active"); 1.124 + is(result[2], "OK"); 1.125 + hangUpOutgoing(); 1.126 + }); 1.127 + }; 1.128 + incomingCall.answer(); 1.129 +} 1.130 + 1.131 +// Hang-up original outgoing (now held) call 1.132 +function hangUpOutgoing() { 1.133 + log("Hanging up the original outgoing (now held) call."); 1.134 + 1.135 + let gotDisconnecting = false; 1.136 + outgoingCall.ondisconnecting = function ondisconnectingOut(event) { 1.137 + log("Received 'disconnecting' call event for original outgoing call."); 1.138 + is(outgoingCall, event.call); 1.139 + is(outgoingCall.state, "disconnecting"); 1.140 + gotDisconnecting = true; 1.141 + }; 1.142 + 1.143 + outgoingCall.ondisconnected = function ondisconnectedOut(event) { 1.144 + log("Received 'disconnected' call event for original outgoing call."); 1.145 + is(outgoingCall, event.call); 1.146 + is(outgoingCall.state, "disconnected"); 1.147 + ok(gotDisconnecting); 1.148 + 1.149 + // Back to one call now 1.150 + is(telephony.calls.length, 1); 1.151 + is(incomingCall.state, "connected"); 1.152 + 1.153 + emulator.run("gsm list", function(result) { 1.154 + log("Call list is now: " + result); 1.155 + is(result[0], "inbound from " + inNumber + " : active"); 1.156 + is(result[1], "OK"); 1.157 + hangUpIncoming(); 1.158 + }); 1.159 + }; 1.160 + outgoingCall.hangUp(); 1.161 +} 1.162 + 1.163 +// Hang-up remaining (incoming) call 1.164 +function hangUpIncoming() { 1.165 + log("Hanging up the remaining (incoming) call."); 1.166 + 1.167 + let gotDisconnecting = false; 1.168 + incomingCall.ondisconnecting = function ondisconnectingIn(event) { 1.169 + log("Received 'disconnecting' call event for remaining (incoming) call."); 1.170 + is(incomingCall, event.call); 1.171 + is(incomingCall.state, "disconnecting"); 1.172 + gotDisconnecting = true; 1.173 + }; 1.174 + 1.175 + incomingCall.ondisconnected = function ondisconnectedIn(event) { 1.176 + log("Received 'disconnected' call event for remaining (incoming) call."); 1.177 + is(incomingCall, event.call); 1.178 + is(incomingCall.state, "disconnected"); 1.179 + ok(gotDisconnecting); 1.180 + 1.181 + // Zero calls left 1.182 + is(telephony.active, null); 1.183 + is(telephony.calls.length, 0); 1.184 + 1.185 + emulator.run("gsm list", function(result) { 1.186 + log("Call list is now: " + result); 1.187 + is(result[0], "OK"); 1.188 + cleanUp(); 1.189 + }); 1.190 + }; 1.191 + incomingCall.hangUp(); 1.192 +} 1.193 + 1.194 +function cleanUp() { 1.195 + telephony.onincoming = null; 1.196 + finish(); 1.197 +} 1.198 + 1.199 +startTest(function() { 1.200 + dial(); 1.201 +});