1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/telephony/test/marionette/test_incoming_onstatechange.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,146 @@ 1.4 +/* Any copyright is dedicated to the Public Domain. 1.5 + * http://creativecommons.org/publicdomain/zero/1.0/ */ 1.6 + 1.7 +MARIONETTE_HEAD_JS = 'head.js'; 1.8 +MARIONETTE_TIMEOUT = 60000; 1.9 + 1.10 +let incomingCall; 1.11 +let inNumber = "5555551111"; 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 + gotConnecting = false; 1.40 + incomingCall.onstatechange = function statechangeconnect(event) { 1.41 + log("Received 'onstatechange' call event."); 1.42 + is(incomingCall, event.call); 1.43 + if(!gotConnecting){ 1.44 + is(incomingCall.state, "connecting"); 1.45 + gotConnecting = true; 1.46 + } else { 1.47 + is(incomingCall.state, "connected"); 1.48 + is(telephony.active, incomingCall); 1.49 + is(telephony.calls.length, 1); 1.50 + is(telephony.calls[0], incomingCall); 1.51 + 1.52 + emulator.run("gsm list", function(result) { 1.53 + log("Call list is now: " + result); 1.54 + is(result[0], "inbound from " + inNumber + " : active"); 1.55 + is(result[1], "OK"); 1.56 + hold(); 1.57 + }); 1.58 + } 1.59 + }; 1.60 + incomingCall.answer(); 1.61 +} 1.62 + 1.63 +function hold() { 1.64 + log("Putting the call on hold."); 1.65 + 1.66 + let gotHolding = false; 1.67 + incomingCall.onstatechange = function onstatechangehold(event) { 1.68 + log("Received 'onstatechange' call event."); 1.69 + is(incomingCall, event.call); 1.70 + if(!gotHolding){ 1.71 + is(incomingCall.state, "holding"); 1.72 + gotHolding = true; 1.73 + } else { 1.74 + is(incomingCall.state, "held"); 1.75 + is(telephony.active, null); 1.76 + is(telephony.calls.length, 1); 1.77 + is(telephony.calls[0], incomingCall); 1.78 + 1.79 + emulator.run("gsm list", function(result) { 1.80 + log("Call list is now: " + result); 1.81 + is(result[0], "inbound from " + inNumber + " : held"); 1.82 + is(result[1], "OK"); 1.83 + resume(); 1.84 + }); 1.85 + } 1.86 + }; 1.87 + incomingCall.hold(); 1.88 +} 1.89 + 1.90 +function resume() { 1.91 + log("Resuming the held call."); 1.92 + 1.93 + let gotResuming = false; 1.94 + incomingCall.onstatechange = function onstatechangeresume(event) { 1.95 + log("Received 'onstatechange' call event."); 1.96 + is(incomingCall, event.call); 1.97 + if(!gotResuming){ 1.98 + is(incomingCall.state, "resuming"); 1.99 + gotResuming = true; 1.100 + } else { 1.101 + is(incomingCall.state, "connected"); 1.102 + is(telephony.active, incomingCall); 1.103 + is(telephony.calls.length, 1); 1.104 + is(telephony.calls[0], incomingCall); 1.105 + 1.106 + emulator.run("gsm list", function(result) { 1.107 + log("Call list is now: " + result); 1.108 + is(result[0], "inbound from " + inNumber + " : active"); 1.109 + is(result[1], "OK"); 1.110 + hangUp(); 1.111 + }); 1.112 + } 1.113 + }; 1.114 + incomingCall.resume(); 1.115 +} 1.116 + 1.117 +function hangUp() { 1.118 + log("Hanging up the incoming call (local hang-up)."); 1.119 + 1.120 + let gotDisconnecting = false; 1.121 + incomingCall.onstatechange = function onstatechangedisconnect(event) { 1.122 + log("Received 'onstatechange' call event."); 1.123 + is(incomingCall, event.call); 1.124 + if(!gotDisconnecting){ 1.125 + is(incomingCall.state, "disconnecting"); 1.126 + gotDisconnecting = true; 1.127 + } else { 1.128 + is(incomingCall.state, "disconnected"); 1.129 + is(telephony.active, null); 1.130 + is(telephony.calls.length, 0); 1.131 + 1.132 + emulator.run("gsm list", function(result) { 1.133 + log("Call list is now: " + result); 1.134 + is(result[0], "OK"); 1.135 + cleanUp(); 1.136 + }); 1.137 + } 1.138 + }; 1.139 + incomingCall.hangUp(); 1.140 +} 1.141 + 1.142 +function cleanUp() { 1.143 + telephony.onincoming = null; 1.144 + finish(); 1.145 +} 1.146 + 1.147 +startTest(function() { 1.148 + simulateIncoming(); 1.149 +});