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