Index: third_party/WebKit/LayoutTests/battery-status/no-gc-with-eventlisteners.html |
diff --git a/third_party/WebKit/LayoutTests/battery-status/no-gc-with-eventlisteners.html b/third_party/WebKit/LayoutTests/battery-status/no-gc-with-eventlisteners.html |
index 21649370bf86f8833528ce64d142e666216c6dfe..4bc9108f83d31273a156e5bcff2d30fc8cf2ae05 100644 |
--- a/third_party/WebKit/LayoutTests/battery-status/no-gc-with-eventlisteners.html |
+++ b/third_party/WebKit/LayoutTests/battery-status/no-gc-with-eventlisteners.html |
@@ -2,52 +2,36 @@ |
<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 no garbage collection of battery manager object when listeners are attached."); |
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; |
- shouldBe('batteryInfo.charging', 'mockBatteryInfo.charging'); |
- shouldBe('batteryInfo.chargingTime', 'mockBatteryInfo.chargingTime'); |
- shouldBe('batteryInfo.dischargingTime', 'mockBatteryInfo.dischargingTime'); |
- shouldBe('batteryInfo.level', 'mockBatteryInfo.level'); |
-} |
- |
function fireLevelChange() { |
gc(); |
setAndFireMockBatteryInfo(false, 10, 20, 0.6); |
} |
-navigator.getBattery().then(function(battery) { |
- battery.addEventListener('levelchange', function() { |
- checkBatteryInfo(battery); |
- battery.removeEventListener('levelchange', arguments.callee); |
- setTimeout(finishJSTest, 0); |
+mockBatteryMonitorReady.then(() => { |
+ navigator.getBattery().then(function(battery) { |
+ battery.addEventListener('levelchange', function() { |
+ testIfBatteryStatusIsUpToDate(battery); |
+ battery.removeEventListener('levelchange', arguments.callee); |
+ setTimeout(finishJSTest, 0); |
+ }); |
+ setTimeout(fireLevelChange, 0); |
}); |
- setTimeout(fireLevelChange, 0); |
-}); |
-setAndFireMockBatteryInfo(false, 10, 20, 0.5); |
+ setAndFireMockBatteryInfo(false, 10, 20, 0.5); |
+}); |
</script> |
</body> |
</html> |