patina-firefox-theme.sh (4531B)
1 #!/bin/sh 2 # Tests patina-firefox-theme (linux/system/usr/libexec/): what it does to a home folder at login. 3 # It runs the script against throwaway home folders, with the system's CSS file and `pgrep` stood in. 4 # Usage: sh linux/tests/patina-firefox-theme.sh 5 here=$(cd "$(dirname "$0")" && pwd) 6 script=$here/../system/usr/libexec/patina-firefox-theme 7 css=$here/../system/usr/share/patina-os/firefox/patina-default.css 8 tmp=$(mktemp -d); trap 'rm -rf "$tmp"' EXIT 9 mkdir -p "$tmp/share" "$tmp/bin"; cp "$css" "$tmp/share/" 10 sed "s#/usr/share/patina-os/firefox#$tmp/share#" "$script" > "$tmp/run.sh" 11 printf '#!/bin/sh\nexit 1\n' > "$tmp/bin/pgrep"; chmod +x "$tmp/bin/pgrep" # no Firefox is running 12 run() { HOME=$1 XDG_CONFIG_HOME= PATH="$tmp/bin:$PATH" sh "$tmp/run.sh"; } 13 fail=0 14 check() { if eval "$2"; then echo "ok $1"; else echo "FAIL $1"; fail=1; fi; } 15 snapshot() { (cd "$1" && find . -type f | sort | xargs md5sum | md5sum); } 16 17 # 1. A machine with no Firefox profile: one is made, seeded, mapped to this install, and themed. 18 h=$tmp/fresh; mkdir -p "$h"; run "$h"; r=$h/.config/mozilla/firefox; p=$r/patina.default-release 19 check "a fresh machine gets one profile, and profiles.ini and installs.ini say it is the install's" \ 20 '[ "$(ls -d $r/*.default-release | wc -l)" = 1 ] && grep -q "Default=patina.default-release" $r/installs.ini && grep -q "Path=patina.default-release" $r/profiles.ini && grep -q "^\[Install11457493C5A56847\]" $r/profiles.ini' 21 check "the new tab widgets and weather are off in it, as the user's own prefs" \ 22 'for k in widgets.enabled widgets.clocks.enabled widgets.focusTimer.enabled widgets.lists.enabled widgets.sportsWidget.enabled widgets.weather.enabled; do grep -q "user_pref(\"browser.newtabpage.activity-stream.$k\", false);" $p/prefs.js || exit 1; done; grep -q "showWeather\", false" $p/prefs.js' 23 check "it is themed before Firefox has ever started (the import first in userChrome.css)" \ 24 '[ "$(head -n 1 $p/chrome/userChrome.css)" = "@import url(\"patina-default.css\");" ] && [ -f $p/chrome/patina-default.css ]' 25 check "the GTK corner block is written" 'grep -q ">>> patina" $h/.config/gtk-3.0/gtk.css' 26 before=$(snapshot "$h"); run "$h" 27 check "a second run (the next login) changes nothing" '[ "$before" = "$(snapshot "$h")" ]' 28 29 # 2. A user who has changed a seeded pref, then logs in again: their value stays. 30 sed -i 's/widgets.enabled", false/widgets.enabled", true/' "$p/prefs.js"; run "$h" 31 check "the user's own value is not put back at the next login" 'grep -q "widgets.enabled\", true" $p/prefs.js' 32 33 # 3. A machine that already has a profile: left alone (themed, not seeded or replaced). 34 h=$tmp/existing; r=$h/.config/mozilla/firefox; mkdir -p "$r/abc.default-release" 35 printf '[Profile0]\nName=x\nIsRelative=1\nPath=abc.default-release\nDefault=1\n' > "$r/profiles.ini" 36 echo 'user_pref("browser.newtabpage.activity-stream.widgets.enabled", true);' > "$r/abc.default-release/prefs.js" 37 ini=$(md5sum < "$r/profiles.ini"); prefs=$(md5sum < "$r/abc.default-release/prefs.js"); run "$h" 38 check "an existing profile keeps its prefs.js and profiles.ini, and no second profile appears" \ 39 '[ "$ini" = "$(md5sum < $r/profiles.ini)" ] && [ "$prefs" = "$(md5sum < $r/abc.default-release/prefs.js)" ] && [ "$(ls -d $r/*.default* | wc -l)" = 1 ] && [ ! -e $r/installs.ini ]' 40 check "but it is themed" '[ -f $r/abc.default-release/chrome/patina-default.css ]' 41 42 # 4. The older profile location counts as "has a profile" too. 43 h=$tmp/legacy; mkdir -p "$h/.mozilla/firefox"; printf '[Profile0]\nPath=x\n' > "$h/.mozilla/firefox/profiles.ini"; run "$h" 44 check "a profile under ~/.mozilla is not mistaken for none" '[ ! -e $h/.config/mozilla/firefox/profiles.ini ]' 45 46 # 5. The user's own CSS survives, and a do-not-manage line is respected. 47 h=$tmp/css; r=$h/.config/mozilla/firefox; mkdir -p "$r/p.default/chrome" "$h/.config/gtk-3.0" 48 printf '[Profile0]\nPath=p.default\nIsRelative=1\n' > "$r/profiles.ini"; printf '#nav-bar { color: red; }\n' > "$r/p.default/chrome/userChrome.css" 49 printf '/* patina: do not manage */\nbutton { color: red; }\n' > "$h/.config/gtk-3.0/gtk.css"; run "$h" 50 check "the user's own userChrome rules are kept, with the import first" 'grep -q "color: red" $r/p.default/chrome/userChrome.css && [ "$(head -n 1 $r/p.default/chrome/userChrome.css)" = "@import url(\"patina-default.css\");" ]' 51 check "a gtk.css with the do-not-manage line is left alone" '! grep -q ">>> patina" $h/.config/gtk-3.0/gtk.css' 52 53 [ $fail = 0 ] && echo "patina-firefox-theme does what it should" 54 exit $fail