Files
magpie/internal/gui/webkit_linux_test.go
T
yetone b90e81da14 gui: on Linux without gst-plugins-good the masking demo shows her poster
On stock Omarchy (Arch + Hyprland, WebKitGTK 2.52.6, GStreamer 1.28.6
with gst-plugins-base and -bad only), opening the masking demo aborted
WebKitWebProcess about three seconds in, so the app's window went blank.
WebKitGTK gives every video, a muted one too, an audio sink it makes with
autoaudiosink ("GStreamer element autoaudiosink not found", then a NULL
g_signal_connect, then SIGABRT); that element is in gst-plugins-good.
canPlayType can't tell: an Ogg Theora copy, "probably" playable there,
crashed the same way, so no other format would do.

The Linux app now looks for libgstautodetect.so in GStreamer's plugin
folders (its variables' and the system's): GStreamer's core there and
autodetect in none of them means no video (webkitPlaysVideo). Settings
state says noVideo then, in the app only (magpie web plays in the user's
own browser), and the demo sets no src: she is her poster and the sheets
move on the frame clock, as when the video can't load. No GStreamer folder
found says nothing, and video stays on.

Run at this head (origin/main 0f053024f + this change; the runs were at
ec6c2de52 + this change, and 0f053024f changes only README and site/):
- mote: node --test masking-demo, masking-records: 110 pass, 0 fail
  (Chromium and WebKit; the new poster test in both).
- magpie-desktop (WSL, Ubuntu 24.04): go test -tags gtk3 -run
  'TestGstAutodetect|TestWebkitDefaults|TestRenderNodeOpens|TestSettings'
  ./internal/gui: ok.
- mote: GOOS=linux CGO_ENABLED=0 go vet -tags gtk3, GOOS=windows go vet
  and go vet of ./internal/gui: ok. gofmt -l: none.
- omarchy, the real check on the real system, from a test binary built
  at this head: webkitPlaysVideo() is false
  ([/usr/lib/gstreamer-1.0 /usr/lib64/gstreamer-1.0]); on magpie-desktop,
  which has gst-plugins-good, true.
- omarchy, WebKitGTK driven from Python on `magpie web`'s page: with the
  demo's webm src set, the web process aborts every time (core dumps
  23:07:33, 23:10:17, 23:12:59, and 23:18:30 with an .ogv); with no src,
  as this change does, it stays up and T runs (2.99 -> 4.39 s).
- Broken by hand: gstAutodetect returning true makes TestGstAutodetect
  red ("stock omarchy: gstAutodetect = true, want false"); demo.js setting
  src regardless makes the poster test red in both engines.

Not tried: clicking the demo row in the real desktop app on omarchy (no
pointer tool there); the app's half was checked through the same
WebKitGTK and the detection through the real folders, separately.
2026-10-28 07:31:02 +08:00

97 lines
3.9 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package gui
import (
"errors"
"slices"
"testing"
)
// Under Wayland the pages are drawn without accelerated compositing, which
// flickered (myxxts); under X11 too when no GPU can be reached, where
// compositing fell back to llvmpipe and took 459%–830% CPU (#2827). X11
// with a GPU is left alone, and so is a user's own setting.
func TestWebkitDefaults(t *testing.T) {
for _, c := range []struct {
name string
env map[string]string
gpu bool
want string
}{
{"wayland", map[string]string{"XDG_SESSION_TYPE": "wayland"}, true, "1"},
{"wayland display only", map[string]string{"WAYLAND_DISPLAY": "wayland-0"}, true, "1"},
{"x11", map[string]string{"XDG_SESSION_TYPE": "x11"}, true, ""},
{"x11 without a gpu (xrdp)", map[string]string{"XDG_SESSION_TYPE": "x11", "DISPLAY": ":10"}, false, "1"},
{"user turned it on again", map[string]string{"XDG_SESSION_TYPE": "wayland", "WEBKIT_DISABLE_COMPOSITING_MODE": "0"}, true, "0"},
{"user turned it on again without a gpu", map[string]string{"XDG_SESSION_TYPE": "x11", "WEBKIT_DISABLE_COMPOSITING_MODE": "0"}, false, "0"},
{"user chose dmabuf off", map[string]string{"XDG_SESSION_TYPE": "wayland", "WEBKIT_DISABLE_DMABUF_RENDERER": "1"}, true, ""},
{"user chose dmabuf off without a gpu", map[string]string{"XDG_SESSION_TYPE": "x11", "WEBKIT_DISABLE_DMABUF_RENDERER": "1"}, false, ""},
} {
env := map[string]string{}
for k, v := range c.env {
env[k] = v
}
webkitDefaultsFor(func(k string) string { return env[k] }, func(k, v string) error { env[k] = v; return nil }, func() bool { return c.gpu })
if got := env["WEBKIT_DISABLE_COMPOSITING_MODE"]; got != c.want {
t.Errorf("%s: WEBKIT_DISABLE_COMPOSITING_MODE=%q, want %q", c.name, got, c.want)
}
}
}
// A GPU is reachable when one render node opens: none there, or each one
// refused (the xrdp user outside the render group), is software drawing.
func TestRenderNodeOpens(t *testing.T) {
denied := errors.New("permission denied")
for _, c := range []struct {
name string
nodes []string
ok map[string]bool
want bool
}{
{"no render node", nil, nil, false},
{"every node refused", []string{"/dev/dri/renderD128", "/dev/dri/renderD129"}, nil, false},
{"the second node opens", []string{"/dev/dri/renderD128", "/dev/dri/renderD129"}, map[string]bool{"/dev/dri/renderD129": true}, true},
} {
got := renderNodeOpens(c.nodes, func(p string) error {
if c.ok[p] {
return nil
}
return denied
})
if got != c.want {
t.Errorf("%s: renderNodeOpens = %v, want %v", c.name, got, c.want)
}
}
}
// WebKitGTK's web process aborts on any video where autoaudiosink is
// missing (stock Omarchy: gst-plugins-base and -bad, no -good), so video is
// off only there; with GStreamer's folder not found, nothing is known and
// video stays on.
func TestGstAutodetect(t *testing.T) {
for _, c := range []struct {
name string
files []string
want bool
}{
{"plugins-good installed", []string{"/usr/lib/gstreamer-1.0/libgstcoreelements.so", "/usr/lib/gstreamer-1.0/libgstautodetect.so"}, true},
{"stock omarchy", []string{"/usr/lib/gstreamer-1.0/libgstcoreelements.so", "/usr/lib/gstreamer-1.0/libgsttheora.so"}, false},
{"good in a folder the variable names", []string{"/usr/lib/gstreamer-1.0/libgstcoreelements.so", "/opt/gst/libgstautodetect.so"}, true},
{"no gstreamer folder found", nil, true},
} {
have := map[string]bool{}
for _, f := range c.files {
have[f] = true
}
if got := gstAutodetect([]string{"/opt/gst", "/usr/lib/gstreamer-1.0"}, func(p string) bool { return have[p] }); got != c.want {
t.Errorf("%s: gstAutodetect = %v, want %v", c.name, got, c.want)
}
}
env := map[string]string{"GST_PLUGIN_PATH_1_0": "/opt/gst:/opt/more", "GST_PLUGIN_SYSTEM_PATH": "/sys/gst"}
dirs := gstPluginDirs(func(k string) string { return env[k] })
for _, d := range []string{"/opt/gst", "/opt/more", "/sys/gst"} {
if !slices.Contains(dirs, d) {
t.Errorf("gstPluginDirs = %v, missing %s", dirs, d)
}
}
}