1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/telephony/test/marionette/test_emergency_label.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,123 @@ 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; 1.11 +let emergency; 1.12 +let outgoing; 1.13 + 1.14 +let testCase = 0; 1.15 +let expectedResults = [ 1.16 + ["112", true], 1.17 + ["911", true], 1.18 + ["0912345678", false], 1.19 + ["777", false], 1.20 +]; 1.21 + 1.22 +function createGoldenCallListResult0(number, state) { 1.23 + // "outbound to xxxxxxxxxx : ringing" 1.24 + let padPattern = " "; 1.25 + let pad = padPattern.substring(0, padPattern.length - number.length); 1.26 + return "outbound to " + number + pad + " : " + state; 1.27 +} 1.28 + 1.29 +function dial() { 1.30 + log("Make an outgoing call."); 1.31 + 1.32 + telephony.dial(number).then(call => { 1.33 + outgoing = call; 1.34 + ok(outgoing); 1.35 + is(outgoing.number, number); 1.36 + is(outgoing.state, "dialing"); 1.37 + 1.38 + is(outgoing, telephony.active); 1.39 + is(telephony.calls.length, 1); 1.40 + is(telephony.calls[0], outgoing); 1.41 + 1.42 + outgoing.onalerting = function onalerting(event) { 1.43 + log("Received 'onalerting' call event."); 1.44 + is(outgoing, event.call); 1.45 + is(outgoing.state, "alerting"); 1.46 + is(outgoing.emergency, emergency); 1.47 + 1.48 + emulator.run("gsm list", function(result) { 1.49 + log("Call list is now: " + result); 1.50 + is(result[0], createGoldenCallListResult0(number, "ringing")); 1.51 + is(result[1], "OK"); 1.52 + answer(); 1.53 + }); 1.54 + }; 1.55 + }); 1.56 +} 1.57 + 1.58 +function answer() { 1.59 + log("Answering the call."); 1.60 + 1.61 + // We get no "connecting" event when the remote party answers the call. 1.62 + 1.63 + outgoing.onconnected = function onconnected(event) { 1.64 + log("Received 'connected' call event."); 1.65 + is(outgoing, event.call); 1.66 + is(outgoing.state, "connected"); 1.67 + is(outgoing.emergency, emergency); 1.68 + 1.69 + is(outgoing, telephony.active); 1.70 + 1.71 + emulator.run("gsm list", function(result) { 1.72 + log("Call list is now: " + result); 1.73 + is(result[0], createGoldenCallListResult0(number, "active")); 1.74 + is(result[1], "OK"); 1.75 + hangUp(); 1.76 + }); 1.77 + }; 1.78 + emulator.run("gsm accept " + number); 1.79 +} 1.80 + 1.81 +function hangUp() { 1.82 + log("Hanging up the call."); 1.83 + 1.84 + // We get no "disconnecting" event when the remote party terminates the call. 1.85 + 1.86 + outgoing.ondisconnected = function ondisconnected(event) { 1.87 + log("Received 'disconnected' call event."); 1.88 + is(outgoing, event.call); 1.89 + is(outgoing.state, "disconnected"); 1.90 + is(outgoing.emergency, emergency); 1.91 + 1.92 + is(telephony.active, null); 1.93 + is(telephony.calls.length, 0); 1.94 + 1.95 + emulator.run("gsm list", function(result) { 1.96 + log("Call list is now: " + result); 1.97 + is(result[0], "OK"); 1.98 + verifyNextEmergencyLabel(); 1.99 + }); 1.100 + }; 1.101 + emulator.run("gsm cancel " + number); 1.102 +} 1.103 + 1.104 +function cleanUp() { 1.105 + finish(); 1.106 +} 1.107 + 1.108 +function verifyNextEmergencyLabel() { 1.109 + if (testCase >= expectedResults.length) { 1.110 + cleanUp(); 1.111 + } else { 1.112 + log("Running test case: " + testCase + "/" + expectedResults.length); 1.113 + number = expectedResults[testCase][0]; 1.114 + emergency = expectedResults[testCase][1]; 1.115 + testCase++; 1.116 + 1.117 + // No more calls in the list; give time for emulator to catch up 1.118 + waitFor(dial, function() { 1.119 + return (telephony.calls.length === 0); 1.120 + }); 1.121 + } 1.122 +} 1.123 + 1.124 +startTest(function() { 1.125 + verifyNextEmergencyLabel(); 1.126 +});