#!/usr/bin/env bash # Run the portal package's end-to-end test: Chandra's Settings portal backend behind the real # xdg-desktop-portal on a private session bus, configured by session/chandra.portal and # session/chandra-portals.conf exactly as session/install.py installs them (apt: dbus # xdg-desktop-portal). It checks what Chrome, Firefox, GTK 4 and Qt 6 see: ReadOne of # org.freedesktop.appearance color-scheme, and SettingChanged when the Dark mode switch flips. set -euo pipefail ROOT="$(cd "$(dirname "$0")/.." && pwd)"; cd "$ROOT" XDP="" for x in /usr/libexec/xdg-desktop-portal /usr/lib/xdg-desktop-portal; do [ -x "$x" ] && XDP="$x" && break done [ -n "$XDP" ] || { echo "xdg-desktop-portal not found (apt install xdg-desktop-portal)" >&2; exit 1; } tmp=$(mktemp -d) mkdir -p "$tmp/portals" "$tmp/config" "$tmp/run" cp session/chandra.portal "$tmp/portals/" # The distro's backends too, as on a real system (chandra-portals.conf lists them after chandra). cp /usr/share/xdg-desktop-portal/portals/*.portal "$tmp/portals/" 2>/dev/null || true # With XDG_DESKTOP_PORTAL_DIR set, xdg-desktop-portal reads its config from there too. cp session/chandra-portals.conf "$tmp/portals/" export XDG_DESKTOP_PORTAL_DIR="$tmp/portals" XDG_CONFIG_HOME="$tmp/config" \ XDG_RUNTIME_DIR="$tmp/run" XDG_CURRENT_DESKTOP=chandra addr_pid=$(dbus-daemon --session --fork --print-address=1 --print-pid=1) export DBUS_SESSION_BUS_ADDRESS=$(echo "$addr_pid" | sed -n 1p) DPID=$(echo "$addr_pid" | sed -n 2p) trap 'kill ${XPID:-} "$DPID" 2>/dev/null || true; rm -rf "$tmp"' EXIT dbus-update-activation-environment XDG_DESKTOP_PORTAL_DIR XDG_CONFIG_HOME XDG_RUNTIME_DIR \ XDG_CURRENT_DESKTOP # Start xdg-desktop-portal before the backend is on the bus (the harder order: it must still find # it once it appears); its log is printed if the test fails. "$XDP" -v >"$tmp/xdp.log" 2>&1 & XPID=$! sleep 1 CHANDRA_PORTAL_E2E=1 moon test --target native --warn-list -a compositor/portal "$@" || { cat "$tmp/xdp.log"; exit 1; }