4 <script src=
"../../../resources/js-test.js"></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);
45 debug('This test can not be run without the TestRunner');
47 debug("* Page is visible");
48 window
.addEventListener('devicelight', deviceLightListener
);