events-manual.html (1102B)
1 <!doctype html> 2 <html> 3 <head> 4 <title>Manual Gamepad events tests</title> 5 <link rel="help" href="https://w3c.github.io/gamepad/#the-gamepadconnected-event"> 6 <link rel="help" href="https://w3c.github.io/gamepad/#the-gamepaddisconnected-event"> 7 <script src="/resources/testharness.js"></script> 8 <script src="/resources/testharnessreport.js"></script> 9 <script> 10 setup({explicit_timeout: true}); 11 12 function set_instructions(text) { 13 document.getElementById("instructions").textContent = text; 14 } 15 16 var index = -1; 17 addEventListener("gamepadconnected", function (e) { 18 assert_equals(index, -1, "Too many connected events?"); 19 assert_class_string(e, "GamepadEvent"); 20 assert_class_string(e.gamepad, "Gamepad"); 21 index = e.gamepad.index; 22 set_instructions("Found a gamepad. Now disconnect the gamepad."); 23 }); 24 addEventListener("gamepaddisconnected", function (e) { 25 assert_class_string(e, "GamepadEvent"); 26 assert_equals(e.gamepad.index, index); 27 done(); 28 }); 29 </script> 30 </head> 31 <body> 32 <p id="instructions">This test requires a gamepad. Connect one and press any button to start the test.</p> 33 </body> 34 </html>