diff --git a/tests/__init__.py b/tests/__init__.py index 0bb3bffbb..e0c9c338c 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -341,6 +341,7 @@ def __init__( self.dbus_test_case = dbus_test_case self.portal_name = portal_name self.portal_frontend = None + self.permission_store = None self.dbus_monitor = None self.portal_interfaces: Dict[str, dbus.Interface] = {} self.app_id = app_id @@ -444,6 +445,7 @@ def start_xdp(self): self.start_dbus_monitor() self.start_portal_frontend(env) + self.start_permission_store(env) def start_portal_frontend(self, env): # This roughly resembles test-portals.c and glib's test behavior @@ -478,6 +480,43 @@ def start_portal_frontend(self, env): self.portal_frontend = portal_frontend + def start_permission_store(self, env): + """ + Start the xdg-permission-store process + """ + + # This roughly resembles test-portals.c and glib's test behavior + # but preferences in-tree testing by running pytest in meson's + # project_build_root + libexecdir = os.getenv("LIBEXECDIR") + if libexecdir: + permission_store_path = Path(libexecdir) / "xdg-permission-store" + else: + permission_store_path = ( + Path(os.getenv("G_TEST_BUILDDIR") or "tests") + / ".." + / "document-portal" + / "xdg-permission-store" + ) + + if not permission_store_path.exists(): + raise FileNotFoundError( + f"{permission_store_path} does not exist, try running from meson build dir or setting G_TEST_BUILDDIR" + ) + + permission_store = subprocess.Popen([permission_store_path], env=env) + + for _ in range(50): + if self.dbus_test_case.dbus_con.name_has_owner("org.freedesktop.impl.portal.PermissionStore"): + break + time.sleep(0.1) + else: + assert ( + False + ), "Timeout while waiting for xdg-permission-store to claim the bus" + + self.permission_store = permission_store + def start_dbus_monitor(self): if not os.getenv("XDP_DBUS_MONITOR"): return @@ -493,6 +532,10 @@ def tearDown(self): self.portal_frontend.terminate() self.portal_frontend.wait() + if self.permission_store: + self.permission_store.terminate() + self.permission_store.wait() + for server in self.busses[dbusmock.BusType.SYSTEM]: self._terminate_mock_p (server.process) for server in self.busses[dbusmock.BusType.SESSION]: