|
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 incomingCall; |
|
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 let gotConnecting = false; |
|
37 incomingCall.onconnecting = function onconnectingIn(event) { |
|
38 log("Received 'connecting' call event for incoming call."); |
|
39 is(incomingCall, event.call); |
|
40 is(incomingCall.state, "connecting"); |
|
41 gotConnecting = true; |
|
42 }; |
|
43 |
|
44 incomingCall.onconnected = function onconnectedIn(event) { |
|
45 log("Received 'connected' call event for incoming call."); |
|
46 is(incomingCall, event.call); |
|
47 is(incomingCall.state, "connected"); |
|
48 ok(gotConnecting); |
|
49 |
|
50 is(incomingCall, telephony.active); |
|
51 |
|
52 emulator.run("gsm list", function(result) { |
|
53 log("Call list is now: " + result); |
|
54 is(result[0], "inbound from " + inNumber + " : active"); |
|
55 is(result[1], "OK"); |
|
56 remoteHangUp(); |
|
57 }); |
|
58 }; |
|
59 incomingCall.answer(); |
|
60 } |
|
61 |
|
62 function remoteHangUp() { |
|
63 log("Hanging up the call (remotely)"); |
|
64 |
|
65 // We get no 'disconnecting' event when remote party hangs-up the call |
|
66 |
|
67 incomingCall.ondisconnected = function ondisconnected(event) { |
|
68 log("Received 'disconnected' call event."); |
|
69 is(incomingCall, event.call); |
|
70 is(incomingCall.state, "disconnected"); |
|
71 |
|
72 is(telephony.active, null); |
|
73 is(telephony.calls.length, 0); |
|
74 |
|
75 emulator.run("gsm list", function(result) { |
|
76 log("Call list is now: " + result); |
|
77 is(result[0], "OK"); |
|
78 cleanUp(); |
|
79 }); |
|
80 }; |
|
81 emulator.run("gsm cancel " + inNumber); |
|
82 } |
|
83 |
|
84 function cleanUp() { |
|
85 telephony.onincoming = null; |
|
86 finish(); |
|
87 } |
|
88 |
|
89 startTest(function() { |
|
90 simulateIncoming(); |
|
91 }); |