Chromium Code Reviews| Index: LayoutTests/fast/dom/DeviceLight/page-visibility.html |
| diff --git a/LayoutTests/fast/dom/DeviceLight/page-visibility.html b/LayoutTests/fast/dom/DeviceLight/page-visibility.html |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..db77b7267ce73d282a632bc753f6b1dee5244130 |
| --- /dev/null |
| +++ b/LayoutTests/fast/dom/DeviceLight/page-visibility.html |
| @@ -0,0 +1,55 @@ |
| +<!DOCTYPE html> |
| +<html> |
| +<body> |
| +<script src="../../../resources/js-test.js"></script> |
| +<script> |
| + |
| +description('Tests to check that devicelight events are not fired when the page is not visible.'); |
| +window.jsTestIsAsync = true; |
| + |
| +function succeedAndFinish() |
| +{ |
| + testPassed("Received a devicelight event"); |
| + finishJSTest(); |
| +} |
| + |
| +function testWithPageVisible() |
| +{ |
| + testPassed("Did not receive a devicelight event"); |
| + window.removeEventListener('devicelight', failAndFinish); |
| + if (window.testRunner) |
| + testRunner.setPageVisibility("visible"); |
| + debug("* Page is visible"); |
| + window.addEventListener('devicelight', succeedAndFinish); |
| +} |
| + |
| +function failAndFinish() |
| +{ |
| + testFailed('Should not have received a devicelight event while the page was hidden'); |
| + finishJSTest(); |
| +} |
| + |
| +function testWithPageHidden() |
| +{ |
| + testPassed("Received a devicelight event"); |
|
timvolodine
2014/09/29 16:43:53
nit: a better place for this is inside "deviceLigh
riju_
2015/03/27 12:25:36
Done.
|
| + window.removeEventListener('devicelight', deviceLightListener); |
| + if (window.testRunner) |
| + testRunner.setPageVisibility("hidden"); |
| + debug("* Page is hidden"); |
| + window.addEventListener('devicelight', failAndFinish); |
| + |
| + setTimeout(testWithPageVisible, 100); |
| +} |
| + |
| +function deviceLightListener(event) { |
| + setTimeout(testWithPageHidden, 0); |
| +} |
| + |
| +if (window.testRunner) |
| + testRunner.setMockDeviceLight(100); |
| + |
| +debug("* Page is visible"); |
| +window.addEventListener('devicelight', deviceLightListener); |
| +</script> |
| +</body> |
| +</html> |