gecko/dom/fmradio/test/marionette/test_bug876597.js
Pin Zhang ebbb894f25 Bug 997064 - Do not call navigator.mozFMRadio from system app. r=baku
- Revert "Bug 938015 - Do not turn off FM radio when enabling airplane mode."
- Use setting "airplaneMode.enabled" instead of "ril.radio.disabled"
2014-04-25 17:24:00 -04:00

91 lines
2.2 KiB
JavaScript

/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
MARIONETTE_TIMEOUT = 10000;
SpecialPowers.addPermission("fmradio", true, document);
SpecialPowers.addPermission("settings-read", true, document);
SpecialPowers.addPermission("settings-write", true, document);
let FMRadio = window.navigator.mozFMRadio;
let mozSettings = window.navigator.mozSettings;
let KEY = "airplaneMode.enabled";
function verifyInitialState() {
log("Verifying initial state.");
ok(FMRadio);
is(FMRadio.enabled, false);
ok(mozSettings);
checkAirplaneModeSettings();
}
function checkAirplaneModeSettings() {
log("Checking airplane mode settings");
let req = mozSettings.createLock().get(KEY);
req.onsuccess = function(event) {
ok(!req.result[KEY], "Airplane mode is disabled.");
enableFMRadio();
};
req.onerror = function() {
ok(false, "Error occurs when reading settings value.");
finish();
};
}
function enableFMRadio() {
log("Enable FM radio");
let frequency = FMRadio.frequencyLowerBound + FMRadio.channelWidth;
let req = FMRadio.enable(frequency);
req.onsuccess = function() {
enableAirplaneMode();
};
req.onerror = function() {
ok(false, "Failed to enable FM radio.");
};
}
function enableAirplaneMode() {
log("Enable airplane mode");
FMRadio.ondisabled = function() {
FMRadio.ondisabled = null;
enableFMRadioWithAirplaneModeEnabled();
};
let settings = {};
settings[KEY] = true;
mozSettings.createLock().set(settings);
}
function enableFMRadioWithAirplaneModeEnabled() {
log("Enable FM radio with airplane mode enabled");
let frequency = FMRadio.frequencyLowerBound + FMRadio.channelWidth;
let req = FMRadio.enable(frequency);
req.onerror = cleanUp();
req.onsuccess = function() {
ok(false, "FMRadio could be enabled when airplane mode is enabled.");
};
}
function cleanUp() {
let settings = {};
settings[KEY] = false;
let req = mozSettings.createLock().set(settings);
req.onsuccess = function() {
ok(!FMRadio.enabled);
finish();
};
req.onerror = function() {
ok(false, "Error occurs when setting value");
};
}
verifyInitialState();