#!/usr/bin/env python3 """Smoke-test stand-in for a browser: plays a stream and reports it as a tab. fake-browser.py : starts the host as its child, like a browser does, then pw-play (its "audio service") and a moment later one audible tab. Exits when stdin closes. """ import json import os import struct import subprocess import sys import time def message(tabs): body = json.dumps({"tabs": tabs}).encode() return struct.pack("=I", len(body)) + body def play(): # exec keeps the pid the stream announces. os.execvp("pw-play", ["pw-play", "-P", json.dumps({ "application.name": "Fake Browser", "application.process.id": str(os.getpid()), "media.name": "Playback", }), sys.argv[2]]) host = subprocess.Popen([sys.argv[1]], stdin=subprocess.PIPE) host.stdin.write(message([])) host.stdin.flush() time.sleep(3) # let it connect to PipeWire audio = os.fork() if audio == 0: play() time.sleep(0.5) host.stdin.write(message([{"id": 7, "title": "Smoke test tab", "audible": True}])) host.stdin.flush() sys.stdin.read() os.kill(audio, 15) host.stdin.close() host.wait(5)