Integrazione 0.1.1: unione di correzione/vista-remota-navigazione
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> # Conflicts: # docs/decisioni.md
This commit is contained in:
commit
058c0e8a4d
10 files changed
+586
-28
No files matched your search
@@ -252,20 +252,44 @@ public sealed partial class ServerEndToEndTests
|
||||
await server.Running.WaitAsync(TimeSpan.FromSeconds(60), ct);
|
||||
var host = server.RemoteView!;
|
||||
var gate = server.Browser!.UserDriving;
|
||||
var released = 0;
|
||||
void OnChanged(object? sender, bool driving)
|
||||
{
|
||||
if (!driving)
|
||||
{
|
||||
Interlocked.Increment(ref released);
|
||||
}
|
||||
}
|
||||
|
||||
for (var round = 0; round < 5; round++)
|
||||
{
|
||||
// From the rest page: where the browser starts, and where the engine puts it once nobody is at the browser.
|
||||
// Page.getFrameTree is answered by the page itself, which DevTools holds back while a navigation is pending:
|
||||
// «about:blank» here means the engine's rest has committed.
|
||||
await ServerTestBed.WaitUntilAsync(
|
||||
async () => await Febe.Browser.Cdp.CdpPageExtensions.GetMainFrameUrlAsync(server.Browser.Cdp, ct) == "about:blank",
|
||||
TimeSpan.FromSeconds(20),
|
||||
"la pagina di riposo");
|
||||
|
||||
// Two tabs restored together, or the phone and the PC at once: the newest wins, the other is ended.
|
||||
var views = await Task.WhenAll(Task.Run(() => host.OpenAsync(ct), ct), Task.Run(() => host.OpenAsync(ct), ct));
|
||||
// Two tabs restored together, or the phone and the PC at once: the newest wins, the other is ended — and the
|
||||
// engine never sees nobody at the browser in between (it would put the page to rest under the newer view).
|
||||
Volatile.Write(ref released, 0);
|
||||
gate.Changed += OnChanged;
|
||||
IRemoteViewConnection[] views;
|
||||
try
|
||||
{
|
||||
views = await Task.WhenAll(Task.Run(() => host.OpenAsync(ct), ct), Task.Run(() => host.OpenAsync(ct), ct));
|
||||
}
|
||||
finally
|
||||
{
|
||||
gate.Changed -= OnChanged;
|
||||
}
|
||||
|
||||
var open = views.Where(v => v.Ended is null).ToList();
|
||||
Assert.HasCount(1, open, $"Round {round}: one view stays open.");
|
||||
Assert.AreEqual(RemoteViewEnd.Replaced, views.Single(v => v.Ended is not null).Ended);
|
||||
Assert.AreEqual(1, gate.Leases, $"Round {round}: only the open view holds the browser.");
|
||||
Assert.AreEqual(0, Volatile.Read(ref released), $"Round {round}: the browser was never left without a driver while one view replaced the other.");
|
||||
|
||||
// The page of the replaced view closes its socket: the open view still gets its frames.
|
||||
await views.Single(v => v.Ended is not null).DisposeAsync();
|
||||
@@ -277,6 +301,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);
|
||||
|
||||
Reference in new issue
Block a user