Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1718)

Unified Diff: third_party/WebKit/LayoutTests/battery-status/api-defined.html

Issue 1836203002: Change the battery-status layout tests to use JS mocks. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/LayoutTests/battery-status/api-defined.html
diff --git a/third_party/WebKit/LayoutTests/battery-status/api-defined.html b/third_party/WebKit/LayoutTests/battery-status/api-defined.html
index 3dfb9ae309eb839e17d4f213d2a2c0a9e33e69cf..7753e89e0f407d185882903323060d80ee19d4c7 100644
--- a/third_party/WebKit/LayoutTests/battery-status/api-defined.html
+++ b/third_party/WebKit/LayoutTests/battery-status/api-defined.html
@@ -2,6 +2,8 @@
<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 basic API definitions.");
@@ -15,16 +17,8 @@ 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);
-}
-
var battery;
Yuki 2016/03/30 02:39:45 We don't need this variable. Let's add |let| on li
Sam McNally 2016/03/30 03:15:32 Unfortunately, we do need this. The test assertion
+var promise;
Yuki 2016/03/30 02:39:45 nit: Better to declare this variable just before l
Sam McNally 2016/03/30 03:15:32 Done.
function batteryStatusSuccess(batteryManager) {
debug('batteryStatusSuccess invoked');
battery = batteryManager;
@@ -54,16 +48,13 @@ function batteryStatusSuccess(batteryManager) {
setTimeout(finishJSTest, 0);
}
-function batteryStatusFailure() {
- testFailed('failed to successfully resolve the promise');
- setTimeout(finishJSTest, 0);
-}
-
-promise = navigator.getBattery();
-shouldBeDefined("promise");
-shouldBeDefined("promise.then");
-promise.then(batteryStatusSuccess, batteryStatusFailure);
-setAndFireMockBatteryInfo(false, 10, 20, 0.5);
+ready.then(() => {
+ promise = navigator.getBattery();
+ shouldBeDefined("promise");
+ shouldBeDefined("promise.then");
+ promise.then(batteryStatusSuccess, batteryStatusFailure);
+ setAndFireMockBatteryInfo(false, 10, 20, 0.5);
+});
</script>
</body>
</html>

Powered by Google App Engine
This is Rietveld 408576698