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);