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:
Sam Atkins
2026-01-06 12:20:27 +00:00
committed by Tim Flynn
parent 3c1d6dd38f
commit f2dd3d89d1
Notes: github-actions[bot] 2026-02-06 11:24:20 +00:00

View File

@@ -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.