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

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

Issue 976373002: Return same promise consistently when using navigator.getBattery() (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: rebase, make compile, fix comment Created 5 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
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> 5 <script>
6 description("Test battery status API with multiple promises after resolve."); 6 description("Test battery status API with multiple promises after resolve.");
7 7
8 if (!window.testRunner) 8 if (!window.testRunner)
9 debug('This test cannot be run without the TestRunner'); 9 debug('This test cannot be run without the TestRunner');
10 10
11 // Clean-up any unused battery manager objects from previous tests. 11 // Clean-up any unused battery manager objects from previous tests.
12 gc(); 12 gc();
13 jsTestIsAsync = true; 13 jsTestIsAsync = true;
14 testRunner.waitUntilDone(); 14 testRunner.waitUntilDone();
15 15
16 var promise1;
16 var mockBatteryInfo; 17 var mockBatteryInfo;
17 function setAndFireMockBatteryInfo(charging, chargingTime, dischargingTime, leve l) { 18 function setAndFireMockBatteryInfo(charging, chargingTime, dischargingTime, leve l) {
18 mockBatteryInfo = { charging: charging, 19 mockBatteryInfo = { charging: charging,
19 chargingTime: chargingTime, 20 chargingTime: chargingTime,
20 dischargingTime: dischargingTime, 21 dischargingTime: dischargingTime,
21 level: level }; 22 level: level };
22 testRunner.didChangeBatteryStatus(charging, chargingTime, dischargingTime, l evel); 23 testRunner.didChangeBatteryStatus(charging, chargingTime, dischargingTime, l evel);
23 } 24 }
24 25
25 // compare obtained battery values with the mock values 26 // compare obtained battery values with the mock values
26 function checkBatteryInfo(batteryManager) { 27 function checkBatteryInfo(batteryManager) {
27 batteryInfo = batteryManager; 28 batteryInfo = batteryManager;
28 shouldBeDefined("batteryInfo"); 29 shouldBeDefined("batteryInfo");
29 shouldBeDefined("mockBatteryInfo"); 30 shouldBeDefined("mockBatteryInfo");
30 shouldBe('batteryInfo.charging', 'mockBatteryInfo.charging'); 31 shouldBe('batteryInfo.charging', 'mockBatteryInfo.charging');
31 shouldBe('batteryInfo.chargingTime', 'mockBatteryInfo.chargingTime'); 32 shouldBe('batteryInfo.chargingTime', 'mockBatteryInfo.chargingTime');
32 shouldBe('batteryInfo.dischargingTime', 'mockBatteryInfo.dischargingTime'); 33 shouldBe('batteryInfo.dischargingTime', 'mockBatteryInfo.dischargingTime');
33 shouldBe('batteryInfo.level', 'mockBatteryInfo.level'); 34 shouldBe('batteryInfo.level', 'mockBatteryInfo.level');
34 } 35 }
35 36
36 function batteryStatusFailure() { 37 function batteryStatusFailure() {
37 testFailed('failed to successfully resolve the promise'); 38 testFailed('failed to successfully resolve the promise');
38 setTimeout(finishJSTest, 0); 39 setTimeout(finishJSTest, 0);
39 } 40 }
40 41
41 function batteryStatusSuccess(battery) { 42 function batteryStatusSuccess(battery) {
42 debug('resolution number 1'); 43 debug('resolution number 1');
43 checkBatteryInfo(battery); 44 checkBatteryInfo(battery);
44 45
45 navigator.getBattery().then( 46 promise2 = navigator.getBattery();
47 promise2.then(
46 function(battery) { 48 function(battery) {
47 debug('resolution number 2'); 49 debug('resolution number 2');
48 checkBatteryInfo(battery); 50 checkBatteryInfo(battery);
49 setTimeout(finishJSTest, 0); 51 setTimeout(finishJSTest, 0);
50 }, batteryStatusFailure); 52 }, batteryStatusFailure);
53 shouldBeTrue('promise1 === promise2');
51 } 54 }
52 55
53 navigator.getBattery().then(batteryStatusSuccess, batteryStatusFailure); 56 promise1 = navigator.getBattery();
57 promise1.then(batteryStatusSuccess, batteryStatusFailure);
54 setAndFireMockBatteryInfo(false, 10, 20, 0.5); 58 setAndFireMockBatteryInfo(false, 10, 20, 0.5);
55 </script> 59 </script>
56 </body> 60 </body>
57 </html> 61 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698