dom/telephony/test/marionette/test_outgoing_already_held.js

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

mercurial