OLD | NEW |
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <html> | 2 <html> |
3 <body> | 3 <body> |
4 <script src="../resources/js-test.js"></script> | 4 <script src="../resources/js-test.js"></script> |
5 <script> | 5 <script> |
6 description("Test to ensure level is reported with restricted precision."); | 6 description("Test to ensure level is reported with restricted precision."); |
7 | 7 |
8 if (!window.testRunner) | 8 if (!window.testRunner) |
9 debug('This test cannot be run without the TestRunner'); | 9 debug('This test cannot be run without the TestRunner'); |
| 10 if (!window.internals) |
| 11 debug('This test cannot be run without the window.internals'); |
10 | 12 |
11 // Clean-up any unused battery manager objects from previous tests. | 13 // Clean-up any unused battery manager objects from previous tests. |
12 gc(); | 14 gc(); |
13 jsTestIsAsync = true; | 15 jsTestIsAsync = true; |
14 testRunner.waitUntilDone(); | 16 testRunner.waitUntilDone(); |
15 | 17 |
16 var levelFullPrecision = 0.556789; | 18 var levelFullPrecision = 0.556789; |
17 var levelRounded = 0.56; | 19 var levelRounded = 0.56; |
18 | 20 |
19 function setAndFireMockBatteryInfo(charging, chargingTime, dischargingTime, leve
l) { | 21 function setAndFireMockBatteryInfo(charging, chargingTime, dischargingTime, leve
l) { |
20 testRunner.didChangeBatteryStatus(charging, chargingTime, dischargingTime, l
evel); | 22 window.internals.updateBatteryStatus(charging, chargingTime, dischargingTime
, level); |
21 } | 23 } |
22 | 24 |
23 var battery; | 25 var battery; |
24 function batteryStatusSuccess(batteryManager) { | 26 function batteryStatusSuccess(batteryManager) { |
25 debug('batteryStatusSuccess invoked'); | 27 debug('batteryStatusSuccess invoked'); |
26 battery = batteryManager; | 28 battery = batteryManager; |
27 shouldBe('battery.level', 'levelRounded'); | 29 shouldBe('battery.level', 'levelRounded'); |
28 setTimeout(finishJSTest, 0); | 30 setTimeout(finishJSTest, 0); |
29 } | 31 } |
30 | 32 |
31 function batteryStatusFailure() { | 33 function batteryStatusFailure() { |
32 testFailed('failed to successfully resolve the promise'); | 34 testFailed('failed to successfully resolve the promise'); |
33 setTimeout(finishJSTest, 0); | 35 setTimeout(finishJSTest, 0); |
34 } | 36 } |
35 | 37 |
36 navigator.getBattery().then(batteryStatusSuccess, batteryStatusFailure); | 38 navigator.getBattery().then(batteryStatusSuccess, batteryStatusFailure); |
37 setAndFireMockBatteryInfo(false, 10, 20, levelFullPrecision); | 39 setAndFireMockBatteryInfo(false, 10, 20, levelFullPrecision); |
38 </script> | 40 </script> |
39 </body> | 41 </body> |
40 </html> | 42 </html> |
OLD | NEW |