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

Side by Side Diff: LayoutTests/gamepad/page-visibility.html

Issue 306363002: Gamepad: honor page visibility (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: just a comment that it will be better with Oilpan Created 6 years, 6 months 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 description("Tests that gamepad events are not fired when page is hidden but kep t as pending and fired when the page becomes visible again.");
7 window.jsTestIsAsync = true;
8
9 var listeners;
10 function addListener(eventName, handler) {
11 if (!listeners)
12 listeners = new Array();
13 listeners.push({name: eventName, handler: handler});
14 window.addEventListener(eventName, handler);
15 }
16 function removeListeners() {
17 if (!listeners)
18 return;
19 listeners.forEach(function (l) {
20 window.removeEventListener(l.name, l.handler);
21 });
22 }
23
24 function finishSoon() {
25 setTimeout(finishJSTest, 10);
26 }
27
28 function testWithPageVisibleAgain() {
29 shouldBeEqualToString('document.visibilityState', 'hidden');
30 removeListeners();
31
32 var eventCount = 0;
33 window.addEventListener('gamepadconnected', function(event) {
34 testPassed('gamepadconnected dispatched after page become visible');
35 shouldBeEqualToString('document.visibilityState', 'visible');
36 shouldBeEqualToNumber('event.gamepad.index', 1);
37 if (++eventCount < 2)
38 return;
39 if (eventCount > 2)
40 testFailed("Only one gamepadconnected event should have been receive d. Redundant pending events (like connect and disconnect with the same gamepad) should be suppressed.");
41 finishSoon(); // Give some time to fail if suppression doesn't work.
42 });
43 window.addEventListener('gamepaddisconnected', function(event) {
44 testPassed('gamepaddisconnected dispatched after visibility change');
45 shouldBeEqualToString('document.visibilityState', 'visible');
46 shouldBeEqualToNumber('event.gamepad.index', 0);
47 if (++eventCount < 2)
48 return;
49 if (eventCount > 2)
50 testFailed("Only one gamepaddisconnected event should have been rece ived. Redundant pending events (like connect and disconnect with the same gamepa d) should be suppressed.");
51 finishSoon(); // Give some time to fail if suppression doesn't work.
52 });
53
54 testRunner.setPageVisibility('visible');
55
56 setTimeout(function() {
57 testFailed('gamepad events should have been received');
58 finishJSTest();
59 }, 100);
60 }
61
62 function testWithPageHidden() {
63 testRunner.setPageVisibility('hidden');
64 var shouldNotReceive = function() {
65 testFailed('Should not have received gamepad events while the page was h idden');
66 finishJSTest();
67 };
68 addListener('gamepadconnected', shouldNotReceive);
69 addListener('gamepaddisconnected', shouldNotReceive);
70
71 gamepadController.disconnect(0);
72
73 // These should be suppressed.
74 gamepadController.connect(1);
75 gamepadController.dispatchConnected(1);
76 gamepadController.disconnect(1);
77
78 gamepadController.connect(1);
79 gamepadController.dispatchConnected(1);
80
81 setTimeout(testWithPageVisibleAgain, 0);
82 }
83
84 if (!window.testRunner || !window.gamepadController) {
85 debug("This test cannot work without testRunner and gamepadController.");
86 }
87
88 addListener('gamepadconnected', function() {
89 testPassed("Received a gamepadconnected event");
90 shouldBeEqualToNumber('event.gamepad.index', 0);
91 removeListeners();
92 setTimeout(testWithPageHidden, 0);
93 });
94
95 gamepadController.connect(0);
96 gamepadController.dispatchConnected(0);
97
98 </script>
99 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698