Index: third_party/WebKit/LayoutTests/battery-status/page-visibility.html |
diff --git a/third_party/WebKit/LayoutTests/battery-status/page-visibility.html b/third_party/WebKit/LayoutTests/battery-status/page-visibility.html |
index 028a42bcf2feb6d97e16d4d1acba87b989aabb1d..440a02ec79ba996e5638c84135f7d96fd66af98a 100644 |
--- a/third_party/WebKit/LayoutTests/battery-status/page-visibility.html |
+++ b/third_party/WebKit/LayoutTests/battery-status/page-visibility.html |
@@ -2,48 +2,23 @@ |
<html> |
<body> |
<script src="../resources/js-test.js"></script> |
+<script src="../resources/mojo-helpers.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'); |
-if (!window.internals) |
- debug('This test cannot be run without the window.internals'); |
// Clean-up any unused battery manager objects from previous tests. |
gc(); |
jsTestIsAsync = true; |
testRunner.waitUntilDone(); |
-var mockBatteryInfo; |
-function setAndFireMockBatteryInfo(charging, chargingTime, dischargingTime, level) { |
- mockBatteryInfo = { charging: charging, |
- chargingTime: chargingTime, |
- dischargingTime: dischargingTime, |
- level: level }; |
- window.internals.updateBatteryStatus(charging, chargingTime, dischargingTime, level); |
-} |
- |
-// compare obtained battery values with the mock values |
-function checkBatteryInfo(batteryManager) { |
- batteryInfo = batteryManager; |
- shouldBeDefined("batteryInfo"); |
- shouldBeDefined("mockBatteryInfo"); |
- shouldBe('batteryInfo.charging', 'mockBatteryInfo.charging'); |
- shouldBe('batteryInfo.chargingTime', 'mockBatteryInfo.chargingTime'); |
- shouldBe('batteryInfo.dischargingTime', 'mockBatteryInfo.dischargingTime'); |
- shouldBe('batteryInfo.level', 'mockBatteryInfo.level'); |
-} |
- |
-function batteryStatusFailure() { |
- testFailed('failed to successfully resolve the promise'); |
- setTimeout(cleanupAndFinish, 0); |
-} |
- |
var battery; |
function batteryStatusSuccess(batteryManager) { |
battery = batteryManager; |
- checkBatteryInfo(battery); |
+ testIfBatteryStatusIsUpToDate(battery); |
battery.addEventListener('levelchange', failAndFinish); |
testRunner.setPageVisibility("hidden"); |
debug("page is hidden"); |
@@ -64,7 +39,7 @@ function testWithVisiblePage() { |
} |
function onLevelChange() { |
- checkBatteryInfo(battery); |
+ testIfBatteryStatusIsUpToDate(battery); |
battery.removeEventListener('levelchange', onLevelChange); |
setTimeout(finishJSTest, 0); |
} |
@@ -75,8 +50,10 @@ function failAndFinish() { |
} |
debug("page is visible"); |
-navigator.getBattery().then(batteryStatusSuccess, batteryStatusFailure); |
-setAndFireMockBatteryInfo(false, 10, 20, 0.5); |
+mockBatteryMonitorReady.then(() => { |
+ navigator.getBattery().then(batteryStatusSuccess, batteryStatusFailure); |
+ setAndFireMockBatteryInfo(false, 10, 20, 0.5); |
+}); |
</script> |
</body> |
</html> |