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..11e66055f0a7fc1cc606501da5e01114bfe62001 |
| --- /dev/null |
| +++ b/LayoutTests/fast/dom/DeviceLight/page-visibility.html |
| @@ -0,0 +1,51 @@ |
| +<!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(); |
|
riju_
2015/03/31 11:03:41
I guess it is better to use setTimeout(finishJSTes
|
| +} |
| + |
| +function testWithPageVisible() |
| +{ |
| + testPassed("Did not receive a devicelight event"); |
| + window.removeEventListener('devicelight', failAndFinish); |
| + if (window.testRunner) |
|
timvolodine
2015/03/30 13:00:54
no need for this if you add a check for window.tes
riju_
2015/03/31 11:03:42
Done.
|
| + 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(); |
|
timvolodine
2015/03/30 13:00:54
also better to use setTimeout(finishJSTest, 0); be
riju_
2015/03/31 11:03:41
Done.
|
| +} |
| + |
| +function deviceLightListener(event) |
| +{ |
| + testPassed("Received a devicelight event"); |
| + window.removeEventListener('devicelight', deviceLightListener); |
| + if (window.testRunner) |
|
timvolodine
2015/03/30 13:00:55
same here
riju_
2015/03/31 11:03:41
Done.
|
| + testRunner.setPageVisibility("hidden"); |
| + debug("* Page is hidden"); |
| + window.addEventListener('devicelight', failAndFinish); |
| + |
| + testWithPageVisible(); |
|
timvolodine
2015/03/30 13:00:54
should use setTimeout(testWithPageVisible, 0); bec
riju_
2015/03/31 11:03:41
Done.
|
| +} |
| + |
| +if (window.testRunner) |
| + testRunner.setMockDeviceLight(100); |
|
timvolodine
2015/03/30 13:00:54
nit: in other test you have debug('This test can n
riju_
2015/03/31 11:03:41
Done.
|
| + |
| +debug("* Page is visible"); |
| +window.addEventListener('devicelight', deviceLightListener); |
| +</script> |
| +</body> |
| +</html> |