Files
DroidDeck/tools/tests/test_desktop_chromium_apps.py
T
MaxsTechReview d967dd03a3 fix(desktop): Electron and Chromium apps start however they are launched (#3106)
* fix(desktop): Electron and Chromium apps start however they are launched

The session preload only added --no-sandbox when the program path itself
sat beside chrome-sandbox, so a PATH link such as /usr/bin/vesktop was
missed and the app aborted on the setuid sandbox. It now resolves the
path and also checks the parent folder, and adds --ozone-platform=x11
when an X display is set, since Wayland cannot open the GPU stand-in.

The desktop menu overrides that added the same flags are removed: they
covered only menu launches made after the desktop started, and the
preload now covers every launch. Stale overrides are cleaned up by the
existing marker check.

* fix(preload): execvp checks the program found on PATH for the Chromium flags

* fix(preload): the PATH lookup prefers the program execvp would run
2026-11-23 21:23:56 -05:00

63 lines
2.6 KiB
Python

from pathlib import Path
import tempfile
import unittest
SCRIPT = Path(__file__).resolve().parents[1] / "linuxfs/desktop/droiddeck-desktop-gpu"
def load():
source = SCRIPT.read_text()
assert source.rstrip().endswith("main()")
scope = {"__name__": "droiddeck_desktop_gpu"}
exec(compile(source.rstrip()[:-len("main()")], str(SCRIPT), "exec"), scope)
return scope
class DesktopChromiumAppsTest(unittest.TestCase):
def setUp(self):
self.temp = tempfile.TemporaryDirectory()
self.addCleanup(self.temp.cleanup)
self.root = Path(self.temp.name)
self.gpu = load()
self.electron = self.app("lib/chat/chat", sandbox=True)
self.plain = self.app("lib/editor/editor", sandbox=False)
def app(self, relative, sandbox):
path = self.root / relative
path.parent.mkdir(parents=True)
path.write_text("#!/bin/sh\n")
path.chmod(0o755)
if sandbox:
(path.parent / "chrome-sandbox").write_text("")
return path
def entry(self, exec_line, categories="Network;", actions=""):
text = "[Desktop Entry]\nType=Application\nName=App\nExec=%s\nCategories=%s\n" % (exec_line, categories)
if actions:
text += "Actions=new;\n\n[Desktop Action new]\nName=New\nExec=%s\n" % actions
return text
def exec_lines(self, text):
return [l[5:] for l in text.splitlines() if l.startswith("Exec=")]
def test_electron_apps_keep_their_own_entries(self):
self.assertIsNone(self.gpu["wrap"](self.entry("%s %%U" % self.electron, actions="%s --new" % self.electron)))
self.assertIsNone(self.gpu["wrap"](self.entry(str(self.plain))))
def test_an_electron_game_goes_to_the_gpu_as_installed(self):
out = self.gpu["wrap"](self.entry(str(self.electron), categories="Game;", actions="%s --new" % self.electron))
self.assertEqual(self.exec_lines(out), ["droiddeck-gpu " + str(self.electron), str(self.electron),
"droiddeck-gpu %s --new" % self.electron])
def test_with_the_gpu_off_no_entry_is_written(self):
self.assertIsNone(self.gpu["wrap"](self.entry(str(self.electron), categories="Game;"), False))
self.assertIsNone(self.gpu["wrap"](self.entry(str(self.plain), categories="Game;"), False))
def test_games_that_are_not_chromium_are_unchanged(self):
out = self.gpu["wrap"](self.entry(str(self.plain), categories="Game;"))
self.assertEqual(self.exec_lines(out), ["droiddeck-gpu " + str(self.plain), str(self.plain)])
if __name__ == "__main__":
unittest.main()