Skip to content

Commit

Permalink
app-info: Make use of new XdpAppInfo testing capabilities
Browse files Browse the repository at this point in the history
Now that the subclasses handle testing requirements themselves, the
generic XdpAppInfo code can stop caring about it, and the XdpAppInfoTest
class can be dropped.

The testing harness is also adjusted to take advantage of this new
feature. In particular, for USB query support the flatpak kind needs to
be used.

This makes it possible to run test with specific or all XdpAppInfo types
that we have.
  • Loading branch information
swick committed Feb 12, 2025
1 parent 57ed0bc commit 8a662e1
Show file tree
Hide file tree
Showing 11 changed files with 291 additions and 264 deletions.
1 change: 0 additions & 1 deletion src/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ xdp_utils_sources = files(
'xdp-app-info-host.c',
'xdp-app-info-flatpak.c',
'xdp-app-info-snap.c',
'xdp-app-info-test.c',
'xdp-usb-query.c',
)

Expand Down
1 change: 0 additions & 1 deletion src/registry.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
#include <stdio.h>

#include "xdp-app-info-private.h"
#include "xdp-app-info-test-private.h"
#include "xdp-host-dbus.h"
#include "xdp-utils.h"

Expand Down
2 changes: 1 addition & 1 deletion src/xdp-app-info-host.c
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ xdp_app_info_host_new (int pid,
{
g_assert (g_strcmp0 (test_app_info_kind, "host") == 0);

app_id = g_getenv ("XDG_DESKTOP_PORTAL_TEST_APP_INFO_ID");
app_id = g_getenv ("XDG_DESKTOP_PORTAL_TEST_APP_ID");
}
else
{
Expand Down
36 changes: 0 additions & 36 deletions src/xdp-app-info-test-private.h

This file was deleted.

148 changes: 0 additions & 148 deletions src/xdp-app-info-test.c

This file was deleted.

73 changes: 17 additions & 56 deletions src/xdp-app-info.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
#include "xdp-app-info-flatpak-private.h"
#include "xdp-app-info-snap-private.h"
#include "xdp-app-info-host-private.h"
#include "xdp-app-info-test-private.h"
#include "xdp-utils.h"

#define DBUS_NAME_DBUS "org.freedesktop.DBus"
Expand Down Expand Up @@ -115,21 +114,6 @@ xdp_app_info_init (XdpAppInfo *app_info)
priv->pidfd = -1;
}

static XdpAppInfo *
maybe_create_test_app_info (void)
{
const char *test_override_app_id;
const char *test_override_usb_queries;

test_override_app_id = g_getenv ("XDG_DESKTOP_PORTAL_TEST_APP_ID");
if (!test_override_app_id)
return NULL;

test_override_usb_queries = g_getenv ("XDG_DESKTOP_PORTAL_TEST_USB_QUERIES");
return xdp_app_info_test_new (test_override_app_id,
test_override_usb_queries);
}

static XdpAppInfo *
xdp_app_info_new (uint32_t pid,
int pidfd,
Expand All @@ -138,10 +122,7 @@ xdp_app_info_new (uint32_t pid,
g_autoptr(XdpAppInfo) app_info = NULL;
g_autoptr(GError) local_error = NULL;

app_info = maybe_create_test_app_info ();

if (app_info == NULL)
app_info = xdp_app_info_flatpak_new (pid, pidfd, &local_error);
app_info = xdp_app_info_flatpak_new (pid, pidfd, &local_error);

if (!app_info && !g_error_matches (local_error, XDP_APP_INFO_ERROR,
XDP_APP_INFO_ERROR_WRONG_APP_KIND))
Expand Down Expand Up @@ -229,7 +210,7 @@ xdp_app_info_get_engine_display_name (XdpAppInfo *app_info)
gboolean
xdp_app_info_is_host (XdpAppInfo *app_info)
{
return XDP_IS_APP_INFO_HOST (app_info) || XDP_IS_APP_INFO_TEST (app_info);
return XDP_IS_APP_INFO_HOST (app_info);
}

const char *
Expand Down Expand Up @@ -897,21 +878,6 @@ xdp_invocation_ensure_app_info_sync (GDBusMethodInvocation *invocation,
error);
}

static XdpAppInfo *
maybe_create_registered_test_app_info (const char *registered_app_id)
{
const char *test_override_app_id;
const char *test_override_usb_queries;

test_override_app_id = g_getenv ("XDG_DESKTOP_PORTAL_TEST_APP_ID");
if (!test_override_app_id)
return NULL;

test_override_usb_queries = g_getenv ("XDG_DESKTOP_PORTAL_TEST_USB_QUERIES");
return xdp_app_info_test_new (registered_app_id,
test_override_usb_queries);
}

XdpAppInfo *
xdp_invocation_register_host_app_info_sync (GDBusMethodInvocation *invocation,
const char *app_id,
Expand All @@ -932,30 +898,25 @@ xdp_invocation_register_host_app_info_sync (GDBusMethodInvocation *invocation,
return NULL;
}

app_info = maybe_create_registered_test_app_info (app_id);

if (!app_info)
{
if (!xdp_connection_get_pidfd (connection, sender, cancellable, &pidfd, &pid, error))
return NULL;

detected_app_info = xdp_app_info_new (pid, pidfd, error);
if (!detected_app_info)
return NULL;
if (!xdp_connection_get_pidfd (connection, sender, cancellable, &pidfd, &pid, error))
return NULL;

if (!xdp_app_info_is_host (detected_app_info))
{
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
"Can't manually register a %s application",
xdp_app_info_get_engine_display_name (detected_app_info));
return NULL;
}
detected_app_info = xdp_app_info_new (pid, pidfd, error);
if (!detected_app_info)
return NULL;

app_info = xdp_app_info_host_new_registered (pidfd, app_id, error);
if (!app_info)
return NULL;
if (!xdp_app_info_is_host (detected_app_info))
{
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
"Can't manually register a %s application",
xdp_app_info_get_engine_display_name (detected_app_info));
return NULL;
}

app_info = xdp_app_info_host_new_registered (pidfd, app_id, error);
if (!app_info)
return NULL;

g_debug ("Adding registered host app '%s'", xdp_app_info_get_id (app_info));

cache_insert_app_info (sender, app_info);
Expand Down
Loading

0 comments on commit 8a662e1

Please sign in to comment.