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

Side by Side Diff: LayoutTests/battery-status/multiple-windows-page-visibility.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 multiple windows with page visibility.");
7
8 if (!window.testRunner)
9 debug('This test cannot be run without the TestRunner');
10
11 testRunner.setCanOpenWindows();
12 testRunner.waitUntilDone();
13 jsTestIsAsync = true;
14
15 var mockBatteryInfo;
16 function setAndFireMockBatteryInfo(charging, chargingTime, dischargingTime, leve l) {
17 mockBatteryInfo = { charging: charging,
18 chargingTime: chargingTime,
19 dischargingTime: dischargingTime,
20 level: level };
21 testRunner.didChangeBatteryStatus(charging, chargingTime, dischargingTime, l evel);
22 }
23
24 // compare obtained battery values with the mock values
25 function checkBatteryInfo(batteryManager) {
26 batteryInfo = batteryManager;
27 shouldBeDefined("batteryInfo");
28 shouldBeDefined("mockBatteryInfo");
29 shouldBe('batteryInfo.charging', 'mockBatteryInfo.charging');
30 shouldBe('batteryInfo.chargingTime', 'mockBatteryInfo.chargingTime');
31 shouldBe('batteryInfo.dischargingTime', 'mockBatteryInfo.dischargingTime');
32 shouldBe('batteryInfo.level', 'mockBatteryInfo.level');
33 }
34
35 function batteryStatusFailure() {
36 testFailed('failed to successfully resolve the promise');
37 finishJSTest();
38 }
39
40 var battery;
41 var firstWindow = window;
42 var secondWindow = window.open("");
43
44 function batteryStatusSuccess(batteryManager) {
45 battery = batteryManager;
46 debug('resolution in window');
47 checkBatteryInfo(battery);
48 battery.addEventListener('levelchange', failAndFinish);
49
50 secondWindow.navigator.getBattery().then(
51 function(battery2) {
52 debug('resolution in secondWindow');
53 checkBatteryInfo(battery2);
54 setAndFireMockBatteryInfo(false, 10, 20, 0.6);
55 setTimeout(proceedToVisible, 100);
56 }, batteryStatusFailure);
57
58 firstWindow.testRunner.setPageVisibility("hidden");
59 debug("first window: page is hidden");
60 }
61
62 function proceedToVisible() {
63 battery.removeEventListener('levelchange', failAndFinish);
64 battery.addEventListener('levelchange', onLevelChange);
65 firstWindow.testRunner.setPageVisibility("visible");
66 debug("first window: page is visible");
67 }
68
69 function onLevelChange() {
70 checkBatteryInfo(battery);
71 setTimeout(cleanupAndFinish, 0);
72 }
73
74 function failAndFinish() {
75 testFailed('received event while the page was hidden');
76 setTimeout(cleanupAndFinish, 0);
77 }
78
79 function cleanupAndFinish() {
80 // stops updating battery and clears current battery status.
81 firstWindow.testRunner.setPageVisibility("hidden");
82 secondWindow.testRunner.setPageVisibility("hidden");
83 secondWindow.close();
84 finishJSTest();
85 }
86
87 debug("first window: page is visible");
88 navigator.getBattery().then(batteryStatusSuccess, batteryStatusFailure);
89 setAndFireMockBatteryInfo(false, 10, 20, 0.5);
90 </script>
91 </body>
92 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698