dom/telephony/test/marionette/test_outgoing_emergency_in_airplane_mode.js

branch
TOR_BUG_9701
changeset 15
b8a032363ba2
equal deleted inserted replaced
-1:000000000000 0:3c800f6258bc
1 /* Any copyright is dedicated to the Public Domain.
2 * http://creativecommons.org/publicdomain/zero/1.0/ */
3
4 MARIONETTE_TIMEOUT = 60000;
5 MARIONETTE_HEAD_JS = 'head.js';
6
7 let connection;
8 let number = "112";
9 let outgoing;
10
11 function setRadioEnabled(enabled, callback) {
12 let request = connection.setRadioEnabled(enabled);
13 let desiredRadioState = enabled ? 'enabled' : 'disabled';
14
15 let pending = ['onradiostatechange', 'onsuccess'];
16 let done = callback;
17
18 connection.onradiostatechange = function() {
19 let state = connection.radioState;
20 log("Received 'radiostatechange' event, radioState: " + state);
21
22 if (state == desiredRadioState) {
23 gReceivedPending('onradiostatechange', pending, done);
24 }
25 };
26
27 request.onsuccess = function onsuccess() {
28 gReceivedPending('onsuccess', pending, done);
29 };
30
31 request.onerror = function onerror() {
32 ok(false, "setRadioEnabled should be ok");
33 };
34 }
35
36 function dial() {
37 log("Make an outgoing call.");
38
39 telephony.dial(number).then(call => {
40 outgoing = call;
41 ok(outgoing);
42 is(outgoing.number, number);
43 is(outgoing.state, "dialing");
44
45 is(outgoing, telephony.active);
46 is(telephony.calls.length, 1);
47 is(telephony.calls[0], outgoing);
48
49 outgoing.onalerting = function onalerting(event) {
50 log("Received 'onalerting' call event.");
51 is(outgoing, event.call);
52 is(outgoing.state, "alerting");
53
54 emulator.run("gsm list", function(result) {
55 log("Call list is now: " + result);
56 is(result[0], "outbound to " + number + " : ringing");
57 is(result[1], "OK");
58 answer();
59 });
60 };
61 });
62 }
63
64 function answer() {
65 log("Answering the outgoing call.");
66
67 // We get no "connecting" event when the remote party answers the call.
68
69 outgoing.onconnected = function onconnected(event) {
70 log("Received 'connected' call event.");
71 is(outgoing, event.call);
72 is(outgoing.state, "connected");
73
74 is(outgoing, telephony.active);
75
76 emulator.run("gsm list", function(result) {
77 log("Call list is now: " + result);
78 is(result[0], "outbound to " + number + " : active");
79 is(result[1], "OK");
80 hangUp();
81 });
82 };
83 emulator.run("gsm accept " + number);
84 }
85
86 function hangUp() {
87 log("Hanging up the outgoing call.");
88
89 // We get no "disconnecting" event when the remote party terminates the call.
90
91 outgoing.ondisconnected = function ondisconnected(event) {
92 log("Received 'disconnected' call event.");
93 is(outgoing, event.call);
94 is(outgoing.state, "disconnected");
95
96 is(telephony.active, null);
97 is(telephony.calls.length, 0);
98
99 emulator.run("gsm list", function(result) {
100 log("Call list is now: " + result);
101 is(result[0], "OK");
102 cleanUp();
103 });
104 };
105 emulator.run("gsm cancel " + number);
106 }
107
108 function cleanUp() {
109 finish();
110 }
111
112 startTestWithPermissions(['mobileconnection'], function() {
113 connection = navigator.mozMobileConnections[0];
114 ok(connection instanceof MozMobileConnection,
115 "connection is instanceof " + connection.constructor);
116
117 setRadioEnabled(false, function() {
118 dial();
119 });
120 });

mercurial