dom/fmradio/test/marionette/test_bug876597.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/fmradio/test/marionette/test_bug876597.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,90 @@
     1.4 +/* Any copyright is dedicated to the Public Domain.
     1.5 + * http://creativecommons.org/publicdomain/zero/1.0/ */
     1.6 +
     1.7 +MARIONETTE_TIMEOUT = 10000;
     1.8 +
     1.9 +SpecialPowers.addPermission("fmradio", true, document);
    1.10 +SpecialPowers.addPermission("settings-read", true, document);
    1.11 +SpecialPowers.addPermission("settings-write", true, document);
    1.12 +
    1.13 +let FMRadio = window.navigator.mozFMRadio;
    1.14 +let mozSettings = window.navigator.mozSettings;
    1.15 +let KEY = "airplaneMode.enabled";
    1.16 +
    1.17 +function verifyInitialState() {
    1.18 +  log("Verifying initial state.");
    1.19 +  ok(FMRadio);
    1.20 +  is(FMRadio.enabled, false);
    1.21 +  ok(mozSettings);
    1.22 +
    1.23 +  checkAirplaneModeSettings();
    1.24 +}
    1.25 +
    1.26 +function checkAirplaneModeSettings() {
    1.27 +  log("Checking airplane mode settings");
    1.28 +  let req = mozSettings.createLock().get(KEY);
    1.29 +  req.onsuccess = function(event) {
    1.30 +    ok(!req.result[KEY], "Airplane mode is disabled.");
    1.31 +    enableFMRadio();
    1.32 +  };
    1.33 +
    1.34 +  req.onerror = function() {
    1.35 +    ok(false, "Error occurs when reading settings value.");
    1.36 +    finish();
    1.37 +  };
    1.38 +}
    1.39 +
    1.40 +function enableFMRadio() {
    1.41 +  log("Enable FM radio");
    1.42 +  let frequency = FMRadio.frequencyLowerBound + FMRadio.channelWidth;
    1.43 +  let req = FMRadio.enable(frequency);
    1.44 +
    1.45 +  req.onsuccess = function() {
    1.46 +    enableAirplaneMode();
    1.47 +  };
    1.48 +
    1.49 +  req.onerror = function() {
    1.50 +    ok(false, "Failed to enable FM radio.");
    1.51 +  };
    1.52 +}
    1.53 +
    1.54 +function enableAirplaneMode() {
    1.55 +  log("Enable airplane mode");
    1.56 +  FMRadio.ondisabled = function() {
    1.57 +    FMRadio.ondisabled = null;
    1.58 +    enableFMRadioWithAirplaneModeEnabled();
    1.59 +  };
    1.60 +
    1.61 +  let settings = {};
    1.62 +  settings[KEY] = true;
    1.63 +  mozSettings.createLock().set(settings);
    1.64 +}
    1.65 +
    1.66 +function enableFMRadioWithAirplaneModeEnabled() {
    1.67 +  log("Enable FM radio with airplane mode enabled");
    1.68 +  let frequency = FMRadio.frequencyLowerBound + FMRadio.channelWidth;
    1.69 +  let req = FMRadio.enable(frequency);
    1.70 +  req.onerror = cleanUp();
    1.71 +
    1.72 +  req.onsuccess = function() {
    1.73 +    ok(false, "FMRadio could be enabled when airplane mode is enabled.");
    1.74 +  };
    1.75 +}
    1.76 +
    1.77 +function cleanUp() {
    1.78 +  let settings = {};
    1.79 +  settings[KEY] = false;
    1.80 +  let req = mozSettings.createLock().set(settings);
    1.81 +
    1.82 +  req.onsuccess = function() {
    1.83 +    ok(!FMRadio.enabled);
    1.84 +    finish();
    1.85 +  };
    1.86 +
    1.87 +  req.onerror = function() {
    1.88 +    ok(false, "Error occurs when setting value");
    1.89 +  };
    1.90 +}
    1.91 +
    1.92 +verifyInitialState();
    1.93 +

mercurial