1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/telephony/test/marionette/test_incoming_answer_hangup_oncallschanged.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,131 @@ 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 number = "5555552368"; 1.11 +let incoming; 1.12 + 1.13 +function simulateIncoming() { 1.14 + log("Simulating an incoming call."); 1.15 + 1.16 + telephony.oncallschanged = function oncallschanged(event) { 1.17 + log("Received 'callschanged' event."); 1.18 + 1.19 + if (!event.call) { 1.20 + log("Notifying calls array is loaded. No call information accompanies."); 1.21 + return; 1.22 + } 1.23 + 1.24 + telephony.oncallschanged = null; 1.25 + 1.26 + incoming = event.call; 1.27 + ok(incoming); 1.28 + is(incoming.number, number); 1.29 + is(incoming.state, "incoming"); 1.30 + 1.31 + is(telephony.calls.length, 1); 1.32 + is(telephony.calls[0], incoming); 1.33 + 1.34 + emulator.run("gsm list", function(result) { 1.35 + log("Call list is now: " + result); 1.36 + is(result[0], "inbound from " + number + " : incoming"); 1.37 + is(result[1], "OK"); 1.38 + answer(); 1.39 + }); 1.40 + }; 1.41 + 1.42 + emulator.run("gsm call " + number); 1.43 +} 1.44 + 1.45 +function answer() { 1.46 + log("Answering the incoming call."); 1.47 + 1.48 + let gotConnecting = false; 1.49 + incoming.onconnecting = function onconnecting(event) { 1.50 + log("Received 'connecting' call event."); 1.51 + is(incoming, event.call); 1.52 + is(incoming.state, "connecting"); 1.53 + 1.54 + // Incoming call is not 'active' until its state becomes 'connected'. 1.55 + isnot(incoming, telephony.active); 1.56 + gotConnecting = true; 1.57 + }; 1.58 + 1.59 + incoming.onconnected = function onconnected(event) { 1.60 + log("Received 'connected' call event."); 1.61 + is(incoming, event.call); 1.62 + is(incoming.state, "connected"); 1.63 + ok(gotConnecting); 1.64 + 1.65 + is(incoming, telephony.active); 1.66 + 1.67 + emulator.run("gsm list", function(result) { 1.68 + log("Call list is now: " + result); 1.69 + is(result[0], "inbound from " + number + " : active"); 1.70 + is(result[1], "OK"); 1.71 + hangUp(); 1.72 + }); 1.73 + }; 1.74 + incoming.answer(); 1.75 +} 1.76 + 1.77 +function hangUp() { 1.78 + log("Hanging up the incoming call."); 1.79 + 1.80 + // Should received 'diconnecting', 'callschanged', 'disconnected' events in 1.81 + // order. 1.82 + let gotDisconnecting = false; 1.83 + let gotCallschanged = false; 1.84 + 1.85 + incoming.ondisconnecting = function ondisconnecting(event) { 1.86 + log("Received 'disconnecting' call event."); 1.87 + is(incoming, event.call); 1.88 + is(incoming.state, "disconnecting"); 1.89 + gotDisconnecting = true; 1.90 + }; 1.91 + 1.92 + telephony.oncallschanged = function oncallschanged(event) { 1.93 + log("Received 'callschanged' event."); 1.94 + 1.95 + if (!event.call) { 1.96 + log("Notifying calls array is loaded. No call information accompanies."); 1.97 + return; 1.98 + } 1.99 + 1.100 + is(incoming, event.call); 1.101 + is(incoming.state, "disconnected"); 1.102 + is(telephony.active, null); 1.103 + is(telephony.calls.length, 0); 1.104 + gotCallschanged = true; 1.105 + }; 1.106 + 1.107 + incoming.ondisconnected = function ondisconnected(event) { 1.108 + log("Received 'disconnected' call event."); 1.109 + is(incoming, event.call); 1.110 + is(incoming.state, "disconnected"); 1.111 + ok(gotDisconnecting); 1.112 + ok(gotCallschanged); 1.113 + 1.114 + is(telephony.active, null); 1.115 + is(telephony.calls.length, 0); 1.116 + 1.117 + emulator.run("gsm list", function(result) { 1.118 + log("Call list is now: " + result); 1.119 + is(result[0], "OK"); 1.120 + cleanUp(); 1.121 + }); 1.122 + }; 1.123 + 1.124 + incoming.hangUp(); 1.125 +} 1.126 + 1.127 +function cleanUp() { 1.128 + telephony.oncallschanged = null; 1.129 + finish(); 1.130 +} 1.131 + 1.132 +startTest(function() { 1.133 + simulateIncoming(); 1.134 +});