| Index: LayoutTests/battery-status/multiple-promises-after-resolve.html
|
| diff --git a/LayoutTests/battery-status/multiple-promises-after-resolve.html b/LayoutTests/battery-status/multiple-promises-after-resolve.html
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..86bdeec52df695fca298e8b35d836181e55ab97d
|
| --- /dev/null
|
| +++ b/LayoutTests/battery-status/multiple-promises-after-resolve.html
|
| @@ -0,0 +1,61 @@
|
| +<!DOCTYPE html>
|
| +<html>
|
| +<body>
|
| +<script src="../resources/js-test.js"></script>
|
| +<script>
|
| +description("Test battery status API with multiple promises after resolve.");
|
| +
|
| +if (!window.testRunner)
|
| + debug('This test cannot be run without the TestRunner');
|
| +
|
| +testRunner.waitUntilDone();
|
| +jsTestIsAsync = true;
|
| +
|
| +var mockBatteryInfo;
|
| +function setAndFireMockBatteryInfo(charging, chargingTime, dischargingTime, level) {
|
| + mockBatteryInfo = { charging: charging,
|
| + chargingTime: chargingTime,
|
| + dischargingTime: dischargingTime,
|
| + level: level };
|
| + testRunner.didChangeBatteryStatus(charging, chargingTime, dischargingTime, level);
|
| +}
|
| +
|
| +// compare obtained battery values with the mock values
|
| +function checkBatteryInfo(batteryManager) {
|
| + batteryInfo = batteryManager;
|
| + shouldBeDefined("batteryInfo");
|
| + shouldBeDefined("mockBatteryInfo");
|
| + shouldBe('batteryInfo.charging', 'mockBatteryInfo.charging');
|
| + shouldBe('batteryInfo.chargingTime', 'mockBatteryInfo.chargingTime');
|
| + shouldBe('batteryInfo.dischargingTime', 'mockBatteryInfo.dischargingTime');
|
| + shouldBe('batteryInfo.level', 'mockBatteryInfo.level');
|
| +}
|
| +
|
| +function batteryStatusFailure() {
|
| + testFailed('failed to successfully resolve the promise');
|
| + finishJSTest();
|
| +}
|
| +
|
| +function batteryStatusSuccess(battery) {
|
| + debug('resolution number 1');
|
| + checkBatteryInfo(battery);
|
| +
|
| + navigator.getBattery().then(
|
| + function(battery) {
|
| + debug('resolution number 2');
|
| + checkBatteryInfo(battery);
|
| + setTimeout(cleanupAndFinish, 0);
|
| + }, batteryStatusFailure);
|
| +}
|
| +
|
| +function cleanupAndFinish() {
|
| + // stops updating battery and clears current battery status.
|
| + window.testRunner.setPageVisibility("hidden");
|
| + finishJSTest();
|
| +}
|
| +
|
| +navigator.getBattery().then(batteryStatusSuccess, batteryStatusFailure);
|
| +setAndFireMockBatteryInfo(false, 10, 20, 0.5);
|
| +</script>
|
| +</body>
|
| +</html>
|
|
|