Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / fast / dom / DeviceOrientation / page-visibility.html
blobe1d7e8940d7d3750f9102670415baaee8996c4cf
1 <!DOCTYPE html>
2 <html>
3 <body>
4 <script src="../../../resources/js-test.js"></script>
5 <script>
6 description('Tests to check that deviceorientation events are not fired when the page is not visible.');
7 window.jsTestIsAsync = true;
9 function succeedAndFinish()
11 testPassed("Received a deviceorientation event");
12 finishJSTest();
15 function testWithPageVisible()
17 testPassed("Did not receive a deviceorientation event");
18 window.removeEventListener('deviceorientation', failAndFinish);
19 if (window.testRunner)
20 testRunner.setPageVisibility("visible");
21 debug("* Page is visible");
22 window.addEventListener('deviceorientation', succeedAndFinish);
25 function failAndFinish()
27 testFailed('Should not have received a deviceorientation event while the page was hidden');
28 finishJSTest();
31 function testWithPageHidden()
33 testPassed("Received a deviceorientation event");
34 window.removeEventListener('deviceorientation', deviceOrientationListener);
35 if (window.testRunner)
36 testRunner.setPageVisibility("hidden");
37 debug("* Page is hidden");
38 window.addEventListener('deviceorientation', failAndFinish);
40 setTimeout(testWithPageVisible, 100);
43 function deviceOrientationListener(event) {
44 setTimeout(testWithPageHidden, 0);
47 if (window.testRunner)
48 testRunner.setMockDeviceOrientation(true, 1, true, 2, true, 3, true, true);
50 debug("* Page is visible");
51 window.addEventListener('deviceorientation', deviceOrientationListener);
52 </script>
53 </body>
54 </html>