|
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 let calls; |
|
10 |
|
11 function dial() { |
|
12 log("Make an outgoing call."); |
|
13 |
|
14 telephony.dial(number).then(call => { |
|
15 outgoing = call; |
|
16 ok(outgoing); |
|
17 is(outgoing.number, number); |
|
18 is(outgoing.state, "dialing"); |
|
19 is(outgoing, telephony.active); |
|
20 //ok(telephony.calls === calls); // bug 717414 |
|
21 is(telephony.calls.length, 1); |
|
22 is(telephony.calls[0], outgoing); |
|
23 |
|
24 outgoing.onalerting = function onalerting(event) { |
|
25 log("Received 'onalerting' call event."); |
|
26 is(outgoing, event.call); |
|
27 is(outgoing.state, "alerting"); |
|
28 |
|
29 emulator.run("gsm list", function(result) { |
|
30 log("Call list is now: " + result); |
|
31 is(result[0], "outbound to " + number + " : ringing"); |
|
32 is(result[1], "OK"); |
|
33 answer(); |
|
34 }); |
|
35 }; |
|
36 }); |
|
37 } |
|
38 |
|
39 function answer() { |
|
40 log("Answering the outgoing call."); |
|
41 |
|
42 // We get no "connecting" event when the remote party answers the call. |
|
43 |
|
44 outgoing.onconnected = function onconnected(event) { |
|
45 log("Received 'connected' call event."); |
|
46 is(outgoing, event.call); |
|
47 is(outgoing.state, "connected"); |
|
48 |
|
49 is(outgoing, telephony.active); |
|
50 |
|
51 emulator.run("gsm list", function(result) { |
|
52 log("Call list is now: " + result); |
|
53 is(result[0], "outbound to " + number + " : active"); |
|
54 is(result[1], "OK"); |
|
55 hold(); |
|
56 }); |
|
57 }; |
|
58 emulator.run("gsm accept " + number); |
|
59 } |
|
60 |
|
61 function hold() { |
|
62 log("Holding the outgoing call."); |
|
63 |
|
64 outgoing.onholding = function onholding(event) { |
|
65 log("Received 'holding' call event."); |
|
66 is(outgoing, event.call); |
|
67 is(outgoing.state, "holding"); |
|
68 |
|
69 is(outgoing, telephony.active); |
|
70 }; |
|
71 |
|
72 outgoing.onheld = function onheld(event) { |
|
73 log("Received 'held' call event."); |
|
74 is(outgoing, event.call); |
|
75 is(outgoing.state, "held"); |
|
76 |
|
77 is(telephony.active, null); |
|
78 is(telephony.calls.length, 1); |
|
79 |
|
80 emulator.run("gsm list", function(result) { |
|
81 log("Call list is now: " + result); |
|
82 is(result[0], "outbound to " + number + " : held"); |
|
83 is(result[1], "OK"); |
|
84 hangUp(); |
|
85 }); |
|
86 }; |
|
87 outgoing.hold(); |
|
88 } |
|
89 |
|
90 function hangUp() { |
|
91 log("Hanging up the outgoing call."); |
|
92 |
|
93 let gotDisconnecting = false; |
|
94 outgoing.ondisconnecting = function ondisconnecting(event) { |
|
95 log("Received disconnecting call event."); |
|
96 is(outgoing, event.call); |
|
97 is(outgoing.state, "disconnecting"); |
|
98 gotDisconnecting = true; |
|
99 }; |
|
100 |
|
101 outgoing.ondisconnected = function ondisconnected(event) { |
|
102 log("Received 'disconnected' call event."); |
|
103 is(outgoing, event.call); |
|
104 is(outgoing.state, "disconnected"); |
|
105 ok(gotDisconnecting); |
|
106 |
|
107 is(telephony.active, null); |
|
108 is(telephony.calls.length, 0); |
|
109 |
|
110 emulator.run("gsm list", function(result) { |
|
111 log("Call list is now: " + result); |
|
112 is(result[0], "OK"); |
|
113 cleanUp(); |
|
114 }); |
|
115 }; |
|
116 |
|
117 outgoing.hangUp(); |
|
118 } |
|
119 |
|
120 function cleanUp() { |
|
121 finish(); |
|
122 } |
|
123 |
|
124 startTest(function() { |
|
125 dial(); |
|
126 }); |