| 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 with page visibility."); | 6 description("Test with page visibility."); |
| 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 mockBatteryInfo; | 18 var mockBatteryInfo; |
| 17 function setAndFireMockBatteryInfo(charging, chargingTime, dischargingTime, leve
l) { | 19 function setAndFireMockBatteryInfo(charging, chargingTime, dischargingTime, leve
l) { |
| 18 mockBatteryInfo = { charging: charging, | 20 mockBatteryInfo = { charging: charging, |
| 19 chargingTime: chargingTime, | 21 chargingTime: chargingTime, |
| 20 dischargingTime: dischargingTime, | 22 dischargingTime: dischargingTime, |
| 21 level: level }; | 23 level: level }; |
| 22 testRunner.didChangeBatteryStatus(charging, chargingTime, dischargingTime, l
evel); | 24 window.internals.updateBatteryStatus(charging, chargingTime, dischargingTime
, level); |
| 23 } | 25 } |
| 24 | 26 |
| 25 // compare obtained battery values with the mock values | 27 // compare obtained battery values with the mock values |
| 26 function checkBatteryInfo(batteryManager) { | 28 function checkBatteryInfo(batteryManager) { |
| 27 batteryInfo = batteryManager; | 29 batteryInfo = batteryManager; |
| 28 shouldBeDefined("batteryInfo"); | 30 shouldBeDefined("batteryInfo"); |
| 29 shouldBeDefined("mockBatteryInfo"); | 31 shouldBeDefined("mockBatteryInfo"); |
| 30 shouldBe('batteryInfo.charging', 'mockBatteryInfo.charging'); | 32 shouldBe('batteryInfo.charging', 'mockBatteryInfo.charging'); |
| 31 shouldBe('batteryInfo.chargingTime', 'mockBatteryInfo.chargingTime'); | 33 shouldBe('batteryInfo.chargingTime', 'mockBatteryInfo.chargingTime'); |
| 32 shouldBe('batteryInfo.dischargingTime', 'mockBatteryInfo.dischargingTime'); | 34 shouldBe('batteryInfo.dischargingTime', 'mockBatteryInfo.dischargingTime'); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 testFailed('received event while the page was hidden'); | 73 testFailed('received event while the page was hidden'); |
| 72 setTimeout(finishJSTest, 0); | 74 setTimeout(finishJSTest, 0); |
| 73 } | 75 } |
| 74 | 76 |
| 75 debug("page is visible"); | 77 debug("page is visible"); |
| 76 navigator.getBattery().then(batteryStatusSuccess, batteryStatusFailure); | 78 navigator.getBattery().then(batteryStatusSuccess, batteryStatusFailure); |
| 77 setAndFireMockBatteryInfo(false, 10, 20, 0.5); | 79 setAndFireMockBatteryInfo(false, 10, 20, 0.5); |
| 78 </script> | 80 </script> |
| 79 </body> | 81 </body> |
| 80 </html> | 82 </html> |
| OLD | NEW |