«Pagina iniziale» solo finché Alberto guida, e la vista che non si blocca (#52)
Una verifica indipendente di 654076d ha trovato tre punti deboli.
- «Pagina iniziale» guardava il permesso di guida una volta sola, prima di
aspettare fino a 15 s la fine della sessione e 15 s il turno della pagina
(che poi prendeva comunque). Se nel frattempo Alberto chiudeva la finestra,
Febe navigava senza permesso e fuori dal Governatore (regole 7 e 8). Ora la
pressione vale finché dura il permesso di chi l'ha premuta: la finestra di
Windows passa un gettone che si annulla con il suo permesso, la vista remota
quello della propria vita. Con il turno della pagina in mano la connessione
guarda di nuovo che Alberto guidi ancora; senza turno rinuncia invece di
prendere la pagina a un passo della ricerca. L'attesa del turno è
BrowserConnectionService.PageTurnWait (15 s, le prove la accorciano).
- Nella vista remota «Pagina iniziale» aspettava dentro il ciclo di ricezione:
la vista restava ferma fino a mezzo minuto e poi riversava clic e tasti sulla
pagina nuova. Ora la pressione corre a parte, una per volta, e intanto clic,
tasti, «Indietro» e «Ricarica» si scartano.
- Repaint chiedeva un ridisegno sincrono (RDW_UPDATENOW) a finestre figlie del
processo del browser di WebView2: uno bloccato avrebbe fermato il thread
dell'interfaccia. Ora si chiede solo di ridisegnare.
Prove nuove, che senza le correzioni non passano: la pressione dimenticata se
Alberto lascia il browser, quella che finisce con il permesso di chi l'ha
premuta, la pagina mai tolta a un passo della ricerca, la vista che non si
blocca e scarta l'input; su Windows con WebView2 vero, il gettone che si
annulla quando la finestra si chiude. PROTOCOLLO.md, la guida e decisioni.md
dicono il comportamento nuovo.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
654076d280
commit
2bbad2e9b7
12 files changed
+340
-24
No files matched your search
@@ -142,17 +142,77 @@ public sealed class RemoteViewStartTests
|
||||
var view = await bed.Host.OpenAsync(ct);
|
||||
|
||||
await view.NavigateAsync(RemoteViewNavigation.Home, ct);
|
||||
await StartPageOf(view).WaitAsync(TimeSpan.FromSeconds(10), ct);
|
||||
Assert.AreEqual(start, bed.LastNavigation, "not connected: the login page");
|
||||
|
||||
// Connected meanwhile: the same button opens the site's home.
|
||||
start = "http://127.0.0.1:8481/";
|
||||
await view.NavigateAsync(RemoteViewNavigation.Home, ct);
|
||||
await StartPageOf(view).WaitAsync(TimeSpan.FromSeconds(10), ct);
|
||||
Assert.AreEqual(start, bed.LastNavigation);
|
||||
Assert.AreEqual(2, bed.Cdp.Sent.Count(c => c.Method == "Page.navigate"), "Alberto's own navigations, one per press");
|
||||
|
||||
await view.DisposeAsync();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[Timeout(30_000, CooperativeCancellation = true)]
|
||||
public async Task PaginaInizialeWaitsBesideTheViewDroppingItsInputAndEndsWithIt()
|
||||
{
|
||||
var ct = TestContext.CancellationToken;
|
||||
var presses = 0;
|
||||
var pressedWith = new TaskCompletionSource<CancellationToken>(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||
await using var bed = new Bed(_ => null, open: async token =>
|
||||
{
|
||||
Interlocked.Increment(ref presses);
|
||||
pressedWith.TrySetResult(token);
|
||||
|
||||
// As the connection while a session ends or a search step holds the page: up to half a minute.
|
||||
await Task.Delay(Timeout.Infinite, token);
|
||||
});
|
||||
var view = await bed.Host.OpenAsync(ct);
|
||||
bed.Cdp.Raise("Page.screencastFrame", Frame());
|
||||
await ReadUntilFrameAsync(view, ct);
|
||||
bed.Cdp.ClearSent();
|
||||
|
||||
// The receive loop goes on at once: the press waits beside it.
|
||||
await view.NavigateAsync(RemoteViewNavigation.Home, ct).WaitAsync(TimeSpan.FromSeconds(5), ct);
|
||||
var token = await pressedWith.Task.WaitAsync(TimeSpan.FromSeconds(10), ct);
|
||||
Assert.IsFalse(StartPageOf(view).IsCompleted, "still waiting for its turn");
|
||||
|
||||
// Meanwhile clicks, keys and the other buttons are dropped (they would land on the start page as it loads), and a
|
||||
// second press waits for the first.
|
||||
await view.MouseAsync(new RemoteViewMouse(RemoteViewMouseAction.Down, 0.5, 0.5, RemoteViewButton.Left, 1, 0, 0), ct);
|
||||
await view.KeyAsync(new RemoteViewKey(RemoteViewKeyAction.Char, "a", "KeyA", "a", 0), ct);
|
||||
await view.NavigateAsync(RemoteViewNavigation.Reload, ct);
|
||||
await view.NavigateAsync(RemoteViewNavigation.Home, ct);
|
||||
Assert.IsFalse(bed.Cdp.Sent.Any(c => IsInputOrNavigation(c.Method)), "nothing reached the browser: " + string.Join(", ", bed.Cdp.Sent.Select(c => c.Method)));
|
||||
Assert.AreEqual(1, Volatile.Read(ref presses));
|
||||
|
||||
// The view closes: its lease is gone, and so is the press.
|
||||
Assert.IsFalse(token.IsCancellationRequested);
|
||||
await view.DisposeAsync();
|
||||
Assert.IsTrue(token.IsCancellationRequested, "the press lasts as long as the view");
|
||||
await StartPageOf(view).WaitAsync(TimeSpan.FromSeconds(10), ct);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[Timeout(30_000, CooperativeCancellation = true)]
|
||||
public async Task AfterPaginaInizialeTheInputReachesTheBrowserAgain()
|
||||
{
|
||||
var ct = TestContext.CancellationToken;
|
||||
await using var bed = new Bed(_ => null, () => "http://127.0.0.1:8481/benvenuto");
|
||||
var view = await bed.Host.OpenAsync(ct);
|
||||
|
||||
await view.NavigateAsync(RemoteViewNavigation.Home, ct);
|
||||
await StartPageOf(view).WaitAsync(TimeSpan.FromSeconds(10), ct);
|
||||
bed.Cdp.ClearSent();
|
||||
await view.KeyAsync(new RemoteViewKey(RemoteViewKeyAction.Char, "a", "KeyA", "a", 0), ct);
|
||||
|
||||
Assert.IsTrue(bed.Cdp.Sent.Any(c => c.Method.StartsWith("Input.", StringComparison.Ordinal)), string.Join(", ", bed.Cdp.Sent.Select(c => c.Method)));
|
||||
await view.DisposeAsync();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[Timeout(30_000, CooperativeCancellation = true)]
|
||||
public async Task WithoutAStartPageTheButtonDoesNothing()
|
||||
@@ -162,6 +222,7 @@ public sealed class RemoteViewStartTests
|
||||
var view = await bed.Host.OpenAsync(ct);
|
||||
|
||||
await view.NavigateAsync(RemoteViewNavigation.Home, ct);
|
||||
await StartPageOf(view).WaitAsync(TimeSpan.FromSeconds(10), ct);
|
||||
|
||||
Assert.IsFalse(bed.Cdp.Sent.Any(c => c.Method == "Page.navigate"));
|
||||
await view.DisposeAsync();
|
||||
@@ -191,6 +252,11 @@ public sealed class RemoteViewStartTests
|
||||
await view.DisposeAsync();
|
||||
}
|
||||
|
||||
private static bool IsInputOrNavigation(string method) =>
|
||||
method.StartsWith("Input.", StringComparison.Ordinal) || method is "Page.navigate" or "Page.reload";
|
||||
|
||||
private static Task StartPageOf(IRemoteViewConnection view) => ((BrowserRemoteViewConnection)view).StartPageOpening;
|
||||
|
||||
private static CdpCommandException InactivePage() =>
|
||||
new("Page.startScreencast", CdpCommandException.ServerErrorCode, CdpCommandException.InactivePageMessage);
|
||||
|
||||
@@ -233,7 +299,8 @@ public sealed class RemoteViewStartTests
|
||||
/// Where «Pagina iniziale» goes, as the connection would open it (BrowserConnectionService.OpenStartPageAsync,
|
||||
/// tested in BrowserStartPageTests); null: nowhere.
|
||||
/// </param>
|
||||
public Bed(Func<int, Exception?> startFailure, Func<string>? startPage = null)
|
||||
/// <param name="open">What «Pagina iniziale» does instead (it wins over <paramref name="startPage"/>).</param>
|
||||
public Bed(Func<int, Exception?> startFailure, Func<string>? startPage = null, Func<CancellationToken, Task>? open = null)
|
||||
{
|
||||
Clock = new VirtualClock();
|
||||
_start = Clock.Now;
|
||||
@@ -259,7 +326,7 @@ public sealed class RemoteViewStartTests
|
||||
};
|
||||
Browser = new PageBrowser(Cdp);
|
||||
_log = new FebeLog(null, null, Clock);
|
||||
Host = new BrowserRemoteViewHost(Browser, new BrowserUseTracker(), Clock, _log, browserClock: Clock, openStartPage: startPage is null ? null : async ct => await Cdp.NavigateAsync(startPage(), ct))
|
||||
Host = new BrowserRemoteViewHost(Browser, new BrowserUseTracker(), Clock, _log, browserClock: Clock, openStartPage: open ?? (startPage is null ? null : async ct => await Cdp.NavigateAsync(startPage(), ct)))
|
||||
{
|
||||
// The virtual clock moves only in the pauses: a watchdog on it would never wait.
|
||||
Watchdog = null,
|
||||
|
||||
Reference in new issue
Block a user