mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-12-08 06:09:58 +00:00
LibWeb: Add tests for Gamepad API by utilising virtual SDL3 joysticks
This commit is contained in:
parent
74e0483ea5
commit
9adf27f009
Notes:
github-actions[bot]
2025-09-01 19:11:51 +00:00
Author: https://github.com/Lubrsi
Commit: 9adf27f009
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/5902
Reviewed-by: https://github.com/gmta
Reviewed-by: https://github.com/trflynn89
28 changed files with 897 additions and 0 deletions
44
Tests/LibWeb/Text/input/GamepadAPI/gamepad-helper.js
Normal file
44
Tests/LibWeb/Text/input/GamepadAPI/gamepad-helper.js
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
(() => {
|
||||
globalThis.handleSDLInputEvents = () => {
|
||||
internals.handleSDLInputEvents();
|
||||
return new Promise(resolve => {
|
||||
setTimeout(() => resolve(), 0);
|
||||
});
|
||||
};
|
||||
|
||||
globalThis.getStringifiedGamepads = () => {
|
||||
const gamepads = navigator.getGamepads().map(gamepad => ({
|
||||
id: gamepad.id,
|
||||
index: gamepad.index,
|
||||
connected: gamepad.connected,
|
||||
mapping: gamepad.mapping,
|
||||
axes: gamepad.axes,
|
||||
buttons: gamepad.buttons.map(button => ({
|
||||
pressed: button.pressed,
|
||||
touched: button.touched,
|
||||
value: button.value,
|
||||
})),
|
||||
vibrationActuator: {
|
||||
effects: gamepad.vibrationActuator.effects,
|
||||
},
|
||||
}));
|
||||
|
||||
return JSON.stringify(gamepads);
|
||||
};
|
||||
|
||||
globalThis.listenForGamepadConnected = () => {
|
||||
window.addEventListener("gamepadconnected", ({ gamepad }) => {
|
||||
println(
|
||||
`Received gamepadconnected event for '${gamepad.id}' at index ${gamepad.index}`
|
||||
);
|
||||
});
|
||||
};
|
||||
|
||||
globalThis.listenForGamepadDisconnected = () => {
|
||||
window.addEventListener("gamepaddisconnected", ({ gamepad }) => {
|
||||
println(
|
||||
`Received gamepaddisconnected event for '${gamepad.id}' at index ${gamepad.index}`
|
||||
);
|
||||
});
|
||||
};
|
||||
})();
|
||||
Loading…
Add table
Add a link
Reference in a new issue