Files
Febe/tests/Febe.Tests.Windows/Support/WebView2Runtime.cs
T
Alby96andClaude Opus 5.5 a25f60970d Prove per Windows con WebView2 vero, e la prova che riproduce l'avvio mancato
Nuovo progetto tests/Febe.Tests.Windows (net10.0-windows, WPF, solo MSTest e riferimenti ai
progetti): un thread STA con un Dispatcher di WPF vero, come il thread dell'interfaccia di
Febe.exe, e il browser di Febe costruito come lo costruisce la composizione e avviato da un
thread del pool, come fa FebeApp. Si compila anche da Linux (EnableWindowsTargeting, come
Febe.Desktop) perché la CI compila tutta la soluzione, ma gira solo su Windows; dove manca il
runtime WebView2 le prove risultano inconcludenti.

La prima prova riproduce il registro di Alberto del 14 e del 19 ottobre: «WebView2 non parte
(InvalidOperationException: CoreWebView2Environment members can only be accessed from the UI
thread.)» a ogni tentativo. Con il codice di questo commit fallisce così; la correzione è nel
commit seguente.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-20 10:09:30 +02:00

40 lines
1.4 KiB
C#

using System.Runtime.CompilerServices;
using Microsoft.Web.WebView2.Core;
namespace Febe.Tests.Windows.Support;
/// <summary>Whether these tests can run here: Windows with the WebView2 runtime (the tests are inconclusive otherwise).</summary>
internal static class WebView2Runtime
{
/// <summary>Null when WebView2 can run; otherwise why not, in Italian (the text of the inconclusive result).</summary>
public static string? UnavailableReason()
{
if (!OperatingSystem.IsWindows())
{
return "Prova solo per Windows: qui non c'è WebView2.";
}
try
{
return InstalledVersion() is null ? "Runtime WebView2 non installato su questo Windows." : null;
}
catch (Exception ex) when (ex is WebView2RuntimeNotFoundException or DllNotFoundException or BadImageFormatException)
{
return $"Runtime WebView2 non disponibile ({ex.GetType().Name}).";
}
}
/// <summary>The version of the installed WebView2 runtime, e.g. «141.0.3537.71».</summary>
[MethodImpl(MethodImplOptions.NoInlining)]
public static string? InstalledVersion() => CoreWebView2Environment.GetAvailableBrowserVersionString();
/// <summary>Marks the test inconclusive where WebView2 cannot run.</summary>
public static void Require()
{
if (UnavailableReason() is { } reason)
{
Assert.Inconclusive(reason);
}
}
}