dom/battery/test/marionette/test_battery_level.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     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;
     8 function verifyInitialState() {
     9   ok(battery, "battery");
    10   is(battery.level, 0.5, "battery.level");
    11   runEmulatorCmd("power display", function (result) {
    12     is(result.pop(), "OK", "power display successful");
    13     ok(result.indexOf("capacity: 50") !== -1, "power capacity");
    14     setUp();
    15   });
    16 }
    18 function unexpectedEvent(event) {
    19   ok(false, "Unexpected " + event.type + " event");
    20 }
    22 function setUp() {
    23   battery.onchargingchange = unexpectedEvent;
    24   battery.onlevelchange = unexpectedEvent;
    25   levelUp();
    26 }
    28 function changeCapacity(capacity, changeExpected, nextFunction) {
    29   log("Changing power capacity to " + capacity);
    30   if (changeExpected) {
    31     battery.onlevelchange = function (event) {
    32      battery.onlevelchange = unexpectedEvent;
    33      is(event.type, "levelchange", "event.type");
    34      is(battery.level, capacity / 100, "battery.level");
    35      nextFunction();
    36     };
    37     runEmulatorCmd("power capacity " + capacity);
    38   }
    39   else {
    40     runEmulatorCmd("power capacity " + capacity, function () {
    41       is(battery.level, capacity / 100, "battery.level");
    42       nextFunction();
    43     });
    44   }
    45 }
    47 function levelUp() {
    48   changeCapacity("90", true, levelDown);
    49 }
    51 function levelDown() {
    52   changeCapacity("10", true, levelSame);
    53 }
    55 function levelSame() {
    56   changeCapacity("10", false, cleanUp);
    57 }
    59 function cleanUp() {
    60   battery.onchargingchange = null;
    61   battery.onlevelchange = function () {
    62     battery.onlevelchange = null;
    63     finish();
    64   };
    65   runEmulatorCmd("power capacity 50");
    66 }
    68 verifyInitialState();

mercurial