tests/utils: Add helper to find a window given a title

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2262>
This commit is contained in:
Jonas Ådahl 2022-01-27 18:58:56 +01:00 committed by Marge Bot
parent b522e3cecd
commit b7f23c1baf
2 changed files with 30 additions and 25 deletions

View File

@ -335,47 +335,48 @@ meta_test_client_wait (MetaTestClient *client,
} }
} }
MetaWindow *
meta_find_window_from_title (MetaContext *context,
const char *title)
{
g_autoptr (GList) windows = NULL;
GList *l;
windows = meta_display_list_all_windows (meta_context_get_display (context));
for (l = windows; l; l = l->next)
{
MetaWindow *window = l->data;
if (g_strcmp0 (window->title, title) == 0)
return window;
}
return NULL;
}
MetaWindow * MetaWindow *
meta_test_client_find_window (MetaTestClient *client, meta_test_client_find_window (MetaTestClient *client,
const char *window_id, const char *window_id,
GError **error) GError **error)
{ {
MetaDisplay *display = meta_get_display (); MetaDisplay *display = meta_get_display ();
GSList *windows; g_autofree char *expected_title = NULL;
GSList *l; MetaWindow *window;
MetaWindow *result;
char *expected_title;
windows =
meta_display_list_windows (display,
META_LIST_INCLUDE_OVERRIDE_REDIRECT);
expected_title = g_strdup_printf ("test/%s/%s", client->id, window_id); expected_title = g_strdup_printf ("test/%s/%s", client->id, window_id);
window = meta_find_window_from_title (meta_display_get_context (display),
expected_title);
result = NULL; if (!window)
for (l = windows; l; l = l->next)
{
MetaWindow *window = l->data;
if (g_strcmp0 (window->title, expected_title) == 0)
{
result = window;
break;
}
}
g_slist_free (windows);
g_free (expected_title);
if (result == NULL)
{ {
g_set_error (error, g_set_error (error,
META_TEST_CLIENT_ERROR, META_TEST_CLIENT_ERROR,
META_TEST_CLIENT_ERROR_RUNTIME_ERROR, META_TEST_CLIENT_ERROR_RUNTIME_ERROR,
"window %s/%s isn't known to Mutter", client->id, window_id); "window %s/%s isn't known to Mutter", client->id, window_id);
return NULL;
} }
return result; return window;
} }
typedef struct _WaitForShownData typedef struct _WaitForShownData

View File

@ -84,6 +84,10 @@ gboolean meta_test_client_do (MetaTestClient *client,
GError **error, GError **error,
...) G_GNUC_NULL_TERMINATED; ...) G_GNUC_NULL_TERMINATED;
META_EXPORT
MetaWindow * meta_find_window_from_title (MetaContext *context,
const char *title);
META_EXPORT META_EXPORT
MetaWindow * meta_test_client_find_window (MetaTestClient *client, MetaWindow * meta_test_client_find_window (MetaTestClient *client,
const char *window_id, const char *window_id,