|
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 connection; |
|
8 |
|
9 function setRadioEnabled(enabled, callback) { |
|
10 let request = connection.setRadioEnabled(enabled); |
|
11 let desiredRadioState = enabled ? 'enabled' : 'disabled'; |
|
12 |
|
13 let pending = ['onradiostatechange', 'onsuccess']; |
|
14 let done = callback; |
|
15 |
|
16 connection.onradiostatechange = function() { |
|
17 let state = connection.radioState; |
|
18 log("Received 'radiostatechange' event, radioState: " + state); |
|
19 |
|
20 if (state == desiredRadioState) { |
|
21 gReceivedPending('onradiostatechange', pending, done); |
|
22 } |
|
23 }; |
|
24 |
|
25 request.onsuccess = function onsuccess() { |
|
26 gReceivedPending('onsuccess', pending, done); |
|
27 }; |
|
28 |
|
29 request.onerror = function onerror() { |
|
30 ok(false, "setRadioEnabled should be ok"); |
|
31 }; |
|
32 } |
|
33 |
|
34 function dial(number) { |
|
35 // Verify initial state before dial. |
|
36 ok(telephony); |
|
37 is(telephony.active, null); |
|
38 ok(telephony.calls); |
|
39 is(telephony.calls.length, 0); |
|
40 |
|
41 log("Make an outgoing call."); |
|
42 |
|
43 telephony.dial(number).then(null, cause => { |
|
44 log("Received promise 'reject'"); |
|
45 |
|
46 is(telephony.active, null); |
|
47 is(telephony.calls.length, 0); |
|
48 is(cause, "RadioNotAvailable"); |
|
49 |
|
50 emulator.run("gsm list", function(result) { |
|
51 log("Initial call list: " + result); |
|
52 is(result[0], "OK"); |
|
53 |
|
54 setRadioEnabled(true, cleanUp); |
|
55 }); |
|
56 }); |
|
57 } |
|
58 |
|
59 function cleanUp() { |
|
60 finish(); |
|
61 } |
|
62 |
|
63 startTestWithPermissions(['mobileconnection'], function() { |
|
64 connection = navigator.mozMobileConnections[0]; |
|
65 ok(connection instanceof MozMobileConnection, |
|
66 "connection is instanceof " + connection.constructor); |
|
67 |
|
68 setRadioEnabled(false, function() { |
|
69 dial("0912345678"); |
|
70 }); |
|
71 }); |