Il browser di Febe a volte era bianco o non mostrava nulla. Le cause erano
diverse e si correggono insieme.
- Pagina iniziale. Se il browser è a riposo su about:blank e Alberto lo apre
(«Usa il browser», «Apri il browser»), Febe lo porta sulla home del sito
quando è collegato, altrimenti sulla pagina di accesso. È un'azione di
Alberto, sotto il suo permesso di guida, non del motore: Febe aspetta che
la sessione finisca e prende il turno della pagina.
Il nuovo pulsante «Pagina iniziale» sta nella barra della finestra di
Windows e nella vista remota. Su about:blank la barra dice «Il browser è a
riposo su una pagina vuota». «Indietro» non torna più sulla pagina di
riposo.
- Disconnessione. «Apri il browser» nella striscia rossa apre la pagina di
accesso. Con --accesso-di-prova il primo controllo all'avvio non segnala
più una disconnessione finta.
- Windows: la finestra resta.
- Lasciare una pagina di Febe non nasconde più la finestra «Browser di
Febe» e non la rimette a riposo: finisce solo il permesso tenuto dalla
pagina (cancel con pageLeft, IConnectionService.ReleaseAsync).
- Sullo schermo la finestra ha il suo pulsante nella barra delle
applicazioni, così ridurla a icona non la fa sparire. Dopo 2 minuti
ridotta a icona torna fuori vista (S2).
- Se lo schermo è troppo piccolo, la finestra si restringe all'area di
lavoro e la pagina si rimpicciolisce con ZoomFactor, con le stesse misure
CSS.
- I bordi della pagina si riapplicano, con NotifyParentWindowPositionChanged,
quando la finestra si mostra, si sposta o riparte il processo GPU.
- Una pagina che non risponde mentre Alberto guida resta com'è.
- IBrowserWindow.ShowAsync lascia il posto a
IConnectionService.ShowBrowserAsync.
- Docker: fotogrammi che ripartono. La vista remota ha un watchdog. Riavvia
i fotogrammi dopo una pagina nuova caricata senza fotogrammi e dopo circa
2 s di silenzio. L'attesa raddoppia fino a 30 s finché la pagina resta
ferma. Se il riavvio non porta nulla, la vista riceve un'immagine ferma
(Page.captureScreenshot, già fra i comandi ammessi).
RemoteViewSession ha ora un registro vero: avvii, riavvii e silenzi vanno
a livello Info, categoria «vista», senza indirizzi.
Se dopo 8 s non arriva nessuna immagine, l'interfaccia mostra «Nessuna
immagine dal browser» con «Riprova».
Nessun comando CDP nuovo e nessuna dipendenza nuova. Aggiornati PROTOCOLLO.md
e la guida (Primo collegamento, Attività e arresti, Installazione Windows,
Problemi comuni).
Prove nuove:
- ScreencastWatchdogTests, RemoteViewFramesTests (Chromium vero, solo CI
Linux)
- Home e Indietro in RemoteViewStartTests
- RemoteViewSocketTests
- ConnectionApiTests
- BrowserStartPageTests
- BrowserWindowDecisionTests e BrowserWindowTests (WebView2 vero)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
141 lines
7.5 KiB
C#
141 lines
7.5 KiB
C#
using System.Net;
|
|
using Febe.Tests.Web.Part2Support;
|
|
using Febe.Tests.Web.Support;
|
|
using Febe.Web.Connection;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
namespace Febe.Tests.Web;
|
|
|
|
/// <summary>
|
|
/// The link to Instagram over <see cref="IConnectionService"/> (Connection/PROTOCOLLO.md, spec §4.1): the default
|
|
/// «browser non disponibile» when the composition registers none, a registered service used as it is, the Origin
|
|
/// check on the commands (§13.1), and the configuration problems of <c>/api/capabilities</c> (§8.2, §11).
|
|
/// </summary>
|
|
[TestClass]
|
|
public sealed class ConnectionApiTests
|
|
{
|
|
[TestMethod]
|
|
public async Task WithoutAServiceTheBrowserIsUnavailableAndCommandsSaySo()
|
|
{
|
|
await using var server = await Part2.StartAsync();
|
|
var status = await server.GetJsonAsync("/api/connection");
|
|
Assert.AreEqual("browserUnavailable", status.Str("state"));
|
|
Assert.IsFalse(status.Bool("userIsDriving"));
|
|
|
|
var (beginStatus, begin) = await server.SendJsonAsync(HttpMethod.Post, "/api/connection/begin", new { openLogin = true });
|
|
Assert.AreEqual(HttpStatusCode.BadRequest, beginStatus);
|
|
StringAssert.Contains(begin.Str("message"), "browser di Febe non è disponibile");
|
|
|
|
var (finishStatus, finish) = await server.SendJsonAsync(HttpMethod.Post, "/api/connection/finish");
|
|
Assert.AreEqual(HttpStatusCode.OK, finishStatus);
|
|
Assert.IsFalse(finish.Bool("connected"));
|
|
Assert.IsFalse(string.IsNullOrWhiteSpace(finish.Str("message")));
|
|
|
|
var (cancelStatus, _) = await server.SendJsonAsync(HttpMethod.Post, "/api/connection/cancel");
|
|
Assert.AreEqual(HttpStatusCode.NoContent, cancelStatus);
|
|
var (disconnectStatus, _) = await server.SendJsonAsync(HttpMethod.Post, "/api/connection/disconnect");
|
|
Assert.AreEqual(HttpStatusCode.BadRequest, disconnectStatus);
|
|
}
|
|
|
|
[TestMethod]
|
|
public async Task ARegisteredServiceIsUsedAndHoFinitoLetsRiprendiActivate()
|
|
{
|
|
var connection = new RecordingConnection();
|
|
await using var server = await Part2.StartAsync(services: s => s.AddSingleton<IConnectionService>(connection));
|
|
|
|
var status = await server.GetJsonAsync("/api/connection");
|
|
Assert.AreEqual("notConnected", status.Str("state"));
|
|
Assert.AreEqual("https://www.instagram.com/accounts/login/", status.Str("currentUrl"));
|
|
|
|
var (beginStatus, _) = await server.SendJsonAsync(HttpMethod.Post, "/api/connection/begin", new { openLogin = true });
|
|
Assert.AreEqual(HttpStatusCode.NoContent, beginStatus);
|
|
Assert.IsTrue((await server.GetJsonAsync("/api/connection")).Bool("userIsDriving"));
|
|
|
|
var (finishStatus, finish) = await server.SendJsonAsync(HttpMethod.Post, "/api/connection/finish");
|
|
Assert.AreEqual(HttpStatusCode.OK, finishStatus);
|
|
Assert.IsTrue(finish.Bool("connected"));
|
|
Assert.AreEqual("connected", (await server.GetJsonAsync("/api/connection")).Str("state"));
|
|
Assert.IsNotNull(server.App.Services.GetRequiredService<Febe.Web.Engine.BrowserUseTracker>().LastUsedAt, "«Ho finito» counts as having used the browser");
|
|
|
|
await server.SendJsonAsync(HttpMethod.Post, "/api/connection/cancel");
|
|
await server.SendJsonAsync(HttpMethod.Post, "/api/connection/disconnect");
|
|
CollectionAssert.AreEqual(new[] { "begin:True", "finish", "cancel", "disconnect" }, connection.Calls);
|
|
}
|
|
|
|
[TestMethod]
|
|
public async Task LeavingThePageIsAnnullaInDockerAndOnlyTheEndOfTheHoldOnWindows()
|
|
{
|
|
// Docker: the remote view is the page, leaving it gives the browser back to rest.
|
|
var docker = new RecordingConnection();
|
|
await using (var server = await Part2.StartAsync(services: s => s.AddSingleton<IConnectionService>(docker)))
|
|
{
|
|
var (status, _) = await server.SendJsonAsync(HttpMethod.Post, "/api/connection/cancel", new { pageLeft = true });
|
|
Assert.AreEqual(HttpStatusCode.NoContent, status);
|
|
var (showStatus, _) = await server.SendJsonAsync(HttpMethod.Post, "/api/browser/show");
|
|
Assert.AreEqual(HttpStatusCode.BadRequest, showStatus, "in Docker the browser is the Browser page");
|
|
}
|
|
|
|
CollectionAssert.AreEqual(new[] { "cancel" }, docker.Calls);
|
|
|
|
// Windows (issue #52): the window stays as it is; «Annulla» is still «Annulla»; «Apri il browser» says which page.
|
|
var windows = new RecordingConnection();
|
|
await using (var server = await Part2.StartAsync(services: s => s
|
|
.AddSingleton<IConnectionService>(windows)
|
|
.AddSingleton<Febe.Web.Native.IBrowserWindow>(new SeparateWindow())))
|
|
{
|
|
await server.SendJsonAsync(HttpMethod.Post, "/api/connection/cancel", new { pageLeft = true });
|
|
await server.SendJsonAsync(HttpMethod.Post, "/api/connection/cancel");
|
|
var (shown, message) = await server.SendJsonAsync(HttpMethod.Post, "/api/browser/show");
|
|
Assert.AreEqual(HttpStatusCode.OK, shown);
|
|
StringAssert.Contains(message.Str("message"), "primo piano");
|
|
await server.SendJsonAsync(HttpMethod.Post, "/api/browser/show", new { openLogin = true });
|
|
}
|
|
|
|
CollectionAssert.AreEqual(new[] { "release", "cancel", "show:False", "show:True" }, windows.Calls);
|
|
}
|
|
|
|
[TestMethod]
|
|
public async Task CommandsFromAnotherPageAreRefused()
|
|
{
|
|
var connection = new RecordingConnection();
|
|
await using var server = await Part2.StartAsync(services: s => s.AddSingleton<IConnectionService>(connection));
|
|
foreach (var path in new[] { "/api/connection/begin", "/api/connection/finish", "/api/connection/disconnect" })
|
|
{
|
|
using var request = server.Request(HttpMethod.Post, path, new { openLogin = true }, origin: "http://altro.example");
|
|
using var response = await server.Client.SendAsync(request);
|
|
Assert.AreEqual(HttpStatusCode.Forbidden, response.StatusCode, path);
|
|
}
|
|
|
|
using var crossSite = server.Request(HttpMethod.Post, "/api/connection/disconnect", origin: null);
|
|
crossSite.Headers.Add("Sec-Fetch-Site", "cross-site");
|
|
using var crossResponse = await server.Client.SendAsync(crossSite);
|
|
Assert.AreEqual(HttpStatusCode.Forbidden, crossResponse.StatusCode);
|
|
Assert.IsEmpty(connection.Calls, "no command reached the service");
|
|
}
|
|
|
|
[TestMethod]
|
|
public async Task CapabilitiesListTheConfigurationProblems()
|
|
{
|
|
await using (var clean = await Part2.StartAsync())
|
|
{
|
|
var caps = await clean.GetJsonAsync("/api/capabilities");
|
|
Assert.AreEqual(0, caps.GetProperty("problems").GetArrayLength(), "the default registration has no problems");
|
|
}
|
|
|
|
var problem = new ConfigurationProblem("password-mancante", "Manca la password dell'interfaccia", "Il motore non è partito.", "Imposta FEBE_PASSWORD e riavvia.");
|
|
await using var server = await Part2.StartAsync(services: s => s.AddSingleton<IConfigurationProblems>(new FixedProblems(problem)));
|
|
var listed = (await server.GetJsonAsync("/api/capabilities")).Items("problems").ToList();
|
|
Assert.HasCount(1, listed);
|
|
Assert.AreEqual("password-mancante", listed[0].Str("code"));
|
|
Assert.AreEqual(problem.Title, listed[0].Str("title"));
|
|
Assert.AreEqual(problem.Message, listed[0].Str("message"));
|
|
Assert.AreEqual(problem.Remedy, listed[0].Str("remedy"));
|
|
}
|
|
|
|
/// <summary>The browser as a window of its own, as on Windows.</summary>
|
|
private sealed class SeparateWindow : Febe.Web.Native.IBrowserWindow
|
|
{
|
|
public bool IsSeparateWindow => true;
|
|
}
|
|
}
|