dom/telephony/test/marionette/test_incoming_hold_resume.js

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:dff32910048e
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 number = "5555551234";
8 let connectedCalls;
9 let incomingCall;
10
11 function simulateIncoming() {
12 log("Simulating an incoming call.");
13
14 telephony.onincoming = function onincoming(event) {
15 log("Received 'incoming' call event.");
16 incomingCall = event.call;
17 ok(incomingCall);
18 is(incomingCall.number, number);
19 is(incomingCall.state, "incoming");
20
21 is(telephony.calls.length, 1);
22 is(telephony.calls[0], incomingCall);
23
24 emulator.run("gsm list", function(result) {
25 log("Call list is now: " + result);
26 is(result[0], "inbound from " + number + " : incoming");
27 is(result[1], "OK");
28 answer();
29 });
30 };
31 emulator.run("gsm call " + number);
32 }
33
34 function answer() {
35 log("Answering the incoming call.");
36
37 let gotConnecting = false;
38 incomingCall.onconnecting = function onconnecting(event) {
39 log("Received 'connecting' call event.");
40 is(incomingCall, event.call);
41 is(incomingCall.state, "connecting");
42 gotConnecting = true;
43 };
44
45 incomingCall.onconnected = function onconnected(event) {
46 log("Received 'connected' call event.");
47 is(incomingCall, event.call);
48 is(incomingCall.state, "connected");
49 ok(gotConnecting);
50
51 is(incomingCall, telephony.active);
52
53 emulator.run("gsm list", function(result) {
54 log("Call list is now: " + result);
55 is(result[0], "inbound from " + number + " : active");
56 is(result[1], "OK");
57 hold();
58 });
59 };
60 incomingCall.answer();
61 }
62
63 function hold() {
64 log("Putting the call on hold.");
65
66 let gotHolding = false;
67 incomingCall.onholding = function onholding(event) {
68 log("Received 'holding' call event");
69 is(incomingCall, event.call);
70 is(incomingCall.state, "holding");
71 gotHolding = true;
72 };
73
74 incomingCall.onheld = function onheld(event) {
75 log("Received 'held' call event");
76 is(incomingCall, event.call);
77 is(incomingCall.state, "held");
78 ok(gotHolding);
79
80 is(telephony.active, null);
81 is(telephony.calls.length, 1);
82 is(telephony.calls[0], incomingCall);
83
84 emulator.run("gsm list", function(result) {
85 log("Call list is now: " + result);
86 is(result[0], "inbound from " + number + " : held");
87 is(result[1], "OK");
88 // Wait on hold for a couple of seconds
89 log("Pausing 2 seconds while on hold");
90 setTimeout(resume, 2000);
91 });
92 };
93 incomingCall.hold();
94 }
95
96 function resume() {
97 log("Resuming the held call.");
98
99 let gotResuming = false;
100 incomingCall.onresuming = function onresuming(event) {
101 log("Received 'resuming' call event");
102 is(incomingCall, event.call);
103 is(incomingCall.state, "resuming");
104 gotResuming = true;
105 };
106
107 incomingCall.onconnected = function onconnected(event) {
108 log("Received 'connected' call event");
109 is(incomingCall, event.call);
110 is(incomingCall.state, "connected");
111 ok(gotResuming);
112
113 is(incomingCall, telephony.active);
114 is(telephony.calls.length, 1);
115 is(telephony.calls[0], incomingCall);
116
117 emulator.run("gsm list", function(result) {
118 log("Call list is now: " + result);
119 is(result[0], "inbound from " + number + " : active");
120 is(result[1], "OK");
121 hangUp();
122 });
123 };
124 incomingCall.resume();
125 }
126
127 function hangUp() {
128 log("Hanging up the incoming call.");
129
130 let gotDisconnecting = false;
131 incomingCall.ondisconnecting = function ondisconnecting(event) {
132 log("Received 'disconnecting' call event.");
133 is(incomingCall, event.call);
134 is(incomingCall.state, "disconnecting");
135 gotDisconnecting = true;
136 };
137
138 incomingCall.ondisconnected = function ondisconnected(event) {
139 log("Received 'disconnected' call event.");
140 is(incomingCall, event.call);
141 is(incomingCall.state, "disconnected");
142 ok(gotDisconnecting);
143
144 is(telephony.active, null);
145 is(telephony.calls.length, 0);
146
147 emulator.run("gsm list", function(result) {
148 log("Call list is now: " + result);
149 is(result[0], "OK");
150 cleanUp();
151 });
152 };
153 incomingCall.hangUp();
154 }
155
156 function cleanUp() {
157 telephony.onincoming = null;
158 finish();
159 }
160
161 startTest(function() {
162 simulateIncoming();
163 });

mercurial