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

Unified Diff: third_party/WebKit/LayoutTests/battery-status/multiple-promises.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/multiple-promises.html
diff --git a/third_party/WebKit/LayoutTests/battery-status/multiple-promises.html b/third_party/WebKit/LayoutTests/battery-status/multiple-promises.html
index 68e58003e39e8cb4d0bdb46da998cd138835bdd3..8bfcedc85ae861f99588cad936d32cb8a8d3f12c 100644
--- a/third_party/WebKit/LayoutTests/battery-status/multiple-promises.html
+++ b/third_party/WebKit/LayoutTests/battery-status/multiple-promises.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 multiple promise resolution.");
@@ -17,31 +19,6 @@ testRunner.waitUntilDone();
testRunner.setCanOpenWindows();
Yuki 2016/03/30 02:39:45 We're not opening any windows, right? Let's remov
Sam McNally 2016/03/30 03:15:32 Done.
testRunner.setCloseRemainingWindowsWhenComplete(true);
-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(finishJSTest, 0);
-}
-
var promise1Count = 0;
var promise2Count = 0;
@@ -50,26 +27,31 @@ function finishIfReady() {
setTimeout(finishJSTest, 0);
}
-promise1 = navigator.getBattery();
-promise1.then(
- function(battery) {
- debug('first resolution');
- checkBatteryInfo(battery);
- promise1Count++;
- finishIfReady();
- }, batteryStatusFailure);
-
-promise2 = navigator.getBattery();
-promise2.then(
- function(battery) {
- debug('second resolution');
- checkBatteryInfo(battery);
- promise2Count++;
- finishIfReady();
- }, batteryStatusFailure);
-
-shouldBeTrue('promise1 === promise2');
-setAndFireMockBatteryInfo(false, 10, 20, 0.5);
+var promise1;
+var promise2;
+
+ready.then(() => {
+ promise1 = navigator.getBattery();
+ promise1.then(
+ function(battery) {
+ debug('first resolution');
+ checkBatteryInfo(battery);
+ promise1Count++;
+ finishIfReady();
+ }, batteryStatusFailure);
+
+ promise2 = navigator.getBattery();
+ promise2.then(
+ function(battery) {
+ debug('second resolution');
+ checkBatteryInfo(battery);
+ promise2Count++;
+ finishIfReady();
+ }, batteryStatusFailure);
+
+ shouldBeTrue('promise1 === promise2');
+ setAndFireMockBatteryInfo(false, 10, 20, 0.5);
+});
</script>
</body>
</html>

Powered by Google App Engine
This is Rietveld 408576698