La revisione di c49df4c ha trovato alcuni punti deboli. Si correggono qui.
- Fuori vista la pagina torna al 100%. Lo zoom calcolato per uno schermo
piccolo restava anche per le sessioni del motore, e le pagine vedevano un
devicePixelRatio diverso (regola 4). Il rapporto si ricalcola solo quando
la finestra viene sullo schermo.
- Pulsante nella barra delle applicazioni. WPF lo cambia nascondendo la
finestra e mostrandola di nuovo (verificato con un aggancio a
WM_WINDOWPOSCHANGED). Ora il pulsante cambia solo mentre la finestra è
fuori vista. Sullo schermo la finestra chiede di ridisegnarsi
(RedrawWindow), senza nulla che la pagina veda. Una prova con WebView2
vero controlla che la finestra non si nasconda mai sullo schermo.
- Ridotta a icona troppo a lungo, la finestra si ripristina coperta (DWM) e
senza prendere il fuoco, e si sposta fuori vista prima di scoprirsi. Prima
ricompariva per un attimo dove stava. Spostare la posizione di ripristino
non basta: Windows la riporta su uno schermo (provato).
- Dopo un riavvio del processo GPU i bordi della pagina cambiano davvero: un
pixel in meno, poi quelli veri. Gli stessi bordi di nuovo potevano non
servire a nulla.
- «Pagina iniziale», sulla barra di Windows e nella vista remota, passa da
BrowserConnectionService.OpenStartPageAsync. Aspetta la fine della
sessione del motore e il turno della pagina, come l'apertura dal riposo,
e agisce solo mentre Alberto guida.
- Vista remota.
- Dopo un riavvio dei fotogrammi la vista aspetta il primo fotogramma per
mezzo secondo prima dell'immagine ferma: Chromium lo manda solo dopo la
risposta allo start, e prima quasi ogni riavvio costava una cattura.
- L'immagine ferma si scarta se nel frattempo arriva un fotogramma vero.
- Il silenzio si conta dall'avvio.
- Un riavvio del browser durante la chiusura non lascia eccezioni non
osservate.
- Un POST vuoto senza Content-Length (a pezzi, HTTP/2) non dà più 400 su
begin, cancel e browser/show (ApiHttp.OptionalBodyAsync).
- La pagina Browser toglie ?accesso=1 dall'indirizzo. Ricaricarla riapriva
la pagina di accesso.
- RemoteViewFramesTests aspetta fino a 20 s invece di 5. Controlla che
l'immagine arrivi, non quanto in fretta; il tempo va nell'uscita della
prova.
Aggiornati PROTOCOLLO.md, la guida (Primo collegamento, Installazione
Windows) e docs/decisioni.md con le righe di #52.
Prove nuove:
- AFrameSoonAfterARestartNeedsNoStillPicture
- PaginaInizialeWaitsForThePageTurnAndActsOnlyWhileAlbertoIsAtTheBrowser
- ABodyWithoutALengthIsReadAndAnEmptyOneIsNoBody
- nella prova della finestra vera: nessun nascondere sullo schermo e pagina
al 100% fuori vista
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
138 lines
5.4 KiB
C#
138 lines
5.4 KiB
C#
using Febe.App;
|
|
using Febe.Browser.Cdp;
|
|
using Febe.Core.Abstractions;
|
|
using Febe.Core.Library;
|
|
using Febe.Data;
|
|
using Febe.Desktop.Browser;
|
|
using Febe.Desktop.Core;
|
|
using Febe.Web.Engine;
|
|
|
|
namespace Febe.Tests.Windows.Support;
|
|
|
|
/// <summary>
|
|
/// The browser of Febe for Windows on its own, as the composition builds it (<see cref="DesktopPlatform"/> through
|
|
/// <c>DesktopShell</c>): a <see cref="WebView2Browser"/> with its window «Browser di Febe» and WebView2 on a real UI
|
|
/// thread, a profile in a temporary Data folder, the switches of S2 and the log of Febe captured.
|
|
/// </summary>
|
|
internal sealed class BrowserBed : IAsyncDisposable
|
|
{
|
|
private BrowserBed(TestFolder folder, UiThread ui, LogLines lines, FebeLog log, FebeDatabase database, BrowserUseTracker tracker, WebView2Browser browser)
|
|
{
|
|
Folder = folder;
|
|
Ui = ui;
|
|
Lines = lines;
|
|
Log = log;
|
|
Database = database;
|
|
Tracker = tracker;
|
|
Browser = browser;
|
|
}
|
|
|
|
public TestFolder Folder { get; }
|
|
|
|
public UiThread Ui { get; }
|
|
|
|
/// <summary>What Febe wrote in its log.</summary>
|
|
public LogLines Lines { get; }
|
|
|
|
public FebeLog Log { get; }
|
|
|
|
public FebeDatabase Database { get; }
|
|
|
|
/// <summary>When Alberto last used the browser («Riprendi» after a verification).</summary>
|
|
public BrowserUseTracker Tracker { get; }
|
|
|
|
public WebView2Browser Browser { get; }
|
|
|
|
/// <param name="name">Prefix of the temporary folder.</param>
|
|
/// <param name="hosting">How WebView2 draws (S2).</param>
|
|
/// <param name="startPage">
|
|
/// Where «Pagina iniziale» goes, opened as the connection would (here without an engine to wait for); null: the button
|
|
/// does nothing (never the default login page of the options, which is Instagram's).
|
|
/// </param>
|
|
public static async Task<BrowserBed> CreateAsync(string name, BrowserHosting hosting = BrowserHosting.Window, Func<string>? startPage = null)
|
|
{
|
|
var folder = new TestFolder(name);
|
|
var ui = await UiThread.StartAsync();
|
|
var lines = new LogLines();
|
|
var clock = new SystemClock();
|
|
var log = new FebeLog(null, lines, clock);
|
|
var data = new DataFolderLayout(folder.Combine("dati"));
|
|
var database = await FebeDatabase.OpenAsync(data.Root);
|
|
var options = new FebeAppOptions { DataFolder = data.Root, LibraryFolder = folder.Combine("libreria") };
|
|
var tracker = new BrowserUseTracker();
|
|
WebView2Browser? built = null;
|
|
Func<CancellationToken, Task>? openStartPage = startPage is null ? null : async ct => await built!.Cdp.NavigateAsync(startPage(), ct);
|
|
var context = new FebePlatformContext(options, data, database, clock, log, tracker, openStartPage);
|
|
var settings = new WebView2BrowserSettings(data.BrowserProfile, 1280, 900, hosting, BrowserArguments.ForWebView2());
|
|
|
|
// Built off the UI thread, as DesktopPlatform.CreateBrowserAsync does after its awaits.
|
|
var browser = new WebView2Browser(ui.Dispatcher, settings, context, icon: null);
|
|
built = browser;
|
|
return new BrowserBed(folder, ui, lines, log, database, tracker, browser);
|
|
}
|
|
|
|
/// <summary>Waits (real time) until <paramref name="condition"/> holds; fails with <paramref name="what"/> and the log otherwise.</summary>
|
|
public async Task WaitUntilAsync(Func<bool> condition, TimeSpan timeout, string what, CancellationToken ct)
|
|
{
|
|
var deadline = DateTime.UtcNow + timeout;
|
|
while (!condition())
|
|
{
|
|
if (DateTime.UtcNow > deadline)
|
|
{
|
|
Assert.Fail($"Tempo scaduto: {what}.\n{Lines.Text}");
|
|
}
|
|
|
|
await Task.Delay(50, ct);
|
|
}
|
|
}
|
|
|
|
/// <summary>Reads a value of the UI thread (the window, its position) through the dispatcher.</summary>
|
|
public Task<T> OnUiAsync<T>(Func<T> read) => Ui.InvokeAsync(read);
|
|
|
|
/// <summary>The class names of the child windows of «Browser di Febe»: one per WebView hosted in it.</summary>
|
|
public Task<IReadOnlyList<string>> ChildWindowsAsync() =>
|
|
OnUiAsync(() => Browser.Host.Window is { } window ? ChildWindows.Of(window.Handle) : (IReadOnlyList<string>)[]);
|
|
|
|
/// <summary>
|
|
/// Starts the browser from a thread-pool thread, like <c>FebeApp.BringUpBrowserAsync</c>, and waits until
|
|
/// <see cref="WebView2Browser.RunAsync"/> returns. Fails at once when the log reports a failed start: the loop of
|
|
/// retries would otherwise go on for ever.
|
|
/// </summary>
|
|
public async Task StartAsync(CancellationToken ct, TimeSpan? timeout = null)
|
|
{
|
|
var run = Task.Run(() => Browser.RunAsync(ct), ct);
|
|
var deadline = DateTime.UtcNow + (timeout ?? TimeSpan.FromSeconds(60));
|
|
while (!run.IsCompleted)
|
|
{
|
|
if (Lines.Any("non parte"))
|
|
{
|
|
Assert.Fail("Il browser di Febe non è partito al primo tentativo:\n" + Lines.Text);
|
|
}
|
|
|
|
if (DateTime.UtcNow > deadline)
|
|
{
|
|
Assert.Fail("Il browser di Febe non è diventato disponibile in tempo:\n" + Lines.Text);
|
|
}
|
|
|
|
await Task.Delay(50, ct);
|
|
}
|
|
|
|
await run;
|
|
}
|
|
|
|
public async ValueTask DisposeAsync()
|
|
{
|
|
try
|
|
{
|
|
await Browser.DisposeAsync();
|
|
}
|
|
finally
|
|
{
|
|
await Ui.DisposeAsync();
|
|
await Database.DisposeAsync();
|
|
Log.Dispose();
|
|
Folder.Dispose();
|
|
}
|
|
}
|
|
}
|