| 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> |
| 5 <script> | 7 <script> |
| 6 description("Test multiple windows with page visibility."); | 8 description("Test multiple windows with page visibility."); |
| 7 | 9 |
| 8 if (!window.testRunner) | 10 if (!window.testRunner) |
| 9 debug('This test cannot be run without the TestRunner'); | 11 debug('This test cannot be run without the TestRunner'); |
| 10 if (!window.internals) | 12 if (!window.internals) |
| 11 debug('This test cannot be run without the window.internals'); | 13 debug('This test cannot be run without the window.internals'); |
| 12 | 14 |
| 13 // Clean-up any unused battery manager objects from previous tests. | 15 // Clean-up any unused battery manager objects from previous tests. |
| 14 gc(); | 16 gc(); |
| 15 jsTestIsAsync = true; | 17 jsTestIsAsync = true; |
| 16 testRunner.waitUntilDone(); | 18 testRunner.waitUntilDone(); |
| 17 testRunner.setCanOpenWindows(); | 19 testRunner.setCanOpenWindows(); |
| 18 testRunner.setCloseRemainingWindowsWhenComplete(true); | 20 testRunner.setCloseRemainingWindowsWhenComplete(true); |
| 19 | 21 |
| 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 | |
| 45 var battery; | 22 var battery; |
| 46 function batteryStatusSuccess(batteryManager) { | 23 function batteryStatusSuccess(batteryManager) { |
| 47 battery = batteryManager; | 24 battery = batteryManager; |
| 48 debug('resolution in window'); | 25 debug('resolution in window'); |
| 49 checkBatteryInfo(battery); | 26 checkBatteryInfo(battery); |
| 50 battery.addEventListener('levelchange', failAndFinish); | 27 battery.addEventListener('levelchange', failAndFinish); |
| 51 | 28 |
| 52 firstWindow = window; | 29 firstWindow = window; |
| 53 secondWindow = window.open(""); | 30 secondWindow = window.open(""); |
| 54 secondWindow.navigator.getBattery().then( | 31 secondWindow.navigator.getBattery().then( |
| (...skipping 24 matching lines...) Expand all Loading... |
| 79 battery.removeEventListener('levelchange', onLevelChange); | 56 battery.removeEventListener('levelchange', onLevelChange); |
| 80 setTimeout(finishJSTest, 0); | 57 setTimeout(finishJSTest, 0); |
| 81 } | 58 } |
| 82 | 59 |
| 83 function failAndFinish() { | 60 function failAndFinish() { |
| 84 testFailed('received event while the page was hidden'); | 61 testFailed('received event while the page was hidden'); |
| 85 setTimeout(finishJSTest, 0); | 62 setTimeout(finishJSTest, 0); |
| 86 } | 63 } |
| 87 | 64 |
| 88 debug("first window: page is visible"); | 65 debug("first window: page is visible"); |
| 89 navigator.getBattery().then(batteryStatusSuccess, batteryStatusFailure); | 66 ready.then(() => { |
| 90 setAndFireMockBatteryInfo(false, 10, 20, 0.5); | 67 navigator.getBattery().then(batteryStatusSuccess, batteryStatusFailure); |
| 68 setAndFireMockBatteryInfo(false, 10, 20, 0.5); |
| 69 }); |
| 91 </script> | 70 </script> |
| 92 </body> | 71 </body> |
| 93 </html> | 72 </html> |
| OLD | NEW |