gio/tests/fake-document-portal: Test that the app-id matches the request

Ensure that the app-id requiring the document matches the one we want,
so that we can actually test the code in GDesktopAppInfo that does the
mapping
This commit is contained in:
Marco Trevisan (Treviño)
2025-09-20 02:38:41 +02:00
committed by Marco Trevisan
parent 3eb2abb406
commit eb78cfeeca
4 changed files with 35 additions and 16 deletions

View File

@@ -378,7 +378,8 @@ test_flatpak_doc_export (void)
g_test_summary ("Test that files launched via Flatpak apps are made available via the document portal.");
/* Run a fake-document-portal */
thread = g_fake_document_portal_thread_new (session_bus_get_address ());
thread = g_fake_document_portal_thread_new (session_bus_get_address (),
"org.gtk.test.dbusappinfo.flatpak");
g_fake_document_portal_thread_run (thread);
desktop_file = g_test_build_filename (G_TEST_DIST,
@@ -472,7 +473,8 @@ test_flatpak_missing_doc_export (void)
g_test_summary ("Test that files launched via Flatpak apps are made available via the document portal.");
/* Run a fake-document-portal */
thread = g_fake_document_portal_thread_new (session_bus_get_address ());
thread = g_fake_document_portal_thread_new (session_bus_get_address (),
"NO_PORTAL_CALLED");
g_fake_document_portal_thread_run (thread);
desktop_file = g_test_build_filename (G_TEST_DIST,

View File

@@ -36,11 +36,13 @@ test_document_portal_add_uri (void)
GList *portal_uris = NULL; /* (element-type utf8) */
GFileIOStream *iostream = NULL;
GError *error = NULL;
const char *app_id;
char *basename;
char *expected_name;
/* Run a fake-document-portal */
thread = g_fake_document_portal_thread_new (session_bus_get_address ());
app_id = "org.gnome.glib.gio";
thread = g_fake_document_portal_thread_new (session_bus_get_address (), app_id);
g_fake_document_portal_thread_run (thread);
file = g_file_new_tmp ("test_document_portal_add_uri_XXXXXX",
@@ -51,7 +53,7 @@ test_document_portal_add_uri (void)
g_object_unref (iostream);
uris = g_list_append (uris, g_file_get_uri (file));
portal_uris = g_document_portal_add_documents (uris, "org.gnome.glib.gio", &error);
portal_uris = g_document_portal_add_documents (uris, app_id, &error);
g_assert_no_error (error);
basename = g_file_get_basename (file);
@@ -76,15 +78,17 @@ test_document_portal_add_not_existent_uri (void)
GList *uris = NULL; /* (element-type const char*) */
GList *portal_uris = NULL; /* (element-type utf8) */
GError *error = NULL;
const char *app_id;
const char *uri;
/* Run a fake-document-portal */
thread = g_fake_document_portal_thread_new (session_bus_get_address ());
app_id = "org.gnome.glib.gio.not-existent-uri";
thread = g_fake_document_portal_thread_new (session_bus_get_address (), app_id);
g_fake_document_portal_thread_run (thread);
uri = "file:/no-existent-path-really!";
uris = g_list_append (uris, (char *) uri);
portal_uris = g_document_portal_add_documents (uris, "org.gnome.glib.gio", &error);
portal_uris = g_document_portal_add_documents (uris, app_id, &error);
g_assert_no_error (error);
g_assert_cmpuint (g_list_length (portal_uris), ==, 1);
@@ -105,13 +109,15 @@ test_document_portal_add_existent_and_not_existent_uris (void)
GList *portal_uris = NULL; /* (element-type utf8) */
GFileIOStream *iostream = NULL;
GError *error = NULL;
const char *app_id;
const char *invalid_uri;
char *basename;
char *expected_name0;
char *expected_name1;
/* Run a fake-document-portal */
thread = g_fake_document_portal_thread_new (session_bus_get_address ());
app_id = "org.gnome.glib.gio.mixed-uris";
thread = g_fake_document_portal_thread_new (session_bus_get_address (), app_id);
g_fake_document_portal_thread_run (thread);
file = g_file_new_tmp ("test_document_portal_add_existent_and_not_existent_uris_XXXXXX",
@@ -128,7 +134,7 @@ test_document_portal_add_existent_and_not_existent_uris (void)
uris = g_list_append (uris, g_file_get_uri (file));
uris = g_list_append (uris, g_strdup (invalid_uri));
portal_uris = g_document_portal_add_documents (uris, "org.gnome.glib.gio", &error);
portal_uris = g_document_portal_add_documents (uris, app_id, &error);
g_assert_no_error (error);
basename = g_file_get_basename (file);
@@ -163,12 +169,14 @@ test_document_portal_add_symlink_uri (void)
GList *portal_uris = NULL; /* (element-type utf8) */
GFileIOStream *iostream = NULL;
GError *error = NULL;
const char *app_id;
char *tmpdir_path;
char *basename;
char *expected_name;
/* Run a fake-document-portal */
thread = g_fake_document_portal_thread_new (session_bus_get_address ());
app_id = "org.gnome.glib.gio.symlinks";
thread = g_fake_document_portal_thread_new (session_bus_get_address (), app_id);
g_fake_document_portal_thread_run (thread);
target = g_file_new_tmp ("test_document_portal_add_symlink_uri_XXXXXX",
@@ -203,7 +211,7 @@ test_document_portal_add_symlink_uri (void)
uris = g_list_append (uris, g_file_get_uri (link1));
uris = g_list_append (uris, g_file_get_uri (link2));
portal_uris = g_document_portal_add_documents (uris, "org.gnome.glib.gio", &error);
portal_uris = g_document_portal_add_documents (uris, app_id, &error);
g_assert_no_error (error);
basename = g_file_get_basename (target);

View File

@@ -34,6 +34,7 @@ struct _GFakeDocumentPortalThread
GObject parent_instance;
char *address; /* (not nullable) */
char *app_id; /* (nullable) */
GCancellable *cancellable; /* (not nullable) (owned) */
GThread *thread; /* (not nullable) (owned) */
GCond cond; /* (mutex mutex) */
@@ -72,6 +73,7 @@ g_fake_document_portal_thread_finalize (GObject *object)
g_cond_clear (&self->cond);
g_clear_object (&self->cancellable);
g_clear_pointer (&self->address, g_free);
g_clear_pointer (&self->app_id, g_free);
G_OBJECT_CLASS (g_fake_document_portal_thread_parent_class)->finalize (object);
}
@@ -97,6 +99,7 @@ on_handle_add_full (FakeDocuments *object,
const gchar * const *permissions,
gpointer user_data)
{
GFakeDocumentPortalThread *self = G_FAKE_DOCUMENT_PORTAL_THREAD (user_data);
gchar **doc_ids = NULL;
GVariant *extra_out = NULL;
gsize length, i;
@@ -106,6 +109,9 @@ on_handle_add_full (FakeDocuments *object,
else
length = 0;
if (self->app_id)
g_assert_cmpstr (self->app_id, ==, app_id);
doc_ids = g_new0 (gchar *, length + 1 /* NULL terminator */);
for (i = 0; i < length; i++)
{
@@ -192,10 +198,10 @@ fake_document_portal_thread_cb (gpointer user_data)
"handle-get-mount-point",
G_CALLBACK (on_handle_get_mount_point),
NULL);
g_signal_connect (interface,
"handle-add-full",
G_CALLBACK (on_handle_add_full),
NULL);
g_signal_connect_object (interface,
"handle-add-full",
G_CALLBACK (on_handle_add_full),
self, G_CONNECT_DEFAULT);
g_dbus_interface_skeleton_export (G_DBUS_INTERFACE_SKELETON (interface),
connection,
@@ -233,10 +239,12 @@ fake_document_portal_thread_cb (gpointer user_data)
* Returns: (transfer full): the new fake document portal wrapper
*/
GFakeDocumentPortalThread *
g_fake_document_portal_thread_new (const char *address)
g_fake_document_portal_thread_new (const char *address,
const char *app_id)
{
GFakeDocumentPortalThread *self = g_object_new (G_TYPE_FAKE_DOCUMENT_PORTAL_THREAD, NULL);
self->address = g_strdup (address);
self->app_id = g_strdup (app_id);
return g_steal_pointer (&self);
}

View File

@@ -28,7 +28,8 @@ G_BEGIN_DECLS
#define G_TYPE_FAKE_DOCUMENT_PORTAL_THREAD (g_fake_document_portal_thread_get_type ())
G_DECLARE_FINAL_TYPE (GFakeDocumentPortalThread, g_fake_document_portal_thread, G, FAKE_DOCUMENT_PORTAL_THREAD, GObject)
GFakeDocumentPortalThread *g_fake_document_portal_thread_new (const char *address);
GFakeDocumentPortalThread *g_fake_document_portal_thread_new (const char *address,
const char *app_id);
void g_fake_document_portal_thread_run (GFakeDocumentPortalThread *self);
void g_fake_document_portal_thread_stop (GFakeDocumentPortalThread *self);