| OLD | NEW |
| 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 battery status API with multiple windows."); | 6 description("Test battery status API with multiple windows."); |
| 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 function batteryStatusSuccess(battery) { | 45 function batteryStatusSuccess(battery) { |
| 21 debug('resolution in window'); | 46 debug('resolution in window'); |
| 22 testIfBatteryStatusIsUpToDate(battery); | 47 checkBatteryInfo(battery); |
| 23 | 48 |
| 24 secondWindow = window.open(""); | 49 secondWindow = window.open(""); |
| 25 secondWindow.navigator.getBattery().then( | 50 secondWindow.navigator.getBattery().then( |
| 26 function(battery2) { | 51 function(battery2) { |
| 27 debug('resolution in secondWindow'); | 52 debug('resolution in secondWindow'); |
| 28 testIfBatteryStatusIsUpToDate(battery2); | 53 checkBatteryInfo(battery2); |
| 29 setTimeout(finishJSTest, 0); | 54 setTimeout(finishJSTest, 0); |
| 30 }, batteryStatusFailure); | 55 }, batteryStatusFailure); |
| 31 } | 56 } |
| 32 | 57 |
| 33 mockBatteryMonitorReady.then(() => { | 58 navigator.getBattery().then(batteryStatusSuccess, batteryStatusFailure); |
| 34 navigator.getBattery().then(batteryStatusSuccess, batteryStatusFailure); | 59 setAndFireMockBatteryInfo(false, 10, 20, 0.5); |
| 35 setAndFireMockBatteryInfo(false, 10, 20, 0.5); | |
| 36 }); | |
| 37 </script> | 60 </script> |
| 38 </body> | 61 </body> |
| 39 </html> | 62 </html> |
| OLD | NEW |