|
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 incomingCall; |
|
9 |
|
10 function simulateIncoming() { |
|
11 log("Simulating an incoming call."); |
|
12 |
|
13 telephony.onincoming = function onincoming(event) { |
|
14 log("Received 'incoming' call event."); |
|
15 incomingCall = event.call; |
|
16 ok(incomingCall); |
|
17 is(incomingCall.number, inNumber); |
|
18 is(incomingCall.state, "incoming"); |
|
19 |
|
20 is(telephony.calls.length, 1); |
|
21 is(telephony.calls[0], incomingCall); |
|
22 |
|
23 emulator.run("gsm list", function(result) { |
|
24 log("Call list is now: " + result); |
|
25 is(result[0], "inbound from " + inNumber + " : incoming"); |
|
26 is(result[1], "OK"); |
|
27 answerIncoming(); |
|
28 }); |
|
29 }; |
|
30 emulator.run("gsm call " + inNumber); |
|
31 } |
|
32 |
|
33 function answerIncoming() { |
|
34 log("Answering the incoming call."); |
|
35 |
|
36 let gotConnecting = false; |
|
37 incomingCall.onconnecting = function onconnectingIn(event) { |
|
38 log("Received 'connecting' call event for incoming call."); |
|
39 is(incomingCall, event.call); |
|
40 is(incomingCall.state, "connecting"); |
|
41 gotConnecting = true; |
|
42 }; |
|
43 |
|
44 incomingCall.onconnected = function onconnectedIn(event) { |
|
45 log("Received 'connected' call event for incoming call."); |
|
46 is(incomingCall, event.call); |
|
47 is(incomingCall.state, "connected"); |
|
48 ok(gotConnecting); |
|
49 |
|
50 is(incomingCall, telephony.active); |
|
51 |
|
52 emulator.run("gsm list", function(result) { |
|
53 log("Call list is now: " + result); |
|
54 is(result[0], "inbound from " + inNumber + " : active"); |
|
55 is(result[1], "OK"); |
|
56 answerAlreadyConnected(); |
|
57 }); |
|
58 }; |
|
59 incomingCall.answer(); |
|
60 } |
|
61 |
|
62 function answerAlreadyConnected() { |
|
63 log("Attempting to answer already connected call, should be ignored."); |
|
64 |
|
65 incomingCall.onconnecting = function onconnectingErr(event) { |
|
66 log("Received 'connecting' call event, but should not have."); |
|
67 ok(false, "Received 'connecting' event when answered already active call"); |
|
68 }; |
|
69 |
|
70 incomingCall.onconnected = function onconnectedErr(event) { |
|
71 log("Received 'connected' call event, but should not have."); |
|
72 ok(false, "Received 'connected' event when answered already active call"); |
|
73 }; |
|
74 |
|
75 incomingCall.answer(); |
|
76 |
|
77 is(incomingCall.state, "connected"); |
|
78 is(telephony.calls.length, 1); |
|
79 is(telephony.calls[0], incomingCall); |
|
80 is(incomingCall, telephony.active); |
|
81 hold(); |
|
82 } |
|
83 |
|
84 function hold() { |
|
85 log("Putting the call on hold."); |
|
86 |
|
87 let gotHolding = false; |
|
88 incomingCall.onholding = function onholding(event) { |
|
89 log("Received 'holding' call event."); |
|
90 is(incomingCall, event.call); |
|
91 is(incomingCall.state, "holding"); |
|
92 gotHolding = true; |
|
93 }; |
|
94 |
|
95 incomingCall.onheld = function onheld(event) { |
|
96 log("Received 'held' call event."); |
|
97 is(incomingCall, event.call); |
|
98 is(incomingCall.state, "held"); |
|
99 ok(gotHolding); |
|
100 |
|
101 is(telephony.active, null); |
|
102 is(telephony.calls.length, 1); |
|
103 is(telephony.calls[0], incomingCall); |
|
104 |
|
105 emulator.run("gsm list", function(result) { |
|
106 log("Call list is now: " + result); |
|
107 is(result[0], "inbound from " + inNumber + " : held"); |
|
108 is(result[1], "OK"); |
|
109 holdAlreadyHeld(); |
|
110 }); |
|
111 }; |
|
112 incomingCall.hold(); |
|
113 } |
|
114 |
|
115 function holdAlreadyHeld() { |
|
116 log("Attempting to hold an already held call, should be ignored."); |
|
117 |
|
118 incomingCall.onholding = function onholding(event) { |
|
119 log("Received 'holding' call event, but should not have."); |
|
120 ok(false, "Received 'holding' event when held an already held call"); |
|
121 }; |
|
122 |
|
123 incomingCall.onheld = function onheldErr(event) { |
|
124 log("Received 'held' call event, but should not have."); |
|
125 ok(false, "Received 'held' event when held an already held call"); |
|
126 }; |
|
127 |
|
128 incomingCall.hold(); |
|
129 |
|
130 is(incomingCall.state, "held"); |
|
131 is(telephony.active, null); |
|
132 is(telephony.calls.length, 1); |
|
133 is(telephony.calls[0], incomingCall); |
|
134 |
|
135 answerHeld(); |
|
136 } |
|
137 |
|
138 function answerHeld() { |
|
139 log("Attempting to answer a held call, should be ignored."); |
|
140 |
|
141 incomingCall.onconnecting = function onconnectingErr(event) { |
|
142 log("Received 'connecting' call event, but should not have."); |
|
143 ok(false, "Received 'connecting' event when answered a held call"); |
|
144 }; |
|
145 |
|
146 incomingCall.onconnected = function onconnectedErr(event) { |
|
147 log("Received 'connected' call event, but should not have."); |
|
148 ok(false, "Received 'connected' event when answered a held call"); |
|
149 }; |
|
150 |
|
151 incomingCall.answer(); |
|
152 |
|
153 is(incomingCall.state, "held"); |
|
154 is(telephony.active, null); |
|
155 is(telephony.calls.length, 1); |
|
156 is(telephony.calls[0], incomingCall); |
|
157 |
|
158 resume(); |
|
159 } |
|
160 |
|
161 function resume() { |
|
162 log("Resuming the held call."); |
|
163 |
|
164 let gotResuming = false; |
|
165 incomingCall.onresuming = function onresuming(event) { |
|
166 log("Received 'resuming' call event."); |
|
167 is(incomingCall, event.call); |
|
168 is(incomingCall.state, "resuming"); |
|
169 gotResuming = true; |
|
170 }; |
|
171 |
|
172 incomingCall.onconnected = function onconnected(event) { |
|
173 log("Received 'connected' call event."); |
|
174 is(incomingCall, event.call); |
|
175 is(incomingCall.state, "connected"); |
|
176 ok(gotResuming); |
|
177 |
|
178 is(incomingCall, telephony.active); |
|
179 is(telephony.calls.length, 1); |
|
180 is(telephony.calls[0], incomingCall); |
|
181 |
|
182 emulator.run("gsm list", function(result) { |
|
183 log("Call list is now: " + result); |
|
184 is(result[0], "inbound from " + inNumber + " : active"); |
|
185 is(result[1], "OK"); |
|
186 resumeNonHeld(); |
|
187 }); |
|
188 }; |
|
189 incomingCall.resume(); |
|
190 } |
|
191 |
|
192 function resumeNonHeld() { |
|
193 log("Attempting to resume non-held call, should be ignored."); |
|
194 |
|
195 incomingCall.onresuming = function onresumingErr(event) { |
|
196 log("Received 'resuming' call event, but should not have."); |
|
197 ok(false, "Received 'resuming' event when resumed non-held call"); |
|
198 }; |
|
199 |
|
200 incomingCall.onconnected = function onconnectedErr(event) { |
|
201 log("Received 'connected' call event, but should not have."); |
|
202 ok(false, "Received 'connected' event when resumed non-held call"); |
|
203 }; |
|
204 |
|
205 incomingCall.resume(); |
|
206 |
|
207 is(incomingCall.state, "connected"); |
|
208 is(telephony.calls.length, 1); |
|
209 is(telephony.calls[0], incomingCall); |
|
210 is(incomingCall, telephony.active); |
|
211 hangUp(); |
|
212 } |
|
213 |
|
214 function hangUp() { |
|
215 log("Hanging up the call (local hang-up)."); |
|
216 |
|
217 let gotDisconnecting = false; |
|
218 incomingCall.ondisconnecting = function ondisconnecting(event) { |
|
219 log("Received 'disconnecting' call event."); |
|
220 is(incomingCall, event.call); |
|
221 is(incomingCall.state, "disconnecting"); |
|
222 gotDisconnecting = true; |
|
223 }; |
|
224 |
|
225 incomingCall.ondisconnected = function ondisconnectedOut(event) { |
|
226 log("Received 'disconnected' call event."); |
|
227 is(incomingCall, event.call); |
|
228 is(incomingCall.state, "disconnected"); |
|
229 ok(gotDisconnecting); |
|
230 |
|
231 is(telephony.active, null); |
|
232 is(telephony.calls.length, 0); |
|
233 |
|
234 emulator.run("gsm list", function(result) { |
|
235 log("Call list is now: " + result); |
|
236 is(result[0], "OK"); |
|
237 answerDisconnected(); |
|
238 }); |
|
239 }; |
|
240 incomingCall.hangUp(); |
|
241 } |
|
242 |
|
243 function answerDisconnected() { |
|
244 log("Attempting to answer disconnected call, should be ignored."); |
|
245 |
|
246 incomingCall.onconnecting = function onconnectingErr(event) { |
|
247 log("Received 'connecting' call event, but should not have."); |
|
248 ok(false, "Received 'connecting' event when answered disconnected call"); |
|
249 }; |
|
250 |
|
251 incomingCall.onconnected = function onconnectedErr(event) { |
|
252 log("Received 'connected' call event, but should not have."); |
|
253 ok(false, "Received 'connected' event when answered disconnected call"); |
|
254 }; |
|
255 |
|
256 incomingCall.answer(); |
|
257 |
|
258 is(telephony.active, null); |
|
259 is(telephony.calls.length, 0); |
|
260 holdDisconnected(); |
|
261 } |
|
262 |
|
263 function holdDisconnected() { |
|
264 log("Attempting to hold disconnected call, should be ignored."); |
|
265 |
|
266 incomingCall.onholding = function onholdingErr(event) { |
|
267 log("Received 'holding' call event, but should not have."); |
|
268 ok(false, "Received 'holding' event when held a disconnected call"); |
|
269 }; |
|
270 |
|
271 incomingCall.onheld = function onheldErr(event) { |
|
272 log("Received 'held' call event, but should not have."); |
|
273 ok(false, "Received 'held' event when held a disconnected call"); |
|
274 }; |
|
275 |
|
276 incomingCall.hold(); |
|
277 |
|
278 is(telephony.active, null); |
|
279 is(telephony.calls.length, 0); |
|
280 resumeDisconnected(); |
|
281 } |
|
282 |
|
283 function resumeDisconnected() { |
|
284 log("Attempting to resume disconnected call, should be ignored."); |
|
285 |
|
286 incomingCall.onresuming = function onresumingErr(event) { |
|
287 log("Received 'resuming' call event, but should not have."); |
|
288 ok(false, "Received 'resuming' event when resumed disconnected call"); |
|
289 }; |
|
290 |
|
291 incomingCall.onconnected = function onconnectedErr(event) { |
|
292 log("Received 'connected' call event, but should not have."); |
|
293 ok(false, "Received 'connected' event when resumed disconnected call"); |
|
294 }; |
|
295 |
|
296 incomingCall.resume(); |
|
297 |
|
298 is(telephony.active, null); |
|
299 is(telephony.calls.length, 0); |
|
300 hangUpNonConnected(); |
|
301 } |
|
302 |
|
303 function hangUpNonConnected() { |
|
304 log("Attempting to hang-up disconnected call, should be ignored."); |
|
305 |
|
306 incomingCall.ondisconnecting = function ondisconnectingErr(event) { |
|
307 log("Received 'disconnecting' call event, but should not have."); |
|
308 ok(false, "Received 'disconnecting' event when hung-up non-active call"); |
|
309 }; |
|
310 |
|
311 incomingCall.ondisconnected = function ondisconnectedErr(event) { |
|
312 log("Received 'disconnected' call event, but should not have."); |
|
313 ok(false, "Received 'disconnected' event when hung-up non-active call"); |
|
314 }; |
|
315 |
|
316 incomingCall.hangUp(); |
|
317 |
|
318 is(telephony.active, null); |
|
319 is(telephony.calls.length, 0); |
|
320 cleanUp(); |
|
321 } |
|
322 |
|
323 function cleanUp() { |
|
324 telephony.onincoming = null; |
|
325 finish(); |
|
326 } |
|
327 |
|
328 startTest(function() { |
|
329 simulateIncoming(); |
|
330 }); |