mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-04-25 17:25:08 +02:00
LibWeb/Gamepad: Ignore physical gamepads when running in test mode
This solves the issue where having a gamepad connected to a machine running tests would cause different results for a few gamepad-related tests. Conveniently, all our fake testing gamepads are "virtual" in SDL, and those are the only virtual ones.
This commit is contained in:
Notes:
github-actions[bot]
2026-02-06 11:24:20 +00:00
Author: https://github.com/AtkinsSJ Commit: https://github.com/LadybirdBrowser/ladybird/commit/f2dd3d89d1e Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/7346 Reviewed-by: https://github.com/trflynn89 ✅
@@ -97,8 +97,6 @@ void NavigatorGamepadPartial::handle_gamepad_connected(SDL_JoystickID sdl_joysti
|
||||
if (m_available_gamepads.contains_slow(sdl_joystick_id))
|
||||
return;
|
||||
|
||||
m_available_gamepads.append(sdl_joystick_id);
|
||||
|
||||
// 1. Let document be the current global object's associated Document; otherwise null.
|
||||
// FIXME: We can't use the current global object here, since it's not executing in a scripting context.
|
||||
// NOTE: NavigatorGamepad is only available on Window.
|
||||
@@ -112,6 +110,13 @@ void NavigatorGamepadPartial::handle_gamepad_connected(SDL_JoystickID sdl_joysti
|
||||
if (!document.is_allowed_to_use_feature(DOM::PolicyControlledFeature::Gamepad))
|
||||
return;
|
||||
|
||||
// AD-HOC: In test mode, ignore any non-virtual gamepads.
|
||||
// All fake gamepads added by Internals are always virtual, and no other ones are.
|
||||
if (HTML::Window::in_test_mode() && !SDL_IsJoystickVirtual(sdl_joystick_id))
|
||||
return;
|
||||
|
||||
m_available_gamepads.append(sdl_joystick_id);
|
||||
|
||||
// 3. Queue a global task on the gamepad task source with the current global object to perform the following steps:
|
||||
HTML::queue_global_task(HTML::Task::Source::Gamepad, window, GC::create_function(realm.heap(), [&realm, &document, sdl_joystick_id] mutable {
|
||||
// 1. Let gamepad be a new Gamepad representing the gamepad.
|
||||
|
||||
Reference in New Issue
Block a user