Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
1 /* Any copyright is dedicated to the Public Domain.
2 * http://creativecommons.org/publicdomain/zero/1.0/ */
4 MARIONETTE_TIMEOUT = 60000;
5 MARIONETTE_HEAD_JS = 'head.js';
7 let connection;
8 let number = "112";
9 let outgoing;
11 function setRadioEnabled(enabled, callback) {
12 let request = connection.setRadioEnabled(enabled);
13 let desiredRadioState = enabled ? 'enabled' : 'disabled';
15 let pending = ['onradiostatechange', 'onsuccess'];
16 let done = callback;
18 connection.onradiostatechange = function() {
19 let state = connection.radioState;
20 log("Received 'radiostatechange' event, radioState: " + state);
22 if (state == desiredRadioState) {
23 gReceivedPending('onradiostatechange', pending, done);
24 }
25 };
27 request.onsuccess = function onsuccess() {
28 gReceivedPending('onsuccess', pending, done);
29 };
31 request.onerror = function onerror() {
32 ok(false, "setRadioEnabled should be ok");
33 };
34 }
36 function dial() {
37 log("Make an outgoing call.");
39 telephony.dial(number).then(call => {
40 outgoing = call;
41 ok(outgoing);
42 is(outgoing.number, number);
43 is(outgoing.state, "dialing");
45 is(outgoing, telephony.active);
46 is(telephony.calls.length, 1);
47 is(telephony.calls[0], outgoing);
49 outgoing.onalerting = function onalerting(event) {
50 log("Received 'onalerting' call event.");
51 is(outgoing, event.call);
52 is(outgoing.state, "alerting");
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 }
64 function answer() {
65 log("Answering the outgoing call.");
67 // We get no "connecting" event when the remote party answers the call.
69 outgoing.onconnected = function onconnected(event) {
70 log("Received 'connected' call event.");
71 is(outgoing, event.call);
72 is(outgoing.state, "connected");
74 is(outgoing, telephony.active);
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 }
86 function hangUp() {
87 log("Hanging up the outgoing call.");
89 // We get no "disconnecting" event when the remote party terminates the call.
91 outgoing.ondisconnected = function ondisconnected(event) {
92 log("Received 'disconnected' call event.");
93 is(outgoing, event.call);
94 is(outgoing.state, "disconnected");
96 is(telephony.active, null);
97 is(telephony.calls.length, 0);
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 }
108 function cleanUp() {
109 finish();
110 }
112 startTestWithPermissions(['mobileconnection'], function() {
113 connection = navigator.mozMobileConnections[0];
114 ok(connection instanceof MozMobileConnection,
115 "connection is instanceof " + connection.constructor);
117 setRadioEnabled(false, function() {
118 dial();
119 });
120 });