1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/telephony/test/marionette/test_outgoing_emergency_in_airplane_mode.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,120 @@ 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 connection; 1.11 +let number = "112"; 1.12 +let outgoing; 1.13 + 1.14 +function setRadioEnabled(enabled, callback) { 1.15 + let request = connection.setRadioEnabled(enabled); 1.16 + let desiredRadioState = enabled ? 'enabled' : 'disabled'; 1.17 + 1.18 + let pending = ['onradiostatechange', 'onsuccess']; 1.19 + let done = callback; 1.20 + 1.21 + connection.onradiostatechange = function() { 1.22 + let state = connection.radioState; 1.23 + log("Received 'radiostatechange' event, radioState: " + state); 1.24 + 1.25 + if (state == desiredRadioState) { 1.26 + gReceivedPending('onradiostatechange', pending, done); 1.27 + } 1.28 + }; 1.29 + 1.30 + request.onsuccess = function onsuccess() { 1.31 + gReceivedPending('onsuccess', pending, done); 1.32 + }; 1.33 + 1.34 + request.onerror = function onerror() { 1.35 + ok(false, "setRadioEnabled should be ok"); 1.36 + }; 1.37 +} 1.38 + 1.39 +function dial() { 1.40 + log("Make an outgoing call."); 1.41 + 1.42 + telephony.dial(number).then(call => { 1.43 + outgoing = call; 1.44 + ok(outgoing); 1.45 + is(outgoing.number, number); 1.46 + is(outgoing.state, "dialing"); 1.47 + 1.48 + is(outgoing, telephony.active); 1.49 + is(telephony.calls.length, 1); 1.50 + is(telephony.calls[0], outgoing); 1.51 + 1.52 + outgoing.onalerting = function onalerting(event) { 1.53 + log("Received 'onalerting' call event."); 1.54 + is(outgoing, event.call); 1.55 + is(outgoing.state, "alerting"); 1.56 + 1.57 + emulator.run("gsm list", function(result) { 1.58 + log("Call list is now: " + result); 1.59 + is(result[0], "outbound to " + number + " : ringing"); 1.60 + is(result[1], "OK"); 1.61 + answer(); 1.62 + }); 1.63 + }; 1.64 + }); 1.65 +} 1.66 + 1.67 +function answer() { 1.68 + log("Answering the outgoing call."); 1.69 + 1.70 + // We get no "connecting" event when the remote party answers the call. 1.71 + 1.72 + outgoing.onconnected = function onconnected(event) { 1.73 + log("Received 'connected' call event."); 1.74 + is(outgoing, event.call); 1.75 + is(outgoing.state, "connected"); 1.76 + 1.77 + is(outgoing, telephony.active); 1.78 + 1.79 + emulator.run("gsm list", function(result) { 1.80 + log("Call list is now: " + result); 1.81 + is(result[0], "outbound to " + number + " : active"); 1.82 + is(result[1], "OK"); 1.83 + hangUp(); 1.84 + }); 1.85 + }; 1.86 + emulator.run("gsm accept " + number); 1.87 +} 1.88 + 1.89 +function hangUp() { 1.90 + log("Hanging up the outgoing call."); 1.91 + 1.92 + // We get no "disconnecting" event when the remote party terminates the call. 1.93 + 1.94 + outgoing.ondisconnected = function ondisconnected(event) { 1.95 + log("Received 'disconnected' call event."); 1.96 + is(outgoing, event.call); 1.97 + is(outgoing.state, "disconnected"); 1.98 + 1.99 + is(telephony.active, null); 1.100 + is(telephony.calls.length, 0); 1.101 + 1.102 + emulator.run("gsm list", function(result) { 1.103 + log("Call list is now: " + result); 1.104 + is(result[0], "OK"); 1.105 + cleanUp(); 1.106 + }); 1.107 + }; 1.108 + emulator.run("gsm cancel " + number); 1.109 +} 1.110 + 1.111 +function cleanUp() { 1.112 + finish(); 1.113 +} 1.114 + 1.115 +startTestWithPermissions(['mobileconnection'], function() { 1.116 + connection = navigator.mozMobileConnections[0]; 1.117 + ok(connection instanceof MozMobileConnection, 1.118 + "connection is instanceof " + connection.constructor); 1.119 + 1.120 + setRadioEnabled(false, function() { 1.121 + dial(); 1.122 + }); 1.123 +});