| Index: LayoutTests/battery-status/multiple-windows-page-visibility.html
|
| diff --git a/LayoutTests/battery-status/multiple-windows-page-visibility.html b/LayoutTests/battery-status/multiple-windows-page-visibility.html
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..1c4d7e5b374a75144e3b37518f22e45cac79b1bd
|
| --- /dev/null
|
| +++ b/LayoutTests/battery-status/multiple-windows-page-visibility.html
|
| @@ -0,0 +1,92 @@
|
| +<!DOCTYPE html>
|
| +<html>
|
| +<body>
|
| +<script src="../resources/js-test.js"></script>
|
| +<script>
|
| +description("Test multiple windows with page visibility.");
|
| +
|
| +if (!window.testRunner)
|
| + debug('This test cannot be run without the TestRunner');
|
| +
|
| +testRunner.setCanOpenWindows();
|
| +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();
|
| +}
|
| +
|
| +var battery;
|
| +var firstWindow = window;
|
| +var secondWindow = window.open("");
|
| +
|
| +function batteryStatusSuccess(batteryManager) {
|
| + battery = batteryManager;
|
| + debug('resolution in window');
|
| + checkBatteryInfo(battery);
|
| + battery.addEventListener('levelchange', failAndFinish);
|
| +
|
| + secondWindow.navigator.getBattery().then(
|
| + function(battery2) {
|
| + debug('resolution in secondWindow');
|
| + checkBatteryInfo(battery2);
|
| + setAndFireMockBatteryInfo(false, 10, 20, 0.6);
|
| + setTimeout(proceedToVisible, 100);
|
| + }, batteryStatusFailure);
|
| +
|
| + firstWindow.testRunner.setPageVisibility("hidden");
|
| + debug("first window: page is hidden");
|
| +}
|
| +
|
| +function proceedToVisible() {
|
| + battery.removeEventListener('levelchange', failAndFinish);
|
| + battery.addEventListener('levelchange', onLevelChange);
|
| + firstWindow.testRunner.setPageVisibility("visible");
|
| + debug("first window: page is visible");
|
| +}
|
| +
|
| +function onLevelChange() {
|
| + checkBatteryInfo(battery);
|
| + setTimeout(cleanupAndFinish, 0);
|
| +}
|
| +
|
| +function failAndFinish() {
|
| + testFailed('received event while the page was hidden');
|
| + setTimeout(cleanupAndFinish, 0);
|
| +}
|
| +
|
| +function cleanupAndFinish() {
|
| + // stops updating battery and clears current battery status.
|
| + firstWindow.testRunner.setPageVisibility("hidden");
|
| + secondWindow.testRunner.setPageVisibility("hidden");
|
| + secondWindow.close();
|
| + finishJSTest();
|
| +}
|
| +
|
| +debug("first window: page is visible");
|
| +navigator.getBattery().then(batteryStatusSuccess, batteryStatusFailure);
|
| +setAndFireMockBatteryInfo(false, 10, 20, 0.5);
|
| +</script>
|
| +</body>
|
| +</html>
|
|
|