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 outNumber = "5555551111";
8 let inNumber = "5555552222";
9 let outgoingCall;
10 let incomingCall;
11 let gotOriginalConnected = false;
13 function dial() {
14 log("Make an outgoing call.");
15 telephony.dial(outNumber).then(call => {
16 outgoingCall = call;
17 ok(outgoingCall);
18 is(outgoingCall.number, outNumber);
19 is(outgoingCall.state, "dialing");
21 is(outgoingCall, telephony.active);
22 is(telephony.calls.length, 1);
23 is(telephony.calls[0], outgoingCall);
25 outgoingCall.onalerting = function onalerting(event) {
26 log("Received 'onalerting' call event.");
27 is(outgoingCall, event.call);
28 is(outgoingCall.state, "alerting");
30 emulator.run("gsm list", function(result) {
31 log("Call list is now: " + result);
32 is(result[0], "outbound to " + outNumber + " : ringing");
33 is(result[1], "OK");
34 answer();
35 });
36 };
37 });
38 }
40 function answer() {
41 log("Answering the outgoing call.");
43 // We get no "connecting" event when the remote party answers the call.
44 outgoingCall.onconnected = function onconnectedOut(event) {
45 log("Received 'connected' call event for the original outgoing call.");
47 is(outgoingCall, event.call);
48 is(outgoingCall.state, "connected");
49 is(outgoingCall, telephony.active);
51 emulator.run("gsm list", function(result) {
52 log("Call list is now: " + result);
53 is(result[0], "outbound to " + outNumber + " : active");
54 is(result[1], "OK");
56 if(!gotOriginalConnected){
57 gotOriginalConnected = true;
58 simulateIncoming();
59 } else {
60 // Received connected event for original call multiple times (fail)
61 ok(false,
62 "Received 'connected' event for original call multiple times");
63 }
64 });
65 };
66 emulator.run("gsm accept " + outNumber);
67 }
69 // With one connected call already, simulate an incoming call
70 function simulateIncoming() {
71 log("Simulating an incoming call (with one call already connected).");
73 telephony.onincoming = function onincoming(event) {
74 log("Received 'incoming' call event.");
75 incomingCall = event.call;
76 ok(incomingCall);
77 is(incomingCall.number, inNumber);
78 is(incomingCall.state, "incoming");
80 // Should be two calls now
81 is(telephony.calls.length, 2);
82 is(telephony.calls[0], outgoingCall);
83 is(telephony.calls[1], incomingCall);
85 emulator.run("gsm list", function(result) {
86 log("Call list is now: " + result);
87 is(result[0], "outbound to " + outNumber + " : active");
88 is(result[1], "inbound from " + inNumber + " : incoming");
89 is(result[2], "OK");
90 answerIncoming();
91 });
92 };
93 emulator.run("gsm call " + inNumber);
94 }
96 // Answer incoming call; original outgoing call should be held
97 function answerIncoming() {
98 log("Answering the incoming call.");
100 let gotConnecting = false;
101 incomingCall.onconnecting = function onconnectingIn(event) {
102 log("Received 'connecting' call event for incoming/2nd call.");
103 is(incomingCall, event.call);
104 is(incomingCall.state, "connecting");
105 gotConnecting = true;
106 };
108 incomingCall.onconnected = function onconnectedIn(event) {
109 log("Received 'connected' call event for incoming/2nd call.");
110 is(incomingCall, event.call);
111 is(incomingCall.state, "connected");
112 ok(gotConnecting);
114 is(incomingCall, telephony.active);
115 is(outgoingCall.state, "held");
117 emulator.run("gsm list", function(result) {
118 log("Call list is now: " + result);
119 is(result[0], "outbound to " + outNumber + " : held");
120 is(result[1], "inbound from " + inNumber + " : active");
121 is(result[2], "OK");
122 hangUpOutgoing();
123 });
124 };
125 incomingCall.answer();
126 }
128 // Hang-up original outgoing (now held) call
129 function hangUpOutgoing() {
130 log("Hanging up the original outgoing (now held) call.");
132 let gotDisconnecting = false;
133 outgoingCall.ondisconnecting = function ondisconnectingOut(event) {
134 log("Received 'disconnecting' call event for original outgoing call.");
135 is(outgoingCall, event.call);
136 is(outgoingCall.state, "disconnecting");
137 gotDisconnecting = true;
138 };
140 outgoingCall.ondisconnected = function ondisconnectedOut(event) {
141 log("Received 'disconnected' call event for original outgoing call.");
142 is(outgoingCall, event.call);
143 is(outgoingCall.state, "disconnected");
144 ok(gotDisconnecting);
146 // Back to one call now
147 is(telephony.calls.length, 1);
148 is(incomingCall.state, "connected");
150 emulator.run("gsm list", function(result) {
151 log("Call list is now: " + result);
152 is(result[0], "inbound from " + inNumber + " : active");
153 is(result[1], "OK");
154 hangUpIncoming();
155 });
156 };
157 outgoingCall.hangUp();
158 }
160 // Hang-up remaining (incoming) call
161 function hangUpIncoming() {
162 log("Hanging up the remaining (incoming) call.");
164 let gotDisconnecting = false;
165 incomingCall.ondisconnecting = function ondisconnectingIn(event) {
166 log("Received 'disconnecting' call event for remaining (incoming) call.");
167 is(incomingCall, event.call);
168 is(incomingCall.state, "disconnecting");
169 gotDisconnecting = true;
170 };
172 incomingCall.ondisconnected = function ondisconnectedIn(event) {
173 log("Received 'disconnected' call event for remaining (incoming) call.");
174 is(incomingCall, event.call);
175 is(incomingCall.state, "disconnected");
176 ok(gotDisconnecting);
178 // Zero calls left
179 is(telephony.active, null);
180 is(telephony.calls.length, 0);
182 emulator.run("gsm list", function(result) {
183 log("Call list is now: " + result);
184 is(result[0], "OK");
185 cleanUp();
186 });
187 };
188 incomingCall.hangUp();
189 }
191 function cleanUp() {
192 telephony.onincoming = null;
193 finish();
194 }
196 startTest(function() {
197 dial();
198 });