Prova d'insieme: vista remota aperta mentre il browser naviga

Sul server vero, la vista si apre insieme alla navigazione verso una pagina del sito
(come «Accedi a Instagram» dalla pagina Collegamento) o insieme al riposo del motore:
deve aprirsi, tenere un solo permesso e ricevere i fotogrammi. È una guardia di queste
coppie, non del ritentativo: con la navigazione già partita Page.getFrameTree risponde
solo dopo il commit. Il ritentativo lo prova RemoteViewDuringNavigationTests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Alby96andClaude Opus 5.5 committed 2026-10-20 17:39:22 +02:00
1 parent 67568ae36f
commit 62941b104d
1 file changed
+49
@@ -299,6 +299,55 @@ public sealed partial class ServerEndToEndTests
}
}
[TestMethod]
[Timeout(180_000, CooperativeCancellation = true)]
public async Task AViewOpenedWhileThePageIsNavigatingOpensAndShowsItsFrames()
{
var ct = TestContext.CancellationToken;
await using var bed = await ServerTestBed.StartAsync();
var server = bed.Server;
await server.Running.WaitAsync(TimeSpan.FromSeconds(60), ct);
var host = server.RemoteView!;
var browser = server.Browser!;
for (var round = 0; round < 6; round++)
{
// From the rest page, as in TwoViews…: the previous round ends on a site page, so «about:blank» here means the
// engine's rest after the last view has committed and nothing else navigates.
await ServerTestBed.WaitUntilAsync(
async () => await Febe.Browser.Cdp.CdpPageExtensions.GetMainFrameUrlAsync(browser.Cdp, ct) == "about:blank",
TimeSpan.FromSeconds(20),
"la pagina di riposo");
// Even rounds: «Accedi a Instagram» on the Collegamento page navigates to the login page while the same page
// opens the view. Odd rounds: the rest page, as the engine puts it after a session or after the last view.
// A guard of these pairs, not of the retry: with the navigation already sent, the view's first look at the
// page (Page.getFrameTree) is answered only once it has committed, so the start comes after the commit (seen
// with Chrome 155). RemoteViewDuringNavigationTests makes the start meet the refusal on purpose.
var navigation = round % 2 == 0
? Febe.Browser.Cdp.CdpPageExtensions.NavigateAsync(browser.Cdp, $"{bed.Site.SiteUrl}/?vista={round}", ct)
: browser.RestAsync(ct);
var view = await host.OpenAsync(ct);
try
{
var navigated = await navigation;
Assert.IsTrue(navigated.Succeeded, $"Round {round}: {navigated.ErrorText}");
Assert.IsNull(view.Ended, $"Round {round}: the view is open.");
Assert.AreEqual(1, browser.UserDriving.Leases, $"Round {round}: only the view holds the browser.");
// A new page paints: its frames reach the view.
await Febe.Browser.Cdp.CdpPageExtensions.NavigateAsync(browser.Cdp, $"{bed.Site.SiteUrl}/?giro={round}", ct);
Assert.IsTrue(await FrameArrivesAsync(view, ct), $"Round {round}: frames of the page.");
}
finally
{
await view.DisposeAsync();
}
Assert.AreEqual(0, browser.UserDriving.Leases, $"Round {round}: no view, no lease.");
}
}
private static async Task<bool> FrameArrivesAsync(IRemoteViewConnection view, CancellationToken ct)
{
using var timeout = CancellationTokenSource.CreateLinkedTokenSource(ct);