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.
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 = "charging";
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 toDischarging();
28 }
30 function resetStatus(charging, nextFunction) {
31 log("Resetting power status to " + fromStatus);
32 if (charging !== fromCharging) {
33 battery.onchargingchange = function () {
34 battery.onchargingchange = unexpectedEvent;
35 nextFunction();
36 };
37 runEmulatorCmd("power status " + fromStatus);
38 }
39 else {
40 runEmulatorCmd("power status " + fromStatus, nextFunction);
41 }
42 }
44 function changeStatus(toStatus, toCharging, nextFunction) {
45 log("Changing power status to " + toStatus);
46 if (fromCharging !== toCharging) {
47 battery.onchargingchange = function (event) {
48 battery.onchargingchange = unexpectedEvent;
49 is(event.type, "chargingchange", "event type");
50 is(battery.charging, toCharging, "battery.charging");
51 resetStatus(toCharging, nextFunction);
52 };
53 runEmulatorCmd("power status " + toStatus);
54 }
55 else {
56 runEmulatorCmd("power status " + toStatus, function () {
57 is(battery.charging, toCharging, "battery.charging");
58 resetStatus(toCharging, nextFunction);
59 });
60 }
61 }
63 function toDischarging() {
64 changeStatus("discharging", false, toFull);
65 }
67 function toFull() {
68 changeStatus("full", true, toNotCharging);
69 }
71 function toNotCharging() {
72 changeStatus("not-charging", false, toUnknown);
73 }
75 function toUnknown() {
76 changeStatus("unknown", false, cleanUp);
77 }
79 function cleanUp() {
80 battery.onchargingchange = null;
81 battery.onlevelchange = null;
82 finish();
83 }
85 verifyInitialState();