|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 * http://creativecommons.org/publicdomain/zero/1.0/ */ |
|
3 |
|
4 MARIONETTE_TIMEOUT = 10000; |
|
5 |
|
6 SpecialPowers.addPermission("fmradio", true, document); |
|
7 |
|
8 let FMRadio = window.navigator.mozFMRadio; |
|
9 |
|
10 function verifyInitialState() { |
|
11 log("Verifying initial state."); |
|
12 ok(FMRadio); |
|
13 is(FMRadio.enabled, false); |
|
14 enableThenDisable(); |
|
15 } |
|
16 |
|
17 function enableThenDisable() { |
|
18 log("Enable FM Radio and disable it immediately."); |
|
19 var frequency = FMRadio.frequencyLowerBound + FMRadio.channelWidth; |
|
20 var request = FMRadio.enable(frequency); |
|
21 ok(request); |
|
22 |
|
23 var failedToEnable = false; |
|
24 request.onerror = function() { |
|
25 failedToEnable = true; |
|
26 }; |
|
27 |
|
28 var enableCompleted = false; |
|
29 request.onsuccess = function() { |
|
30 ok(!failedToEnable); |
|
31 enableCompleted = true; |
|
32 }; |
|
33 |
|
34 var disableReq = FMRadio.disable(); |
|
35 ok(disableReq); |
|
36 |
|
37 disableReq.onsuccess = function() { |
|
38 // There are two possibilities which depends on the system |
|
39 // process scheduling (bug 911063 comment 0): |
|
40 // - enable fails |
|
41 // - enable's onsuccess fires before disable's onsucess |
|
42 ok(failedToEnable || enableCompleted); |
|
43 ok(!FMRadio.enabled); |
|
44 finish(); |
|
45 }; |
|
46 |
|
47 disableReq.onerror = function() { |
|
48 ok(false, "Disable request should not fail."); |
|
49 }; |
|
50 } |
|
51 |
|
52 verifyInitialState(); |
|
53 |