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

Side by Side Diff: third_party/WebKit/LayoutTests/battery-status/multiple-windows-page-visibility.html

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

Powered by Google App Engine
This is Rietveld 408576698