|
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 incomingCall.onconnecting = function onconnecting(event) { |
|
37 log("Received 'connecting' call event."); |
|
38 is(incomingCall, event.call); |
|
39 is(incomingCall.state, "connecting"); |
|
40 // Now hang-up the call before it is fully connected |
|
41 |
|
42 // Bug 784429: Hang-up while connecting, call is not terminated |
|
43 // If hang-up between 'connecting' and 'connected' states, receive the |
|
44 // 'disconnecting' event but then a 'connected' event, and the call is |
|
45 // never terminated; this test times out waiting for 'disconnected', and |
|
46 // will leave the emulator in a bad state (with an active incoming call). |
|
47 // For now, hangUp after the 'connected' event so this test doesn't |
|
48 // timeout; once the bug is fixed then update and remove the setTimeout |
|
49 |
|
50 //hangUp(); |
|
51 log("==> Waiting one second, remove wait once bug 784429 is fixed <=="); |
|
52 setTimeout(hangUp, 1000); |
|
53 }; |
|
54 |
|
55 incomingCall.onconnected = function onconnected(event) { |
|
56 log("Received 'connected' call event."); |
|
57 }; |
|
58 incomingCall.answer(); |
|
59 } |
|
60 |
|
61 function hangUp() { |
|
62 log("Hanging up the incoming call before fully connected."); |
|
63 |
|
64 let gotDisconnecting = false; |
|
65 incomingCall.ondisconnecting = function ondisconnecting(event) { |
|
66 log("Received 'disconnecting' call event."); |
|
67 is(incomingCall, event.call); |
|
68 is(incomingCall.state, "disconnecting"); |
|
69 gotDisconnecting = true; |
|
70 }; |
|
71 |
|
72 incomingCall.ondisconnected = function ondisconnected(event) { |
|
73 log("Received 'disconnected' call event."); |
|
74 is(incomingCall, event.call); |
|
75 is(incomingCall.state, "disconnected"); |
|
76 ok(gotDisconnecting); |
|
77 |
|
78 is(telephony.active, null); |
|
79 is(telephony.calls.length, 0); |
|
80 |
|
81 emulator.run("gsm list", function(result) { |
|
82 log("Call list is now: " + result); |
|
83 is(result[0], "OK"); |
|
84 cleanUp(); |
|
85 }); |
|
86 }; |
|
87 incomingCall.hangUp(); |
|
88 } |
|
89 |
|
90 function cleanUp() { |
|
91 telephony.onincoming = null; |
|
92 finish(); |
|
93 } |
|
94 |
|
95 startTest(function() { |
|
96 simulateIncoming(); |
|
97 }); |