ShellLauncher opens only http(s) and ms-windows-store URLs and reveals files
(SHOpenFolderAndSelectItems) or folders ("explore") on an STA. TaskbarProgress
wraps ITaskbarList3 and returns false for null or stale windows. KnownFolders
reads LocalAppData/Pictures via SHGetKnownFolderPath. AppPaths resolves the
data root (%LOCALAPPDATA%\Titano or .\data in portable mode) and refuses to
create it inside a OneDrive sync root (environment variables and
HKCU\Software\Microsoft\OneDrive\Accounts\*\UserFolder).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
58 lines
2.1 KiB
C#
58 lines
2.1 KiB
C#
using Titano.Core.Windows.Shell;
|
|
using Titano.Testing;
|
|
|
|
namespace Titano.Core.Windows.Tests.Shell;
|
|
|
|
public sealed class ShellTests(TestContext context)
|
|
{
|
|
private static readonly nint StaleWindow = 0x0BAD_F00D;
|
|
|
|
[Theory]
|
|
[Case("https://apps.microsoft.com/detail/9nctdw2w1bh8")]
|
|
[Case("http://nas.local:8443/admin")]
|
|
[Case("ms-windows-store://pdp/?ProductId=9NCTDW2W1BH8")]
|
|
public void WebAndStoreUrlsAreAllowed(string url) => Assert.True(ShellLauncher.IsAllowedUrl(url));
|
|
|
|
[Theory]
|
|
[Case("file:///C:/Windows/System32/cmd.exe")]
|
|
[Case(@"C:\Windows\System32\cmd.exe")]
|
|
[Case(@"\\server\share\run.bat")]
|
|
[Case("javascript:alert(1)")]
|
|
[Case("mailto:someone@example.com")]
|
|
[Case("relative/page.html")]
|
|
[Case("")]
|
|
public void OtherTargetsAreRejected(string url) => Assert.False(ShellLauncher.IsAllowedUrl(url));
|
|
|
|
[Test]
|
|
public void OpenUrlRefusesRejectedTargetsBeforeTouchingTheShell() =>
|
|
Assert.Throws<ArgumentException>(() => ShellLauncher.OpenUrl("file:///C:/Windows/System32/cmd.exe"));
|
|
|
|
[Test]
|
|
public void RevealOfAMissingPathReturnsFalse() =>
|
|
Assert.False(ShellLauncher.RevealInExplorer(Path.Combine(context.CreateTempDirectory(), "missing.jpg")));
|
|
|
|
[Test]
|
|
[WindowsOnly]
|
|
public void KnownFoldersMatchTheSystem()
|
|
{
|
|
Assert.Equal(
|
|
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData).ToUpperInvariant(),
|
|
KnownFolders.LocalAppData.ToUpperInvariant());
|
|
Assert.True(Path.IsPathFullyQualified(KnownFolders.Pictures), KnownFolders.Pictures);
|
|
}
|
|
|
|
[Test]
|
|
[WindowsOnly]
|
|
public void TaskbarCallsWithoutAValidWindowReturnFalse()
|
|
{
|
|
using var taskbar = new TaskbarProgress();
|
|
Assert.False(taskbar.SetState(0, TaskbarProgressState.Normal));
|
|
Assert.False(taskbar.SetValue(0, 1, 2));
|
|
Assert.False(taskbar.SetState(StaleWindow, TaskbarProgressState.Indeterminate));
|
|
Assert.False(taskbar.SetValue(StaleWindow, 1, 2));
|
|
taskbar.Dispose();
|
|
Assert.False(taskbar.IsAvailable);
|
|
Assert.False(taskbar.SetValue(StaleWindow, 1, 2));
|
|
}
|
|
}
|