diff options
Diffstat (limited to 'testing/web-platform/tests/gamepad')
-rw-r--r-- | testing/web-platform/tests/gamepad/gamepad-dual-rumble-effect-manual.https.html | 94 | ||||
-rw-r--r-- | testing/web-platform/tests/gamepad/gamepad-trigger-rumble-effect-manual.https.html | 95 |
2 files changed, 189 insertions, 0 deletions
diff --git a/testing/web-platform/tests/gamepad/gamepad-dual-rumble-effect-manual.https.html b/testing/web-platform/tests/gamepad/gamepad-dual-rumble-effect-manual.https.html new file mode 100644 index 0000000000..4a1c5ba8c5 --- /dev/null +++ b/testing/web-platform/tests/gamepad/gamepad-dual-rumble-effect-manual.https.html @@ -0,0 +1,94 @@ +<!DOCTYPE html> +<html> + <head> + <meta charset="utf-8"> + <title></title> + <script src="/resources/testharness.js"></script> + <script src="/resources/testharnessreport.js"></script> + </head> + <body> + <p> + This test requires a gamepad device to be connected. Please interact with + the gamepad for it to be recognized. The "Dual rumble!" button will be + enabled after that. + </p> + <p> + After pressing the "Dual rumble!" button below, you should expect all the + "dual-rumble" compatible gamepads to vibrate for one second. + </p> + <p> + Please press the "Confirm effect has played" button to conclude + the test. + </p> + <button id="play_dual_rumble_button" disabled>No dual-rumble gamepads detected</button> + <button id="confirm_effect_button" disabled>Confirm effect has played</button> + <script> + async_test(t => { + let connectedDualRumbleGamepads = {}; + playEffectButton = document.getElementById('play_dual_rumble_button'); + + function isDualRumbleSupported(gamepad) { + return gamepad.vibrationActuator.effects.includes('dual-rumble'); + } + + window.addEventListener('gamepadconnected', (e) => { + if (!e.gamepad || !e.gamepad.vibrationActuator || !e.gamepad.vibrationActuator.effects) { + return; + } + + if (isDualRumbleSupported(e.gamepad)) { + connectedDualRumbleGamepads[e.gamepad.index] = e.gamepad; + + if (playEffectButton.disabled) { + playEffectButton.disabled = false; + playEffectButton.innerText = 'Dual rumble!' + } + } + }); + + window.addEventListener('gamepaddisconnected', (e) => { + delete connectedDualRumbleGamepads[e.gamepad.index]; + + let anyDualRumbleGamepad = false; + for (let index in connectedDualRumbleGamepads){ + const gamepad = connectedDualRumbleGamepads[index]; + if (!gamepad || !gamepad.vibrationActuator || !gamepad.vibrationActuator.effects) { + continue; + } + + if (isDualRumbleSupported(gamepad)){ + anyDualRumbleGamepad = true; + break; + } + } + + if (!anyDualRumbleGamepad && !playEffectButton.disabled) { + playEffectButton.disabled = true; + playEffectButton.innerText = "No dual-rumble gamepads detected"; + } + }); + + playEffectButton.addEventListener("click", () => { + let gamepads = navigator.getGamepads(); + for (const gamepad of gamepads) { + if (gamepad && isDualRumbleSupported(gamepad)) { + gamepad.vibrationActuator.playEffect("dual-rumble", { + duration: 1000, + strongMagnitude: 1.0, + weakMagnitude: 1.0, + }); + } + } + + const confirmButton = document.getElementById("confirm_effect_button"); + if (confirmButton.disabled) { + confirmButton.disabled = false; + } + confirmButton.addEventListener('click', () => { + t.done(); + }); + }); + }, "Gamepads with dual-rumble capabilities should have the body's motors activated."); + </script> + </body> +</html>
\ No newline at end of file diff --git a/testing/web-platform/tests/gamepad/gamepad-trigger-rumble-effect-manual.https.html b/testing/web-platform/tests/gamepad/gamepad-trigger-rumble-effect-manual.https.html new file mode 100644 index 0000000000..f436a60aac --- /dev/null +++ b/testing/web-platform/tests/gamepad/gamepad-trigger-rumble-effect-manual.https.html @@ -0,0 +1,95 @@ +<!DOCTYPE html> +<html> + <head> + <meta charset="utf-8"> + <title></title> + <script src="/resources/testharness.js"></script> + <script src="/resources/testharnessreport.js"></script> + </head> + <body> + <p> + This test requires a gamepad device to be connected. Please interact with + the gamepad for it to be recognized. The "Trigger rumble!" button will be + enabled after that. + </p> + <p> + After pressing the "Trigger rumble!" button below, you should expect to + feel a localized vibration in both triggers of all connected + trigger-rumble compatible gamepads for one second. + </p> + <p> + Please press the "Confirm effect has played" button to conclude + the test. + </p> + <button id="play_trigger_rumble_button" disabled>No trigger-rumble gamepads detected</button> + <button id="confirm_effect_button" disabled>Confirm effect has played</button> + <script> + async_test(t => { + let connectedTriggerRumbleGamepads = {}; + playEffectButton = document.getElementById('play_trigger_rumble_button'); + + function isTriggerRumbleSupported(gamepad) { + return gamepad.vibrationActuator.effects.includes('trigger-rumble'); + } + + window.addEventListener('gamepadconnected', (e) => { + if (!e.gamepad || !e.gamepad.vibrationActuator || !e.gamepad.vibrationActuator.effects) { + return; + } + + if (isTriggerRumbleSupported(e.gamepad)) { + connectedTriggerRumbleGamepads[e.gamepad.index] = e.gamepad; + + if (playEffectButton.disabled) { + playEffectButton.disabled = false; + playEffectButton.innerText = 'Trigger rumble!' + } + } + }); + + window.addEventListener('gamepaddisconnected', (e) => { + delete connectedTriggerRumbleGamepads[e.gamepad.index]; + + let anyTriggerRumbleGamepad = false; + for (let index in connectedTriggerRumbleGamepads){ + const gamepad = connectedTriggerRumbleGamepads[index]; + if (!gamepad || !gamepad.vibrationActuator || !gamepad.vibrationActuator.effects) { + continue; + } + + if (isTriggerRumbleSupported(gamepad)){ + anyTriggerRumbleGamepad = true; + break; + } + } + + if (!anyTriggerRumbleGamepad && !playEffectButton.disabled) { + playEffectButton.disabled = true; + playEffectButton.innerText = "No trigger-rumble gamepads detected"; + } + }); + + playEffectButton.addEventListener("click", () => { + let gamepads = navigator.getGamepads(); + for (const gamepad of gamepads) { + if (gamepad && isTriggerRumbleSupported(gamepad)) { + gamepad.vibrationActuator.playEffect("trigger-rumble", { + duration: 1000, + leftTrigger: 1.0, + rightTrigger: 1.0, + }); + } + } + + const confirmButton = document.getElementById("confirm_effect_button"); + if (confirmButton.disabled) { + confirmButton.disabled = false; + } + confirmButton.addEventListener('click', () => { + t.done(); + }); + }); + }, "Gamepads with trigger-rumble capabilities should have the triggers' motors activated."); + </script> + </body> +</html>
\ No newline at end of file |