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>
51 lines
2.3 KiB
C#
51 lines
2.3 KiB
C#
using System.Text.RegularExpressions;
|
||
using Febe.Browser.Cdp;
|
||
using Febe.Tests.Windows.Support;
|
||
|
||
namespace Febe.Tests.Windows;
|
||
|
||
/// <summary>
|
||
/// The start of the browser of Febe on a real Windows (regression of 14 and 19 October 2026: «WebView2 non parte
|
||
/// (InvalidOperationException: CoreWebView2Environment members can only be accessed from the UI thread.)» at every
|
||
/// attempt, for ever). The composition starts the browser from a thread-pool thread; every WebView2 object lives on the
|
||
/// UI thread of WPF.
|
||
/// </summary>
|
||
[TestClass]
|
||
public sealed partial class WebView2BrowserStartTests
|
||
{
|
||
public TestContext TestContext { get; set; } = null!;
|
||
|
||
[TestInitialize]
|
||
public void RequireWebView2() => WebView2Runtime.Require();
|
||
|
||
[TestMethod]
|
||
[Timeout(120_000, CooperativeCancellation = true)]
|
||
public async Task StartedFromAThreadPoolThreadTheBrowserIsReadyAtTheFirstAttempt()
|
||
{
|
||
var ct = TestContext.CancellationToken;
|
||
await using var bed = await BrowserBed.CreateAsync("avvio");
|
||
|
||
await bed.StartAsync(ct);
|
||
|
||
TestContext.WriteLine(bed.Lines.Text);
|
||
Assert.IsTrue(bed.Browser.IsAvailable, "the browser is available once RunAsync returned");
|
||
Assert.IsNull(bed.Browser.LastError);
|
||
var ready = bed.Lines.Lines.Where(l => l.Contains("Browser di Febe pronto: WebView2 ", StringComparison.Ordinal)).ToList();
|
||
Assert.HasCount(1, ready, "one «ready» line: " + bed.Lines.Text);
|
||
Assert.MatchesRegex(ReadyLine(), ready[0]);
|
||
Assert.IsFalse(bed.Lines.Any("non parte"), "no failed attempt: " + bed.Lines.Text);
|
||
Assert.IsFalse(bed.Lines.Any("ERRORE"), "no error at all: " + bed.Lines.Text);
|
||
|
||
// The version is a plain value now: it can be read from any thread.
|
||
var version = await Task.Run(() => bed.Browser.Host.Version, ct);
|
||
Assert.IsNotNull(version);
|
||
StringAssert.Contains(ready[0], version);
|
||
|
||
// The engine's threads use the page through the session: the command hops to the UI thread and back.
|
||
Assert.AreEqual("about:blank", await Task.Run(() => bed.Browser.Cdp.GetMainFrameUrlAsync(ct), ct));
|
||
}
|
||
|
||
[GeneratedRegex(@"\[browser\] Browser di Febe pronto: WebView2 \d+\.\d+\.\d+\.\d+, pagina 1280×900, finestra, fuori vista\.$")]
|
||
private static partial Regex ReadyLine();
|
||
}
|