|
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 SpecialPowers.addPermission("settings-read", true, document); |
|
8 SpecialPowers.addPermission("settings-write", true, document); |
|
9 |
|
10 let FMRadio = window.navigator.mozFMRadio; |
|
11 let mozSettings = window.navigator.mozSettings; |
|
12 let KEY = "airplaneMode.enabled"; |
|
13 |
|
14 function verifyInitialState() { |
|
15 log("Verifying initial state."); |
|
16 ok(FMRadio); |
|
17 is(FMRadio.enabled, false); |
|
18 ok(mozSettings); |
|
19 |
|
20 checkAirplaneModeSettings(); |
|
21 } |
|
22 |
|
23 function checkAirplaneModeSettings() { |
|
24 log("Checking airplane mode settings"); |
|
25 let req = mozSettings.createLock().get(KEY); |
|
26 req.onsuccess = function(event) { |
|
27 ok(!req.result[KEY], "Airplane mode is disabled."); |
|
28 enableFMRadio(); |
|
29 }; |
|
30 |
|
31 req.onerror = function() { |
|
32 ok(false, "Error occurs when reading settings value."); |
|
33 finish(); |
|
34 }; |
|
35 } |
|
36 |
|
37 function enableFMRadio() { |
|
38 log("Enable FM radio"); |
|
39 let frequency = FMRadio.frequencyLowerBound + FMRadio.channelWidth; |
|
40 let req = FMRadio.enable(frequency); |
|
41 |
|
42 req.onsuccess = function() { |
|
43 enableAirplaneMode(); |
|
44 }; |
|
45 |
|
46 req.onerror = function() { |
|
47 ok(false, "Failed to enable FM radio."); |
|
48 }; |
|
49 } |
|
50 |
|
51 function enableAirplaneMode() { |
|
52 log("Enable airplane mode"); |
|
53 FMRadio.ondisabled = function() { |
|
54 FMRadio.ondisabled = null; |
|
55 enableFMRadioWithAirplaneModeEnabled(); |
|
56 }; |
|
57 |
|
58 let settings = {}; |
|
59 settings[KEY] = true; |
|
60 mozSettings.createLock().set(settings); |
|
61 } |
|
62 |
|
63 function enableFMRadioWithAirplaneModeEnabled() { |
|
64 log("Enable FM radio with airplane mode enabled"); |
|
65 let frequency = FMRadio.frequencyLowerBound + FMRadio.channelWidth; |
|
66 let req = FMRadio.enable(frequency); |
|
67 req.onerror = cleanUp(); |
|
68 |
|
69 req.onsuccess = function() { |
|
70 ok(false, "FMRadio could be enabled when airplane mode is enabled."); |
|
71 }; |
|
72 } |
|
73 |
|
74 function cleanUp() { |
|
75 let settings = {}; |
|
76 settings[KEY] = false; |
|
77 let req = mozSettings.createLock().set(settings); |
|
78 |
|
79 req.onsuccess = function() { |
|
80 ok(!FMRadio.enabled); |
|
81 finish(); |
|
82 }; |
|
83 |
|
84 req.onerror = function() { |
|
85 ok(false, "Error occurs when setting value"); |
|
86 }; |
|
87 } |
|
88 |
|
89 verifyInitialState(); |
|
90 |