1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/telephony/test/marionette/test_outgoing_onstatechange.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,148 @@ 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 outgoingCall; 1.11 +let outNumber = "5555551111"; 1.12 + 1.13 +function dial() { 1.14 + log("Make an outgoing call."); 1.15 + 1.16 + telephony.dial(outNumber).then(call => { 1.17 + outgoingCall = call; 1.18 + ok(outgoingCall); 1.19 + is(outgoingCall.number, outNumber); 1.20 + is(outgoingCall.state, "dialing"); 1.21 + 1.22 + is(outgoingCall, telephony.active); 1.23 + is(telephony.calls.length, 1); 1.24 + is(telephony.calls[0], outgoingCall); 1.25 + 1.26 + outgoingCall.onstatechange = function statechangering(event) { 1.27 + log("Received 'onstatechange' call event."); 1.28 + 1.29 + is(outgoingCall, event.call); 1.30 + let expectedStates = ["dialing", "alerting"]; 1.31 + ok(expectedStates.indexOf(event.call.state) != -1); 1.32 + 1.33 + if (event.call.state == "alerting") { 1.34 + emulator.run("gsm list", function(result) { 1.35 + log("Call list is now: " + result); 1.36 + is(result[0], "outbound to " + outNumber + " : ringing"); 1.37 + is(result[1], "OK"); 1.38 + answer(); 1.39 + }); 1.40 + } 1.41 + }; 1.42 + }); 1.43 +} 1.44 + 1.45 +function answer() { 1.46 + log("Answering the outgoing call."); 1.47 + 1.48 + // We get no "connecting" event when the remote party answers the call. 1.49 + 1.50 + outgoingCall.onstatechange = function onstatechangeanswer(event) { 1.51 + log("Received 'onstatechange' call event."); 1.52 + is(outgoingCall, event.call); 1.53 + is(outgoingCall.state, "connected"); 1.54 + is(outgoingCall, telephony.active); 1.55 + 1.56 + emulator.run("gsm list", function(result) { 1.57 + log("Call list is now: " + result); 1.58 + is(result[0], "outbound to " + outNumber + " : active"); 1.59 + is(result[1], "OK"); 1.60 + hold(); 1.61 + }); 1.62 + }; 1.63 + emulator.run("gsm accept " + outNumber); 1.64 +} 1.65 + 1.66 +function hold() { 1.67 + log("Putting the call on hold."); 1.68 + 1.69 + let gotHolding = false; 1.70 + outgoingCall.onstatechange = function onstatechangehold(event) { 1.71 + log("Received 'onstatechange' call event."); 1.72 + is(outgoingCall, event.call); 1.73 + if(!gotHolding){ 1.74 + is(outgoingCall.state, "holding"); 1.75 + gotHolding = true; 1.76 + } else { 1.77 + is(outgoingCall.state, "held"); 1.78 + is(telephony.active, null); 1.79 + is(telephony.calls.length, 1); 1.80 + is(telephony.calls[0], outgoingCall); 1.81 + 1.82 + emulator.run("gsm list", function(result) { 1.83 + log("Call list is now: " + result); 1.84 + is(result[0], "outbound to " + outNumber + " : held"); 1.85 + is(result[1], "OK"); 1.86 + resume(); 1.87 + }); 1.88 + } 1.89 + }; 1.90 + outgoingCall.hold(); 1.91 +} 1.92 + 1.93 +function resume() { 1.94 + log("Resuming the held call."); 1.95 + 1.96 + let gotResuming = false; 1.97 + outgoingCall.onstatechange = function onstatechangeresume(event) { 1.98 + log("Received 'onstatechange' call event."); 1.99 + is(outgoingCall, event.call); 1.100 + if(!gotResuming){ 1.101 + is(outgoingCall.state, "resuming"); 1.102 + gotResuming = true; 1.103 + } else { 1.104 + is(outgoingCall.state, "connected"); 1.105 + is(telephony.active, outgoingCall); 1.106 + is(telephony.calls.length, 1); 1.107 + is(telephony.calls[0], outgoingCall); 1.108 + 1.109 + emulator.run("gsm list", function(result) { 1.110 + log("Call list is now: " + result); 1.111 + is(result[0], "outbound to " + outNumber + " : active"); 1.112 + is(result[1], "OK"); 1.113 + hangUp(); 1.114 + }); 1.115 + } 1.116 + }; 1.117 + outgoingCall.resume(); 1.118 +} 1.119 + 1.120 +function hangUp() { 1.121 + log("Hanging up the outgoing call (local hang-up)."); 1.122 + 1.123 + let gotDisconnecting = false; 1.124 + outgoingCall.onstatechange = function onstatechangedisconnect(event) { 1.125 + log("Received 'onstatechange' call event."); 1.126 + is(outgoingCall, event.call); 1.127 + if(!gotDisconnecting){ 1.128 + is(outgoingCall.state, "disconnecting"); 1.129 + gotDisconnecting = true; 1.130 + } else { 1.131 + is(outgoingCall.state, "disconnected"); 1.132 + is(telephony.active, null); 1.133 + is(telephony.calls.length, 0); 1.134 + 1.135 + emulator.run("gsm list", function(result) { 1.136 + log("Call list is now: " + result); 1.137 + is(result[0], "OK"); 1.138 + cleanUp(); 1.139 + }); 1.140 + } 1.141 + }; 1.142 + outgoingCall.hangUp(); 1.143 +} 1.144 + 1.145 +function cleanUp() { 1.146 + finish(); 1.147 +} 1.148 + 1.149 +startTest(function() { 1.150 + dial(); 1.151 +});