Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
1 /* Any copyright is dedicated to the Public Domain.
2 * http://creativecommons.org/publicdomain/zero/1.0/ */
4 MARIONETTE_TIMEOUT = 10000;
6 SpecialPowers.addPermission("fmradio", true, document);
7 SpecialPowers.addPermission("settings-read", true, document);
8 SpecialPowers.addPermission("settings-write", true, document);
10 let FMRadio = window.navigator.mozFMRadio;
11 let mozSettings = window.navigator.mozSettings;
12 let KEY = "airplaneMode.enabled";
14 function verifyInitialState() {
15 log("Verifying initial state.");
16 ok(FMRadio);
17 is(FMRadio.enabled, false);
18 ok(mozSettings);
20 checkAirplaneModeSettings();
21 }
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 };
31 req.onerror = function() {
32 ok(false, "Error occurs when reading settings value.");
33 finish();
34 };
35 }
37 function enableFMRadio() {
38 log("Enable FM radio");
39 let frequency = FMRadio.frequencyLowerBound + FMRadio.channelWidth;
40 let req = FMRadio.enable(frequency);
42 req.onsuccess = function() {
43 enableAirplaneMode();
44 };
46 req.onerror = function() {
47 ok(false, "Failed to enable FM radio.");
48 };
49 }
51 function enableAirplaneMode() {
52 log("Enable airplane mode");
53 FMRadio.ondisabled = function() {
54 FMRadio.ondisabled = null;
55 enableFMRadioWithAirplaneModeEnabled();
56 };
58 let settings = {};
59 settings[KEY] = true;
60 mozSettings.createLock().set(settings);
61 }
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();
69 req.onsuccess = function() {
70 ok(false, "FMRadio could be enabled when airplane mode is enabled.");
71 };
72 }
74 function cleanUp() {
75 let settings = {};
76 settings[KEY] = false;
77 let req = mozSettings.createLock().set(settings);
79 req.onsuccess = function() {
80 ok(!FMRadio.enabled);
81 finish();
82 };
84 req.onerror = function() {
85 ok(false, "Error occurs when setting value");
86 };
87 }
89 verifyInitialState();