dom/battery/test/marionette/test_battery_status_full.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.

     1 /* Any copyright is dedicated to the Public Domain.
     2  * http://creativecommons.org/publicdomain/zero/1.0/ */
     4 MARIONETTE_TIMEOUT = 10000;
     6 let battery = window.navigator.battery;
     7 let fromStatus = "full";
     8 let fromCharging = true;
    10 function verifyInitialState() {
    11   ok(battery, "battery");
    12   ok(battery.charging, "battery.charging");
    13   runEmulatorCmd("power display", function (result) {
    14     is(result.pop(), "OK", "power display successful");
    15     ok(result.indexOf("status: Charging") !== -1, "power status charging");
    16     setUp();
    17   });
    18 }
    20 function unexpectedEvent(event) {
    21   ok(false, "Unexpected " + event.type + " event");
    22 }
    24 function setUp() {
    25   battery.onchargingchange = unexpectedEvent;
    26   battery.onlevelchange = unexpectedEvent;
    27   log("Changing power status to " + fromStatus);
    28   runEmulatorCmd("power status " + fromStatus, toCharging);
    29 }
    31 function resetStatus(charging, nextFunction) {
    32   log("Resetting power status to " + fromStatus);
    33   if (charging !== fromCharging) {
    34     battery.onchargingchange = function () {
    35       battery.onchargingchange = unexpectedEvent;
    36       nextFunction();
    37     };
    38     runEmulatorCmd("power status " + fromStatus);
    39   }
    40   else {
    41     runEmulatorCmd("power status " + fromStatus, nextFunction);
    42   }
    43 }
    45 function changeStatus(toStatus, toCharging, nextFunction) {
    46   log("Changing power status to " + toStatus);
    47   if (fromCharging !== toCharging) {
    48     battery.onchargingchange = function (event) {
    49       battery.onchargingchange = unexpectedEvent;
    50       is(event.type, "chargingchange", "event type");
    51       is(battery.charging, toCharging, "battery.charging");
    52       resetStatus(toCharging, nextFunction);
    53     };
    54     runEmulatorCmd("power status " + toStatus);
    55   }
    56   else {
    57     runEmulatorCmd("power status " + toStatus, function () {
    58       is(battery.charging, toCharging, "battery.charging");
    59       resetStatus(toCharging, nextFunction);
    60     });
    61   }
    62 }
    64 function toCharging() {
    65   changeStatus("charging", true, toDischarging);
    66 }
    68 function toDischarging() {
    69   changeStatus("discharging", false, toNotCharging);
    70 }
    72 function toNotCharging() {
    73   changeStatus("not-charging", false, toUnknown);
    74 }
    76 function toUnknown() {
    77   changeStatus("unknown", false, cleanUp);
    78 }
    80 function cleanUp() {
    81   battery.onchargingchange = null;
    82   battery.onlevelchange = null;
    83   log("Resetting power status to charging");
    84   runEmulatorCmd("power status charging", finish);
    85 }
    87 verifyInitialState();

mercurial