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..ac929ad168a95b42c42595864da64e2f67f34f8a |
| --- /dev/null |
| +++ b/LayoutTests/fast/dom/DeviceMotion/page-visibility.html |
| @@ -0,0 +1,68 @@ |
| +<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; |
| + |
| +var eventCount = 0; |
| + |
| +function generateDeviceMotionEvent() |
| +{ |
| + if (!window.testRunner) |
| + return; |
| + |
| + debug("Sending mock device motion event"); |
| + testRunner.setMockDeviceMotion(true, 0, true, 0, true, 0, |
| + true, 0, true, 0, true, 0, |
| + true, 0, true, 0, true, 0, |
| + 0); |
| +} |
| + |
| +function deviceMotionListener(event) { |
| + debug("Received a device motion event"); |
| + ++eventCount; |
|
timvolodine
2013/09/18 13:03:16
if (++eventCount == 1)
setTimeout(function(){c
|
| +} |
| + |
| +function checkGotEventAndFinish() |
| +{ |
|
timvolodine
2013/09/18 13:03:16
debug("Received a device motion event");
++eventCo
|
| + shouldBe('eventCount', '2'); |
| + finishJSTest(); |
| +} |
| + |
| +function checkNoEventAndShowPage() |
| +{ |
| + shouldBe('eventCount', '1'); |
| + window.removeEventListener('devicemotion', deviceMotionListener); |
| + if (window.testRunner) |
| + testRunner.setPageVisibility("visible"); |
| + debug("* Page is visible"); |
| + generateDeviceMotionEvent(); |
|
timvolodine
2013/09/18 13:03:16
remove
|
| + window.addEventListener('devicemotion', deviceMotionListener); |
|
timvolodine
2013/09/18 13:03:16
I would put checkGotEventAndFinish here as callbac
|
| + setTimeout(checkGotEventAndFinish, 100); |
| +} |
| + |
| +function checkGotEventAndHidePage() |
| +{ |
| + shouldBe('eventCount', '1'); |
| + window.removeEventListener('devicemotion', deviceMotionListener); |
| + if (window.testRunner) |
| + testRunner.setPageVisibility("hidden"); |
| + debug("* Page is hidden"); |
| + generateDeviceMotionEvent(); |
|
timvolodine
2013/09/18 13:03:16
pls remove this line, not necessary to call genera
|
| + window.addEventListener('devicemotion', deviceMotionListener); |
| + |
| + setTimeout(checkNoEventAndShowPage, 100); |
| +} |
| + |
| +debug("* Page is visible"); |
| +generateDeviceMotionEvent(); |
|
timvolodine
2013/09/18 13:03:16
the name is somewhat misleading, it is actually mo
|
| +window.addEventListener('devicemotion', deviceMotionListener); |
| +setTimeout(checkGotEventAndHidePage, 100); |
|
timvolodine
2013/09/18 13:03:16
instead of using a timeout of 100ms you could use
|
| +</script> |
| +<script src="../../js/resources/js-test-post.js"></script> |
| +</body> |
| +</html> |