4 <script src=
"../resources/js-test.js"></script>
6 description("Test multiple promise resolution.");
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();
15 testRunner
.setCanOpenWindows();
16 testRunner
.setCloseRemainingWindowsWhenComplete(true);
19 function setAndFireMockBatteryInfo(charging
, chargingTime
, dischargingTime
, level
) {
20 mockBatteryInfo
= { charging
: charging
,
21 chargingTime
: chargingTime
,
22 dischargingTime
: dischargingTime
,
24 testRunner
.didChangeBatteryStatus(charging
, chargingTime
, dischargingTime
, level
);
27 // compare obtained battery values with the mock values
28 function checkBatteryInfo(batteryManager
) {
29 batteryInfo
= batteryManager
;
30 shouldBeDefined("batteryInfo");
31 shouldBeDefined("mockBatteryInfo");
32 shouldBe('batteryInfo.charging', 'mockBatteryInfo.charging');
33 shouldBe('batteryInfo.chargingTime', 'mockBatteryInfo.chargingTime');
34 shouldBe('batteryInfo.dischargingTime', 'mockBatteryInfo.dischargingTime');
35 shouldBe('batteryInfo.level', 'mockBatteryInfo.level');
38 function batteryStatusFailure() {
39 testFailed('failed to successfully resolve the promise');
40 setTimeout(finishJSTest
, 0);
43 var promise1Count
= 0;
44 var promise2Count
= 0;
46 function finishIfReady() {
47 if (promise1Count
== 1 && promise2Count
== 1)
48 setTimeout(finishJSTest
, 0);
51 promise1
= navigator
.getBattery();
54 debug('first resolution');
55 checkBatteryInfo(battery
);
58 }, batteryStatusFailure
);
60 promise2
= navigator
.getBattery();
63 debug('second resolution');
64 checkBatteryInfo(battery
);
67 }, batteryStatusFailure
);
69 shouldBeTrue('promise1 === promise2');
70 setAndFireMockBatteryInfo(false, 10, 20, 0.5);