Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / fast / dom / DeviceLight / page-visibility.html
blob073ab4b35af8db7d212e17e6e4df1f0288605c0b
1 <!DOCTYPE html>
2 <html>
3 <body>
4 <script src="../../../resources/js-test.js"></script>
5 <script>
7 description('Tests to check that devicelight events are not fired when the page is not visible.');
8 window.jsTestIsAsync = true;
10 function succeedAndFinish()
12 testPassed("Received a devicelight event");
13 setTimeout(finishJSTest, 0);
16 function testWithPageVisible()
18 testPassed("Did not receive a devicelight event");
19 window.removeEventListener('devicelight', failAndFinish);
20 testRunner.setPageVisibility("visible");
21 debug("* Page is visible");
22 window.addEventListener('devicelight', succeedAndFinish);
25 function failAndFinish()
27 testFailed('Should not have received a devicelight event while the page was hidden');
28 setTimeout(finishJSTest, 0);
31 function deviceLightListener(event)
33 testPassed("Received a devicelight event");
34 window.removeEventListener('devicelight', deviceLightListener);
35 testRunner.setPageVisibility("hidden");
36 debug("* Page is hidden");
37 window.addEventListener('devicelight', failAndFinish);
39 setTimeout(testWithPageVisible, 0);
42 if (window.testRunner)
43 testRunner.setMockDeviceLight(100);
44 else
45 debug('This test can not be run without the TestRunner');
47 debug("* Page is visible");
48 window.addEventListener('devicelight', deviceLightListener);
49 </script>
50 </body>
51 </html>