La revisione di c49df4c ha trovato alcuni punti deboli. Si correggono qui.
- Fuori vista la pagina torna al 100%. Lo zoom calcolato per uno schermo
piccolo restava anche per le sessioni del motore, e le pagine vedevano un
devicePixelRatio diverso (regola 4). Il rapporto si ricalcola solo quando
la finestra viene sullo schermo.
- Pulsante nella barra delle applicazioni. WPF lo cambia nascondendo la
finestra e mostrandola di nuovo (verificato con un aggancio a
WM_WINDOWPOSCHANGED). Ora il pulsante cambia solo mentre la finestra è
fuori vista. Sullo schermo la finestra chiede di ridisegnarsi
(RedrawWindow), senza nulla che la pagina veda. Una prova con WebView2
vero controlla che la finestra non si nasconda mai sullo schermo.
- Ridotta a icona troppo a lungo, la finestra si ripristina coperta (DWM) e
senza prendere il fuoco, e si sposta fuori vista prima di scoprirsi. Prima
ricompariva per un attimo dove stava. Spostare la posizione di ripristino
non basta: Windows la riporta su uno schermo (provato).
- Dopo un riavvio del processo GPU i bordi della pagina cambiano davvero: un
pixel in meno, poi quelli veri. Gli stessi bordi di nuovo potevano non
servire a nulla.
- «Pagina iniziale», sulla barra di Windows e nella vista remota, passa da
BrowserConnectionService.OpenStartPageAsync. Aspetta la fine della
sessione del motore e il turno della pagina, come l'apertura dal riposo,
e agisce solo mentre Alberto guida.
- Vista remota.
- Dopo un riavvio dei fotogrammi la vista aspetta il primo fotogramma per
mezzo secondo prima dell'immagine ferma: Chromium lo manda solo dopo la
risposta allo start, e prima quasi ogni riavvio costava una cattura.
- L'immagine ferma si scarta se nel frattempo arriva un fotogramma vero.
- Il silenzio si conta dall'avvio.
- Un riavvio del browser durante la chiusura non lascia eccezioni non
osservate.
- Un POST vuoto senza Content-Length (a pezzi, HTTP/2) non dà più 400 su
begin, cancel e browser/show (ApiHttp.OptionalBodyAsync).
- La pagina Browser toglie ?accesso=1 dall'indirizzo. Ricaricarla riapriva
la pagina di accesso.
- RemoteViewFramesTests aspetta fino a 20 s invece di 5. Controlla che
l'immagine arrivi, non quanto in fretta; il tempo va nell'uscita della
prova.
Aggiornati PROTOCOLLO.md, la guida (Primo collegamento, Installazione
Windows) e docs/decisioni.md con le righe di #52.
Prove nuove:
- AFrameSoonAfterARestartNeedsNoStillPicture
- PaginaInizialeWaitsForThePageTurnAndActsOnlyWhileAlbertoIsAtTheBrowser
- ABodyWithoutALengthIsReadAndAnEmptyOneIsNoBody
- nella prova della finestra vera: nessun nascondere sullo schermo e pagina
al 100% fuori vista
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
226 lines
11 KiB
C#
226 lines
11 KiB
C#
using System.Net;
|
|
using Febe.Core.Abstractions;
|
|
using Febe.Tests.Desktop.Support;
|
|
using Febe.Tests.Support;
|
|
|
|
namespace Febe.Tests.Desktop;
|
|
|
|
/// <summary>
|
|
/// The browser that showed nothing (Gitea issue #52), in the shared composition with the fake window «Browser di Febe»:
|
|
/// opened from the empty rest page it goes to a page of its own, «Apri il browser» of a disconnection opens the login,
|
|
/// leaving a page of Febe leaves the window as it is, and the test site's automatic login raises no false alarm.
|
|
/// Never Instagram: the fake browser answers by itself.
|
|
/// </summary>
|
|
[TestClass]
|
|
public sealed class BrowserStartPageTests
|
|
{
|
|
private const string Login = "https://www.instagram.com/accounts/login/";
|
|
private const string Home = "https://www.instagram.com/";
|
|
|
|
public TestContext TestContext { get; set; } = null!;
|
|
|
|
[TestMethod]
|
|
[Timeout(60_000, CooperativeCancellation = true)]
|
|
public async Task UsaIlBrowserFromTheRestPageOpensTheLoginOrTheHomeAndAnyOtherPageStays()
|
|
{
|
|
var ct = TestContext.CancellationToken;
|
|
await using var bed = await DesktopTestBed.StartAsync();
|
|
await bed.App.Running.WaitAsync(TimeSpan.FromSeconds(20), ct);
|
|
var browser = bed.Browser!;
|
|
Assert.AreEqual("about:blank", browser.FakeCdp.Url);
|
|
|
|
// Not connected: never a white window, the login page.
|
|
await BeginAsync(bed, openLogin: false);
|
|
Assert.AreEqual(Login, browser.FakeCdp.Url);
|
|
Assert.AreEqual(1, browser.Shown, "the window came to the front");
|
|
|
|
browser.FakeCdp.LoggedIn = true;
|
|
var finish = await bed.JsonAsync(HttpMethod.Post, "/api/connection/finish");
|
|
Assert.IsTrue(finish.GetProperty("connected").GetBoolean());
|
|
await DesktopTestBed.WaitUntilAsync(() => browser.FakeCdp.Url == "about:blank", TimeSpan.FromSeconds(10), "la pagina di riposo dopo «Ho finito»");
|
|
|
|
// Connected: the site's home.
|
|
await BeginAsync(bed, openLogin: false);
|
|
Assert.AreEqual(Home, browser.FakeCdp.Url);
|
|
|
|
// A page he opened stays as it is.
|
|
browser.FakeCdp.Navigated("https://www.instagram.com/marta.prova/");
|
|
var navigations = Navigations(browser);
|
|
await BeginAsync(bed, openLogin: false);
|
|
Assert.AreEqual("https://www.instagram.com/marta.prova/", browser.FakeCdp.Url);
|
|
Assert.AreEqual(navigations, Navigations(browser), "no navigation of his page");
|
|
|
|
var status = await bed.JsonAsync(HttpMethod.Get, "/api/connection");
|
|
Assert.IsTrue(status.GetProperty("userIsDriving").GetBoolean());
|
|
}
|
|
|
|
[TestMethod]
|
|
[Timeout(60_000, CooperativeCancellation = true)]
|
|
public async Task ApriIlBrowserBringsTheWindowWithItsStartPageAndTheLoginAfterADisconnection()
|
|
{
|
|
var ct = TestContext.CancellationToken;
|
|
await using var bed = await DesktopTestBed.StartAsync();
|
|
await bed.App.Running.WaitAsync(TimeSpan.FromSeconds(20), ct);
|
|
var browser = bed.Browser!;
|
|
|
|
// Connected, at rest: «Apri il browser» (Attività) opens the home, the window in front.
|
|
await LoginAsync(bed);
|
|
await DesktopTestBed.WaitUntilAsync(() => browser.FakeCdp.Url == "about:blank", TimeSpan.FromSeconds(10), "la pagina di riposo dopo «Ho finito»");
|
|
var shown = browser.Shown;
|
|
var result = await bed.JsonAsync(HttpMethod.Post, "/api/browser/show");
|
|
StringAssert.Contains(result.GetProperty("message").GetString(), "primo piano");
|
|
Assert.AreEqual(Home, browser.FakeCdp.Url);
|
|
Assert.AreEqual(shown + 1, browser.Shown);
|
|
Assert.IsTrue(browser.UserIsDriving, "the window on screen holds the engine still");
|
|
|
|
// Closed with its X: out of view, the engine puts the page to rest.
|
|
await browser.HideFromUserAsync(ct);
|
|
await DesktopTestBed.WaitUntilAsync(() => browser.FakeCdp.Url == "about:blank", TimeSpan.FromSeconds(10), "la pagina di riposo dopo la chiusura");
|
|
|
|
// The session goes while nobody looks: a disconnection. The red strip's «Apri il browser» asks for the login.
|
|
browser.FakeCdp.LoggedIn = false;
|
|
await bed.App.Connection!.RefreshAsync(ct);
|
|
var breaker = bed.App.Engine!.Services.Breaker;
|
|
await breaker.FlushAsync();
|
|
Assert.AreEqual(BreakerStatus.Disconnected, breaker.State.Status);
|
|
Assert.AreEqual(Login, bed.App.Connection.StartPageUrl, "disconnected: the start page is the login");
|
|
|
|
using (var show = await bed.SendAsync(HttpMethod.Post, "/api/browser/show", """{"openLogin":true}"""))
|
|
{
|
|
Assert.AreEqual(HttpStatusCode.OK, show.StatusCode, await show.Content.ReadAsStringAsync(ct));
|
|
}
|
|
|
|
Assert.AreEqual(Login, browser.FakeCdp.Url);
|
|
}
|
|
|
|
[TestMethod]
|
|
[Timeout(60_000, CooperativeCancellation = true)]
|
|
public async Task LeavingThePageOfFebeLeavesTheWindowOnScreenButAnnullaPutsItAway()
|
|
{
|
|
var ct = TestContext.CancellationToken;
|
|
await using var bed = await DesktopTestBed.StartAsync();
|
|
await bed.App.Running.WaitAsync(TimeSpan.FromSeconds(20), ct);
|
|
var browser = bed.Browser!;
|
|
await LoginAsync(bed);
|
|
await DesktopTestBed.WaitUntilAsync(() => browser.FakeCdp.Url == "about:blank", TimeSpan.FromSeconds(10), "la pagina di riposo dopo «Ho finito»");
|
|
|
|
await BeginAsync(bed, openLogin: false);
|
|
Assert.AreEqual(Home, browser.FakeCdp.Url);
|
|
var hidden = browser.Hidden;
|
|
|
|
// Another page of Febe, the tab closed or reloaded: the page's hold ends, the window stays where it is.
|
|
using (var left = await bed.SendAsync(HttpMethod.Post, "/api/connection/cancel", """{"pageLeft":true}"""))
|
|
{
|
|
Assert.AreEqual(HttpStatusCode.NoContent, left.StatusCode);
|
|
}
|
|
|
|
await Task.Delay(TimeSpan.FromSeconds(1), ct);
|
|
Assert.AreEqual(hidden, browser.Hidden, "not put out of view");
|
|
Assert.AreEqual(Home, browser.FakeCdp.Url, "not put to rest");
|
|
Assert.IsTrue(browser.UserIsDriving, "on screen, the window still holds the engine");
|
|
Assert.IsTrue(bed.App.Engine!.Services.Runtime.UserIsDriving);
|
|
|
|
// «Annulla» from the page is still «Annulla»: out of view and at rest.
|
|
await BeginAsync(bed, openLogin: false);
|
|
using (var cancel = await bed.SendAsync(HttpMethod.Post, "/api/connection/cancel"))
|
|
{
|
|
Assert.AreEqual(HttpStatusCode.NoContent, cancel.StatusCode);
|
|
}
|
|
|
|
Assert.AreEqual(hidden + 1, browser.Hidden);
|
|
await DesktopTestBed.WaitUntilAsync(() => !browser.UserIsDriving, TimeSpan.FromSeconds(10), "la fine della guida dopo «Annulla»");
|
|
Assert.AreEqual("about:blank", browser.FakeCdp.Url);
|
|
}
|
|
|
|
[TestMethod]
|
|
[Timeout(60_000, CooperativeCancellation = true)]
|
|
public async Task HoFinitoWithoutTheLoginSaysTheSessionIsNotThere()
|
|
{
|
|
var ct = TestContext.CancellationToken;
|
|
await using var bed = await DesktopTestBed.StartAsync();
|
|
await bed.App.Running.WaitAsync(TimeSpan.FromSeconds(20), ct);
|
|
|
|
await BeginAsync(bed, openLogin: true);
|
|
var finish = await bed.JsonAsync(HttpMethod.Post, "/api/connection/finish");
|
|
|
|
Assert.IsFalse(finish.GetProperty("connected").GetBoolean());
|
|
StringAssert.Contains(finish.GetProperty("message").GetString(), "non trova la sessione");
|
|
}
|
|
|
|
[TestMethod]
|
|
[Timeout(90_000, CooperativeCancellation = true)]
|
|
public async Task TheTestSitesAutomaticLoginIsNoDisconnectionAtTheNextStart()
|
|
{
|
|
var ct = TestContext.CancellationToken;
|
|
const string site = "http://127.0.0.1:8481";
|
|
string[] args = ["--sito-di-prova", site, "--accesso-di-prova"];
|
|
using var temp = new TempFolder("accesso-di-prova");
|
|
var locations = new MemoryLocationStore();
|
|
FakeDesktopShell Shell() => new() { OnCreated = b => b.FakeCdp.LogsInOnVisit = site };
|
|
|
|
await using (var bed = await DesktopTestBed.StartAsync(args, Shell(), temp, locations))
|
|
{
|
|
await bed.App.Running.WaitAsync(TimeSpan.FromSeconds(20), ct);
|
|
Assert.IsTrue(bed.App.Connection!.IsConnected, "logged in by the automatic login");
|
|
await bed.StopAsync();
|
|
}
|
|
|
|
// The next start: the new browser has no session yet (the test site forgot it); the automatic login opens it again.
|
|
await using (var bed = await DesktopTestBed.StartAsync(args, Shell(), temp, locations))
|
|
{
|
|
await bed.App.Running.WaitAsync(TimeSpan.FromSeconds(20), ct);
|
|
var breaker = bed.App.Engine!.Services.Breaker;
|
|
await breaker.FlushAsync();
|
|
Assert.IsTrue(bed.App.Connection!.IsConnected);
|
|
Assert.AreEqual(BreakerStatus.Closed, breaker.State.Status, "not a disconnection: the session the login was about to open");
|
|
Assert.IsEmpty(await bed.App.Database.Incidents.ListOpenAsync(ct));
|
|
await bed.StopAsync();
|
|
}
|
|
}
|
|
|
|
[TestMethod]
|
|
[Timeout(60_000, CooperativeCancellation = true)]
|
|
public async Task PaginaInizialeWaitsForThePageTurnAndActsOnlyWhileAlbertoIsAtTheBrowser()
|
|
{
|
|
var ct = TestContext.CancellationToken;
|
|
await using var bed = await DesktopTestBed.StartAsync();
|
|
await bed.App.Running.WaitAsync(TimeSpan.FromSeconds(20), ct);
|
|
var browser = bed.Browser!;
|
|
var connection = bed.App.Connection!;
|
|
|
|
// Nobody at the browser: the page is the engine's, the button does nothing.
|
|
var navigations = Navigations(browser);
|
|
await connection.OpenStartPageAsync(ct);
|
|
Assert.AreEqual(navigations, Navigations(browser));
|
|
|
|
// At the browser, on a page of his: the start page — but only once a step of the profile search let go of the page.
|
|
await BeginAsync(bed, openLogin: false);
|
|
browser.FakeCdp.Navigated("https://www.instagram.com/marta.prova/");
|
|
var turns = bed.App.Engine!.Services.PageTurns;
|
|
var turn = await turns.TakeAsync(Febe.Core.Engine.PageUser.Search, ct);
|
|
var home = connection.OpenStartPageAsync(ct);
|
|
await DesktopTestBed.WaitUntilAsync(() => turns.IsWaiting(Febe.Core.Engine.PageUser.Engine), TimeSpan.FromSeconds(10), "«Pagina iniziale» in attesa del turno della pagina");
|
|
Assert.IsFalse(home.IsCompleted, "the search step still has the page");
|
|
Assert.AreEqual("https://www.instagram.com/marta.prova/", browser.FakeCdp.Url);
|
|
turn.Dispose();
|
|
await home.WaitAsync(TimeSpan.FromSeconds(10), ct);
|
|
Assert.AreEqual(Login, browser.FakeCdp.Url, "not connected: the login page");
|
|
}
|
|
|
|
private static int Navigations(FakeBrowser browser) => browser.FakeCdp.Methods.Count(m => m == "Page.navigate");
|
|
|
|
private static async Task BeginAsync(DesktopTestBed bed, bool openLogin)
|
|
{
|
|
using var begin = await bed.SendAsync(HttpMethod.Post, "/api/connection/begin", openLogin ? """{"openLogin":true}""" : """{"openLogin":false}""");
|
|
Assert.AreEqual(HttpStatusCode.NoContent, begin.StatusCode);
|
|
}
|
|
|
|
private static async Task LoginAsync(DesktopTestBed bed)
|
|
{
|
|
await BeginAsync(bed, openLogin: true);
|
|
bed.Browser!.FakeCdp.LoggedIn = true;
|
|
var finish = await bed.JsonAsync(HttpMethod.Post, "/api/connection/finish");
|
|
Assert.IsTrue(finish.GetProperty("connected").GetBoolean(), finish.GetProperty("message").GetString());
|
|
}
|
|
}
|