1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/telephony/test/marionette/test_outgoing_answer_hangup_oncallschanged.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,94 @@ 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 outgoing; 1.12 + 1.13 +function dial() { 1.14 + log("Make an outgoing call."); 1.15 + 1.16 + telephony.oncallschanged = function oncallschanged(event) { 1.17 + log("Received 'callschanged' call 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 + let expected_states = ["dialing", "disconnected"]; 1.25 + ok(expected_states.indexOf(event.call.state) != -1, 1.26 + "Unexpected call state: " + event.call.state); 1.27 + 1.28 + if (event.call.state == "dialing") { 1.29 + outgoing = event.call; 1.30 + ok(outgoing); 1.31 + is(outgoing.number, number); 1.32 + 1.33 + is(outgoing, telephony.active); 1.34 + is(telephony.calls.length, 1); 1.35 + is(telephony.calls[0], outgoing); 1.36 + 1.37 + checkCallList(); 1.38 + } 1.39 + 1.40 + if (event.call.state == "disconnected") { 1.41 + is(outgoing.state, "disconnected"); 1.42 + is(telephony.active, null); 1.43 + is(telephony.calls.length, 0); 1.44 + cleanUp(); 1.45 + } 1.46 + }; 1.47 + 1.48 + telephony.dial(number); 1.49 +} 1.50 + 1.51 +function checkCallList() { 1.52 + emulator.run("gsm list", function(result) { 1.53 + log("Call list is now: " + result); 1.54 + if ((result[0] == "outbound to " + number + " : unknown") && (result[1] == "OK")) { 1.55 + answer(); 1.56 + } else { 1.57 + window.setTimeout(checkCallList, 100); 1.58 + } 1.59 + }); 1.60 +} 1.61 + 1.62 +function answer() { 1.63 + log("Answering the outgoing call."); 1.64 + 1.65 + // We get no "connecting" event when the remote party answers the call. 1.66 + 1.67 + outgoing.onconnected = function onconnected(event) { 1.68 + log("Received 'connected' call event."); 1.69 + is(outgoing, event.call); 1.70 + is(outgoing.state, "connected"); 1.71 + 1.72 + is(outgoing, telephony.active); 1.73 + 1.74 + emulator.run("gsm list", function(result) { 1.75 + log("Call list (after 'connected' event) is now: " + result); 1.76 + is(result[0], "outbound to " + number + " : active"); 1.77 + is(result[1], "OK"); 1.78 + hangUp(); 1.79 + }); 1.80 + }; 1.81 + emulator.run("gsm accept " + number); 1.82 +} 1.83 + 1.84 +function hangUp() { 1.85 + log("Hanging up the outgoing call."); 1.86 + 1.87 + emulator.run("gsm cancel " + number); 1.88 +} 1.89 + 1.90 +function cleanUp() { 1.91 + telephony.oncallschanged = null; 1.92 + finish(); 1.93 +} 1.94 + 1.95 +startTest(function() { 1.96 + dial(); 1.97 +});