|
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 outgoing; |
|
9 |
|
10 function dial() { |
|
11 log("Make an outgoing call."); |
|
12 |
|
13 telephony.oncallschanged = function oncallschanged(event) { |
|
14 log("Received 'callschanged' call event."); |
|
15 |
|
16 if (!event.call) { |
|
17 log("Notifying calls array is loaded. No call information accompanies."); |
|
18 return; |
|
19 } |
|
20 |
|
21 let expected_states = ["dialing", "disconnected"]; |
|
22 ok(expected_states.indexOf(event.call.state) != -1, |
|
23 "Unexpected call state: " + event.call.state); |
|
24 |
|
25 if (event.call.state == "dialing") { |
|
26 outgoing = event.call; |
|
27 ok(outgoing); |
|
28 is(outgoing.number, number); |
|
29 |
|
30 is(outgoing, telephony.active); |
|
31 is(telephony.calls.length, 1); |
|
32 is(telephony.calls[0], outgoing); |
|
33 |
|
34 checkCallList(); |
|
35 } |
|
36 |
|
37 if (event.call.state == "disconnected") { |
|
38 is(outgoing.state, "disconnected"); |
|
39 is(telephony.active, null); |
|
40 is(telephony.calls.length, 0); |
|
41 cleanUp(); |
|
42 } |
|
43 }; |
|
44 |
|
45 telephony.dial(number); |
|
46 } |
|
47 |
|
48 function checkCallList() { |
|
49 emulator.run("gsm list", function(result) { |
|
50 log("Call list is now: " + result); |
|
51 if ((result[0] == "outbound to " + number + " : unknown") && (result[1] == "OK")) { |
|
52 answer(); |
|
53 } else { |
|
54 window.setTimeout(checkCallList, 100); |
|
55 } |
|
56 }); |
|
57 } |
|
58 |
|
59 function answer() { |
|
60 log("Answering the outgoing call."); |
|
61 |
|
62 // We get no "connecting" event when the remote party answers the call. |
|
63 |
|
64 outgoing.onconnected = function onconnected(event) { |
|
65 log("Received 'connected' call event."); |
|
66 is(outgoing, event.call); |
|
67 is(outgoing.state, "connected"); |
|
68 |
|
69 is(outgoing, telephony.active); |
|
70 |
|
71 emulator.run("gsm list", function(result) { |
|
72 log("Call list (after 'connected' event) is now: " + result); |
|
73 is(result[0], "outbound to " + number + " : active"); |
|
74 is(result[1], "OK"); |
|
75 hangUp(); |
|
76 }); |
|
77 }; |
|
78 emulator.run("gsm accept " + number); |
|
79 } |
|
80 |
|
81 function hangUp() { |
|
82 log("Hanging up the outgoing call."); |
|
83 |
|
84 emulator.run("gsm cancel " + number); |
|
85 } |
|
86 |
|
87 function cleanUp() { |
|
88 telephony.oncallschanged = null; |
|
89 finish(); |
|
90 } |
|
91 |
|
92 startTest(function() { |
|
93 dial(); |
|
94 }); |