| <!DOCTYPE html> |
| <html> |
| <body> |
| <script src="../resources/js-test.js"></script> |
| <script src="file:///gen/layout_test_data/mojo/public/js/mojo_bindings.js"></script> |
| <script src="file:///gen/services/device/public/interfaces/battery_monitor.mojom.js"></script> |
| <script src="resources/mock-battery-monitor.js"></script> |
| <script> |
| description("Test with page visibility."); |
| |
| if (!window.testRunner) |
| debug('This test cannot be run without the TestRunner'); |
| |
| // Clean-up any unused battery manager objects from previous tests. |
| gc(); |
| jsTestIsAsync = true; |
| testRunner.waitUntilDone(); |
| |
| var battery; |
| function batteryStatusSuccess(batteryManager) { |
| battery = batteryManager; |
| testIfBatteryStatusIsUpToDate(battery); |
| battery.addEventListener('levelchange', failAndFinish); |
| testRunner.setPageVisibility("hidden"); |
| debug("page is hidden"); |
| setTimeout(fireNextMockBatteryInfo, 0); |
| } |
| |
| function fireNextMockBatteryInfo() { |
| setAndFireMockBatteryInfo(false, 10, 20, 0.55); |
| testWithVisiblePage(); |
| } |
| |
| function testWithVisiblePage() { |
| battery.removeEventListener('levelchange', failAndFinish); |
| battery.addEventListener('levelchange', onLevelChange); |
| testRunner.setPageVisibility("visible"); |
| debug("page is visible"); |
| setAndFireMockBatteryInfo(false, 10, 20, 0.6); |
| } |
| |
| function onLevelChange() { |
| testIfBatteryStatusIsUpToDate(battery); |
| battery.removeEventListener('levelchange', onLevelChange); |
| setTimeout(finishJSTest, 0); |
| } |
| |
| function failAndFinish() { |
| testFailed('received event while the page was hidden'); |
| setTimeout(finishJSTest, 0); |
| } |
| |
| debug("page is visible"); |
| navigator.getBattery().then(batteryStatusSuccess, batteryStatusFailure); |
| setAndFireMockBatteryInfo(false, 10, 20, 0.5); |
| </script> |
| </body> |
| </html> |