Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 <html> | |
| 2 <head> | |
| 3 <script src="../../js/resources/js-test-pre.js"></script> | |
| 4 </head> | |
| 5 <body> | |
| 6 <script> | |
| 7 | |
| 8 description('Tests to check that devicemotion events are not fired when the page is not visible.'); | |
| 9 window.jsTestIsAsync = true; | |
| 10 | |
| 11 var eventCount = 0; | |
| 12 | |
| 13 function generateDeviceMotionEvent() | |
| 14 { | |
| 15 if (!window.testRunner) | |
| 16 return; | |
| 17 | |
| 18 debug("Sending mock device motion event"); | |
| 19 testRunner.setMockDeviceMotion(true, 0, true, 0, true, 0, | |
| 20 true, 0, true, 0, true, 0, | |
| 21 true, 0, true, 0, true, 0, | |
| 22 0); | |
| 23 } | |
| 24 | |
| 25 function deviceMotionListener(event) { | |
| 26 debug("Received a device motion event"); | |
| 27 ++eventCount; | |
|
timvolodine
2013/09/18 13:03:16
if (++eventCount == 1)
setTimeout(function(){c
| |
| 28 } | |
| 29 | |
| 30 function checkGotEventAndFinish() | |
| 31 { | |
|
timvolodine
2013/09/18 13:03:16
debug("Received a device motion event");
++eventCo
| |
| 32 shouldBe('eventCount', '2'); | |
| 33 finishJSTest(); | |
| 34 } | |
| 35 | |
| 36 function checkNoEventAndShowPage() | |
| 37 { | |
| 38 shouldBe('eventCount', '1'); | |
| 39 window.removeEventListener('devicemotion', deviceMotionListener); | |
| 40 if (window.testRunner) | |
| 41 testRunner.setPageVisibility("visible"); | |
| 42 debug("* Page is visible"); | |
| 43 generateDeviceMotionEvent(); | |
|
timvolodine
2013/09/18 13:03:16
remove
| |
| 44 window.addEventListener('devicemotion', deviceMotionListener); | |
|
timvolodine
2013/09/18 13:03:16
I would put checkGotEventAndFinish here as callbac
| |
| 45 setTimeout(checkGotEventAndFinish, 100); | |
| 46 } | |
| 47 | |
| 48 function checkGotEventAndHidePage() | |
| 49 { | |
| 50 shouldBe('eventCount', '1'); | |
| 51 window.removeEventListener('devicemotion', deviceMotionListener); | |
| 52 if (window.testRunner) | |
| 53 testRunner.setPageVisibility("hidden"); | |
| 54 debug("* Page is hidden"); | |
| 55 generateDeviceMotionEvent(); | |
|
timvolodine
2013/09/18 13:03:16
pls remove this line, not necessary to call genera
| |
| 56 window.addEventListener('devicemotion', deviceMotionListener); | |
| 57 | |
| 58 setTimeout(checkNoEventAndShowPage, 100); | |
| 59 } | |
| 60 | |
| 61 debug("* Page is visible"); | |
| 62 generateDeviceMotionEvent(); | |
|
timvolodine
2013/09/18 13:03:16
the name is somewhat misleading, it is actually mo
| |
| 63 window.addEventListener('devicemotion', deviceMotionListener); | |
| 64 setTimeout(checkGotEventAndHidePage, 100); | |
|
timvolodine
2013/09/18 13:03:16
instead of using a timeout of 100ms you could use
| |
| 65 </script> | |
| 66 <script src="../../js/resources/js-test-post.js"></script> | |
| 67 </body> | |
| 68 </html> | |
| OLD | NEW |