|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 * http://creativecommons.org/publicdomain/zero/1.0/ */ |
|
3 |
|
4 MARIONETTE_HEAD_JS = 'head.js'; |
|
5 MARIONETTE_TIMEOUT = 60000; |
|
6 |
|
7 let incomingCall; |
|
8 let inNumber = "5555551111"; |
|
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 gotConnecting = false; |
|
37 incomingCall.onstatechange = function statechangeconnect(event) { |
|
38 log("Received 'onstatechange' call event."); |
|
39 is(incomingCall, event.call); |
|
40 if(!gotConnecting){ |
|
41 is(incomingCall.state, "connecting"); |
|
42 gotConnecting = true; |
|
43 } else { |
|
44 is(incomingCall.state, "connected"); |
|
45 is(telephony.active, incomingCall); |
|
46 is(telephony.calls.length, 1); |
|
47 is(telephony.calls[0], incomingCall); |
|
48 |
|
49 emulator.run("gsm list", function(result) { |
|
50 log("Call list is now: " + result); |
|
51 is(result[0], "inbound from " + inNumber + " : active"); |
|
52 is(result[1], "OK"); |
|
53 hold(); |
|
54 }); |
|
55 } |
|
56 }; |
|
57 incomingCall.answer(); |
|
58 } |
|
59 |
|
60 function hold() { |
|
61 log("Putting the call on hold."); |
|
62 |
|
63 let gotHolding = false; |
|
64 incomingCall.onstatechange = function onstatechangehold(event) { |
|
65 log("Received 'onstatechange' call event."); |
|
66 is(incomingCall, event.call); |
|
67 if(!gotHolding){ |
|
68 is(incomingCall.state, "holding"); |
|
69 gotHolding = true; |
|
70 } else { |
|
71 is(incomingCall.state, "held"); |
|
72 is(telephony.active, null); |
|
73 is(telephony.calls.length, 1); |
|
74 is(telephony.calls[0], incomingCall); |
|
75 |
|
76 emulator.run("gsm list", function(result) { |
|
77 log("Call list is now: " + result); |
|
78 is(result[0], "inbound from " + inNumber + " : held"); |
|
79 is(result[1], "OK"); |
|
80 resume(); |
|
81 }); |
|
82 } |
|
83 }; |
|
84 incomingCall.hold(); |
|
85 } |
|
86 |
|
87 function resume() { |
|
88 log("Resuming the held call."); |
|
89 |
|
90 let gotResuming = false; |
|
91 incomingCall.onstatechange = function onstatechangeresume(event) { |
|
92 log("Received 'onstatechange' call event."); |
|
93 is(incomingCall, event.call); |
|
94 if(!gotResuming){ |
|
95 is(incomingCall.state, "resuming"); |
|
96 gotResuming = true; |
|
97 } else { |
|
98 is(incomingCall.state, "connected"); |
|
99 is(telephony.active, incomingCall); |
|
100 is(telephony.calls.length, 1); |
|
101 is(telephony.calls[0], incomingCall); |
|
102 |
|
103 emulator.run("gsm list", function(result) { |
|
104 log("Call list is now: " + result); |
|
105 is(result[0], "inbound from " + inNumber + " : active"); |
|
106 is(result[1], "OK"); |
|
107 hangUp(); |
|
108 }); |
|
109 } |
|
110 }; |
|
111 incomingCall.resume(); |
|
112 } |
|
113 |
|
114 function hangUp() { |
|
115 log("Hanging up the incoming call (local hang-up)."); |
|
116 |
|
117 let gotDisconnecting = false; |
|
118 incomingCall.onstatechange = function onstatechangedisconnect(event) { |
|
119 log("Received 'onstatechange' call event."); |
|
120 is(incomingCall, event.call); |
|
121 if(!gotDisconnecting){ |
|
122 is(incomingCall.state, "disconnecting"); |
|
123 gotDisconnecting = true; |
|
124 } else { |
|
125 is(incomingCall.state, "disconnected"); |
|
126 is(telephony.active, null); |
|
127 is(telephony.calls.length, 0); |
|
128 |
|
129 emulator.run("gsm list", function(result) { |
|
130 log("Call list is now: " + result); |
|
131 is(result[0], "OK"); |
|
132 cleanUp(); |
|
133 }); |
|
134 } |
|
135 }; |
|
136 incomingCall.hangUp(); |
|
137 } |
|
138 |
|
139 function cleanUp() { |
|
140 telephony.onincoming = null; |
|
141 finish(); |
|
142 } |
|
143 |
|
144 startTest(function() { |
|
145 simulateIncoming(); |
|
146 }); |