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

Side by Side Diff: third_party/WebKit/LayoutTests/battery-status/restricted-level-precision.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, 8 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 unified diff | Download patch
OLDNEW
1 <!DOCTYPE html> 1 <!DOCTYPE html>
2 <html> 2 <html>
3 <body> 3 <body>
4 <script src="../resources/js-test.js"></script> 4 <script src="../resources/js-test.js"></script>
5 <script src="../resources/mojo-helpers.js"></script>
6 <script src="resources/mock-battery-monitor.js"></script>
5 <script> 7 <script>
6 description("Test to ensure level is reported with restricted precision."); 8 description("Test to ensure level is reported with restricted precision.");
7 9
8 if (!window.testRunner) 10 if (!window.testRunner)
9 debug('This test cannot be run without the TestRunner'); 11 debug('This test cannot be run without the TestRunner');
10 if (!window.internals)
11 debug('This test cannot be run without the window.internals');
12 12
13 // Clean-up any unused battery manager objects from previous tests. 13 // Clean-up any unused battery manager objects from previous tests.
14 gc(); 14 gc();
15 jsTestIsAsync = true; 15 jsTestIsAsync = true;
16 testRunner.waitUntilDone(); 16 testRunner.waitUntilDone();
17 17
18 var levelFullPrecision = 0.556789; 18 var levelFullPrecision = 0.556789;
19 var levelRounded = 0.56; 19 var levelRounded = 0.56;
20 20
21 function setAndFireMockBatteryInfo(charging, chargingTime, dischargingTime, leve l) {
22 window.internals.updateBatteryStatus(charging, chargingTime, dischargingTime , level);
23 }
24
25 var battery; 21 var battery;
26 function batteryStatusSuccess(batteryManager) { 22 function batteryStatusSuccess(batteryManager) {
27 debug('batteryStatusSuccess invoked'); 23 debug('batteryStatusSuccess invoked');
28 battery = batteryManager; 24 battery = batteryManager;
29 shouldBe('battery.level', 'levelRounded'); 25 shouldBe('battery.level', 'levelRounded');
30 setTimeout(finishJSTest, 0); 26 setTimeout(finishJSTest, 0);
31 } 27 }
32 28
33 function batteryStatusFailure() { 29 mockBatteryMonitorReady.then(() => {
34 testFailed('failed to successfully resolve the promise'); 30 navigator.getBattery().then(batteryStatusSuccess, batteryStatusFailure);
35 setTimeout(finishJSTest, 0); 31 setAndFireMockBatteryInfo(false, 10, 20, levelFullPrecision);
36 } 32 });
37
38 navigator.getBattery().then(batteryStatusSuccess, batteryStatusFailure);
39 setAndFireMockBatteryInfo(false, 10, 20, levelFullPrecision);
40 </script> 33 </script>
41 </body> 34 </body>
42 </html> 35 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698