From 62941b104d1a19c841f5f7b5c430910bd3b747d8 Mon Sep 17 00:00:00 2001 From: Alberto Balbo Date: Tue, 20 Oct 2026 17:39:22 +0200 Subject: [PATCH] Prova d'insieme: vista remota aperta mentre il browser naviga MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- .../Febe.Tests/Server/ServerEndToEndTests.cs | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/tests/Febe.Tests/Server/ServerEndToEndTests.cs b/tests/Febe.Tests/Server/ServerEndToEndTests.cs index ec283c0..44f6d85 100644 --- a/tests/Febe.Tests/Server/ServerEndToEndTests.cs +++ b/tests/Febe.Tests/Server/ServerEndToEndTests.cs @@ -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 FrameArrivesAsync(IRemoteViewConnection view, CancellationToken ct) { using var timeout = CancellationTokenSource.CreateLinkedTokenSource(ct);