dom/telephony/test/marionette/test_incoming_already_held.js

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:86ec821fbb27
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 outNumber = "5555551111";
8 let inNumber = "5555552222";
9 let outgoingCall;
10 let incomingCall;
11 let gotOriginalConnected = false;
12
13 function dial() {
14 log("Make an outgoing call.");
15 telephony.dial(outNumber).then(call => {
16 outgoingCall = call;
17 ok(outgoingCall);
18 is(outgoingCall.number, outNumber);
19 is(outgoingCall.state, "dialing");
20
21 is(outgoingCall, telephony.active);
22 is(telephony.calls.length, 1);
23 is(telephony.calls[0], outgoingCall);
24
25 outgoingCall.onalerting = function onalerting(event) {
26 log("Received 'onalerting' call event.");
27 is(outgoingCall, event.call);
28 is(outgoingCall.state, "alerting");
29
30 emulator.run("gsm list", function(result) {
31 log("Call list is now: " + result);
32 is(result[0], "outbound to " + outNumber + " : ringing");
33 is(result[1], "OK");
34 answer();
35 });
36 };
37 });
38 }
39
40 function answer() {
41 log("Answering the outgoing call.");
42
43 // We get no "connecting" event when the remote party answers the call.
44 outgoingCall.onconnected = function onconnectedOut(event) {
45 log("Received 'connected' call event for the original outgoing call.");
46
47 is(outgoingCall, event.call);
48 is(outgoingCall.state, "connected");
49 is(outgoingCall, telephony.active);
50
51 emulator.run("gsm list", function(result) {
52 log("Call list is now: " + result);
53 is(result[0], "outbound to " + outNumber + " : active");
54 is(result[1], "OK");
55
56 if(!gotOriginalConnected){
57 gotOriginalConnected = true;
58 holdCall();
59 } else {
60 // Received connected event for original call multiple times (fail)
61 ok(false,
62 "Received 'connected' event for original call multiple times");
63 }
64 });
65 };
66 emulator.run("gsm accept " + outNumber);
67 }
68
69 function holdCall() {
70 log("Putting the original (outgoing) call on hold.");
71
72 let gotHolding = false;
73 outgoingCall.onholding = function onholding(event) {
74 log("Received 'holding' call event");
75 is(outgoingCall, event.call);
76 is(outgoingCall.state, "holding");
77 gotHolding = true;
78 };
79
80 outgoingCall.onheld = function onheld(event) {
81 log("Received 'held' call event");
82 is(outgoingCall, event.call);
83 is(outgoingCall.state, "held");
84 ok(gotHolding);
85
86 is(telephony.active, null);
87 is(telephony.calls.length, 1);
88 is(telephony.calls[0], outgoingCall);
89
90 emulator.run("gsm list", function(result) {
91 log("Call list is now: " + result);
92 is(result[0], "outbound to " + outNumber + " : held");
93 is(result[1], "OK");
94 simulateIncoming();
95 });
96 };
97 outgoingCall.hold();
98 }
99
100 // With one call on hold, simulate an incoming call
101 function simulateIncoming() {
102 log("Simulating an incoming call (with one call already held).");
103
104 telephony.onincoming = function onincoming(event) {
105 log("Received 'incoming' call event.");
106 incomingCall = event.call;
107 ok(incomingCall);
108 is(incomingCall.number, inNumber);
109 is(incomingCall.state, "incoming");
110
111 // Should be two calls now
112 is(telephony.calls.length, 2);
113 is(telephony.calls[0], outgoingCall);
114 is(telephony.calls[1], incomingCall);
115
116 emulator.run("gsm list", function(result) {
117 log("Call list is now: " + result);
118 is(result[0], "outbound to " + outNumber + " : held");
119 is(result[1], "inbound from " + inNumber + " : incoming");
120 is(result[2], "OK");
121 answerIncoming();
122 });
123 };
124 emulator.run("gsm call " + inNumber);
125 }
126
127 // Answer incoming call; original outgoing call should be held
128 function answerIncoming() {
129 log("Answering the incoming call.");
130
131 let gotConnecting = false;
132 incomingCall.onconnecting = function onconnectingIn(event) {
133 log("Received 'connecting' call event for incoming/2nd call.");
134 is(incomingCall, event.call);
135 is(incomingCall.state, "connecting");
136 gotConnecting = true;
137 };
138
139 incomingCall.onconnected = function onconnectedIn(event) {
140 log("Received 'connected' call event for incoming/2nd call.");
141 is(incomingCall, event.call);
142 is(incomingCall.state, "connected");
143 ok(gotConnecting);
144
145 is(incomingCall, telephony.active);
146 is(outgoingCall.state, "held");
147
148 emulator.run("gsm list", function(result) {
149 log("Call list is now: " + result);
150 is(result[0], "outbound to " + outNumber + " : held");
151 is(result[1], "inbound from " + inNumber + " : active");
152 is(result[2], "OK");
153 hangUpOutgoing();
154 });
155 };
156 incomingCall.answer();
157 }
158
159 // Hang-up original outgoing (now held) call
160 function hangUpOutgoing() {
161 log("Hanging up the original outgoing (now held) call.");
162
163 let gotDisconnecting = false;
164 outgoingCall.ondisconnecting = function ondisconnectingOut(event) {
165 log("Received 'disconnecting' call event for original outgoing call.");
166 is(outgoingCall, event.call);
167 is(outgoingCall.state, "disconnecting");
168 gotDisconnecting = true;
169 };
170
171 outgoingCall.ondisconnected = function ondisconnectedOut(event) {
172 log("Received 'disconnected' call event for original outgoing call.");
173 is(outgoingCall, event.call);
174 is(outgoingCall.state, "disconnected");
175 ok(gotDisconnecting);
176
177 // Back to one call now
178 is(telephony.calls.length, 1);
179 is(incomingCall.state, "connected");
180
181 emulator.run("gsm list", function(result) {
182 log("Call list is now: " + result);
183 is(result[0], "inbound from " + inNumber + " : active");
184 is(result[1], "OK");
185 hangUpIncoming();
186 });
187 };
188 outgoingCall.hangUp();
189 }
190
191 // Hang-up remaining (incoming) call
192 function hangUpIncoming() {
193 log("Hanging up the remaining (incoming) call.");
194
195 let gotDisconnecting = false;
196 incomingCall.ondisconnecting = function ondisconnectingIn(event) {
197 log("Received 'disconnecting' call event for remaining (incoming) call.");
198 is(incomingCall, event.call);
199 is(incomingCall.state, "disconnecting");
200 gotDisconnecting = true;
201 };
202
203 incomingCall.ondisconnected = function ondisconnectedIn(event) {
204 log("Received 'disconnected' call event for remaining (incoming) call.");
205 is(incomingCall, event.call);
206 is(incomingCall.state, "disconnected");
207 ok(gotDisconnecting);
208
209 // Zero calls left
210 is(telephony.active, null);
211 is(telephony.calls.length, 0);
212
213 emulator.run("gsm list", function(result) {
214 log("Call list is now: " + result);
215 is(result[0], "OK");
216 cleanUp();
217 });
218 };
219 incomingCall.hangUp();
220 }
221
222 function cleanUp() {
223 telephony.onincoming = null;
224 finish();
225 }
226
227 startTest(function() {
228 dial();
229 });

mercurial