Add test suite (box rules, Python, QML against a fake Jellyfin server) and local preview jobs
- freebox-jellyfin test: box-only rules (ES5, QtQuick 2.5, qmldir, singletons), tooling unit tests, qmltestrunner on tests/qml against fake_server.py - freebox-jellyfin fake-server and preview --fake-server - package enforces the box rules; CI runs the tests - JetBrains run configs: Local Preview, Local Preview (faux serveur), Tests Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
d0d019ac1e
commit
1b2acae316
19 files changed
+2097
-17
No files matched your search
@@ -0,0 +1,258 @@
|
||||
import QtQuick 2.5
|
||||
import QtTest 1.2
|
||||
import "../../app/Views"
|
||||
|
||||
// Views/PlayerView.qml : ce qui est signalé au serveur (reprise, « vu »).
|
||||
// Règle critique : ne jamais écraser le point de reprise. Rien n'est signalé avant que la
|
||||
// lecture ait démarré ET atteint la position de reprise, et jamais d'arrêt à la position 0.
|
||||
//
|
||||
// La session est simulée, et l'état du lecteur est piloté directement sur le VideoSurface
|
||||
// (sans source, son interrogation périodique du lecteur reste à l'arrêt). Le lecteur est créé
|
||||
// dans « stage » : le TestCase est invisible, et le focus ignore les éléments invisibles.
|
||||
Item {
|
||||
id: stage
|
||||
width: 1280
|
||||
height: 720
|
||||
|
||||
TestCase {
|
||||
id: testCase
|
||||
name: "PlayerView"
|
||||
when: windowShown
|
||||
|
||||
property var player: null
|
||||
property var video: null
|
||||
property var session: null
|
||||
property var navigator: null
|
||||
|
||||
Component {
|
||||
id: fakeSessionComponent
|
||||
QtObject {
|
||||
property var reports: []
|
||||
property var pending: null
|
||||
property string preparedItem: ""
|
||||
function preparePlayback(itemId, callback) {
|
||||
preparedItem = itemId;
|
||||
pending = callback;
|
||||
}
|
||||
function reportPlayback(event, info, positionMs, paused) {
|
||||
var list = reports.slice();
|
||||
list.push({ event: event, position: positionMs, paused: paused, itemId: info.itemId });
|
||||
reports = list;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Component {
|
||||
id: fakeNavigatorComponent
|
||||
QtObject {
|
||||
property int pops: 0
|
||||
function pop() {
|
||||
pops++;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Component {
|
||||
id: playerComponent
|
||||
PlayerView {
|
||||
anchors.fill: parent
|
||||
}
|
||||
}
|
||||
|
||||
function open(startMs) {
|
||||
session = fakeSessionComponent.createObject(testCase);
|
||||
navigator = fakeNavigatorComponent.createObject(testCase);
|
||||
player = playerComponent.createObject(stage, {
|
||||
session: session, navigator: navigator, itemId: "movie-01", title: "Film", startMs: startMs || 0
|
||||
});
|
||||
verify(player !== null, "PlayerView non créé");
|
||||
video = findVideo(player);
|
||||
verify(video !== null, "VideoSurface introuvable");
|
||||
compare(session.preparedItem, "movie-01");
|
||||
}
|
||||
|
||||
// Réponse de Session.preparePlayback (URL vide : aucun vrai lecteur ne démarre).
|
||||
function prepared() {
|
||||
session.pending(null, { url: "", itemId: "movie-01", mediaSourceId: "src", playSessionId: "ps",
|
||||
playMethod: "Transcode" });
|
||||
}
|
||||
|
||||
// Même ordre que VideoSurface._poll() : position et durée, puis état.
|
||||
function play(positionMs, durationMs) {
|
||||
video.duration = durationMs || 7200000;
|
||||
video.position = positionMs;
|
||||
video.playerState = "playing";
|
||||
}
|
||||
|
||||
function close() {
|
||||
player.destroy();
|
||||
player = null;
|
||||
wait(20);
|
||||
}
|
||||
|
||||
function events() {
|
||||
return session.reports.map(function (r) { return r.event + "@" + Math.round(r.position); });
|
||||
}
|
||||
|
||||
function findVideo(root) {
|
||||
var queue = [root];
|
||||
while (queue.length > 0) {
|
||||
var item = queue.shift();
|
||||
if (item !== root && item.backendName !== undefined && item.playerState !== undefined)
|
||||
return item;
|
||||
for (var i = 0; i < item.children.length; i++)
|
||||
queue.push(item.children[i]);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
function findTimer(root, interval) {
|
||||
for (var i = 0; i < root.resources.length; i++) {
|
||||
if (root.resources[i].interval === interval)
|
||||
return root.resources[i];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
function cleanup() {
|
||||
if (player)
|
||||
close();
|
||||
if (session)
|
||||
session.destroy();
|
||||
if (navigator)
|
||||
navigator.destroy();
|
||||
session = navigator = video = null;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- reprise
|
||||
|
||||
// Le cas qui a déjà effacé des points de reprise : lecture lancée mais position de
|
||||
// reprise jamais atteinte (déplacement initial raté), puis Retour.
|
||||
function test_resume_nothingReportedBeforeResumePoint() {
|
||||
open(600000);
|
||||
prepared();
|
||||
play(0);
|
||||
play(1000);
|
||||
compare(events(), [], "rien avant la position de reprise");
|
||||
close();
|
||||
compare(events(), [], "pas d'arrêt signalé : le point de reprise serait écrasé");
|
||||
}
|
||||
|
||||
function test_resume_reportedOnceReached() {
|
||||
open(600000);
|
||||
prepared();
|
||||
play(0);
|
||||
video.position = 590000; // à moins de 15 s de la reprise
|
||||
compare(events(), ["start@590000"]);
|
||||
video.position = 601000;
|
||||
compare(events(), ["start@590000"], "start une seule fois");
|
||||
close();
|
||||
compare(events(), ["start@590000", "stop@601000"]);
|
||||
}
|
||||
|
||||
function test_resume_notStartedWhilePaused() {
|
||||
open(600000);
|
||||
prepared();
|
||||
video.duration = 7200000;
|
||||
video.playerState = "paused";
|
||||
video.position = 600000;
|
||||
compare(events(), [], "pas de start tant que la lecture n'a pas démarré");
|
||||
video.playerState = "playing";
|
||||
compare(events(), ["start@600000"]);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------ depuis le début
|
||||
|
||||
function test_fromStart_startAtZeroButNoStopAtZero() {
|
||||
open(0);
|
||||
prepared();
|
||||
play(0);
|
||||
compare(events(), ["start@0"]);
|
||||
close();
|
||||
compare(events(), ["start@0"], "jamais d'arrêt signalé à la position 0");
|
||||
}
|
||||
|
||||
function test_fromStart_stopWithPositionAndPause() {
|
||||
open(0);
|
||||
prepared();
|
||||
play(5000);
|
||||
video.playerState = "paused";
|
||||
close();
|
||||
compare(events(), ["start@5000", "stop@5000"]);
|
||||
compare(session.reports[1].paused, true);
|
||||
}
|
||||
|
||||
function test_progressEvery10s() {
|
||||
open(0);
|
||||
prepared();
|
||||
play(1000);
|
||||
var timer = findTimer(player, 10000);
|
||||
verify(timer !== null, "minuterie de progression introuvable");
|
||||
verify(timer.running);
|
||||
timer.interval = 50;
|
||||
video.position = 2000;
|
||||
tryVerify(function () { return events().indexOf("progress@2000") >= 0; }, 2000);
|
||||
video.position = 0;
|
||||
var count = session.reports.length;
|
||||
wait(200);
|
||||
compare(session.reports.length, count, "pas de progression signalée à la position 0");
|
||||
}
|
||||
|
||||
// ------------------------------------------------------- échecs et fin
|
||||
|
||||
function test_prepareError_nothingReported() {
|
||||
open(600000);
|
||||
session.pending("Lecture impossible (NoCompatibleStream).");
|
||||
compare(player.error, "Lecture impossible (NoCompatibleStream).");
|
||||
video.playerState = "playing";
|
||||
close();
|
||||
compare(events(), []);
|
||||
}
|
||||
|
||||
function test_playerError_nothingReported() {
|
||||
open(0);
|
||||
prepared();
|
||||
video.playerState = "error";
|
||||
close();
|
||||
compare(events(), []);
|
||||
}
|
||||
|
||||
function test_ended_stopsOnceAndLeaves() {
|
||||
open(0);
|
||||
prepared();
|
||||
play(7199000);
|
||||
video.ended();
|
||||
compare(navigator.pops, 1);
|
||||
close();
|
||||
compare(events(), ["start@7199000", "stop@7199000"], "un seul arrêt, même à la destruction");
|
||||
}
|
||||
|
||||
// ------------------------------------------------------- télécommande
|
||||
|
||||
// Haut/Bas réaffichent les informations de lecture (masquées au bout de 4 s).
|
||||
function test_keys_showOsd() {
|
||||
open(0);
|
||||
prepared();
|
||||
play(100000);
|
||||
player.forceActiveFocus();
|
||||
var osd = findChild(player, function (o) { return o.shown !== undefined; });
|
||||
verify(osd !== null, "OSD introuvable");
|
||||
osd.shown = false;
|
||||
keyClick(Qt.Key_Down);
|
||||
verify(osd.shown);
|
||||
}
|
||||
|
||||
function findChild(root, predicate) {
|
||||
var queue = [root];
|
||||
while (queue.length > 0) {
|
||||
var item = queue.shift();
|
||||
if (item !== root && predicate(item))
|
||||
return item;
|
||||
for (var i = 0; i < item.children.length; i++)
|
||||
queue.push(item.children[i]);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user