Compare commits
8
Commits
v0.1.1
..
e73292516d
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e73292516d | ||
|
|
44f7f93783 | ||
|
|
4b35178880 | ||
|
|
fe4ef9f048 | ||
|
|
7513f41d4d | ||
|
|
7a9c235552 | ||
|
|
d07ed07db6 | ||
|
|
248e9f74ce |
No files matched your search
@@ -1,5 +1,13 @@
|
|||||||
# Novità
|
# Novità
|
||||||
|
|
||||||
|
## 0.1.2 (in preparazione)
|
||||||
|
|
||||||
|
Sviluppo e qualità:
|
||||||
|
|
||||||
|
- Prove dell'interfaccia senza attese a tempo fisso (#8): le risposte in ritardo si trattengono finché la prova non le
|
||||||
|
rilascia, e ciò che non deve succedere si controlla quando la pagina ha finito le sue richieste. Restano verdi anche
|
||||||
|
con Chrome rallentato 20 volte.
|
||||||
|
|
||||||
## 0.1.1
|
## 0.1.1
|
||||||
|
|
||||||
Versione correttiva: **Febe per Windows si collega**. Con la 0.1.0 il browser di Febe non diventava mai pronto e
|
Versione correttiva: **Febe per Windows si collega**. Con la 0.1.0 il browser di Febe non diventava mai pronto e
|
||||||
|
|||||||
@@ -279,3 +279,8 @@ Ogni scelta tecnica presa strada facendo, con data e motivo (specifica §15).
|
|||||||
| 2026-10-20 | Le prove dell'interfaccia aspettano lo stato finale di una pagina, mai uno di passaggio come il mosaico vuoto che la Libreria mette sullo schermo prima della risposta di `/api/library/days` | Issue #5: `TheBackButtonAsksBeforeLosingUnsavedChanges` aspettava `.vuoto-pagina` o `.mosaico`, ma una libreria vuota con Febe non collegato finisce sul benvenuto; la prova passava solo se il primo controllo cadeva nei circa 10 ms in cui c'è il mosaico vuoto (provato con Chrome: con il primo controllo ritardato di 5 ms o più falliva sempre) |
|
| 2026-10-20 | Le prove dell'interfaccia aspettano lo stato finale di una pagina, mai uno di passaggio come il mosaico vuoto che la Libreria mette sullo schermo prima della risposta di `/api/library/days` | Issue #5: `TheBackButtonAsksBeforeLosingUnsavedChanges` aspettava `.vuoto-pagina` o `.mosaico`, ma una libreria vuota con Febe non collegato finisce sul benvenuto; la prova passava solo se il primo controllo cadeva nei circa 10 ms in cui c'è il mosaico vuoto (provato con Chrome: con il primo controllo ritardato di 5 ms o più falliva sempre) |
|
||||||
| 2026-10-20 | Lo stato vuoto della Libreria senza filtri segue il collegamento finché è sullo schermo: se il motore risponde dopo la libreria, al suo arrivo compare il benvenuto del primo avvio; quando Febe si collega, il benvenuto lascia il posto alla libreria vuota. Si ridisegna solo quando cambia tipo. La prova trattiene `/api/engine` fino a un suo segnale e toglie `EventSource` (l'interfaccia ripiega su `/api/engine`) | Prima la scelta si faceva una volta sola, alla risposta della libreria: con il motore in ritardo il primo avvio mostrava la libreria vuota invece dei due pulsanti di §10.3, e ci restava (provato con Chrome trattenendo `/api/engine`). Un segnale invece di un ritardo: l'ordine delle risposte non dipende dalla velocità della macchina |
|
| 2026-10-20 | Lo stato vuoto della Libreria senza filtri segue il collegamento finché è sullo schermo: se il motore risponde dopo la libreria, al suo arrivo compare il benvenuto del primo avvio; quando Febe si collega, il benvenuto lascia il posto alla libreria vuota. Si ridisegna solo quando cambia tipo. La prova trattiene `/api/engine` fino a un suo segnale e toglie `EventSource` (l'interfaccia ripiega su `/api/engine`) | Prima la scelta si faceva una volta sola, alla risposta della libreria: con il motore in ritardo il primo avvio mostrava la libreria vuota invece dei due pulsanti di §10.3, e ci restava (provato con Chrome trattenendo `/api/engine`). Un segnale invece di un ritardo: l'ordine delle risposte non dipende dalla velocità della macchina |
|
||||||
| 2026-10-20 | Finché lo stato del motore non è noto, la Libreria vuota senza filtri non mostra nessuno stato vuoto: un riquadro vuoto con `aria-busy`, come il mosaico mentre carica, che il primo stato del motore sostituisce con il benvenuto o con «La libreria è ancora vuota». La prova aspetta quel riquadro, il conteggio «0 …» e nessuno stato vuoto | Senza il motore non si sa se è il primo avvio: «La libreria è ancora vuota» mostrata nell'attesa era falsa al primo avvio e poi lasciava il posto al benvenuto con un salto della pagina (rilievo della revisione). Il riquadro della barra laterale dice già «Caricamento…» finché il motore non risponde, e il motore arriva comunque: il flusso `/api/eventi` lo manda appena si apre e, senza flusso, l'interfaccia lo richiede a intervalli |
|
| 2026-10-20 | Finché lo stato del motore non è noto, la Libreria vuota senza filtri non mostra nessuno stato vuoto: un riquadro vuoto con `aria-busy`, come il mosaico mentre carica, che il primo stato del motore sostituisce con il benvenuto o con «La libreria è ancora vuota». La prova aspetta quel riquadro, il conteggio «0 …» e nessuno stato vuoto | Senza il motore non si sa se è il primo avvio: «La libreria è ancora vuota» mostrata nell'attesa era falsa al primo avvio e poi lasciava il posto al benvenuto con un salto della pagina (rilievo della revisione). Il riquadro della barra laterale dice già «Caricamento…» finché il motore non risponde, e il motore arriva comunque: il flusso `/api/eventi` lo manda appena si apre e, senza flusso, l'interfaccia lo richiede a intervalli |
|
||||||
|
| 2026-10-21 | Nelle prove dell'interfaccia una risposta è in ritardo perché la prova la trattiene, mai per un tempo fisso. `UiBrowser.Requests` (al posto di `FetchDelays`) trattiene le richieste scelte finché la prova non le rilascia (`__hold`, `__release`: il rilascio chiude la regola, così lo stesso indirizzo si può trattenere di nuovo, e trattenerlo due volte insieme è un errore), conta quelle partite (`__started`) e quelle finite (`__done`: dopo la continuazione della pagina e, se lo legge, dopo il corpo della risposta) e registra ogni richiesta della pagina (`__asked`). La prova aspetta che la pagina abbia chiesto, fa ciò che deve venire prima (lasciare la pagina, cambiare filtro), rilascia e controlla quando la pagina ne ha finito | Issue #8: `APageLeftWhileLoadingLeavesNothingBehind` tornava alla Libreria 200 ms dopo `navigate('/attivita')`. Su una macchina lenta Attività non aveva ancora caricato `activity.js` e `day-strip.js`: la pagina era lasciata prima di montarsi, `/api/alerts` non partiva mai e l'attesa scadeva dopo 30 s. Con Chrome rallentato 20 volte (`Emulation.setCPUThrottlingRate`, solo in locale) falliva 3 volte su 3 con lo stesso messaggio e la stessa riga, e in 4 giri su 5 i due moduli arrivavano dopo il ritorno alla Libreria (fra 212 e 549 ms). `ABrowserPageLeftWhileLoadingNeverTakesTheBrowser` aveva una finestra di 150 ms, e la sua regola di 600 ms tratteneva anche un `begin` mandato per errore, che arrivava al server dopo il controllo: con la pagina Browser rotta apposta la prova passava. Una regola rilasciata restava e valeva per prima: un secondo `__hold` dello stesso indirizzo lasciava passare subito la richiesta, e la prova avrebbe lasciato la pagina a risposta già arrivata (rilievo della revisione) |
|
||||||
|
| 2026-10-21 | Che dopo «Ho finito», dopo «Riprendi» o lasciando una pagina il browser non sia preso né restituito un'altra volta, le prove lo controllano quando la pagina è quieta (`WaitForQuietAsync`: nessuna richiesta in volo, quindi ogni comando è arrivato al server e la pagina ha finito il seguito di ogni risposta, comprese le richieste che fa partire lì; non aspetta ciò che la pagina rimanda, come le richieste di un osservatore, di un fotogramma, di un timer, del flusso degli eventi o di un modulo che si carica dopo, e qui basta perché il comando sbagliato partirebbe lasciando la pagina o nel seguito di una risposta) sull'elenco delle richieste della pagina (`__asked`) e su quelle viste dal server; non dopo una pausa di 300 o 500 ms. La vista chiusa sul server si aspetta | Con la pausa una macchina lenta poteva controllare prima che il comando sbagliato arrivasse, e la prova passava lo stesso; dopo «Riprendi» la vista chiusa si controllava dopo 300 ms, e lì una macchina lenta faceva fallire la prova. Con copie dell'interfaccia rotte apposta (un «cancel» dopo «Ho finito» nelle pagine Browser e Collegamento, un «begin» dopo «Riprendi», un «begin» che parte solo dopo una risposta del motore) le quattro prove falliscono in ogni giro provato, anche con Chrome rallentato 20 volte. La quiete non copre ciò che parte più tardi (rilievo della revisione): sulla Libreria con 40 elementi, al primo momento senza richieste in volo le 11 righe del mosaico, chieste da un IntersectionObserver dopo il disegno dei giorni, non erano ancora partite in 3 giri su 6 |
|
||||||
|
| 2026-10-21 | La prova dei tasti della vista remota li manda quando il WebSocket della pagina è aperto (`__sockets` di `UiBrowser.Requests`), non 300 ms dopo che il server ha aperto la vista; la prova del mouse scrive meta e fotogramma senza pausa | Il server apre la vista prima di rispondere al socket (`RemoteViewSocket.HandleAsync`) e la pagina scarta i messaggi finché il socket non è aperto: su una macchina più lenta di 300 ms i tasti andavano persi e la prova falliva dopo 30 s. Ciò che il server scrive resta nella vista finché il socket non è aperto e la pagina ascolta da subito, quindi la pausa del mouse non serviva: il primo fotogramma sullo schermo dice già che il socket è aperto |
|
||||||
|
| 2026-10-21 | I ridisegni rimandati di una pagina (`later`: 150 ms in «In evidenza») le prove li aspettano come timer: `PageTimers` dice quali timeout erano in sospeso in un dato momento e quando sono finiti; dopo un cambio di dimensione si aspetta un ResizeObserver della prova, chiamato dopo quelli della pagina, e i timer che quelli hanno lasciato. Il trascinamento della maniglia della fascia aspetta ogni passo nel campo dell'ora prima del successivo; l'intestazione dell'account non ha più una pausa fra un'azione e l'altra | Con pause di 500 e 600 ms il ridisegno sbagliato poteva arrivare dopo il controllo. Con 60 ms fra un passo e l'altro una macchina lenta può consegnare più passi come un solo movimento: la prova vedeva solo l'ultimo e non provava più che la maniglia segua tutto il trascinamento. La pausa dell'intestazione non proteggeva nulla: ogni giro aspetta già il menu ridisegnato. Con copie rotte apposta (ridisegno non annullato, osservatore non staccato, tessere tardive disegnate, trascinamento che finisce al primo passo) le prove falliscono in ogni giro provato, anche a 20x; il ridisegno non annullato si vede quando è ancora in sospeso al cambio di filtro, come prima (in tutti i giri provati lo era) |
|
||||||
|
| 2026-10-21 | `APageLeftWhileLoadingLeavesNothingBehind` controlla che Attività, lasciata mentre carica, non lasci né il timer di un minuto, né l'ascolto della libreria, né avvisi sulla Libreria; e che, aperta, a una modifica della libreria si ricarichi. La modifica la prova la manda alla pagina come la manda il flusso degli eventi (un evento «libreria» sul suo `EventSource`, che chiama subito chi ascolta) e ne ha conferma quando la Libreria richiede i suoi giorni; gli avvisi li registra un MutationObserver, anche quelli già spariti | Rilievo della revisione: il controllo «niente di Attività sulla Libreria» guardava solo `main`, dove Attività non disegna (la sua cornice ne esce prima ancora che il modulo si carichi), e poteva fallire solo per un nodo messo lì direttamente. Con copie rotte apposta la prova di prima passava con l'ascolto della libreria rimasto e con l'errore delle richieste annullate mostrato sulla Libreria; ora le trova entrambe, a velocità normale e con Chrome rallentato 20 volte. Una modifica pubblicata sul server non darebbe lo stesso ordine: il flusso si iscrive alle modifiche in un `Task.Run`, senza dire quando, e le raccoglie per 300 ms |
|
||||||
@@ -50,6 +50,33 @@ public sealed class InterfaceTests
|
|||||||
})();
|
})();
|
||||||
""";
|
""";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Installed before the page scripts: <c>window.__timers()</c> lists the timeouts of the page still pending and
|
||||||
|
/// <c>window.__timersOver(ids)</c> says whether those have all run or been cleared. A test waits for the timers that
|
||||||
|
/// were pending at a given moment (a debounced redraw, say) to be over, instead of a pause that may be too short.
|
||||||
|
/// </summary>
|
||||||
|
private const string PageTimers = """
|
||||||
|
(() => {
|
||||||
|
const set = window.setTimeout.bind(window);
|
||||||
|
const clear = window.clearTimeout.bind(window);
|
||||||
|
const pending = new Set();
|
||||||
|
window.setTimeout = (fn, ms, ...rest) => {
|
||||||
|
const id = set((...args) => {
|
||||||
|
pending.delete(id);
|
||||||
|
fn(...args);
|
||||||
|
}, ms, ...rest);
|
||||||
|
pending.add(id);
|
||||||
|
return id;
|
||||||
|
};
|
||||||
|
window.clearTimeout = (id) => {
|
||||||
|
pending.delete(id);
|
||||||
|
clear(id);
|
||||||
|
};
|
||||||
|
window.__timers = () => [...pending];
|
||||||
|
window.__timersOver = (ids) => ids.every((id) => !pending.has(id));
|
||||||
|
})();
|
||||||
|
""";
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------ the driving lease
|
// ------------------------------------------------------------------------------------------ the driving lease
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
@@ -94,22 +121,23 @@ public sealed class InterfaceTests
|
|||||||
var view = new FakeRemoteViewHost();
|
var view = new FakeRemoteViewHost();
|
||||||
await using var server = await DockerAsync(connection, view);
|
await using var server = await DockerAsync(connection, view);
|
||||||
await using var ui = await UiBrowser.StartAsync();
|
await using var ui = await UiBrowser.StartAsync();
|
||||||
await ui.AddInitScriptAsync(UiBrowser.FetchDelays);
|
await ui.AddInitScriptAsync(UiBrowser.Requests);
|
||||||
await ui.OpenAsync(new Uri(server.Address, "/libreria"));
|
await ui.OpenAsync(new Uri(server.Address, "/libreria"));
|
||||||
|
|
||||||
// The status of the connection answers late; Alberto is already elsewhere.
|
// The status of the connection answers late: the Browser page asks for it, Alberto goes elsewhere, then it
|
||||||
await ui.EvalAsync("""
|
// comes. In this order on any machine (issue #8: a page left after a fixed delay may not have asked yet).
|
||||||
import('/js/core/shell.js').then((m) => {
|
await ui.EvalAsync("window.__hold('/api/connection')");
|
||||||
window.__delays.push({ match: '/api/connection', ms: 600 });
|
await ui.NavigateAsync("/browser");
|
||||||
m.navigate('/browser');
|
await ui.WaitAsync("window.__started['/api/connection'] >= 1", "pagina Browser in attesa dello stato del collegamento");
|
||||||
setTimeout(() => m.navigate('/libreria'), 150);
|
await ui.NavigateAsync("/libreria");
|
||||||
return true;
|
|
||||||
})
|
|
||||||
""");
|
|
||||||
await ui.WaitAsync("location.pathname === '/libreria'", "Libreria");
|
await ui.WaitAsync("location.pathname === '/libreria'", "Libreria");
|
||||||
|
await ui.EvalAsync("window.__release('/api/connection')");
|
||||||
await ui.WaitAsync("window.__done['/api/connection'] >= 1", "risposta in ritardo arrivata");
|
await ui.WaitAsync("window.__done['/api/connection'] >= 1", "risposta in ritardo arrivata");
|
||||||
await Task.Delay(300);
|
|
||||||
Assert.IsEmpty(connection.Snapshot(), "nothing taken by a page that is gone");
|
// What the page did with the late answer is done: whatever it asked then is in the list.
|
||||||
|
CollectionAssert.AreEqual(new[] { "GET /api/connection" }, await ui.AskedAsync("/api/connection"), "nothing taken by a page that is gone");
|
||||||
|
Assert.IsEmpty(await ui.AskedAsync("/api/vista"), "no remote view for a page that is gone");
|
||||||
|
Assert.IsEmpty(connection.Snapshot());
|
||||||
Assert.IsEmpty(view.Opened);
|
Assert.IsEmpty(view.Opened);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -120,6 +148,7 @@ public sealed class InterfaceTests
|
|||||||
var view = new FakeRemoteViewHost();
|
var view = new FakeRemoteViewHost();
|
||||||
await using var server = await DockerAsync(connection, view);
|
await using var server = await DockerAsync(connection, view);
|
||||||
await using var ui = await UiBrowser.StartAsync();
|
await using var ui = await UiBrowser.StartAsync();
|
||||||
|
await ui.AddInitScriptAsync(UiBrowser.Requests);
|
||||||
|
|
||||||
await ui.OpenAsync(new Uri(server.Address, "/browser"));
|
await ui.OpenAsync(new Uri(server.Address, "/browser"));
|
||||||
await ui.WaitForAsync(() => connection.Snapshot().Contains("begin:False"), "il browser in uso");
|
await ui.WaitForAsync(() => connection.Snapshot().Contains("begin:False"), "il browser in uso");
|
||||||
@@ -128,8 +157,12 @@ public sealed class InterfaceTests
|
|||||||
await ui.WaitForAsync(() => view.Opened.All(v => v.Disposed), "vista remota chiusa");
|
await ui.WaitForAsync(() => view.Opened.All(v => v.Disposed), "vista remota chiusa");
|
||||||
await ui.NavigateAsync("/libreria");
|
await ui.NavigateAsync("/libreria");
|
||||||
await ui.WaitAsync("location.pathname === '/libreria'", "Libreria");
|
await ui.WaitAsync("location.pathname === '/libreria'", "Libreria");
|
||||||
await Task.Delay(500);
|
|
||||||
CollectionAssert.AreEqual(new[] { "begin:False", "finish" }, connection.Snapshot(), "«Ho finito» already gave the browser back");
|
// A page gives the browser back as it is left (PageFrame.onLeave): a «cancel» would be asked by now, and once
|
||||||
|
// the page is quiet every command it asked has reached the server.
|
||||||
|
await ui.WaitForQuietAsync("richieste della pagina finite");
|
||||||
|
CollectionAssert.AreEqual(new[] { "POST /api/connection/begin", "POST /api/connection/finish" }, await ui.AskedAsync("POST /api/connection/"), "«Ho finito» already gave the browser back");
|
||||||
|
CollectionAssert.AreEqual(new[] { "begin:False", "finish" }, connection.Snapshot());
|
||||||
}
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
@@ -154,6 +187,7 @@ public sealed class InterfaceTests
|
|||||||
var view = new FakeRemoteViewHost();
|
var view = new FakeRemoteViewHost();
|
||||||
await using var server = await DockerAsync(connection, view);
|
await using var server = await DockerAsync(connection, view);
|
||||||
await using var ui = await UiBrowser.StartAsync();
|
await using var ui = await UiBrowser.StartAsync();
|
||||||
|
await ui.AddInitScriptAsync(UiBrowser.Requests);
|
||||||
|
|
||||||
await ui.OpenAsync(new Uri(server.Address, "/impostazioni/collegamento"));
|
await ui.OpenAsync(new Uri(server.Address, "/impostazioni/collegamento"));
|
||||||
await ui.WaitForAsync(() => connection.Snapshot().Contains("begin:True") && view.Opened.Count == 1, "pagina di accesso nella vista remota");
|
await ui.WaitForAsync(() => connection.Snapshot().Contains("begin:True") && view.Opened.Count == 1, "pagina di accesso nella vista remota");
|
||||||
@@ -164,7 +198,9 @@ public sealed class InterfaceTests
|
|||||||
await ui.WaitForAsync(() => view.Opened.All(v => v.Disposed), "vista remota chiusa dopo «Ho finito»");
|
await ui.WaitForAsync(() => view.Opened.All(v => v.Disposed), "vista remota chiusa dopo «Ho finito»");
|
||||||
await ui.NavigateAsync("/libreria");
|
await ui.NavigateAsync("/libreria");
|
||||||
await ui.WaitAsync("location.pathname === '/libreria'", "Libreria");
|
await ui.WaitAsync("location.pathname === '/libreria'", "Libreria");
|
||||||
await Task.Delay(500);
|
await ui.WaitForQuietAsync("richieste della pagina finite");
|
||||||
|
CollectionAssert.AreEqual(new[] { "POST /api/connection/begin", "POST /api/connection/finish" }, await ui.AskedAsync("POST /api/connection/"), "«Ho finito» already gave the browser back");
|
||||||
|
CollectionAssert.AreEqual(new[] { "WS /api/vista" }, await ui.AskedAsync("WS "), "no view opened again");
|
||||||
CollectionAssert.AreEqual(new[] { "begin:True", "finish" }, connection.Snapshot());
|
CollectionAssert.AreEqual(new[] { "begin:True", "finish" }, connection.Snapshot());
|
||||||
Assert.HasCount(1, view.Opened);
|
Assert.HasCount(1, view.Opened);
|
||||||
}
|
}
|
||||||
@@ -176,23 +212,28 @@ public sealed class InterfaceTests
|
|||||||
var view = new FakeRemoteViewHost();
|
var view = new FakeRemoteViewHost();
|
||||||
await using var server = await DockerAsync(connection, view, new FixedMonitor(EngineMode.StoppedForVerification));
|
await using var server = await DockerAsync(connection, view, new FixedMonitor(EngineMode.StoppedForVerification));
|
||||||
await using var ui = await UiBrowser.StartAsync();
|
await using var ui = await UiBrowser.StartAsync();
|
||||||
|
await ui.AddInitScriptAsync(UiBrowser.Requests);
|
||||||
|
|
||||||
await ui.OpenAsync(new Uri(server.Address, "/impostazioni/collegamento"));
|
await ui.OpenAsync(new Uri(server.Address, "/impostazioni/collegamento"));
|
||||||
await ui.WaitForAsync(() => connection.Snapshot().Contains("begin:False") && view.Opened.Count == 1, "verifica nella vista remota");
|
await ui.WaitForAsync(() => connection.Snapshot().Contains("begin:False") && view.Opened.Count == 1, "verifica nella vista remota");
|
||||||
await ui.EvalAsync("document.querySelector('.bottoni-collegamento .btn.primo').click()");
|
await ui.EvalAsync("document.querySelector('.bottoni-collegamento .btn.primo').click()");
|
||||||
await ui.WaitAsync("document.querySelector('.riapri-browser') !== null", "«Ho finito» fatto, in attesa di «Riprendi»");
|
await ui.WaitAsync("document.querySelector('.riapri-browser') !== null", "«Ho finito» fatto, in attesa di «Riprendi»");
|
||||||
await ui.WaitForAsync(() => view.Opened.All(v => v.Disposed), "vista remota chiusa dopo «Ho finito»");
|
await ui.WaitForAsync(() => view.Opened.All(v => v.Disposed), "vista remota chiusa dopo «Ho finito»");
|
||||||
await Task.Delay(500);
|
|
||||||
CollectionAssert.AreEqual(new[] { "begin:False", "finish" }, connection.Snapshot(), "no new lease after «Ho finito»");
|
// «Ho finito» also asks for the engine: what its answer brings has been drawn once the page is quiet.
|
||||||
Assert.HasCount(1, view.Opened, "no new view after «Ho finito»");
|
await ui.WaitForQuietAsync("richieste di «Ho finito» finite");
|
||||||
|
CollectionAssert.AreEqual(new[] { "POST /api/connection/begin", "POST /api/connection/finish" }, await ui.AskedAsync("POST /api/connection/"), "no new lease after «Ho finito»");
|
||||||
|
CollectionAssert.AreEqual(new[] { "WS /api/vista" }, await ui.AskedAsync("WS "), "no new view after «Ho finito»");
|
||||||
|
CollectionAssert.AreEqual(new[] { "begin:False", "finish" }, connection.Snapshot());
|
||||||
|
Assert.HasCount(1, view.Opened);
|
||||||
|
|
||||||
// «Riapri il browser» takes it again; leaving the page then gives it back.
|
// «Riapri il browser» takes it again; leaving the page then gives it back.
|
||||||
await ui.EvalAsync("document.querySelector('.riapri-browser').click()");
|
await ui.EvalAsync("document.querySelector('.riapri-browser').click()");
|
||||||
await ui.WaitForAsync(() => connection.Snapshot().Length == 3 && view.Opened.Count == 2, "browser riaperto");
|
await ui.WaitForAsync(() => connection.Snapshot().Length == 3 && view.Opened.Count == 2, "browser riaperto");
|
||||||
await ui.NavigateAsync("/libreria");
|
await ui.NavigateAsync("/libreria");
|
||||||
await ui.WaitAsync("location.pathname === '/libreria'", "Libreria");
|
await ui.WaitAsync("location.pathname === '/libreria'", "Libreria");
|
||||||
await ui.WaitForAsync(() => connection.Snapshot().Length == 4, "il browser restituito lasciando la pagina");
|
await ui.WaitForQuietAsync("richieste della pagina finite");
|
||||||
CollectionAssert.AreEqual(new[] { "begin:False", "finish", "begin:False", "cancel" }, connection.Snapshot());
|
CollectionAssert.AreEqual(new[] { "begin:False", "finish", "begin:False", "cancel" }, connection.Snapshot(), "leaving the page gives the browser back");
|
||||||
await ui.WaitForAsync(() => view.Opened.All(v => v.Disposed), "vista remota chiusa");
|
await ui.WaitForAsync(() => view.Opened.All(v => v.Disposed), "vista remota chiusa");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -204,6 +245,7 @@ public sealed class InterfaceTests
|
|||||||
var engine = new FixedMonitor(EngineMode.StoppedForVerification);
|
var engine = new FixedMonitor(EngineMode.StoppedForVerification);
|
||||||
await using var server = await DockerAsync(connection, view, engine);
|
await using var server = await DockerAsync(connection, view, engine);
|
||||||
await using var ui = await UiBrowser.StartAsync();
|
await using var ui = await UiBrowser.StartAsync();
|
||||||
|
await ui.AddInitScriptAsync(UiBrowser.Requests);
|
||||||
|
|
||||||
await ui.OpenAsync(new Uri(server.Address, "/impostazioni/collegamento"));
|
await ui.OpenAsync(new Uri(server.Address, "/impostazioni/collegamento"));
|
||||||
await ui.WaitAsync("document.querySelector('.arresto') !== null", "striscia rossa della verifica");
|
await ui.WaitAsync("document.querySelector('.arresto') !== null", "striscia rossa della verifica");
|
||||||
@@ -216,9 +258,11 @@ public sealed class InterfaceTests
|
|||||||
connection.Status = Connected;
|
connection.Status = Connected;
|
||||||
await ui.EvalAsync("import('/js/core/engine.js').then((m) => m.refreshEngine()).then(() => true)");
|
await ui.EvalAsync("import('/js/core/engine.js').then((m) => m.refreshEngine()).then(() => true)");
|
||||||
await ui.WaitAsync("document.querySelector('.pannello.collegato') !== null", "collegato dopo «Riprendi»");
|
await ui.WaitAsync("document.querySelector('.pannello.collegato') !== null", "collegato dopo «Riprendi»");
|
||||||
await Task.Delay(300);
|
await ui.WaitForQuietAsync("richieste dopo «Riprendi» finite");
|
||||||
|
CollectionAssert.AreEqual(new[] { "POST /api/connection/begin", "POST /api/connection/finish" }, await ui.AskedAsync("POST /api/connection/"), "the browser is not taken again");
|
||||||
CollectionAssert.AreEqual(new[] { "begin:False", "finish" }, connection.Snapshot());
|
CollectionAssert.AreEqual(new[] { "begin:False", "finish" }, connection.Snapshot());
|
||||||
Assert.IsTrue(view.Opened.All(v => v.Disposed));
|
await ui.WaitForAsync(() => view.Opened.All(v => v.Disposed), "vista remota chiusa");
|
||||||
|
Assert.HasCount(1, view.Opened);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------ remote view input
|
// ------------------------------------------------------------------------------------------ remote view input
|
||||||
@@ -230,10 +274,13 @@ public sealed class InterfaceTests
|
|||||||
var view = new FakeRemoteViewHost();
|
var view = new FakeRemoteViewHost();
|
||||||
await using var server = await DockerAsync(connection, view);
|
await using var server = await DockerAsync(connection, view);
|
||||||
await using var ui = await UiBrowser.StartAsync();
|
await using var ui = await UiBrowser.StartAsync();
|
||||||
|
await ui.AddInitScriptAsync(UiBrowser.Requests);
|
||||||
await ui.OpenAsync(new Uri(server.Address, "/browser"));
|
await ui.OpenAsync(new Uri(server.Address, "/browser"));
|
||||||
await ui.WaitForAsync(() => view.Opened.Count == 1, "vista aperta");
|
await ui.WaitForAsync(() => view.Opened.Count == 1, "vista aperta");
|
||||||
await ui.WaitAsync("document.querySelector('canvas.vista-schermo') !== null", "schermo della vista");
|
await ui.WaitAsync("document.querySelector('canvas.vista-schermo') !== null", "schermo della vista");
|
||||||
await Task.Delay(300);
|
|
||||||
|
// The view sends keys only once its socket is open (the server opens the view before it answers the socket).
|
||||||
|
await ui.WaitAsync("window.__sockets.some((s) => s.url.endsWith('/api/vista') && s.readyState === WebSocket.OPEN)", "vista collegata");
|
||||||
|
|
||||||
// Italian layout on Windows: AltGr+ò is «@», reported as Ctrl+Alt with the AltGraph modifier.
|
// Italian layout on Windows: AltGr+ò is «@», reported as Ctrl+Alt with the AltGraph modifier.
|
||||||
Assert.IsTrue((await ui.EvalAsync("new KeyboardEvent('keydown', { key: '@', modifierAltGraph: true }).getModifierState('AltGraph')")).GetBoolean());
|
Assert.IsTrue((await ui.EvalAsync("new KeyboardEvent('keydown', { key: '@', modifierAltGraph: true }).getModifierState('AltGraph')")).GetBoolean());
|
||||||
@@ -270,7 +317,9 @@ public sealed class InterfaceTests
|
|||||||
await ui.OpenAsync(new Uri(server.Address, "/browser"));
|
await ui.OpenAsync(new Uri(server.Address, "/browser"));
|
||||||
await ui.WaitForAsync(() => view.Opened.Count == 1, "vista aperta");
|
await ui.WaitForAsync(() => view.Opened.Count == 1, "vista aperta");
|
||||||
var remote = view.Opened.Single();
|
var remote = view.Opened.Single();
|
||||||
await Task.Delay(300);
|
|
||||||
|
// What the view writes waits in it until the socket is open, and the page listens from the start; the first
|
||||||
|
// frame on the screen says that the socket is open, so the buttons can go.
|
||||||
remote.Write(new RemoteViewMeta(320, 225, "https://www.instagram.com/"));
|
remote.Write(new RemoteViewMeta(320, 225, "https://www.instagram.com/"));
|
||||||
remote.Write(new RemoteViewFrame(TestFile.PhotoBytes(3, 320, 225)));
|
remote.Write(new RemoteViewFrame(TestFile.PhotoBytes(3, 320, 225)));
|
||||||
await ui.WaitAsync("!document.querySelector('canvas.vista-schermo').hidden", "primo fotogramma");
|
await ui.WaitAsync("!document.querySelector('canvas.vista-schermo').hidden", "primo fotogramma");
|
||||||
@@ -302,31 +351,64 @@ public sealed class InterfaceTests
|
|||||||
}
|
}
|
||||||
|
|
||||||
await using var ui = await UiBrowser.StartAsync();
|
await using var ui = await UiBrowser.StartAsync();
|
||||||
await ui.AddInitScriptAsync(UiBrowser.FetchDelays);
|
await ui.AddInitScriptAsync(UiBrowser.Requests);
|
||||||
|
await ui.AddInitScriptAsync(PageTimers);
|
||||||
await ui.OpenAsync(new Uri(server.Address, $"/account/{account.Id}?tipo=evidenza"));
|
await ui.OpenAsync(new Uri(server.Address, $"/account/{account.Id}?tipo=evidenza"));
|
||||||
await ui.WaitAsync("document.querySelector('main .raccolta-titolo') !== null", "raccolte in evidenza");
|
await ui.WaitAsync("document.querySelector('main .raccolta-titolo') !== null", "raccolte in evidenza");
|
||||||
|
|
||||||
// «Post» after «In evidenza»: the posts stay, also when the area changes size.
|
// «Post» after «In evidenza»: the posts stay, also once what «In evidenza» left pending has run (it redraws
|
||||||
await ui.EvalAsync("document.querySelectorAll('.strumenti .filtri button')[0].click()");
|
// itself 150 ms after a change of size, and it has just been drawn).
|
||||||
await ui.WaitAsync("document.querySelector('main .mosaico .gruppo-giorno') !== null", "mosaico dei post");
|
|
||||||
await Task.Delay(500);
|
|
||||||
await ui.SendAsync("Emulation.setDeviceMetricsOverride", new JsonObject { ["width"] = 1100, ["height"] = 900, ["deviceScaleFactor"] = 1, ["mobile"] = false });
|
|
||||||
await Task.Delay(600);
|
|
||||||
await AssertPostsShownAsync(ui);
|
|
||||||
|
|
||||||
// «In evidenza» and at once «Post», while the tiles of the collections are still loading.
|
|
||||||
await ui.EvalAsync("""
|
await ui.EvalAsync("""
|
||||||
(() => {
|
(() => {
|
||||||
window.__delays.push({ match: '/api/library/tiles', ms: 600 });
|
window.__pendingAtSwitch = window.__timers();
|
||||||
|
document.querySelectorAll('.strumenti .filtri button')[0].click();
|
||||||
|
return true;
|
||||||
|
})()
|
||||||
|
""");
|
||||||
|
await ui.WaitAsync("document.querySelector('main .mosaico .gruppo-giorno') !== null", "mosaico dei post");
|
||||||
|
await ui.WaitAsync("window.__timersOver(window.__pendingAtSwitch)", "attese di «In evidenza» finite");
|
||||||
|
await AssertPostsShownAsync(ui);
|
||||||
|
|
||||||
|
// The area changes size. The page's own observers see it before this one, which came last: what they left
|
||||||
|
// pending then (a redraw, a frame) runs, and the posts are still there.
|
||||||
|
await ui.EvalAsync("""
|
||||||
|
(() => {
|
||||||
|
let before = null;
|
||||||
|
window.__afterResize = null;
|
||||||
|
new ResizeObserver((entries, observer) => {
|
||||||
|
const width = entries[0].contentRect.width;
|
||||||
|
if (before === null) {
|
||||||
|
before = width;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (Math.abs(width - before) < 1) return;
|
||||||
|
observer.disconnect();
|
||||||
|
const pending = window.__timers();
|
||||||
|
requestAnimationFrame(() => { window.__afterResize = pending; });
|
||||||
|
}).observe(document.querySelector('main .corpo > div'));
|
||||||
|
window.__resizeWatched = () => before !== null;
|
||||||
|
return true;
|
||||||
|
})()
|
||||||
|
""");
|
||||||
|
await ui.WaitAsync("window.__resizeWatched()", "dimensione dei contenuti osservata");
|
||||||
|
await ui.SendAsync("Emulation.setDeviceMetricsOverride", new JsonObject { ["width"] = 1100, ["height"] = 900, ["deviceScaleFactor"] = 1, ["mobile"] = false });
|
||||||
|
await ui.WaitAsync("window.__afterResize !== null && window.__timersOver(window.__afterResize)", "contenuti ridisegnati alla nuova larghezza");
|
||||||
|
await AssertPostsShownAsync(ui);
|
||||||
|
|
||||||
|
// «In evidenza» and at once «Post», while the tiles of the collections are still loading: they come after the
|
||||||
|
// posts are drawn.
|
||||||
|
await ui.EvalAsync("""
|
||||||
|
(() => {
|
||||||
|
window.__hold('/api/library/tiles');
|
||||||
const chips = document.querySelectorAll('.strumenti .filtri button');
|
const chips = document.querySelectorAll('.strumenti .filtri button');
|
||||||
chips[2].click();
|
chips[2].click();
|
||||||
chips[0].click();
|
chips[0].click();
|
||||||
return true;
|
return true;
|
||||||
})()
|
})()
|
||||||
""");
|
""");
|
||||||
|
await ui.WaitAsync("window.__started['/api/library/tiles'] >= 1 && document.querySelector('main .mosaico .gruppo-giorno') !== null", "mosaico dei post");
|
||||||
|
await ui.EvalAsync("window.__release('/api/library/tiles')");
|
||||||
await ui.WaitAsync("window.__done['/api/library/tiles'] >= 1", "tessere delle raccolte arrivate in ritardo");
|
await ui.WaitAsync("window.__done['/api/library/tiles'] >= 1", "tessere delle raccolte arrivate in ritardo");
|
||||||
await ui.WaitAsync("document.querySelector('main .mosaico .gruppo-giorno') !== null", "mosaico dei post");
|
|
||||||
await Task.Delay(400);
|
|
||||||
await AssertPostsShownAsync(ui);
|
await AssertPostsShownAsync(ui);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -336,23 +418,23 @@ public sealed class InterfaceTests
|
|||||||
await using var server = await WebTestServer.StartAsync();
|
await using var server = await WebTestServer.StartAsync();
|
||||||
await server.AddAccountWithEntriesAsync("anna.prova", 5, Make.T0, TimeSpan.FromHours(30));
|
await server.AddAccountWithEntriesAsync("anna.prova", 5, Make.T0, TimeSpan.FromHours(30));
|
||||||
await using var ui = await UiBrowser.StartAsync();
|
await using var ui = await UiBrowser.StartAsync();
|
||||||
await ui.AddInitScriptAsync(UiBrowser.FetchDelays);
|
await ui.AddInitScriptAsync(UiBrowser.Requests);
|
||||||
await ui.OpenAsync(new Uri(server.Address, "/libreria"));
|
await ui.OpenAsync(new Uri(server.Address, "/libreria"));
|
||||||
await ui.WaitAsync("document.querySelector('main .mosaico .gruppo-giorno .tess') !== null", "mosaico");
|
await ui.WaitAsync("document.querySelector('main .mosaico .gruppo-giorno .tess') !== null", "mosaico");
|
||||||
|
|
||||||
// «Storie» (nothing: an empty answer, late) and at once «Foto».
|
// «Storie» (nothing: an empty answer, late) and at once «Foto»: the stories answer after the photos are drawn.
|
||||||
await ui.EvalAsync("""
|
await ui.EvalAsync("""
|
||||||
(() => {
|
(() => {
|
||||||
window.__delays.push({ match: 'kind=stories', ms: 700 });
|
window.__hold('kind=stories');
|
||||||
const chips = document.querySelectorAll('.strumenti .filtri button');
|
const chips = document.querySelectorAll('.strumenti .filtri button');
|
||||||
chips[3].click();
|
chips[3].click();
|
||||||
chips[1].click();
|
chips[1].click();
|
||||||
return true;
|
return true;
|
||||||
})()
|
})()
|
||||||
""");
|
""");
|
||||||
await ui.WaitAsync("document.querySelector('main .mosaico .gruppo-giorno .tess') !== null", "foto");
|
await ui.WaitAsync("window.__started['kind=stories'] >= 1 && document.querySelector('main .mosaico .gruppo-giorno .tess') !== null", "foto");
|
||||||
|
await ui.EvalAsync("window.__release('kind=stories')");
|
||||||
await ui.WaitAsync("window.__done['kind=stories'] >= 1", "risposta delle storie arrivata in ritardo");
|
await ui.WaitAsync("window.__done['kind=stories'] >= 1", "risposta delle storie arrivata in ritardo");
|
||||||
await Task.Delay(300);
|
|
||||||
Assert.IsTrue((await ui.EvalAsync("location.search.includes('tipo=foto')")).GetBoolean());
|
Assert.IsTrue((await ui.EvalAsync("location.search.includes('tipo=foto')")).GetBoolean());
|
||||||
Assert.IsTrue((await ui.EvalAsync("document.querySelector('main .mosaico .gruppo-giorno .tess') !== null")).GetBoolean(), "the photos are shown " + ui.Report());
|
Assert.IsTrue((await ui.EvalAsync("document.querySelector('main .mosaico .gruppo-giorno .tess') !== null")).GetBoolean(), "the photos are shown " + ui.Report());
|
||||||
Assert.IsTrue((await ui.EvalAsync("document.querySelector('main .vuoto-pagina') === null")).GetBoolean(), "no empty state over the results");
|
Assert.IsTrue((await ui.EvalAsync("document.querySelector('main .vuoto-pagina') === null")).GetBoolean(), "no empty state over the results");
|
||||||
@@ -441,7 +523,6 @@ public sealed class InterfaceTests
|
|||||||
})()
|
})()
|
||||||
""",
|
""",
|
||||||
$"intestazione aggiornata dopo «{choice}»");
|
$"intestazione aggiornata dopo «{choice}»");
|
||||||
await Task.Delay(200);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -480,7 +561,7 @@ public sealed class InterfaceTests
|
|||||||
{
|
{
|
||||||
await using var server = await WebTestServer.StartAsync();
|
await using var server = await WebTestServer.StartAsync();
|
||||||
await using var ui = await UiBrowser.StartAsync();
|
await using var ui = await UiBrowser.StartAsync();
|
||||||
await ui.AddInitScriptAsync(UiBrowser.FetchDelays);
|
await ui.AddInitScriptAsync(UiBrowser.Requests);
|
||||||
await ui.AddInitScriptAsync("""
|
await ui.AddInitScriptAsync("""
|
||||||
(() => {
|
(() => {
|
||||||
const live = new Map();
|
const live = new Map();
|
||||||
@@ -489,25 +570,62 @@ public sealed class InterfaceTests
|
|||||||
window.setInterval = (fn, ms, ...rest) => { const id = set(fn, ms, ...rest); live.set(id, ms); return id; };
|
window.setInterval = (fn, ms, ...rest) => { const id = set(fn, ms, ...rest); live.set(id, ms); return id; };
|
||||||
window.clearInterval = (id) => { live.delete(id); clear(id); };
|
window.clearInterval = (id) => { live.delete(id); clear(id); };
|
||||||
window.__intervals = (ms) => [...live.values()].filter((v) => v === ms).length;
|
window.__intervals = (ms) => [...live.values()].filter((v) => v === ms).length;
|
||||||
|
// Every short notice shown, also one already gone again.
|
||||||
|
window.__notices = [];
|
||||||
|
new MutationObserver((records) => {
|
||||||
|
for (const record of records) {
|
||||||
|
for (const node of record.addedNodes) {
|
||||||
|
if (node.nodeType === 1 && node.matches('.brevi > *')) window.__notices.push(node.textContent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}).observe(document, { childList: true, subtree: true });
|
||||||
|
// A change of the library as the event stream brings it: every page that listens is called before this
|
||||||
|
// returns (the number of streams).
|
||||||
|
const NativeSource = window.EventSource;
|
||||||
|
const streams = [];
|
||||||
|
window.EventSource = class extends NativeSource {
|
||||||
|
constructor(...args) {
|
||||||
|
super(...args);
|
||||||
|
streams.push(this);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
window.__libraryChanged = () => {
|
||||||
|
for (const stream of streams) stream.dispatchEvent(new MessageEvent('libreria', { data: '{}' }));
|
||||||
|
return streams.length;
|
||||||
|
};
|
||||||
})();
|
})();
|
||||||
""");
|
""");
|
||||||
await ui.OpenAsync(new Uri(server.Address, "/libreria"));
|
await ui.OpenAsync(new Uri(server.Address, "/libreria"));
|
||||||
await ui.EvalAsync("""
|
|
||||||
import('/js/core/shell.js').then((m) => {
|
// Attività waits for its alerts and Alberto goes back to the Libreria before they come. Issue #8: going back
|
||||||
window.__delays.push({ match: '/api/alerts', ms: 600 });
|
// after a fixed 200 ms, a slow machine had not even loaded the page yet, and the alerts were never asked.
|
||||||
m.navigate('/attivita');
|
await ui.EvalAsync("window.__hold('/api/alerts')");
|
||||||
setTimeout(() => m.navigate('/libreria'), 200);
|
await ui.NavigateAsync("/attivita");
|
||||||
return true;
|
await ui.WaitAsync("window.__started['/api/alerts'] >= 1", "Attività in attesa dei suoi avvisi");
|
||||||
})
|
await ui.NavigateAsync("/libreria");
|
||||||
""");
|
await ui.WaitAsync("location.pathname === '/libreria' && document.querySelector('main .benvenuto') !== null", "Libreria (primo avvio)");
|
||||||
await ui.WaitAsync("location.pathname === '/libreria'", "Libreria");
|
await ui.EvalAsync("window.__release('/api/alerts')");
|
||||||
await ui.WaitAsync("window.__done['/api/alerts'] >= 1", "risposta in ritardo arrivata");
|
await ui.WaitAsync("window.__done['/api/alerts'] >= 1", "risposta in ritardo arrivata");
|
||||||
await Task.Delay(300);
|
|
||||||
Assert.AreEqual(0, (await ui.EvalAsync("window.__intervals(60000)")).GetInt32(), "the minute timer of Attività is gone with its page");
|
Assert.AreEqual(0, (await ui.EvalAsync("window.__intervals(60000)")).GetInt32(), "the minute timer of Attività is gone with its page");
|
||||||
|
|
||||||
// The page that stays open still works as usual.
|
// Nothing of it is shown over the Libreria: what it draws went with its frame, so only a short notice, or a
|
||||||
|
// node put straight into the page area, could show.
|
||||||
|
var notices = await ui.EvalAsync<string[]>("window.__notices");
|
||||||
|
Assert.IsEmpty(notices, "no notice of Attività over the Libreria: " + string.Join(" | ", notices));
|
||||||
|
Assert.IsTrue((await ui.EvalAsync("document.querySelector('main .attivita') === null && document.querySelector('main .benvenuto') !== null")).GetBoolean(), "nothing of Attività in the page area " + ui.Report());
|
||||||
|
|
||||||
|
// Nor does it still listen to the library: a change reaches the Libreria, which asks for its days again, and
|
||||||
|
// Attività asks for nothing more than when it was opened.
|
||||||
|
var days = (await ui.AskedAsync("GET /api/library/days")).Length;
|
||||||
|
Assert.AreEqual(1, (await ui.EvalAsync("window.__libraryChanged()")).GetInt32(), "the event stream of the interface");
|
||||||
|
await ui.WaitAsync($"window.__asked.filter((r) => r.includes('GET /api/library/days')).length > {days}", "Libreria aggiornata dopo la modifica");
|
||||||
|
CollectionAssert.AreEqual(new[] { "GET /api/alerts" }, await ui.AskedAsync("/api/alerts"), "Attività, left, no longer listens to the library");
|
||||||
|
|
||||||
|
// The page that stays open still works as usual: its minute timer runs, and a change of the library reloads it.
|
||||||
await ui.NavigateAsync("/attivita");
|
await ui.NavigateAsync("/attivita");
|
||||||
await ui.WaitAsync("window.__intervals(60000) === 1", "Attività aperta");
|
await ui.WaitAsync("window.__intervals(60000) === 1", "Attività aperta");
|
||||||
|
await ui.EvalAsync("window.__libraryChanged()");
|
||||||
|
await ui.WaitAsync("window.__asked.filter((r) => r.includes('/api/alerts')).length >= 3", "Attività aggiornata dopo la modifica");
|
||||||
await ui.NavigateAsync("/libreria");
|
await ui.NavigateAsync("/libreria");
|
||||||
await ui.WaitAsync("window.__intervals(60000) === 0", "Attività lasciata");
|
await ui.WaitAsync("window.__intervals(60000) === 0", "Attività lasciata");
|
||||||
}
|
}
|
||||||
@@ -524,19 +642,27 @@ public sealed class InterfaceTests
|
|||||||
var handle = await ui.EvalAsync("(() => { const r = document.querySelector('.fascia-barra .maniglia').getBoundingClientRect(); return [r.left + r.width / 2, r.top + r.height / 2]; })()");
|
var handle = await ui.EvalAsync("(() => { const r = document.querySelector('.fascia-barra .maniglia').getBoundingClientRect(); return [r.left + r.width / 2, r.top + r.height / 2]; })()");
|
||||||
var (handleX, handleY) = (handle[0].GetDouble(), handle[1].GetDouble());
|
var (handleX, handleY) = (handle[0].GetDouble(), handle[1].GetDouble());
|
||||||
var left = barX - (barWidth / 2);
|
var left = barX - (barWidth / 2);
|
||||||
|
string TimeAt(double at)
|
||||||
|
{
|
||||||
|
var minutes = (int)(Math.Round((at - left) / barWidth * 1440 / 15) * 15);
|
||||||
|
return $"{minutes / 60:00}:{minutes % 60:00}";
|
||||||
|
}
|
||||||
|
|
||||||
await ui.MouseAsync("mouseMoved", handleX, handleY);
|
await ui.MouseAsync("mouseMoved", handleX, handleY);
|
||||||
await ui.MouseAsync("mousePressed", handleX, handleY, buttons: 1);
|
await ui.MouseAsync("mousePressed", handleX, handleY, buttons: 1);
|
||||||
var x = handleX;
|
var x = handleX;
|
||||||
foreach (var ratio in new[] { 0.30, 0.34, 0.38, 0.42, 0.46 })
|
foreach (var ratio in new[] { 0.30, 0.34, 0.38, 0.42, 0.46 })
|
||||||
{
|
{
|
||||||
|
// Each step is followed before the next one moves: a handle drawn again would lose the drag after the
|
||||||
|
// first step, and steps sent together may reach the page as one move.
|
||||||
x = left + (barWidth * ratio);
|
x = left + (barWidth * ratio);
|
||||||
await ui.MouseAsync("mouseMoved", x, barY, buttons: 1);
|
await ui.MouseAsync("mouseMoved", x, barY, buttons: 1);
|
||||||
await Task.Delay(60);
|
var step = TimeAt(x);
|
||||||
|
await ui.WaitAsync($"document.querySelector('#fascia-inizio').value === '{step}'", $"inizio della fascia a {step} durante il trascinamento");
|
||||||
}
|
}
|
||||||
|
|
||||||
await ui.MouseAsync("mouseReleased", x, barY);
|
await ui.MouseAsync("mouseReleased", x, barY);
|
||||||
var minutes = (int)(Math.Round((x - left) / barWidth * 1440 / 15) * 15);
|
var expected = TimeAt(x);
|
||||||
var expected = $"{minutes / 60:00}:{minutes % 60:00}";
|
|
||||||
await ui.WaitAsync($"document.querySelector('#fascia-inizio').value === '{expected}'", $"inizio della fascia a {expected}");
|
await ui.WaitAsync($"document.querySelector('#fascia-inizio').value === '{expected}'", $"inizio della fascia a {expected}");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,25 +16,93 @@ namespace Febe.Tests.Web.Support;
|
|||||||
internal sealed class UiBrowser : IAsyncDisposable
|
internal sealed class UiBrowser : IAsyncDisposable
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Installed before the page scripts: <c>window.__delays</c> holds { match, ms } rules that hold back a matching
|
/// Installed before the page scripts: what the page asks of the server, and answers that come when the test says.
|
||||||
/// fetch, so that a test can make one answer arrive late (stale answers, slow pages); <c>window.__done[match]</c>
|
/// <list type="bullet">
|
||||||
/// counts the held-back requests that are over (answered, failed or aborted).
|
/// <item><c>window.__asked</c>: every request the page started, in order («GET /api/connection», «POST
|
||||||
|
/// /api/connection/begin», «WS /api/vista»); <c>window.__sockets</c>: its WebSockets.</item>
|
||||||
|
/// <item><c>window.__busy()</c>: the requests not over yet. A fetch is over once the page's own continuation of
|
||||||
|
/// its answer has run, and the body it reads there (as api.js does) has arrived; a WebSocket once it is open or
|
||||||
|
/// closed. See <see cref="WaitForQuietAsync"/>.</item>
|
||||||
|
/// <item><c>window.__hold(match)</c> holds back every fetch whose address contains match, from then until
|
||||||
|
/// <c>window.__release(match)</c>, also one the page aborts meanwhile. The release lets them go and ends the hold:
|
||||||
|
/// later requests pass at once, and the address can be held again (twice at the same time is an error).
|
||||||
|
/// <c>window.__started[match]</c> counts the held-back requests that started and <c>window.__done[match]</c>
|
||||||
|
/// those that are over, adding up all the holds of that address.</item>
|
||||||
|
/// </list>
|
||||||
|
/// An answer is late because the test holds it, never because of a delay the page might outlast on a slow machine:
|
||||||
|
/// the test waits until the page has asked (<c>__started</c>), does what has to come first, releases it, and
|
||||||
|
/// checks once the page is done with it (<c>__done</c>).
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public const string FetchDelays = """
|
public const string Requests = """
|
||||||
(() => {
|
(() => {
|
||||||
const original = window.fetch.bind(window);
|
const fetchNow = window.fetch.bind(window);
|
||||||
window.__delays = [];
|
const later = window.setTimeout.bind(window);
|
||||||
|
const NativeSocket = window.WebSocket;
|
||||||
|
const holds = [];
|
||||||
|
let busy = 0;
|
||||||
|
const count = (counts, key) => { counts[key] = (counts[key] || 0) + 1; };
|
||||||
|
const pathOf = (url) => { const u = new URL(url, location.href); return u.pathname + u.search; };
|
||||||
|
window.__asked = [];
|
||||||
|
window.__sockets = [];
|
||||||
|
window.__started = {};
|
||||||
window.__done = {};
|
window.__done = {};
|
||||||
|
window.__busy = () => busy;
|
||||||
|
window.__hold = (match) => {
|
||||||
|
if (holds.some((h) => h.match === match)) throw new Error(`richieste già trattenute per ${match}`);
|
||||||
|
let release;
|
||||||
|
holds.push({ match, gate: new Promise((resolve) => { release = resolve; }), release: () => release() });
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
// The requests held so far keep their hold and count as over under its match; the next ones pass.
|
||||||
|
window.__release = (match) => {
|
||||||
|
const index = holds.findIndex((h) => h.match === match);
|
||||||
|
if (index < 0) throw new Error(`nessuna richiesta trattenuta per ${match}`);
|
||||||
|
holds.splice(index, 1)[0].release();
|
||||||
|
return true;
|
||||||
|
};
|
||||||
window.fetch = async (input, init) => {
|
window.fetch = async (input, init) => {
|
||||||
const url = typeof input === 'string' ? input : input.url;
|
const url = input instanceof Request ? input.url : String(input);
|
||||||
const rule = window.__delays.find((d) => url.includes(d.match));
|
const method = ((init && init.method) || (input instanceof Request ? input.method : 'GET')).toUpperCase();
|
||||||
if (!rule) return original(input, init);
|
const hold = holds.find((h) => url.includes(h.match));
|
||||||
|
window.__asked.push(`${method} ${pathOf(url)}`);
|
||||||
|
if (hold) count(window.__started, hold.match);
|
||||||
|
busy += 1;
|
||||||
|
let read = Promise.resolve();
|
||||||
try {
|
try {
|
||||||
await new Promise((resolve) => setTimeout(resolve, rule.ms));
|
if (hold) await hold.gate;
|
||||||
return await original(input, init);
|
const response = await fetchNow(input, init);
|
||||||
|
for (const name of ['json', 'text', 'blob', 'arrayBuffer']) {
|
||||||
|
const body = response[name].bind(response);
|
||||||
|
response[name] = () => {
|
||||||
|
const reading = body();
|
||||||
|
read = reading.then(() => {}, () => {});
|
||||||
|
return reading;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return response;
|
||||||
} finally {
|
} finally {
|
||||||
// After the page's own continuation of this answer has run.
|
// The page's continuation of this answer runs before the first timer and, if it reads the body, the
|
||||||
setTimeout(() => { window.__done[rule.match] = (window.__done[rule.match] || 0) + 1; }, 50);
|
// continuation of that read runs before the second.
|
||||||
|
later(() => read.then(() => later(() => {
|
||||||
|
busy -= 1;
|
||||||
|
if (hold) count(window.__done, hold.match);
|
||||||
|
})));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
window.WebSocket = class extends NativeSocket {
|
||||||
|
constructor(...args) {
|
||||||
|
super(...args);
|
||||||
|
window.__asked.push(`WS ${pathOf(this.url)}`);
|
||||||
|
window.__sockets.push(this);
|
||||||
|
busy += 1;
|
||||||
|
let connecting = true;
|
||||||
|
const over = () => {
|
||||||
|
if (!connecting) return;
|
||||||
|
connecting = false;
|
||||||
|
busy -= 1;
|
||||||
|
};
|
||||||
|
this.addEventListener('open', over);
|
||||||
|
this.addEventListener('close', over);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
})();
|
})();
|
||||||
@@ -247,6 +315,21 @@ internal sealed class UiBrowser : IAsyncDisposable
|
|||||||
public Task AddInitScriptAsync(string source) =>
|
public Task AddInitScriptAsync(string source) =>
|
||||||
SendAsync("Page.addScriptToEvaluateOnNewDocument", new JsonObject { ["source"] = source });
|
SendAsync("Page.addScriptToEvaluateOnNewDocument", new JsonObject { ["source"] = source });
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Waits until no request of the page is in flight (<see cref="Requests"/>): every request it started has reached
|
||||||
|
/// the server and been answered, and the page's continuation of each answer has run, a request it started there
|
||||||
|
/// included (that one starts before the answer it follows is over). What the page leaves for later is not waited
|
||||||
|
/// for: a request started by an observer, an animation frame, a timer, a message of the event stream or a module
|
||||||
|
/// still loading may come after (the mosaic asks for its rows from an observer, once it has drawn its days). The
|
||||||
|
/// moment to check that a command the page would send as it is left, or in the continuation of an answer, was not
|
||||||
|
/// sent, instead of a pause a slow machine may not wait out; for one started later, wait for that request itself.
|
||||||
|
/// </summary>
|
||||||
|
public Task WaitForQuietAsync(string what) => WaitAsync("window.__busy() === 0", what);
|
||||||
|
|
||||||
|
/// <summary>The requests the page started so far (<see cref="Requests"/>) whose «METHOD path» contains the text.</summary>
|
||||||
|
public Task<string[]> AskedAsync(string match) =>
|
||||||
|
EvalAsync<string[]>($"window.__asked.filter((r) => r.includes({JsonSerializer.Serialize(match)}))");
|
||||||
|
|
||||||
/// <summary>Loads an address of the interface and waits until the frame and the first page are drawn.</summary>
|
/// <summary>Loads an address of the interface and waits until the frame and the first page are drawn.</summary>
|
||||||
public async Task OpenAsync(Uri address)
|
public async Task OpenAsync(Uri address)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in new issue
Block a user