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

Side by Side Diff: LayoutTests/battery-status/multiple-promises-after-resolve.html

Issue 329723005: Battery Status API: blink promise implementation and layout tests. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: revert to a single resolver at a time Created 6 years, 6 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 <!DOCTYPE html>
2 <html>
3 <body>
4 <script src="../resources/js-test.js"></script>
5 <script>
6 description("Test battery status API with multiple promises after resolve.");
7
8 if (!window.testRunner)
9 debug('This test cannot be run without the TestRunner');
10
11 testRunner.waitUntilDone();
12 jsTestIsAsync = true;
13
14 var mockBatteryInfo;
15 function setAndFireMockBatteryInfo(charging, chargingTime, dischargingTime, leve l) {
16 mockBatteryInfo = { charging: charging,
17 chargingTime: chargingTime,
18 dischargingTime: dischargingTime,
19 level: level };
20 testRunner.didChangeBatteryStatus(charging, chargingTime, dischargingTime, l evel);
21 }
22
23 // compare obtained battery values with the mock values
24 function checkBatteryInfo(batteryManager) {
25 batteryInfo = batteryManager;
26 shouldBeDefined("batteryInfo");
27 shouldBeDefined("mockBatteryInfo");
28 shouldBe('batteryInfo.charging', 'mockBatteryInfo.charging');
29 shouldBe('batteryInfo.chargingTime', 'mockBatteryInfo.chargingTime');
30 shouldBe('batteryInfo.dischargingTime', 'mockBatteryInfo.dischargingTime');
31 shouldBe('batteryInfo.level', 'mockBatteryInfo.level');
32 }
33
34 function batteryStatusFailure() {
35 testFailed('failed to successfully resolve the promise');
36 finishJSTest();
37 }
38
39 function batteryStatusSuccess(battery) {
40 debug('resolution number 1');
41 checkBatteryInfo(battery);
42
43 navigator.getBattery().then(
44 function(battery) {
45 debug('resolution number 2');
46 checkBatteryInfo(battery);
47 setTimeout(cleanupAndFinish, 0);
48 }, batteryStatusFailure);
49 }
50
51 function cleanupAndFinish() {
52 // stops updating battery and clears current battery status.
53 window.testRunner.setPageVisibility("hidden");
54 finishJSTest();
55 }
56
57 navigator.getBattery().then(batteryStatusSuccess, batteryStatusFailure);
58 setAndFireMockBatteryInfo(false, 10, 20, 0.5);
59 </script>
60 </body>
61 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698