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 function succeedAndFinish() |
| 12 { |
| 13 testPassed("Received a devicemotion event"); |
| 14 finishJSTest(); |
| 15 } |
| 16 |
| 17 function testWithPageVisible() |
| 18 { |
| 19 testPassed("Did not receive a devicemotion event"); |
| 20 window.removeEventListener('devicemotion', failAndFinish); |
| 21 if (window.testRunner) |
| 22 testRunner.setPageVisibility("visible"); |
| 23 debug("* Page is visible"); |
| 24 window.addEventListener('devicemotion', succeedAndFinish); |
| 25 } |
| 26 |
| 27 function failAndFinish() |
| 28 { |
| 29 testFailed('Should not have received a devicemotion event while the page was
hidden'); |
| 30 finishJSTest(); |
| 31 } |
| 32 |
| 33 function testWithPageHidden() |
| 34 { |
| 35 testPassed("Received a devicemotion event"); |
| 36 window.removeEventListener('devicemotion', deviceMotionListener); |
| 37 if (window.testRunner) |
| 38 testRunner.setPageVisibility("hidden"); |
| 39 debug("* Page is hidden"); |
| 40 window.addEventListener('devicemotion', failAndFinish); |
| 41 |
| 42 setTimeout(testWithPageVisible, 100); |
| 43 } |
| 44 |
| 45 function deviceMotionListener(event) { |
| 46 setTimeout(testWithPageHidden, 0); |
| 47 } |
| 48 |
| 49 if (window.testRunner) |
| 50 testRunner.setMockDeviceMotion(true, 0, true, 0, true, 0, |
| 51 true, 0, true, 0, true, 0, |
| 52 true, 0, true, 0, true, 0, |
| 53 0); |
| 54 |
| 55 debug("* Page is visible"); |
| 56 window.addEventListener('devicemotion', deviceMotionListener); |
| 57 </script> |
| 58 <script src="../../js/resources/js-test-post.js"></script> |
| 59 </body> |
| 60 </html> |
OLD | NEW |