dom/telephony/test/marionette/test_emergency_label.js

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 /* Any copyright is dedicated to the Public Domain.
michael@0 2 * http://creativecommons.org/publicdomain/zero/1.0/ */
michael@0 3
michael@0 4 MARIONETTE_TIMEOUT = 60000;
michael@0 5 MARIONETTE_HEAD_JS = 'head.js';
michael@0 6
michael@0 7 let number;
michael@0 8 let emergency;
michael@0 9 let outgoing;
michael@0 10
michael@0 11 let testCase = 0;
michael@0 12 let expectedResults = [
michael@0 13 ["112", true],
michael@0 14 ["911", true],
michael@0 15 ["0912345678", false],
michael@0 16 ["777", false],
michael@0 17 ];
michael@0 18
michael@0 19 function createGoldenCallListResult0(number, state) {
michael@0 20 // "outbound to xxxxxxxxxx : ringing"
michael@0 21 let padPattern = " ";
michael@0 22 let pad = padPattern.substring(0, padPattern.length - number.length);
michael@0 23 return "outbound to " + number + pad + " : " + state;
michael@0 24 }
michael@0 25
michael@0 26 function dial() {
michael@0 27 log("Make an outgoing call.");
michael@0 28
michael@0 29 telephony.dial(number).then(call => {
michael@0 30 outgoing = call;
michael@0 31 ok(outgoing);
michael@0 32 is(outgoing.number, number);
michael@0 33 is(outgoing.state, "dialing");
michael@0 34
michael@0 35 is(outgoing, telephony.active);
michael@0 36 is(telephony.calls.length, 1);
michael@0 37 is(telephony.calls[0], outgoing);
michael@0 38
michael@0 39 outgoing.onalerting = function onalerting(event) {
michael@0 40 log("Received 'onalerting' call event.");
michael@0 41 is(outgoing, event.call);
michael@0 42 is(outgoing.state, "alerting");
michael@0 43 is(outgoing.emergency, emergency);
michael@0 44
michael@0 45 emulator.run("gsm list", function(result) {
michael@0 46 log("Call list is now: " + result);
michael@0 47 is(result[0], createGoldenCallListResult0(number, "ringing"));
michael@0 48 is(result[1], "OK");
michael@0 49 answer();
michael@0 50 });
michael@0 51 };
michael@0 52 });
michael@0 53 }
michael@0 54
michael@0 55 function answer() {
michael@0 56 log("Answering the call.");
michael@0 57
michael@0 58 // We get no "connecting" event when the remote party answers the call.
michael@0 59
michael@0 60 outgoing.onconnected = function onconnected(event) {
michael@0 61 log("Received 'connected' call event.");
michael@0 62 is(outgoing, event.call);
michael@0 63 is(outgoing.state, "connected");
michael@0 64 is(outgoing.emergency, emergency);
michael@0 65
michael@0 66 is(outgoing, telephony.active);
michael@0 67
michael@0 68 emulator.run("gsm list", function(result) {
michael@0 69 log("Call list is now: " + result);
michael@0 70 is(result[0], createGoldenCallListResult0(number, "active"));
michael@0 71 is(result[1], "OK");
michael@0 72 hangUp();
michael@0 73 });
michael@0 74 };
michael@0 75 emulator.run("gsm accept " + number);
michael@0 76 }
michael@0 77
michael@0 78 function hangUp() {
michael@0 79 log("Hanging up the call.");
michael@0 80
michael@0 81 // We get no "disconnecting" event when the remote party terminates the call.
michael@0 82
michael@0 83 outgoing.ondisconnected = function ondisconnected(event) {
michael@0 84 log("Received 'disconnected' call event.");
michael@0 85 is(outgoing, event.call);
michael@0 86 is(outgoing.state, "disconnected");
michael@0 87 is(outgoing.emergency, emergency);
michael@0 88
michael@0 89 is(telephony.active, null);
michael@0 90 is(telephony.calls.length, 0);
michael@0 91
michael@0 92 emulator.run("gsm list", function(result) {
michael@0 93 log("Call list is now: " + result);
michael@0 94 is(result[0], "OK");
michael@0 95 verifyNextEmergencyLabel();
michael@0 96 });
michael@0 97 };
michael@0 98 emulator.run("gsm cancel " + number);
michael@0 99 }
michael@0 100
michael@0 101 function cleanUp() {
michael@0 102 finish();
michael@0 103 }
michael@0 104
michael@0 105 function verifyNextEmergencyLabel() {
michael@0 106 if (testCase >= expectedResults.length) {
michael@0 107 cleanUp();
michael@0 108 } else {
michael@0 109 log("Running test case: " + testCase + "/" + expectedResults.length);
michael@0 110 number = expectedResults[testCase][0];
michael@0 111 emergency = expectedResults[testCase][1];
michael@0 112 testCase++;
michael@0 113
michael@0 114 // No more calls in the list; give time for emulator to catch up
michael@0 115 waitFor(dial, function() {
michael@0 116 return (telephony.calls.length === 0);
michael@0 117 });
michael@0 118 }
michael@0 119 }
michael@0 120
michael@0 121 startTest(function() {
michael@0 122 verifyNextEmergencyLabel();
michael@0 123 });

mercurial