dom/telephony/test/marionette/test_multiple_hold.js

branch
TOR_BUG_3246
changeset 7
129ffea94266
equal deleted inserted replaced
-1:000000000000 0:d58e37567c9f
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 inNumber = "5555551111";
8 let outNumber = "5555552222";
9 let incomingCall;
10 let outgoingCall;
11
12 function simulateIncoming() {
13 log("Simulating an incoming call.");
14
15 telephony.onincoming = function onincoming(event) {
16 log("Received 'incoming' call event.");
17 incomingCall = event.call;
18 ok(incomingCall);
19 is(incomingCall.number, inNumber);
20 is(incomingCall.state, "incoming");
21
22 is(telephony.calls.length, 1);
23 is(telephony.calls[0], incomingCall);
24
25 emulator.run("gsm list", function(result) {
26 log("Call list is now: " + result);
27 is(result[0], "inbound from " + inNumber + " : incoming");
28 is(result[1], "OK");
29 answerIncoming();
30 });
31 };
32 emulator.run("gsm call " + inNumber);
33 }
34
35 function answerIncoming() {
36 log("Answering the incoming call.");
37
38 let gotConnecting = false;
39 incomingCall.onconnecting = function onconnectingIn(event) {
40 log("Received 'connecting' call event for original (incoming) call.");
41 is(incomingCall, event.call);
42 is(incomingCall.state, "connecting");
43 gotConnecting = true;
44 };
45
46 incomingCall.onconnected = function onconnectedIn(event) {
47 log("Received 'connected' call event for original (incoming) call.");
48 is(incomingCall, event.call);
49 is(incomingCall.state, "connected");
50 ok(gotConnecting);
51 is(incomingCall, telephony.active);
52
53 emulator.run("gsm list", function(result) {
54 log("Call list is now: " + result);
55 is(result[0], "inbound from " + inNumber + " : active");
56 is(result[1], "OK");
57 holdCall();
58 });
59 };
60 incomingCall.answer();
61 }
62
63 // Put the original (incoming) call on hold
64 function holdCall() {
65 log("Putting the original (incoming) call on hold.");
66
67 let gotHolding = false;
68 incomingCall.onholding = function onholding(event) {
69 log("Received 'holding' call event");
70 is(incomingCall, event.call);
71 is(incomingCall.state, "holding");
72 gotHolding = true;
73 };
74
75 incomingCall.onheld = function onheld(event) {
76 log("Received 'held' call event");
77 is(incomingCall, event.call);
78 is(incomingCall.state, "held");
79 ok(gotHolding);
80
81 is(telephony.active, null);
82 is(telephony.calls.length, 1);
83 is(telephony.calls[0], incomingCall);
84
85 emulator.run("gsm list", function(result) {
86 log("Call list is now: " + result);
87 is(result[0], "inbound from " + inNumber + " : held");
88 is(result[1], "OK");
89 dial();
90 });
91 };
92 incomingCall.hold();
93 }
94
95 // With one call on hold, make outgoing call
96 function dial() {
97 log("Making an outgoing call (while have one call already held).");
98
99 telephony.dial(outNumber).then(call => {
100 outgoingCall = call;
101 ok(outgoingCall);
102 is(outgoingCall.number, outNumber);
103 is(outgoingCall.state, "dialing");
104 is(outgoingCall, telephony.active);
105 is(telephony.calls.length, 2);
106 is(telephony.calls[0], incomingCall);
107 is(telephony.calls[1], outgoingCall);
108
109 outgoingCall.onalerting = function onalerting(event) {
110 log("Received 'onalerting' call event.");
111 is(outgoingCall, event.call);
112 is(outgoingCall.state, "alerting");
113
114 emulator.run("gsm list", function(result) {
115 log("Call list is now: " + result);
116 is(result[0], "inbound from " + inNumber + " : held");
117 is(result[1], "outbound to " + outNumber + " : ringing");
118 is(result[2], "OK");
119 answerOutgoing();
120 });
121 };
122 });
123 }
124
125 // Have the outgoing call answered
126 function answerOutgoing() {
127 log("Answering the outgoing/2nd call");
128
129 // We get no "connecting" event when the remote party answers the call.
130 outgoingCall.onconnected = function onconnectedOut(event) {
131 log("Received 'connected' call event for outgoing/2nd call.");
132 is(outgoingCall, event.call);
133 is(outgoingCall.state, "connected");
134 is(outgoingCall, telephony.active);
135
136 emulator.run("gsm list", function(result) {
137 log("Call list is now: " + result);
138 is(result[0], "inbound from " + inNumber + " : held");
139 is(result[1], "outbound to " + outNumber + " : active");
140 is(result[2], "OK");
141 holdSecondCall();
142 });
143 };
144 emulator.run("gsm accept " + outNumber);
145 }
146
147 // With one held call and one active, hold the active one; expect the first
148 // (held) call to automatically become active, and the 2nd call to go on hold
149 function holdSecondCall() {
150 let firstCallReconnected = false;
151 let secondCallHeld = false;
152
153 log("Putting the 2nd (outgoing) call on hold.");
154
155 // Since first call will become connected again, setup handler
156 incomingCall.onconnected = function onreconnected(event) {
157 log("Received 'connected' call event for original (incoming) call.");
158 is(incomingCall, event.call);
159 is(incomingCall.state, "connected");
160 is(incomingCall, telephony.active);
161 firstCallReconnected = true;
162 if (firstCallReconnected && secondCallHeld) {
163 verifyCalls();
164 }
165 };
166
167 // Handlers for holding 2nd call
168 let gotHolding = false;
169 outgoingCall.onholding = function onholdingOut(event) {
170 log("Received 'holding' call event for 2nd call.");
171 is(outgoingCall, event.call);
172 is(outgoingCall.state, "holding");
173 gotHolding = true;
174 };
175
176 outgoingCall.onheld = function onheldOut(event) {
177 log("Received 'held' call event for 2nd call.");
178 is(outgoingCall, event.call);
179 is(outgoingCall.state, "held");
180 ok(gotHolding);
181 secondCallHeld = true;
182 if (firstCallReconnected && secondCallHeld) {
183 verifyCalls();
184 }
185 };
186 outgoingCall.hold();
187 }
188
189 function verifyCalls() {
190 is(telephony.active, incomingCall);
191 is(telephony.calls.length, 2);
192 is(telephony.calls[0], incomingCall);
193 is(telephony.calls[1], outgoingCall);
194
195 emulator.run("gsm list", function(result) {
196 log("Call list is now: " + result);
197 is(result[0], "inbound from " + inNumber + " : active");
198 is(result[1], "outbound to " + outNumber + " : held");
199 is(result[2], "OK");
200 hangUpIncoming();
201 });
202 }
203
204 // Hang-up the original incoming call, which is now active
205 function hangUpIncoming() {
206 log("Hanging up the original incoming (now active) call.");
207
208 let gotDisconnecting = false;
209 incomingCall.ondisconnecting = function ondisconnectingIn(event) {
210 log("Received 'disconnecting' call event for original (incoming) call.");
211 is(incomingCall, event.call);
212 is(incomingCall.state, "disconnecting");
213 gotDisconnecting = true;
214 };
215
216 incomingCall.ondisconnected = function ondisconnectedIn(event) {
217 log("Received 'disconnected' call event for original (incoming) call.");
218 is(incomingCall, event.call);
219 is(incomingCall.state, "disconnected");
220 ok(gotDisconnecting);
221
222 // Now back to one call
223 is(telephony.active, null);
224 is(telephony.calls.length, 1);
225 is(telephony.calls[0], outgoingCall);
226
227 emulator.run("gsm list", function(result) {
228 log("Call list is now: " + result);
229 is(result[0], "outbound to " + outNumber + " : held");
230 is(result[1], "OK");
231 hangUpOutgoing();
232 });
233 };
234 incomingCall.hangUp();
235 }
236
237 // Hang-up the remaining (outgoing) call, which is held
238 function hangUpOutgoing() {
239 log("Hanging up the remaining (outgoing) held call.");
240
241 let gotDisconnecting = false;
242 outgoingCall.ondisconnecting = function ondisconnectingOut(event) {
243 log("Received 'disconnecting' call event for remaining (outgoing) call.");
244 is(outgoingCall, event.call);
245 is(outgoingCall.state, "disconnecting");
246 gotDisconnecting = true;
247 };
248
249 outgoingCall.ondisconnected = function ondisconnectedOut(event) {
250 log("Received 'disconnected' call event for remaining (outgoing) call.");
251 is(outgoingCall, event.call);
252 is(outgoingCall.state, "disconnected");
253 ok(gotDisconnecting);
254
255 // Now no calls
256 is(telephony.active, null);
257 is(telephony.calls.length, 0);
258
259 emulator.run("gsm list", function(result) {
260 log("Call list is now: " + result);
261 is(result[0], "OK");
262 cleanUp();
263 });
264 };
265 outgoingCall.hangUp();
266 }
267
268 function cleanUp() {
269 telephony.onincoming = null;
270 finish();
271 }
272
273 startTest(function() {
274 simulateIncoming();
275 });

mercurial