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>
140 lines
5.7 KiB
C#
140 lines
5.7 KiB
C#
using System.Diagnostics;
|
|
using Febe.Browser.Cdp;
|
|
using Febe.Browser.RemoteView;
|
|
using Febe.Tests.Browser.TestSupport;
|
|
|
|
namespace Febe.Tests.Browser;
|
|
|
|
/// <summary>
|
|
/// The remote view that stayed white (Gitea issue #52), on a real Chromium on Xvfb and the local test site: a page that
|
|
/// does not move still shows itself, and the frames keep coming when the page changes renderer (another site, the rest
|
|
/// page and back). Only in the Linux CI; never Instagram. The tests ask that a picture arrives, not how fast: the waits are
|
|
/// generous for a busy runner (issue #46), and the time it took goes to the test's output (about two seconds, the
|
|
/// watchdog's silence, at most five on a calm machine).
|
|
/// </summary>
|
|
[TestClass]
|
|
[DoNotParallelize]
|
|
public sealed class RemoteViewFramesTests
|
|
{
|
|
/// <summary>How long a picture may take on a busy runner before the view counts as white.</summary>
|
|
private static readonly TimeSpan Patience = TimeSpan.FromSeconds(20);
|
|
|
|
public TestContext TestContext { get; set; } = null!;
|
|
|
|
[TestInitialize]
|
|
public void RequireBrowser()
|
|
{
|
|
if (RealBrowser.UnavailableReason() is { } reason)
|
|
{
|
|
Assert.Inconclusive(reason);
|
|
}
|
|
}
|
|
|
|
[TestMethod]
|
|
[Timeout(120_000, CooperativeCancellation = true)]
|
|
public async Task AStillPageAndTheRestPageShowAPicture()
|
|
{
|
|
var ct = TestContext.CancellationToken;
|
|
await using var browser = await RealBrowser.StartAsync();
|
|
var cdp = browser.Cdp;
|
|
var opened = await cdp.NavigateAsync(browser.Site.Url("/accesso"), ct);
|
|
Assert.IsTrue(opened.Succeeded, opened.ErrorText);
|
|
await cdp.WaitForLoadAsync(new Febe.Core.Abstractions.SystemClock(), TimeSpan.FromSeconds(15), ct);
|
|
|
|
var view = new RemoteViewSession(cdp, browser.Host.UserDriving);
|
|
try
|
|
{
|
|
await view.StartAsync(new ScreencastOptions(Quality: 60, MaxWidth: 1280, MaxHeight: 900, Watchdog: ScreencastWatchdog.Default), ct);
|
|
var watch = Stopwatch.StartNew();
|
|
Assert.IsTrue(await PictureAfterAsync(view.Screencast, null, Patience, ct), "a picture of the login page");
|
|
TestContext.WriteLine($"pagina di accesso: immagine dopo {watch.ElapsedMilliseconds} ms.");
|
|
|
|
var last = view.Screencast.LastFrame;
|
|
var rest = await cdp.RestAsync(ct);
|
|
Assert.IsTrue(rest.Succeeded, rest.ErrorText);
|
|
watch.Restart();
|
|
Assert.IsTrue(await PictureAfterAsync(view.Screencast, last, Patience, ct), "a picture of the rest page too");
|
|
TestContext.WriteLine($"pagina di riposo: immagine dopo {watch.ElapsedMilliseconds} ms, riavvii {view.Screencast.Restarts}.");
|
|
}
|
|
finally
|
|
{
|
|
await view.DisposeAsync();
|
|
}
|
|
}
|
|
|
|
[TestMethod]
|
|
[Timeout(180_000, CooperativeCancellation = true)]
|
|
public async Task FramesKeepComingWhenThePageChangesRenderer()
|
|
{
|
|
var ct = TestContext.CancellationToken;
|
|
await using var browser = await RealBrowser.StartAsync();
|
|
var cdp = browser.Cdp;
|
|
var first = await cdp.NavigateAsync(browser.Site.Url("/animata"), ct);
|
|
Assert.IsTrue(first.Succeeded, first.ErrorText);
|
|
|
|
var view = new RemoteViewSession(cdp, browser.Host.UserDriving);
|
|
try
|
|
{
|
|
await view.StartAsync(new ScreencastOptions(Quality: 60, MaxWidth: 1280, MaxHeight: 900, Watchdog: ScreencastWatchdog.Default), ct);
|
|
Assert.IsTrue(await FramesAfterAsync(view.Screencast, ct), "frames of the animated page");
|
|
|
|
foreach (var (address, moving) in new[]
|
|
{
|
|
(browser.Site.LocalhostUrl("/animata"), true),
|
|
("about:blank", false),
|
|
(browser.Site.Url("/animata"), true),
|
|
})
|
|
{
|
|
var last = view.Screencast.LastFrame;
|
|
var watch = Stopwatch.StartNew();
|
|
var navigated = await cdp.NavigateAsync(address, ct);
|
|
Assert.IsTrue(navigated.Succeeded, $"{address}: {navigated.ErrorText}");
|
|
var shown = moving
|
|
? await FramesAfterAsync(view.Screencast, ct)
|
|
: await PictureAfterAsync(view.Screencast, last, Patience, ct);
|
|
TestContext.WriteLine($"{address}: {(shown ? "immagini" : "niente")} dopo {watch.ElapsedMilliseconds} ms, riavvii {view.Screencast.Restarts}.");
|
|
Assert.IsTrue(shown, $"{address}: the view is not white");
|
|
}
|
|
}
|
|
finally
|
|
{
|
|
await view.DisposeAsync();
|
|
}
|
|
}
|
|
|
|
/// <summary>A frame or a still picture other than <paramref name="last"/>, within <paramref name="timeout"/>.</summary>
|
|
private static async Task<bool> PictureAfterAsync(ScreencastSession screencast, ScreencastFrame? last, TimeSpan timeout, CancellationToken ct)
|
|
{
|
|
var deadline = Stopwatch.StartNew();
|
|
while (deadline.Elapsed < timeout)
|
|
{
|
|
if (screencast.LastFrame is { Jpeg: [0xFF, 0xD8, ..] } frame && !ReferenceEquals(frame, last))
|
|
{
|
|
return true;
|
|
}
|
|
|
|
await Task.Delay(50, ct);
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
/// <summary>A few real frames of the screencast (not still pictures) after now, within <see cref="Patience"/>.</summary>
|
|
private static async Task<bool> FramesAfterAsync(ScreencastSession screencast, CancellationToken ct)
|
|
{
|
|
var before = screencast.FramesReceived;
|
|
var deadline = Stopwatch.StartNew();
|
|
while (deadline.Elapsed < Patience)
|
|
{
|
|
if (screencast.FramesReceived >= before + 3)
|
|
{
|
|
return true;
|
|
}
|
|
|
|
await Task.Delay(50, ct);
|
|
}
|
|
|
|
return false;
|
|
}
|
|
}
|