1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/telephony/test/marionette/test_redundant_operations.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,330 @@ 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 incomingCall; 1.12 + 1.13 +function simulateIncoming() { 1.14 + log("Simulating an incoming call."); 1.15 + 1.16 + telephony.onincoming = function onincoming(event) { 1.17 + log("Received 'incoming' call event."); 1.18 + incomingCall = event.call; 1.19 + ok(incomingCall); 1.20 + is(incomingCall.number, inNumber); 1.21 + is(incomingCall.state, "incoming"); 1.22 + 1.23 + is(telephony.calls.length, 1); 1.24 + is(telephony.calls[0], incomingCall); 1.25 + 1.26 + emulator.run("gsm list", function(result) { 1.27 + log("Call list is now: " + result); 1.28 + is(result[0], "inbound from " + inNumber + " : incoming"); 1.29 + is(result[1], "OK"); 1.30 + answerIncoming(); 1.31 + }); 1.32 + }; 1.33 + emulator.run("gsm call " + inNumber); 1.34 +} 1.35 + 1.36 +function answerIncoming() { 1.37 + log("Answering the incoming call."); 1.38 + 1.39 + let gotConnecting = false; 1.40 + incomingCall.onconnecting = function onconnectingIn(event) { 1.41 + log("Received 'connecting' call event for incoming call."); 1.42 + is(incomingCall, event.call); 1.43 + is(incomingCall.state, "connecting"); 1.44 + gotConnecting = true; 1.45 + }; 1.46 + 1.47 + incomingCall.onconnected = function onconnectedIn(event) { 1.48 + log("Received 'connected' call event for incoming call."); 1.49 + is(incomingCall, event.call); 1.50 + is(incomingCall.state, "connected"); 1.51 + ok(gotConnecting); 1.52 + 1.53 + is(incomingCall, telephony.active); 1.54 + 1.55 + emulator.run("gsm list", function(result) { 1.56 + log("Call list is now: " + result); 1.57 + is(result[0], "inbound from " + inNumber + " : active"); 1.58 + is(result[1], "OK"); 1.59 + answerAlreadyConnected(); 1.60 + }); 1.61 + }; 1.62 + incomingCall.answer(); 1.63 +} 1.64 + 1.65 +function answerAlreadyConnected() { 1.66 + log("Attempting to answer already connected call, should be ignored."); 1.67 + 1.68 + incomingCall.onconnecting = function onconnectingErr(event) { 1.69 + log("Received 'connecting' call event, but should not have."); 1.70 + ok(false, "Received 'connecting' event when answered already active call"); 1.71 + }; 1.72 + 1.73 + incomingCall.onconnected = function onconnectedErr(event) { 1.74 + log("Received 'connected' call event, but should not have."); 1.75 + ok(false, "Received 'connected' event when answered already active call"); 1.76 + }; 1.77 + 1.78 + incomingCall.answer(); 1.79 + 1.80 + is(incomingCall.state, "connected"); 1.81 + is(telephony.calls.length, 1); 1.82 + is(telephony.calls[0], incomingCall); 1.83 + is(incomingCall, telephony.active); 1.84 + hold(); 1.85 +} 1.86 + 1.87 +function hold() { 1.88 + log("Putting the call on hold."); 1.89 + 1.90 + let gotHolding = false; 1.91 + incomingCall.onholding = function onholding(event) { 1.92 + log("Received 'holding' call event."); 1.93 + is(incomingCall, event.call); 1.94 + is(incomingCall.state, "holding"); 1.95 + gotHolding = true; 1.96 + }; 1.97 + 1.98 + incomingCall.onheld = function onheld(event) { 1.99 + log("Received 'held' call event."); 1.100 + is(incomingCall, event.call); 1.101 + is(incomingCall.state, "held"); 1.102 + ok(gotHolding); 1.103 + 1.104 + is(telephony.active, null); 1.105 + is(telephony.calls.length, 1); 1.106 + is(telephony.calls[0], incomingCall); 1.107 + 1.108 + emulator.run("gsm list", function(result) { 1.109 + log("Call list is now: " + result); 1.110 + is(result[0], "inbound from " + inNumber + " : held"); 1.111 + is(result[1], "OK"); 1.112 + holdAlreadyHeld(); 1.113 + }); 1.114 + }; 1.115 + incomingCall.hold(); 1.116 +} 1.117 + 1.118 +function holdAlreadyHeld() { 1.119 + log("Attempting to hold an already held call, should be ignored."); 1.120 + 1.121 + incomingCall.onholding = function onholding(event) { 1.122 + log("Received 'holding' call event, but should not have."); 1.123 + ok(false, "Received 'holding' event when held an already held call"); 1.124 + }; 1.125 + 1.126 + incomingCall.onheld = function onheldErr(event) { 1.127 + log("Received 'held' call event, but should not have."); 1.128 + ok(false, "Received 'held' event when held an already held call"); 1.129 + }; 1.130 + 1.131 + incomingCall.hold(); 1.132 + 1.133 + is(incomingCall.state, "held"); 1.134 + is(telephony.active, null); 1.135 + is(telephony.calls.length, 1); 1.136 + is(telephony.calls[0], incomingCall); 1.137 + 1.138 + answerHeld(); 1.139 +} 1.140 + 1.141 +function answerHeld() { 1.142 + log("Attempting to answer a held call, should be ignored."); 1.143 + 1.144 + incomingCall.onconnecting = function onconnectingErr(event) { 1.145 + log("Received 'connecting' call event, but should not have."); 1.146 + ok(false, "Received 'connecting' event when answered a held call"); 1.147 + }; 1.148 + 1.149 + incomingCall.onconnected = function onconnectedErr(event) { 1.150 + log("Received 'connected' call event, but should not have."); 1.151 + ok(false, "Received 'connected' event when answered a held call"); 1.152 + }; 1.153 + 1.154 + incomingCall.answer(); 1.155 + 1.156 + is(incomingCall.state, "held"); 1.157 + is(telephony.active, null); 1.158 + is(telephony.calls.length, 1); 1.159 + is(telephony.calls[0], incomingCall); 1.160 + 1.161 + resume(); 1.162 +} 1.163 + 1.164 +function resume() { 1.165 + log("Resuming the held call."); 1.166 + 1.167 + let gotResuming = false; 1.168 + incomingCall.onresuming = function onresuming(event) { 1.169 + log("Received 'resuming' call event."); 1.170 + is(incomingCall, event.call); 1.171 + is(incomingCall.state, "resuming"); 1.172 + gotResuming = true; 1.173 + }; 1.174 + 1.175 + incomingCall.onconnected = function onconnected(event) { 1.176 + log("Received 'connected' call event."); 1.177 + is(incomingCall, event.call); 1.178 + is(incomingCall.state, "connected"); 1.179 + ok(gotResuming); 1.180 + 1.181 + is(incomingCall, telephony.active); 1.182 + is(telephony.calls.length, 1); 1.183 + is(telephony.calls[0], incomingCall); 1.184 + 1.185 + emulator.run("gsm list", function(result) { 1.186 + log("Call list is now: " + result); 1.187 + is(result[0], "inbound from " + inNumber + " : active"); 1.188 + is(result[1], "OK"); 1.189 + resumeNonHeld(); 1.190 + }); 1.191 + }; 1.192 + incomingCall.resume(); 1.193 +} 1.194 + 1.195 +function resumeNonHeld() { 1.196 + log("Attempting to resume non-held call, should be ignored."); 1.197 + 1.198 + incomingCall.onresuming = function onresumingErr(event) { 1.199 + log("Received 'resuming' call event, but should not have."); 1.200 + ok(false, "Received 'resuming' event when resumed non-held call"); 1.201 + }; 1.202 + 1.203 + incomingCall.onconnected = function onconnectedErr(event) { 1.204 + log("Received 'connected' call event, but should not have."); 1.205 + ok(false, "Received 'connected' event when resumed non-held call"); 1.206 + }; 1.207 + 1.208 + incomingCall.resume(); 1.209 + 1.210 + is(incomingCall.state, "connected"); 1.211 + is(telephony.calls.length, 1); 1.212 + is(telephony.calls[0], incomingCall); 1.213 + is(incomingCall, telephony.active); 1.214 + hangUp(); 1.215 +} 1.216 + 1.217 +function hangUp() { 1.218 + log("Hanging up the call (local hang-up)."); 1.219 + 1.220 + let gotDisconnecting = false; 1.221 + incomingCall.ondisconnecting = function ondisconnecting(event) { 1.222 + log("Received 'disconnecting' call event."); 1.223 + is(incomingCall, event.call); 1.224 + is(incomingCall.state, "disconnecting"); 1.225 + gotDisconnecting = true; 1.226 + }; 1.227 + 1.228 + incomingCall.ondisconnected = function ondisconnectedOut(event) { 1.229 + log("Received 'disconnected' call event."); 1.230 + is(incomingCall, event.call); 1.231 + is(incomingCall.state, "disconnected"); 1.232 + ok(gotDisconnecting); 1.233 + 1.234 + is(telephony.active, null); 1.235 + is(telephony.calls.length, 0); 1.236 + 1.237 + emulator.run("gsm list", function(result) { 1.238 + log("Call list is now: " + result); 1.239 + is(result[0], "OK"); 1.240 + answerDisconnected(); 1.241 + }); 1.242 + }; 1.243 + incomingCall.hangUp(); 1.244 +} 1.245 + 1.246 +function answerDisconnected() { 1.247 + log("Attempting to answer disconnected call, should be ignored."); 1.248 + 1.249 + incomingCall.onconnecting = function onconnectingErr(event) { 1.250 + log("Received 'connecting' call event, but should not have."); 1.251 + ok(false, "Received 'connecting' event when answered disconnected call"); 1.252 + }; 1.253 + 1.254 + incomingCall.onconnected = function onconnectedErr(event) { 1.255 + log("Received 'connected' call event, but should not have."); 1.256 + ok(false, "Received 'connected' event when answered disconnected call"); 1.257 + }; 1.258 + 1.259 + incomingCall.answer(); 1.260 + 1.261 + is(telephony.active, null); 1.262 + is(telephony.calls.length, 0); 1.263 + holdDisconnected(); 1.264 +} 1.265 + 1.266 +function holdDisconnected() { 1.267 + log("Attempting to hold disconnected call, should be ignored."); 1.268 + 1.269 + incomingCall.onholding = function onholdingErr(event) { 1.270 + log("Received 'holding' call event, but should not have."); 1.271 + ok(false, "Received 'holding' event when held a disconnected call"); 1.272 + }; 1.273 + 1.274 + incomingCall.onheld = function onheldErr(event) { 1.275 + log("Received 'held' call event, but should not have."); 1.276 + ok(false, "Received 'held' event when held a disconnected call"); 1.277 + }; 1.278 + 1.279 + incomingCall.hold(); 1.280 + 1.281 + is(telephony.active, null); 1.282 + is(telephony.calls.length, 0); 1.283 + resumeDisconnected(); 1.284 +} 1.285 + 1.286 +function resumeDisconnected() { 1.287 + log("Attempting to resume disconnected call, should be ignored."); 1.288 + 1.289 + incomingCall.onresuming = function onresumingErr(event) { 1.290 + log("Received 'resuming' call event, but should not have."); 1.291 + ok(false, "Received 'resuming' event when resumed disconnected call"); 1.292 + }; 1.293 + 1.294 + incomingCall.onconnected = function onconnectedErr(event) { 1.295 + log("Received 'connected' call event, but should not have."); 1.296 + ok(false, "Received 'connected' event when resumed disconnected call"); 1.297 + }; 1.298 + 1.299 + incomingCall.resume(); 1.300 + 1.301 + is(telephony.active, null); 1.302 + is(telephony.calls.length, 0); 1.303 + hangUpNonConnected(); 1.304 +} 1.305 + 1.306 +function hangUpNonConnected() { 1.307 + log("Attempting to hang-up disconnected call, should be ignored."); 1.308 + 1.309 + incomingCall.ondisconnecting = function ondisconnectingErr(event) { 1.310 + log("Received 'disconnecting' call event, but should not have."); 1.311 + ok(false, "Received 'disconnecting' event when hung-up non-active call"); 1.312 + }; 1.313 + 1.314 + incomingCall.ondisconnected = function ondisconnectedErr(event) { 1.315 + log("Received 'disconnected' call event, but should not have."); 1.316 + ok(false, "Received 'disconnected' event when hung-up non-active call"); 1.317 + }; 1.318 + 1.319 + incomingCall.hangUp(); 1.320 + 1.321 + is(telephony.active, null); 1.322 + is(telephony.calls.length, 0); 1.323 + cleanUp(); 1.324 +} 1.325 + 1.326 +function cleanUp() { 1.327 + telephony.onincoming = null; 1.328 + finish(); 1.329 +} 1.330 + 1.331 +startTest(function() { 1.332 + simulateIncoming(); 1.333 +});