|
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 = "5555552368"; |
|
8 let incoming; |
|
9 let calls; |
|
10 |
|
11 function simulateIncoming() { |
|
12 log("Simulating an incoming call."); |
|
13 |
|
14 telephony.onincoming = function onincoming(event) { |
|
15 log("Received 'incoming' call event."); |
|
16 incoming = event.call; |
|
17 ok(incoming); |
|
18 is(incoming.number, number); |
|
19 is(incoming.state, "incoming"); |
|
20 |
|
21 //ok(telephony.calls === calls); // bug 717414 |
|
22 is(telephony.calls.length, 1); |
|
23 is(telephony.calls[0], incoming); |
|
24 |
|
25 emulator.run("gsm list", function(result) { |
|
26 log("Call list is now: " + result); |
|
27 is(result[0], "inbound from " + number + " : incoming"); |
|
28 is(result[1], "OK"); |
|
29 answer(); |
|
30 }); |
|
31 }; |
|
32 emulator.run("gsm call " + number); |
|
33 } |
|
34 |
|
35 function answer() { |
|
36 log("Answering the incoming call."); |
|
37 |
|
38 let gotConnecting = false; |
|
39 incoming.onconnecting = function onconnecting(event) { |
|
40 log("Received 'connecting' call event."); |
|
41 is(incoming, event.call); |
|
42 is(incoming.state, "connecting"); |
|
43 gotConnecting = true; |
|
44 }; |
|
45 |
|
46 incoming.onconnected = function onconnected(event) { |
|
47 log("Received 'connected' call event."); |
|
48 is(incoming, event.call); |
|
49 is(incoming.state, "connected"); |
|
50 ok(gotConnecting); |
|
51 |
|
52 is(incoming, telephony.active); |
|
53 |
|
54 emulator.run("gsm list", function(result) { |
|
55 log("Call list is now: " + result); |
|
56 is(result[0], "inbound from " + number + " : active"); |
|
57 is(result[1], "OK"); |
|
58 hangUp(); |
|
59 }); |
|
60 }; |
|
61 incoming.answer(); |
|
62 } |
|
63 |
|
64 function hangUp() { |
|
65 log("Hanging up the incoming call."); |
|
66 |
|
67 let gotDisconnecting = false; |
|
68 incoming.ondisconnecting = function ondisconnecting(event) { |
|
69 log("Received 'disconnecting' call event."); |
|
70 is(incoming, event.call); |
|
71 is(incoming.state, "disconnecting"); |
|
72 gotDisconnecting = true; |
|
73 }; |
|
74 |
|
75 incoming.ondisconnected = function ondisconnected(event) { |
|
76 log("Received 'disconnected' call event."); |
|
77 is(incoming, event.call); |
|
78 is(incoming.state, "disconnected"); |
|
79 ok(gotDisconnecting); |
|
80 |
|
81 is(telephony.active, null); |
|
82 is(telephony.calls.length, 0); |
|
83 |
|
84 emulator.run("gsm list", function(result) { |
|
85 log("Call list is now: " + result); |
|
86 is(result[0], "OK"); |
|
87 cleanUp(); |
|
88 }); |
|
89 }; |
|
90 incoming.hangUp(); |
|
91 } |
|
92 |
|
93 function cleanUp() { |
|
94 telephony.onincoming = null; |
|
95 finish(); |
|
96 } |
|
97 |
|
98 startTest(function() { |
|
99 simulateIncoming(); |
|
100 }); |