| OLD | NEW |
| 1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
| 2 <html> | 2 <html> |
| 3 <body> | 3 <body> |
| 4 <script src="../resources/js-test.js"></script> | 4 <script src="../resources/js-test.js"></script> |
| 5 <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."); | 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; | 7 window.jsTestIsAsync = true; |
| 8 | 8 |
| 9 var listeners; | 9 var listeners; |
| 10 function addListener(eventName, handler) { | 10 function addListener(eventName, handler) { |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 }, | 35 }, |
| 36 { index: 1, connected: true, check: | 36 { index: 1, connected: true, check: |
| 37 function(event) { | 37 function(event) { |
| 38 shouldBeEqualToString('event.gamepad.id', "new"); | 38 shouldBeEqualToString('event.gamepad.id', "new"); |
| 39 } | 39 } |
| 40 }, | 40 }, |
| 41 { index: 2, connected: true, check: null } | 41 { index: 2, connected: true, check: null } |
| 42 ]; | 42 ]; |
| 43 var expected; | 43 var expected; |
| 44 | 44 |
| 45 function allTestsCompleted() { |
| 46 return eventCounter == expectations.length; |
| 47 } |
| 48 |
| 45 function testWithPageVisibleAgain() { | 49 function testWithPageVisibleAgain() { |
| 46 shouldBeEqualToString('document.visibilityState', 'hidden'); | 50 shouldBeEqualToString('document.visibilityState', 'hidden'); |
| 47 removeListeners(); | 51 removeListeners(); |
| 48 | 52 |
| 49 window.addEventListener('gamepadconnected', function(event) { | 53 window.addEventListener('gamepadconnected', function(event) { |
| 50 shouldBeTrue('eventCounter < expectations.length'); | 54 shouldBeTrue('eventCounter < expectations.length'); |
| 51 expected = expectations[eventCounter++]; | 55 expected = expectations[eventCounter++]; |
| 52 shouldBeEqualToNumber('event.gamepad.index', expected.index); | 56 shouldBeEqualToNumber('event.gamepad.index', expected.index); |
| 53 shouldBeTrue('expected.connected'); | 57 shouldBeTrue('expected.connected'); |
| 54 shouldBeTrue('event.gamepad.connected'); | 58 shouldBeTrue('event.gamepad.connected'); |
| 55 if (expected.check) | 59 if (expected.check) |
| 56 expected.check(event); | 60 expected.check(event); |
| 57 | 61 |
| 58 if (eventCounter == expectations.length) | 62 if (allTestsCompleted()) |
| 59 finishSoon(); // Give some time to fail if unexpecteds events are co
ming. | 63 finishSoon(); // Give some time to fail if unexpecteds events are co
ming. |
| 60 }); | 64 }); |
| 61 window.addEventListener('gamepaddisconnected', function(event) { | 65 window.addEventListener('gamepaddisconnected', function(event) { |
| 62 shouldBeTrue('eventCounter < expectations.length'); | 66 shouldBeTrue('eventCounter < expectations.length'); |
| 63 expected = expectations[eventCounter++]; | 67 expected = expectations[eventCounter++]; |
| 64 shouldBeEqualToNumber('event.gamepad.index', expected.index); | 68 shouldBeEqualToNumber('event.gamepad.index', expected.index); |
| 65 shouldBeFalse('expected.connected'); | 69 shouldBeFalse('expected.connected'); |
| 66 shouldBeFalse('event.gamepad.connected'); | 70 shouldBeFalse('event.gamepad.connected'); |
| 67 if (expected.check) | 71 if (expected.check) |
| 68 expected.check(event); | 72 expected.check(event); |
| 69 | 73 |
| 70 if (eventCounter == expectations.length) | 74 if (allTestsCompleted()) |
| 71 finishSoon(); // Give some time to fail if unexpecteds events are co
ming. | 75 finishSoon(); // Give some time to fail if unexpecteds events are co
ming. |
| 72 }); | 76 }); |
| 73 | 77 |
| 74 testRunner.setPageVisibility('visible'); | 78 testRunner.setPageVisibility('visible'); |
| 75 | |
| 76 setTimeout(function() { | |
| 77 testFailed('More gamepad events should have been received'); | |
| 78 finishJSTest(); | |
| 79 }, 100); | |
| 80 } | 79 } |
| 81 | 80 |
| 82 function testWithPageHidden() { | 81 function testWithPageHidden() { |
| 83 testRunner.setPageVisibility('hidden'); | 82 testRunner.setPageVisibility('hidden'); |
| 84 var shouldNotReceive = function() { | 83 var shouldNotReceive = function() { |
| 85 testFailed('Should not have received gamepad events while the page was h
idden'); | 84 testFailed('Should not have received gamepad events while the page was h
idden'); |
| 86 finishJSTest(); | 85 finishJSTest(); |
| 87 }; | 86 }; |
| 88 addListener('gamepadconnected', shouldNotReceive); | 87 addListener('gamepadconnected', shouldNotReceive); |
| 89 addListener('gamepaddisconnected', shouldNotReceive); | 88 addListener('gamepaddisconnected', shouldNotReceive); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 119 }); | 118 }); |
| 120 | 119 |
| 121 gamepadController.connect(0); | 120 gamepadController.connect(0); |
| 122 gamepadController.dispatchConnected(0); | 121 gamepadController.dispatchConnected(0); |
| 123 gamepadController.setId(1, "old"); | 122 gamepadController.setId(1, "old"); |
| 124 gamepadController.connect(1); | 123 gamepadController.connect(1); |
| 125 gamepadController.dispatchConnected(1); | 124 gamepadController.dispatchConnected(1); |
| 126 | 125 |
| 127 </script> | 126 </script> |
| 128 </html> | 127 </html> |
| OLD | NEW |