using System; using System.IO; using System.Linq; using Paca.Browser.Pwa; using Xunit; namespace Paca.Tests.Browser; public class ChromePwaInstallationManagerTests { [Fact] public void InstallApp_And_Scope_Matching_Work() { var tempFile = Path.Combine(Path.GetTempPath(), "paca_pwa_test_" + Guid.NewGuid().ToString("N") + ".json"); try { var mgr = new WebAppInstallationManager(tempFile); var manifest = new WebAppManifest( Name: "Slack Web", ShortName: "Slack", StartUrl: "https://app.slack.com/client/T123/C456", Display: "standalone", ThemeColor: "#4A154B", BackgroundColor: "#1A1D21", Icons: new[] { new WebAppManifestIcon("https://app.slack.com/icon.png", "192x192", "image/png") } ); var installed = mgr.InstallApp(manifest, scope: "https://app.slack.com/client/"); Assert.NotNull(installed); Assert.Equal("Slack Web", installed.Name); Assert.True(mgr.IsAppInstalled(manifest.StartUrl)); // Matching by URL scope var match1 = mgr.GetAppForUrl("https://app.slack.com/client/T123/C999"); Assert.NotNull(match1); Assert.Equal(installed.Id, match1.Id); // Outside scope var match2 = mgr.GetAppForUrl("https://app.slack.com/help"); Assert.Null(match2); // Uninstall Assert.True(mgr.UninstallApp(installed.Id)); Assert.False(mgr.IsAppInstalled(manifest.StartUrl)); } finally { if (File.Exists(tempFile)) File.Delete(tempFile); } } [Fact] public void InstallationManager_Persistence_Works() { var tempFile = Path.Combine(Path.GetTempPath(), "paca_pwa_persist_" + Guid.NewGuid().ToString("N") + ".json"); try { var mgr1 = new WebAppInstallationManager(tempFile); var manifest = new WebAppManifest( Name: "Spotify Player", ShortName: "Spotify", StartUrl: "https://open.spotify.com/", Display: "standalone", ThemeColor: "#1DB954", BackgroundColor: "#121212", Icons: new[] { new WebAppManifestIcon("https://open.spotify.com/icon.png", "512x512", "image/png") } ); mgr1.InstallApp(manifest); var mgr2 = new WebAppInstallationManager(tempFile); Assert.Single(mgr2.InstalledApps); Assert.Equal("Spotify Player", mgr2.InstalledApps[0].Name); Assert.Equal("standalone", mgr2.InstalledApps[0].DisplayMode); } finally { if (File.Exists(tempFile)) File.Delete(tempFile); } } [Fact] public void GenerateShortcutContent_Produces_Valid_Url_File() { var app = new InstalledWebApp( Id: "app_spotify_123", Name: "Spotify Web", StartUrl: "https://open.spotify.com/", Scope: "https://open.spotify.com/", IconUrl: "https://open.spotify.com/icon.png", InstalledAt: DateTime.UtcNow, DisplayMode: "standalone", ThemeColor: "#1DB954" ); var content = WebAppInstallationManager.GenerateInternetShortcutContent(app); Assert.Contains("[InternetShortcut]", content); Assert.Contains("URL=https://open.spotify.com/", content); Assert.Contains("IconFile=https://open.spotify.com/icon.png", content); } }