4 <script src=
"../resources/js-test.js"></script>
6 description("Test basic API definitions.");
8 if (!window
.testRunner
)
9 debug('This test cannot be run without the TestRunner');
11 // Clean-up any unused battery manager objects from previous tests.
14 testRunner
.waitUntilDone();
17 function setAndFireMockBatteryInfo(charging
, chargingTime
, dischargingTime
, level
) {
18 mockBatteryInfo
= { charging
: charging
,
19 chargingTime
: chargingTime
,
20 dischargingTime
: dischargingTime
,
22 testRunner
.didChangeBatteryStatus(charging
, chargingTime
, dischargingTime
, level
);
26 function batteryStatusSuccess(batteryManager
) {
27 debug('batteryStatusSuccess invoked');
28 battery
= batteryManager
;
30 shouldBeDefined("battery");
31 shouldBeNonNull("battery");
32 shouldBeDefined("battery.charging");
33 shouldBeDefined("battery.chargingTime");
34 shouldBeDefined("battery.dischargingTime");
35 shouldBeDefined("battery.level");
37 shouldBe('battery.charging', 'mockBatteryInfo.charging');
38 shouldBe('battery.chargingTime', 'mockBatteryInfo.chargingTime');
39 shouldBe('battery.dischargingTime', 'mockBatteryInfo.dischargingTime');
40 shouldBe('battery.level', 'mockBatteryInfo.level');
42 shouldBeTrue("typeof battery.onchargingchange == 'object'");
43 shouldBeTrue("typeof battery.onchargingtimechange == 'object'");
44 shouldBeTrue("typeof battery.ondischargingtimechange == 'object'");
45 shouldBeTrue("typeof battery.onlevelchange == 'object'");
47 shouldBeTrue("'onchargingchange' in battery");
48 shouldBeTrue("'onchargingtimechange' in battery");
49 shouldBeTrue("'ondischargingtimechange' in battery");
50 shouldBeTrue("'onlevelchange' in battery");
52 setTimeout(finishJSTest
, 0);
55 function batteryStatusFailure() {
56 testFailed('failed to successfully resolve the promise');
57 setTimeout(finishJSTest
, 0);
60 promise
= navigator
.getBattery();
61 shouldBeDefined("promise");
62 shouldBeDefined("promise.then");
63 promise
.then(batteryStatusSuccess
, batteryStatusFailure
);
64 setAndFireMockBatteryInfo(false, 10, 20, 0.5);