blob: a311437dd3468713396389f319a5e76e6388a504 [file] [log] [blame]
<!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/interfaces/battery_monitor.mojom.js"></script>
<script src="resources/mock-battery-monitor.js"></script>
<script>
description("Test multiple windows with page visibility.");
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();
testRunner.setCanOpenWindows();
testRunner.setCloseRemainingWindowsWhenComplete(true);
var battery;
function batteryStatusSuccess(batteryManager) {
battery = batteryManager;
debug('resolution in window');
testIfBatteryStatusIsUpToDate(battery);
battery.addEventListener('levelchange', failAndFinish);
firstWindow = window;
secondWindow = window.open("");
secondWindow.navigator.getBattery().then(
function(battery2) {
debug('resolution in secondWindow');
testIfBatteryStatusIsUpToDate(battery2);
setTimeout(fireNewMockLevel, 0);
}, batteryStatusFailure);
window.testRunner.setPageVisibility("hidden");
debug("first window: page is hidden");
}
function fireNewMockLevel() {
setAndFireMockBatteryInfo(false, 10, 20, 0.6);
proceedToVisible();
}
function proceedToVisible() {
battery.removeEventListener('levelchange', failAndFinish);
battery.addEventListener('levelchange', onLevelChange);
testRunner.setPageVisibility("visible");
debug("first window: page is visible");
}
function onLevelChange() {
testIfBatteryStatusIsUpToDate(battery);
battery.removeEventListener('levelchange', onLevelChange);
setTimeout(finishJSTest, 0);
}
function failAndFinish() {
testFailed('received event while the page was hidden');
setTimeout(finishJSTest, 0);
}
debug("first window: page is visible");
navigator.getBattery().then(batteryStatusSuccess, batteryStatusFailure);
setAndFireMockBatteryInfo(false, 10, 20, 0.5);
</script>
</body>
</html>