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

Side by Side Diff: LayoutTests/battery-status/api-defined.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
« no previous file with comments | « LayoutTests/TestExpectations ('k') | LayoutTests/battery-status/api-defined-expected.txt » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 <!DOCTYPE html>
2 <html>
3 <body>
4 <script src="../resources/js-test.js"></script>
5 <script>
6 description("Test basic API definitions.");
7
8 if (!window.testRunner)
9 debug('This test cannot be run without the TestRunner');
10
11 jsTestIsAsync = true;
12
13 var mockBatteryInfo;
14 function setAndFireMockBatteryInfo(charging, chargingTime, dischargingTime, leve l) {
15 mockBatteryInfo = { charging: charging,
16 chargingTime: chargingTime,
17 dischargingTime: dischargingTime,
18 level: level };
19 testRunner.didChangeBatteryStatus(charging, chargingTime, dischargingTime, l evel);
20 }
21
22 function batteryStatusSuccess(batteryManager) {
23 debug('batteryStatusSuccess invoked');
24 battery = batteryManager;
25
26 shouldBeDefined("battery");
27 shouldBeNonNull("battery");
28 shouldBeDefined("battery.charging");
29 shouldBeDefined("battery.chargingTime");
30 shouldBeDefined("battery.dischargingTime");
31 shouldBeDefined("battery.level");
32
33 shouldBe('battery.charging', 'mockBatteryInfo.charging');
34 shouldBe('battery.chargingTime', 'mockBatteryInfo.chargingTime');
35 shouldBe('battery.dischargingTime', 'mockBatteryInfo.dischargingTime');
36 shouldBe('battery.level', 'mockBatteryInfo.level');
37
38 shouldBeTrue("typeof battery.onchargingchange == 'object'");
39 shouldBeTrue("typeof battery.onchargingtimechange == 'object'");
40 shouldBeTrue("typeof battery.ondischargingtimechange == 'object'");
41 shouldBeTrue("typeof battery.onlevelchange == 'object'");
42
43 shouldBeTrue("battery.hasOwnProperty('onchargingchange')");
44 shouldBeTrue("battery.hasOwnProperty('onchargingtimechange')");
45 shouldBeTrue("battery.hasOwnProperty('ondischargingtimechange')");
46 shouldBeTrue("battery.hasOwnProperty('onlevelchange')");
47
48 shouldBeTrue("'onchargingchange' in battery");
49 shouldBeTrue("'onchargingtimechange' in battery");
50 shouldBeTrue("'ondischargingtimechange' in battery");
51 shouldBeTrue("'onlevelchange' in battery");
52
53 setTimeout(cleanupAndFinish, 0);
54 }
55
56 function cleanupAndFinish() {
57 // stops updating battery and clears current battery status.
58 window.testRunner.setPageVisibility("hidden");
59 finishJSTest();
60 }
61
62 function batteryStatusFailure() {
63 testFailed('failed to successfully resolve the promise');
64 setTimeout(cleanupAndFinish, 0);
65 }
66
67 promise = navigator.getBattery();
68 shouldBeDefined("promise");
69 shouldBeDefined("promise.then");
70 promise.then(batteryStatusSuccess, batteryStatusFailure);
71 setAndFireMockBatteryInfo(false, 10, 20, 0.5);
72 </script>
73 </body>
74 </html>
OLDNEW
« no previous file with comments | « LayoutTests/TestExpectations ('k') | LayoutTests/battery-status/api-defined-expected.txt » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698