| <!DOCTYPE html> |
| <html> |
| <body> |
| <script src="../resources/js-test.js"></script> |
| <script src="file:///gen/layout_test_data/mojo/public/js/mojo_bindings.js"></script> |
| <script src="file:///gen/services/device/public/mojom/battery_monitor.mojom.js"></script> |
| <script src="resources/mock-battery-monitor.js"></script> |
| <script> |
| description("Test multiple promise resolution."); |
| |
| if (!window.testRunner) |
| debug('This test cannot be run without the TestRunner'); |
| |
| // Clean-up any unused battery manager objects from previous tests. |
| gc(); |
| jsTestIsAsync = true; |
| testRunner.waitUntilDone(); |
| |
| var promise1Count = 0; |
| var promise2Count = 0; |
| |
| function finishIfReady() { |
| if (promise1Count == 1 && promise2Count == 1) |
| setTimeout(finishJSTest, 0); |
| } |
| |
| var promise1; |
| var promise2; |
| |
| promise1 = navigator.getBattery(); |
| promise1.then( |
| function(battery) { |
| debug('first resolution'); |
| testIfBatteryStatusIsUpToDate(battery); |
| promise1Count++; |
| finishIfReady(); |
| }, batteryStatusFailure); |
| |
| promise2 = navigator.getBattery(); |
| promise2.then( |
| function(battery) { |
| debug('second resolution'); |
| testIfBatteryStatusIsUpToDate(battery); |
| promise2Count++; |
| finishIfReady(); |
| }, batteryStatusFailure); |
| |
| shouldBeTrue('promise1 === promise2'); |
| setAndFireMockBatteryInfo(false, 10, 20, 0.5); |
| </script> |
| </body> |
| </html> |