Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
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 | let battery = window.navigator.battery; |
michael@0 | 7 | |
michael@0 | 8 | function verifyInitialState() { |
michael@0 | 9 | ok(battery, "battery"); |
michael@0 | 10 | is(battery.level, 0.5, "battery.level"); |
michael@0 | 11 | runEmulatorCmd("power display", function (result) { |
michael@0 | 12 | is(result.pop(), "OK", "power display successful"); |
michael@0 | 13 | ok(result.indexOf("capacity: 50") !== -1, "power capacity"); |
michael@0 | 14 | setUp(); |
michael@0 | 15 | }); |
michael@0 | 16 | } |
michael@0 | 17 | |
michael@0 | 18 | function unexpectedEvent(event) { |
michael@0 | 19 | ok(false, "Unexpected " + event.type + " event"); |
michael@0 | 20 | } |
michael@0 | 21 | |
michael@0 | 22 | function setUp() { |
michael@0 | 23 | battery.onchargingchange = unexpectedEvent; |
michael@0 | 24 | battery.onlevelchange = unexpectedEvent; |
michael@0 | 25 | levelUp(); |
michael@0 | 26 | } |
michael@0 | 27 | |
michael@0 | 28 | function changeCapacity(capacity, changeExpected, nextFunction) { |
michael@0 | 29 | log("Changing power capacity to " + capacity); |
michael@0 | 30 | if (changeExpected) { |
michael@0 | 31 | battery.onlevelchange = function (event) { |
michael@0 | 32 | battery.onlevelchange = unexpectedEvent; |
michael@0 | 33 | is(event.type, "levelchange", "event.type"); |
michael@0 | 34 | is(battery.level, capacity / 100, "battery.level"); |
michael@0 | 35 | nextFunction(); |
michael@0 | 36 | }; |
michael@0 | 37 | runEmulatorCmd("power capacity " + capacity); |
michael@0 | 38 | } |
michael@0 | 39 | else { |
michael@0 | 40 | runEmulatorCmd("power capacity " + capacity, function () { |
michael@0 | 41 | is(battery.level, capacity / 100, "battery.level"); |
michael@0 | 42 | nextFunction(); |
michael@0 | 43 | }); |
michael@0 | 44 | } |
michael@0 | 45 | } |
michael@0 | 46 | |
michael@0 | 47 | function levelUp() { |
michael@0 | 48 | changeCapacity("90", true, levelDown); |
michael@0 | 49 | } |
michael@0 | 50 | |
michael@0 | 51 | function levelDown() { |
michael@0 | 52 | changeCapacity("10", true, levelSame); |
michael@0 | 53 | } |
michael@0 | 54 | |
michael@0 | 55 | function levelSame() { |
michael@0 | 56 | changeCapacity("10", false, cleanUp); |
michael@0 | 57 | } |
michael@0 | 58 | |
michael@0 | 59 | function cleanUp() { |
michael@0 | 60 | battery.onchargingchange = null; |
michael@0 | 61 | battery.onlevelchange = function () { |
michael@0 | 62 | battery.onlevelchange = null; |
michael@0 | 63 | finish(); |
michael@0 | 64 | }; |
michael@0 | 65 | runEmulatorCmd("power capacity 50"); |
michael@0 | 66 | } |
michael@0 | 67 | |
michael@0 | 68 | verifyInitialState(); |