Files
chandra/compositor/shell/icons_wbtest.mbt
nandiandClaude Sonnet 5.5 44688453d7
CI / test (push) Failing after 31m49s
Icons: load an absolute Icon= path that has no extension
AppImage managers write icons as extensionless files, so those apps got the
generic icon. Any absolute path is now tried, and the loaders tell PNG and SVG
apart from the contents.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-25 23:01:20 -08:00

106 lines
4.3 KiB
MoonBit

///| A trimmed copy of breeze's index.theme (breeze keeps icons in `<context>/<size>`, not
/// hicolor's `<size>x<size>/<context>`).
let breeze_index : String =
#|[Icon Theme]
#|Name=Breeze
#|Inherits=hicolor
#|Directories=apps/16,apps/32,apps/48,mimetypes/64
#|ScaledDirectories=apps/16@2x
#|[apps/16]
#|Size=16
#|Context=Applications
#|Type=Fixed
#|[apps/16@2x]
#|Size=16
#|Scale=2
#|Type=Fixed
#|[apps/32]
#|Size=32
#|Type=Fixed
#|[apps/48]
#|Size=48
#|Context=Applications
#|Type=Scalable
#|MinSize=48
#|MaxSize=256
#|[mimetypes/64]
#|Size=64
#|Type=Fixed
///|
test "index.theme directories, sizes and Inherits are read" {
let t = parse_index_theme("breeze", breeze_index)
assert_eq(t.inherits, ["hicolor"])
assert_eq(t.dirs.map(d => d.path), ["apps/16", "apps/32", "apps/48", "mimetypes/64", "apps/16@2x"])
assert_true(t.dirs[2].matches(48))
assert_true(t.dirs[2].matches(128))
assert_false(t.dirs[0].matches(48))
assert_false(t.dirs[4].matches(32)) // scale 2
assert_eq(t.dirs[3].distance(48), 16)
}
///|
test "breeze's apps/48 is searched for a theme icon like Konsole's utilities-terminal" {
let t = parse_index_theme("breeze", breeze_index)
let c = icon_candidates("utilities-terminal", true, [("breeze", Some(t))], ["/u/icons"], [])
assert_eq(c[0], "/u/icons/breeze/apps/48/utilities-terminal.png")
assert_eq(c[1], "/u/icons/breeze/apps/48/utilities-terminal.svg")
// Then the nearest sizes, bigger first.
assert_eq(c[2], "/u/icons/breeze/mimetypes/64/utilities-terminal.png")
// The software renderer reads PNG only.
let png = icon_candidates("utilities-terminal", false, [("breeze", Some(t))], ["/u/icons"], [])
assert_false(png.iter().any(p => p.has_suffix(".svg")))
}
///|
test "themes without an index.theme use the hicolor layout, then pixmaps" {
let c = icon_candidates("firefox", true, [("hicolor", None)], ["/u/icons"], ["/p"])
assert_eq(c[0], "/u/icons/hicolor/48x48/apps/firefox.png")
assert_eq(c[3], "/u/icons/hicolor/scalable/apps/firefox.svg")
assert_eq(c[c.length() - 2], "/p/firefox.png")
// Icon=foo.png means foo; absolute paths are taken as they are.
assert_eq(icon_candidates("foo.png", false, [("hicolor", None)], ["/b"], [])[0], "/b/hicolor/48x48/apps/foo.png")
assert_eq(icon_candidates("/opt/app/icon.png", false, [], ["/b"], []), ["/opt/app/icon.png"])
assert_eq(icon_candidates("/opt/app/icon.svg", false, [], ["/b"], []), [])
assert_eq(icon_candidates("/opt/app/.icons/app", false, [], ["/b"], []), ["/opt/app/.icons/app"])
assert_eq(icon_candidates("", true, [], ["/b"], []), [])
}
///|
test "theme chain: the user's theme and what it inherits, hicolor, then breeze and Adwaita" {
let installed : Map[String, String] = {
"breeze-dark": "[Icon Theme]\nInherits=breeze,hicolor\n",
"breeze": breeze_index,
"Adwaita": "[Icon Theme]\nInherits=hicolor\n",
"hicolor": "[Icon Theme]\n",
}
let load = fn(n : String) { installed.get(n).map(t => parse_index_theme(n, t)) }
assert_eq(icon_theme_chain("breeze-dark", load).map(t => t.0), [
"breeze-dark", "breeze", "hicolor", "Adwaita",
])
assert_eq(icon_theme_chain("", load).map(t => t.0), ["hicolor", "breeze", "Adwaita"])
// A theme that isn't installed is skipped; hicolor stays even without its index.theme.
let none = fn(_n : String) -> IconTheme? { None }
assert_eq(icon_theme_chain("Papirus", none).map(t => t.0), ["hicolor"])
}
///|
test "the user's icon theme comes from kdeglobals, then GTK settings.ini" {
let files = fn(m : Map[String, String]) { fn(f : String) { m.get(f).unwrap_or("") } }
let kde = files({ "kdeglobals": "[General]\nColorScheme=BreezeDark\n[Icons]\nTheme=breeze-dark\n" })
assert_eq(user_icon_theme("", kde), "breeze-dark")
assert_eq(user_icon_theme("Papirus", kde), "Papirus")
assert_eq(user_icon_theme("", files({ "kdeglobals": "[General]\nfoo=1\n" })), "breeze")
let gtk = files({ "gtk-3.0/settings.ini": "[Settings]\ngtk-icon-theme-name=\"Yaru\"\n" })
assert_eq(user_icon_theme("", gtk), "Yaru")
assert_eq(user_icon_theme("", files({})), "")
}
///|
test "an app's icon names: Icon=, its id, the id's last part, the generic app icon" {
assert_eq(icon_names_for("utilities-terminal", "org.kde.konsole"), [
"utilities-terminal", "org.kde.konsole", "konsole", "application-x-executable",
])
assert_eq(icon_names_for("", "foot"), ["foot", "application-x-executable"])
}