|
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 |
|
15 log("Verifying attributes when disabled."); |
|
16 is(FMRadio.frequency, null); |
|
17 ok(FMRadio.frequencyLowerBound); |
|
18 ok(FMRadio.frequencyUpperBound); |
|
19 ok(FMRadio.frequencyUpperBound > FMRadio.frequencyLowerBound); |
|
20 ok(FMRadio.channelWidth); |
|
21 |
|
22 enableFMRadio(); |
|
23 } |
|
24 |
|
25 function enableFMRadio() { |
|
26 log("Verifying behaviors when enabled."); |
|
27 var frequency = FMRadio.frequencyLowerBound + FMRadio.channelWidth; |
|
28 var request = FMRadio.enable(frequency); |
|
29 ok(request, "FMRadio.enable(r" + frequency + ") returns request"); |
|
30 |
|
31 request.onsuccess = function() { |
|
32 ok(FMRadio.enabled); |
|
33 ok(typeof FMRadio.frequency == "number"); |
|
34 ok(FMRadio.frequency > FMRadio.frequencyLowerBound); |
|
35 }; |
|
36 |
|
37 request.onerror = function() { |
|
38 ok(null, "Failed to enable"); |
|
39 }; |
|
40 |
|
41 var enabled = false; |
|
42 FMRadio.onenabled = function() { |
|
43 FMRadio.onenabled = null; |
|
44 enabled = FMRadio.enabled; |
|
45 }; |
|
46 |
|
47 FMRadio.onfrequencychange = function() { |
|
48 log("Check if 'onfrequencychange' event is fired after the 'enabled' event"); |
|
49 FMRadio.onfrequencychange = null; |
|
50 ok(enabled, "FMRadio is enabled when handling `onfrequencychange`"); |
|
51 disableFMRadio(); |
|
52 }; |
|
53 } |
|
54 |
|
55 function disableFMRadio() { |
|
56 log("Verify behaviors when disabled"); |
|
57 |
|
58 // There are two possibilities which depends on the system |
|
59 // process scheduling (bug 911063 comment 0): |
|
60 // - seek fails |
|
61 // - seek's onsuccess fires before disable's onsucess |
|
62 var seekRequest = FMRadio.seekUp(); |
|
63 var seekCompletes = false; |
|
64 var failedToSeek = false; |
|
65 seekRequest.onerror = function() { |
|
66 ok(!seekCompletes); |
|
67 failedToSeek = true; |
|
68 }; |
|
69 |
|
70 seekRequest.onsuccess = function() { |
|
71 ok(!failedToSeek); |
|
72 seekCompletes = true; |
|
73 }; |
|
74 |
|
75 FMRadio.disable(); |
|
76 FMRadio.ondisabled = function() { |
|
77 FMRadio.ondisabled = null; |
|
78 ok(seekCompletes || failedToSeek); |
|
79 ok(!FMRadio.enabled); |
|
80 finish(); |
|
81 }; |
|
82 } |
|
83 |
|
84 verifyInitialState(); |
|
85 |