#!/usr/bin/env bats load test_helper setup() { common_setup export XDG_DATA_HOME="$HOME/.local/share" export XDG_DATA_DIRS="$BATS_TEST_TMPDIR/share" APPS="$XDG_DATA_HOME/applications" mkdir -p "$XDG_DATA_DIRS/applications" printf '[Desktop Entry]\nExec=test-chromium %%U\n' > "$XDG_DATA_DIRS/applications/helium.desktop" printf '[Desktop Entry]\nExec=/usr/lib/firefox/firefox %%u\n' > "$XDG_DATA_DIRS/applications/firefox.desktop" stub xdg-settings 'echo "${DEFAULT_BROWSER:-helium.desktop}"' export WEBAPP_BROWSERS="test-chromium" stub test-chromium stub xdg-open stub update-desktop-database stub gtk-update-icon-cache # No icon to be had stub curl 'exit 22' } @test "webapp add makes a launcher that opens the site as an app" { run bash "$REPO/webapp" add "Nextcloud" https://nextcloud.example.com/apps/files [ "$status" -eq 0 ] local file="$APPS/webapp-nextcloud.desktop" grep -qx 'Name=Nextcloud' "$file" grep -qx "Exec=\"$HOME/.local/bin/webapp\" open \"https://nextcloud.example.com/apps/files\"" "$file" grep -qx 'StartupWMClass=chrome-nextcloud.example.com__apps_files-Default' "$file" grep -qx 'Icon=applications-internet' "$file" } @test "webapp add quotes a URL's special characters for the launcher" { run bash "$REPO/webapp" add "Search" 'https://example.com/?q=a%20b&x=$y' [ "$status" -eq 0 ] grep -qxF 'Exec="'"$HOME"'/.local/bin/webapp" open "https://example.com/?q=a%%20b&x=\\$y"' "$APPS/webapp-search.desktop" } @test "webapp add refuses addresses that aren't http(s)" { for url in "javascript:alert(1)" "file:///etc/passwd" "example.com" "https://a b"; do run bash "$REPO/webapp" add "Bad" "$url" [ "$status" -eq 1 ] done [ ! -e "$APPS/webapp-bad.desktop" ] } @test "webapp add takes an icon from a file" { # A 1x1 PNG base64 -d > "$BATS_TEST_TMPDIR/icon.png" <<< \ iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR4nGNgYGD4DwABBAEAwS2OUAAAAABJRU5ErkJggg== run bash "$REPO/webapp" add "My App" https://app.example.com "$BATS_TEST_TMPDIR/icon.png" [ "$status" -eq 0 ] local icon="$XDG_DATA_HOME/icons/hicolor/256x256/apps/webapp-my-app.png" [ -f "$icon" ] grep -qx "Icon=$icon" "$APPS/webapp-my-app.desktop" } @test "webapp list and remove handle only web apps" { bash "$REPO/webapp" add "Nextcloud" https://nextcloud.example.com printf '[Desktop Entry]\nName=Other\n' > "$APPS/webapp-other.desktop" run bash "$REPO/webapp" list [[ "$output" == "Nextcloud"*"https://nextcloud.example.com" ]] run bash "$REPO/webapp" remove Other [ "$status" -eq 1 ] [ -f "$APPS/webapp-other.desktop" ] run bash "$REPO/webapp" remove Nextcloud [ "$status" -eq 0 ] [ ! -e "$APPS/webapp-nextcloud.desktop" ] } @test "webapp open uses the default browser when it's Chromium-based" { run bash "$REPO/webapp" open https://example.com [ "$status" -eq 0 ] called test-chromium --app=https://example.com } @test "webapp open falls back to an installed Chromium-based browser" { DEFAULT_BROWSER=firefox.desktop run bash "$REPO/webapp" open https://example.com [ "$status" -eq 0 ] called test-chromium --app=https://example.com } @test "webapp open uses the browser when there's no Chromium-based one" { rm "$STUB_BIN/test-chromium" DEFAULT_BROWSER=firefox.desktop run bash "$REPO/webapp" open https://example.com [ "$status" -eq 0 ] called xdg-open https://example.com }