| OLD | NEW |
| (Empty) |
| 1 <!DOCTYPE html> | |
| 2 <html> | |
| 3 <body> | |
| 4 <script src="../../../resources/js-test.js"></script> | |
| 5 <script> | |
| 6 | |
| 7 description('Tests to check that devicemotion events are not fired when the page
is not visible.'); | |
| 8 window.jsTestIsAsync = true; | |
| 9 | |
| 10 function succeedAndFinish() | |
| 11 { | |
| 12 testPassed("Received a devicemotion event"); | |
| 13 finishJSTest(); | |
| 14 } | |
| 15 | |
| 16 function testWithPageVisible() | |
| 17 { | |
| 18 testPassed("Did not receive a devicemotion event"); | |
| 19 window.removeEventListener('devicemotion', failAndFinish); | |
| 20 if (window.testRunner) | |
| 21 testRunner.setPageVisibility("visible"); | |
| 22 debug("* Page is visible"); | |
| 23 window.addEventListener('devicemotion', succeedAndFinish); | |
| 24 } | |
| 25 | |
| 26 function failAndFinish() | |
| 27 { | |
| 28 testFailed('Should not have received a devicemotion event while the page was
hidden'); | |
| 29 finishJSTest(); | |
| 30 } | |
| 31 | |
| 32 function testWithPageHidden() | |
| 33 { | |
| 34 testPassed("Received a devicemotion event"); | |
| 35 window.removeEventListener('devicemotion', deviceMotionListener); | |
| 36 if (window.testRunner) | |
| 37 testRunner.setPageVisibility("hidden"); | |
| 38 debug("* Page is hidden"); | |
| 39 window.addEventListener('devicemotion', failAndFinish); | |
| 40 | |
| 41 setTimeout(testWithPageVisible, 100); | |
| 42 } | |
| 43 | |
| 44 function deviceMotionListener(event) { | |
| 45 setTimeout(testWithPageHidden, 0); | |
| 46 } | |
| 47 | |
| 48 if (window.testRunner) | |
| 49 testRunner.setMockDeviceMotion(true, 0, true, 0, true, 0, | |
| 50 true, 0, true, 0, true, 0, | |
| 51 true, 0, true, 0, true, 0, | |
| 52 0); | |
| 53 | |
| 54 debug("* Page is visible"); | |
| 55 window.addEventListener('devicemotion', deviceMotionListener); | |
| 56 </script> | |
| 57 </body> | |
| 58 </html> | |
| OLD | NEW |