Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(147)

Side by Side Diff: LayoutTests/fast/dom/DeviceLight/page-visibility.html

Issue 490773003: [DeviceLight] Add Layout tests (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: fix comments Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 devicelight events are not fired when the page is not visible.');
8 window.jsTestIsAsync = true;
9
10 function succeedAndFinish()
11 {
12 testPassed("Received a devicelight event");
13 finishJSTest();
riju_ 2015/03/31 11:03:41 I guess it is better to use setTimeout(finishJSTes
14 }
15
16 function testWithPageVisible()
17 {
18 testPassed("Did not receive a devicelight event");
19 window.removeEventListener('devicelight', failAndFinish);
20 if (window.testRunner)
timvolodine 2015/03/30 13:00:54 no need for this if you add a check for window.tes
riju_ 2015/03/31 11:03:42 Done.
21 testRunner.setPageVisibility("visible");
22 debug("* Page is visible");
23 window.addEventListener('devicelight', succeedAndFinish);
24 }
25
26 function failAndFinish()
27 {
28 testFailed('Should not have received a devicelight event while the page was hidden');
29 finishJSTest();
timvolodine 2015/03/30 13:00:54 also better to use setTimeout(finishJSTest, 0); be
riju_ 2015/03/31 11:03:41 Done.
30 }
31
32 function deviceLightListener(event)
33 {
34 testPassed("Received a devicelight event");
35 window.removeEventListener('devicelight', deviceLightListener);
36 if (window.testRunner)
timvolodine 2015/03/30 13:00:55 same here
riju_ 2015/03/31 11:03:41 Done.
37 testRunner.setPageVisibility("hidden");
38 debug("* Page is hidden");
39 window.addEventListener('devicelight', failAndFinish);
40
41 testWithPageVisible();
timvolodine 2015/03/30 13:00:54 should use setTimeout(testWithPageVisible, 0); bec
riju_ 2015/03/31 11:03:41 Done.
42 }
43
44 if (window.testRunner)
45 testRunner.setMockDeviceLight(100);
timvolodine 2015/03/30 13:00:54 nit: in other test you have debug('This test can n
riju_ 2015/03/31 11:03:41 Done.
46
47 debug("* Page is visible");
48 window.addEventListener('devicelight', deviceLightListener);
49 </script>
50 </body>
51 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698