dom/fmradio/test/marionette/test_bug876597.js

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

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

mercurial