tests/input-capture: Test that a11y isn't triggered when capturing

Accessibility should be handled on the receiving end, if needed. Make
sure this is the case by listening on some signals, verifying they are
only triggered if we're not capturing input.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2628>
This commit is contained in:
Jonas Ådahl 2022-04-28 17:46:34 +02:00 committed by Carlos Garnacho
parent 2fb3bdf774
commit 1513eccc03
2 changed files with 129 additions and 0 deletions

View File

@ -879,6 +879,57 @@ test_events (void)
input_capture_session_close (session); input_capture_session_close (session);
} }
static void
test_a11y (void)
{
InputCapture *input_capture;
InputCaptureSession *session;
g_autolist (Zone) zones = NULL;
Event expected_events[] = {
{
.type = EI_EVENT_POINTER_MOTION,
.motion = { .dx = -10.0, .dy = 0.0 },
},
{
.type = EI_EVENT_FRAME,
},
{
.type = EI_EVENT_BUTTON_BUTTON,
.button = { .button = BTN_LEFT, .is_press = TRUE },
},
{
.type = EI_EVENT_FRAME,
},
{
.type = EI_EVENT_BUTTON_BUTTON,
.button = { .button = BTN_LEFT, .is_press = FALSE },
},
{
.type = EI_EVENT_FRAME,
},
};
input_capture = input_capture_new ();
session = input_capture_create_session (input_capture);
input_capture_session_connect_to_eis (session);
zones = input_capture_session_get_zones (session);
input_capture_session_add_barrier (session, 0, 0, 0, 600);
input_capture_session_enable (session);
set_expected_events (session,
expected_events,
G_N_ELEMENTS (expected_events));
write_state (session, "1");
while (session->next_event < session->n_expected_events)
g_main_context_iteration (NULL, TRUE);
wait_for_state (session, "1");
input_capture_session_close (session);
}
static const struct static const struct
{ {
const char *name; const char *name;
@ -890,6 +941,7 @@ static const struct
{ "clear-barriers", test_clear_barriers, }, { "clear-barriers", test_clear_barriers, },
{ "cancel-keybinding", test_cancel_keybinding, }, { "cancel-keybinding", test_cancel_keybinding, },
{ "events", test_events, }, { "events", test_events, },
{ "a11y", test_a11y, },
}; };
static void static void

View File

@ -468,6 +468,79 @@ meta_test_input_capture_events (void)
input_capture_test_client_finish (test_client); input_capture_test_client_finish (test_client);
} }
static void
on_a11y_timeout_started (ClutterSeat *seat,
ClutterInputDevice *device,
ClutterPointerA11yTimeoutType timeout_type,
unsigned int delay_ms,
int *a11y_started_counter)
{
(*a11y_started_counter)++;
}
static void
meta_test_input_capture_a11y (void)
{
MetaBackend *backend = meta_context_get_backend (test_context);
ClutterSeat *seat = meta_backend_get_default_seat (backend);
g_autoptr (MetaVirtualMonitor) virtual_monitor = NULL;
g_autoptr (ClutterVirtualInputDevice) virtual_pointer = NULL;
InputCaptureTestClient *test_client;
ClutterPointerA11yDwellClickType dwell_click_type;
int a11y_started_counter = 0;
g_autoptr (GSettings) a11y_mouse_settings = NULL;
a11y_mouse_settings = g_settings_new ("org.gnome.desktop.a11y.mouse");
virtual_monitor = meta_create_test_monitor (test_context, 800, 600, 20.0);
virtual_pointer = clutter_seat_create_virtual_device (seat,
CLUTTER_POINTER_DEVICE);
clutter_virtual_input_device_notify_absolute_motion (virtual_pointer,
g_get_monotonic_time (),
10.0, 10.0);
g_settings_set_boolean (a11y_mouse_settings, "dwell-click-enabled", TRUE);
g_settings_set_boolean (a11y_mouse_settings, "secondary-click-enabled", TRUE);
dwell_click_type = CLUTTER_A11Y_DWELL_CLICK_TYPE_SECONDARY;
clutter_seat_set_pointer_a11y_dwell_click_type (seat, dwell_click_type);
g_signal_connect (seat, "ptr-a11y-timeout-started",
G_CALLBACK (on_a11y_timeout_started),
&a11y_started_counter);
click_button (virtual_pointer, CLUTTER_BUTTON_PRIMARY);
meta_flush_input (test_context);
g_assert_cmpint (a11y_started_counter, ==, 1);
test_client = input_capture_test_client_new ("a11y");
input_capture_test_client_wait_for_state (test_client, "1");
click_button (virtual_pointer, CLUTTER_BUTTON_PRIMARY);
meta_flush_input (test_context);
g_assert_cmpint (a11y_started_counter, ==, 2);
clutter_virtual_input_device_notify_relative_motion (virtual_pointer,
g_get_monotonic_time (),
-20.0, 0.0);
click_button (virtual_pointer, CLUTTER_BUTTON_PRIMARY);
meta_flush_input (test_context);
g_assert_cmpint (a11y_started_counter, ==, 2);
input_capture_test_client_write_state (test_client, "1");
input_capture_test_client_finish (test_client);
click_button (virtual_pointer, CLUTTER_BUTTON_PRIMARY);
meta_flush_input (test_context);
g_assert_cmpint (a11y_started_counter, ==, 3);
dwell_click_type = CLUTTER_A11Y_DWELL_CLICK_TYPE_NONE;
clutter_seat_set_pointer_a11y_dwell_click_type (seat, dwell_click_type);
g_settings_set_boolean (a11y_mouse_settings, "dwell-click-enabled", FALSE);
g_settings_set_boolean (a11y_mouse_settings, "secondary-click-enabled", FALSE);
}
static void static void
init_tests (void) init_tests (void)
{ {
@ -483,6 +556,8 @@ init_tests (void)
meta_test_input_capture_cancel_keybinding); meta_test_input_capture_cancel_keybinding);
g_test_add_func ("/backends/native/input-capture/events", g_test_add_func ("/backends/native/input-capture/events",
meta_test_input_capture_events); meta_test_input_capture_events);
g_test_add_func ("/backends/native/input-capture/a11y",
meta_test_input_capture_a11y);
} }
int int
@ -492,6 +567,8 @@ main (int argc,
g_autoptr (MetaContext) context = NULL; g_autoptr (MetaContext) context = NULL;
g_autoptr (GError) error = NULL; g_autoptr (GError) error = NULL;
g_assert_cmpstr (getenv ("GSETTINGS_BACKEND"), ==, "memory");
context = test_context = context = test_context =
meta_create_test_context (META_CONTEXT_TEST_TYPE_HEADLESS, meta_create_test_context (META_CONTEXT_TEST_TYPE_HEADLESS,
META_CONTEXT_TEST_FLAG_NO_X11); META_CONTEXT_TEST_FLAG_NO_X11);