mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-01-23 04:36:17 +01:00
gio/tests: add a test for document portal use when launching flatpaks
We can't use session_bus_down() in the test since gdocumentportal.c holds a reference to the session bus connection, preventing it from being finalised.
This commit is contained in:
parent
27db702ceb
commit
926ff8c6a7
@ -276,12 +276,103 @@ test_dbus_appinfo (void)
|
||||
g_object_unref (app);
|
||||
}
|
||||
|
||||
static void
|
||||
on_flatpak_launch_uris_finish (GObject *object,
|
||||
GAsyncResult *result,
|
||||
gpointer user_data)
|
||||
{
|
||||
GApplication *app = user_data;
|
||||
GError *error = NULL;
|
||||
|
||||
g_app_info_launch_uris_finish (G_APP_INFO (object), result, &error);
|
||||
g_assert_no_error (error);
|
||||
|
||||
g_application_release (app);
|
||||
}
|
||||
|
||||
static void
|
||||
on_flatpak_activate (GApplication *app,
|
||||
gpointer user_data)
|
||||
{
|
||||
GDesktopAppInfo *flatpak_appinfo = user_data;
|
||||
char *uri;
|
||||
GList *uris;
|
||||
|
||||
/* The app will be released in on_flatpak_launch_uris_finish */
|
||||
g_application_hold (app);
|
||||
|
||||
uri = g_filename_to_uri (g_desktop_app_info_get_filename (flatpak_appinfo), NULL, NULL);
|
||||
g_assert_nonnull (uri);
|
||||
uris = g_list_prepend (NULL, uri);
|
||||
g_app_info_launch_uris_async (G_APP_INFO (flatpak_appinfo), uris, NULL,
|
||||
NULL, on_flatpak_launch_uris_finish, app);
|
||||
g_list_free (uris);
|
||||
g_free (uri);
|
||||
}
|
||||
|
||||
static void
|
||||
on_flatpak_open (GApplication *app,
|
||||
GFile **files,
|
||||
gint n_files,
|
||||
const char *hint)
|
||||
{
|
||||
GFile *f;
|
||||
|
||||
g_assert_cmpint (n_files, ==, 1);
|
||||
g_test_message ("on_flatpak_open received file '%s'", g_file_peek_path (files[0]));
|
||||
|
||||
/* The file has been exported via the document portal */
|
||||
f = g_file_new_for_uri ("file:///document-portal/document-id/org.gtk.test.dbusappinfo.flatpak.desktop");
|
||||
g_assert_true (g_file_equal (files[0], f));
|
||||
g_object_unref (f);
|
||||
}
|
||||
|
||||
static void
|
||||
test_flatpak_doc_export (void)
|
||||
{
|
||||
const gchar *argv[] = { "myapp", NULL };
|
||||
gchar *desktop_file = NULL;
|
||||
GDesktopAppInfo *flatpak_appinfo;
|
||||
GApplication *app;
|
||||
int status;
|
||||
|
||||
g_test_summary ("Test that files launched via Flatpak apps are made available via the document portal.");
|
||||
|
||||
desktop_file = g_test_build_filename (G_TEST_DIST,
|
||||
"org.gtk.test.dbusappinfo.flatpak.desktop",
|
||||
NULL);
|
||||
flatpak_appinfo = g_desktop_app_info_new_from_filename (desktop_file);
|
||||
g_assert_nonnull (flatpak_appinfo);
|
||||
g_free (desktop_file);
|
||||
|
||||
app = g_application_new ("org.gtk.test.dbusappinfo.flatpak",
|
||||
G_APPLICATION_HANDLES_OPEN);
|
||||
g_signal_connect (app, "activate", G_CALLBACK (on_flatpak_activate),
|
||||
flatpak_appinfo);
|
||||
g_signal_connect (app, "open", G_CALLBACK (on_flatpak_open), NULL);
|
||||
|
||||
status = g_application_run (app, 1, (gchar **) argv);
|
||||
g_assert_cmpint (status, ==, 0);
|
||||
|
||||
g_object_unref (app);
|
||||
g_object_unref (flatpak_appinfo);
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, char **argv)
|
||||
{
|
||||
int ret;
|
||||
|
||||
g_test_init (&argc, &argv, NULL);
|
||||
|
||||
g_test_add_func ("/appinfo/dbusappinfo", test_dbus_appinfo);
|
||||
g_test_add_func ("/appinfo/flatpak-doc-export", test_flatpak_doc_export);
|
||||
|
||||
return session_bus_run ();
|
||||
session_bus_up ();
|
||||
ret = g_test_run ();
|
||||
/* gdocumentportal.c holds a reference to the session bus
|
||||
* connection, which prevents session_bus_down from completing
|
||||
* successfully. */
|
||||
session_bus_stop ();
|
||||
return ret;
|
||||
}
|
||||
|
@ -474,6 +474,7 @@ if installed_tests_enabled
|
||||
'appinfo-test-static.desktop',
|
||||
'file.c',
|
||||
'org.gtk.test.dbusappinfo.desktop',
|
||||
'org.gtk.test.dbusappinfo.flatpak.desktop',
|
||||
'test1.overlay',
|
||||
install_dir : installed_tests_execdir,
|
||||
)
|
||||
|
5
gio/tests/org.gtk.test.dbusappinfo.flatpak.desktop
Normal file
5
gio/tests/org.gtk.test.dbusappinfo.flatpak.desktop
Normal file
@ -0,0 +1,5 @@
|
||||
[Desktop Entry]
|
||||
Type=Application
|
||||
Name=Test
|
||||
DBusActivatable=true
|
||||
X-Flatpak=org.gtk.test.dbusappinfo.flatpak
|
Loading…
Reference in New Issue
Block a user