Chromium Code Reviews| Index: LayoutTests/fast/dom/DeviceMotion/page-visibility.html |
| diff --git a/LayoutTests/fast/dom/DeviceMotion/page-visibility.html b/LayoutTests/fast/dom/DeviceMotion/page-visibility.html |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..eaff8d1720c524e7276ecffc521f54fb05abdb46 |
| --- /dev/null |
| +++ b/LayoutTests/fast/dom/DeviceMotion/page-visibility.html |
| @@ -0,0 +1,56 @@ |
| +<html> |
| +<head> |
| +<script src="../../js/resources/js-test-pre.js"></script> |
| +</head> |
| +<body> |
| +<script> |
| + |
| +description('Tests to check that devicemotion events are not fired when the page is not visible.'); |
| +window.jsTestIsAsync = true; |
| + |
| +function succeedAndFinish() |
| +{ |
| + testPassed("Received a devicemotion event"); |
| + finishJSTest(); |
| +} |
| + |
| +function testWithPageVisible() |
| +{ |
| + testPassed("Did not receive a devicemotion event"); |
| + window.removeEventListener('devicemotion', failAndFinish); |
| + if (window.testRunner) |
| + testRunner.setPageVisibility("visible"); |
| + debug("* Page is visible"); |
| + window.addEventListener('devicemotion', succeedAndFinish); |
| +} |
| + |
| +function failAndFinish() |
| +{ |
| + testFailed('Should not have received a devicemotion event while the page was hidden'); |
| + finishJSTest(); |
| +} |
| + |
| +function testWithPageHidden() |
|
timvolodine
2013/09/18 13:49:21
this should be called via setTimeout 0, to make su
do-not-use
2013/09/18 14:04:39
Done.
|
| +{ |
| + testPassed("Received a devicemotion event"); |
| + window.removeEventListener('devicemotion', testWithPageHidden); |
| + if (window.testRunner) |
| + testRunner.setPageVisibility("hidden"); |
| + debug("* Page is hidden"); |
| + window.addEventListener('devicemotion', failAndFinish); |
| + |
| + setTimeout(testWithPageVisible, 100); |
| +} |
| + |
| +if (window.testRunner) |
| + testRunner.setMockDeviceMotion(true, 0, true, 0, true, 0, |
| + true, 0, true, 0, true, 0, |
| + true, 0, true, 0, true, 0, |
| + 0); |
| + |
| +debug("* Page is visible"); |
| +window.addEventListener('devicemotion', testWithPageHidden); |
| +</script> |
| +<script src="../../js/resources/js-test-post.js"></script> |
| +</body> |
| +</html> |