Files
yellowjacket/backend/mediacontrols/mpris_metadata_linux_test.go
T
logan 128fa85a65
CI / check (push) Skipped
CI / e2e (push) Skipped
CI / check (pull_request) Successful in 2m30s
CI / e2e (pull_request) Canceled after 0s
fix(mediacontrols): answer "no artwork" instead of saying nothing
A track with no cover art omitted mpris:artUrl entirely, and KDE's
media controller keeps showing the last image it was handed -- so the
taskbar preview for an untagged track displayed the cover of whichever
earlier album happened to have one, where the user has no way to tell
it is stale.

The key is now always published, empty when there is nothing. Omitting
a field is what an absent value naturally reads as, and artwork is the
one field where that is wrong.

The dictionary build is extracted so it can be asserted on without a
bus. Every other field stays absent when empty -- a title of "" would
make players show a blank line where they would otherwise fall back to
the filename.

Refs #41
2026-08-18 11:25:57 -04:00

74 lines
1.8 KiB
Go

//go:build linux && !android
package mediacontrols
import "testing"
// TestArtURLIsAlwaysAnswered pins the one field in the MPRIS metadata
// dictionary that must be published even when it is empty.
//
// Omitting a field is what an absent value naturally reads as, and it
// is wrong for artwork: KDE's media controller keeps showing the last
// image it was handed, so a track with no cover art displayed the
// cover of whichever earlier album had one — in the taskbar preview,
// where the user has no way to tell it is stale.
func TestArtURLIsAlwaysAnswered(t *testing.T) {
t.Parallel()
tests := []struct {
name string
meta Metadata
want string
}{
{
name: "art present",
meta: Metadata{
Title: "Tideline",
ArtFilePath: "/covers/abc_lg.jpg",
},
want: "file:///covers/abc_lg.jpg",
},
{
name: "no art at all",
meta: Metadata{Title: "Untagged"},
want: "",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
m := metadataMap(tt.meta, 1)
got, ok := m["mpris:artUrl"]
if !ok {
t.Fatal("mpris:artUrl absent: a missing key " +
"leaves the previous track's art on screen")
}
if got != tt.want {
t.Errorf("mpris:artUrl = %q, want %q", got, tt.want)
}
})
}
}
// TestEmptyFieldsStayAbsent guards the other half: artUrl is the
// exception, not a new rule for the whole dictionary. A title of ""
// published as "" would make every player show an empty line where it
// would otherwise fall back to the filename.
func TestEmptyFieldsStayAbsent(t *testing.T) {
t.Parallel()
m := metadataMap(Metadata{}, 7)
for _, key := range []string{
"xesam:title", "xesam:artist", "xesam:album", "mpris:length",
} {
if _, ok := m[key]; ok {
t.Errorf("%s should be omitted when it has no value", key)
}
}
}