tests/clutter: Use the headless backend

One test depends on a pointer event having been emitted so that the
stage has a focused pointer; make sure that has happened.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2699>
This commit is contained in:
Jonas Ådahl 2022-11-16 20:16:46 +01:00 committed by Marge Bot
parent b15be5e287
commit 58e89b3a5d
2 changed files with 37 additions and 6 deletions

View File

@ -4,11 +4,14 @@
#include <glib-object.h> #include <glib-object.h>
#include <clutter/clutter.h> #include <clutter/clutter.h>
#include "backends/meta-monitor-manager-private.h"
#include "backends/meta-virtual-monitor.h"
#include "compositor/meta-plugin-manager.h" #include "compositor/meta-plugin-manager.h"
#include "core/meta-context-private.h" #include "core/meta-context-private.h"
typedef struct { typedef struct
gpointer dummy_field; {
MetaContext *context;
} ClutterTestEnvironment; } ClutterTestEnvironment;
static ClutterTestEnvironment *test_environ = NULL; static ClutterTestEnvironment *test_environ = NULL;
@ -46,12 +49,13 @@ clutter_test_init (int *argc,
{ {
MetaContext *context; MetaContext *context;
context = meta_create_test_context (META_CONTEXT_TEST_TYPE_NESTED, context = meta_create_test_context (META_CONTEXT_TEST_TYPE_HEADLESS,
META_CONTEXT_TEST_FLAG_NO_X11); META_CONTEXT_TEST_FLAG_NO_X11);
g_assert (meta_context_configure (context, argc, argv, NULL)); g_assert (meta_context_configure (context, argc, argv, NULL));
g_assert (meta_context_setup (context, NULL)); g_assert (meta_context_setup (context, NULL));
test_environ = g_new0 (ClutterTestEnvironment, 1); test_environ = g_new0 (ClutterTestEnvironment, 1);
test_environ->context = context;
g_assert (meta_context_start (context, NULL)); g_assert (meta_context_start (context, NULL));
@ -251,12 +255,30 @@ clutter_test_add_data_full (const char *test_path,
int int
clutter_test_run (void) clutter_test_run (void)
{ {
MetaBackend *backend = meta_context_get_backend (test_environ->context);
MetaMonitorManager *monitor_manager = meta_backend_get_monitor_manager (backend);
MetaVirtualMonitor *virtual_monitor;
g_autoptr (MetaVirtualMonitorInfo) monitor_info = NULL;
g_autoptr (GError) error = NULL;
int res; int res;
g_assert (test_environ != NULL); monitor_info = meta_virtual_monitor_info_new (1024, 768, 60.0,
"MetaTestVendor",
"ClutterTestMonitor",
"0x123");
virtual_monitor = meta_monitor_manager_create_virtual_monitor (monitor_manager,
monitor_info,
&error);
if (!virtual_monitor)
g_error ("Failed to create virtual monitor: %s", error->message);
meta_monitor_manager_reload (monitor_manager);
res = g_test_run (); res = g_test_run ();
g_object_unref (virtual_monitor);
g_clear_object (&test_environ->context);
g_free (test_environ); g_free (test_environ);
return res; return res;

View File

@ -66,6 +66,8 @@ actor_event_hold (void)
ClutterActor *stage; ClutterActor *stage;
ClutterBackend *backend; ClutterBackend *backend;
ClutterSeat *seat; ClutterSeat *seat;
g_autoptr (ClutterVirtualInputDevice) virtual_pointer = NULL;
int64_t now_us;
ClutterInputDevice *device; ClutterInputDevice *device;
ClutterEvent *event; ClutterEvent *event;
ClutterEvent *captured_event; ClutterEvent *captured_event;
@ -81,8 +83,15 @@ actor_event_hold (void)
/* Get the input device*/ /* Get the input device*/
backend = clutter_get_default_backend (); backend = clutter_get_default_backend ();
seat = clutter_backend_get_default_seat (backend); seat = clutter_backend_get_default_seat (backend);
device = clutter_seat_get_pointer (seat);
virtual_pointer =
clutter_seat_create_virtual_device (seat, CLUTTER_POINTER_DEVICE);
now_us = g_get_monotonic_time ();
clutter_virtual_input_device_notify_absolute_motion (virtual_pointer,
now_us,
1.0, 1.0);
device = clutter_seat_get_pointer (seat);
while (clutter_stage_get_device_actor (CLUTTER_STAGE (stage), device, NULL) == NULL) while (clutter_stage_get_device_actor (CLUTTER_STAGE (stage), device, NULL) == NULL)
g_main_context_iteration (NULL, FALSE); g_main_context_iteration (NULL, FALSE);