60 lines
3.0 KiB
JavaScript
60 lines
3.0 KiB
JavaScript
import nodeTest from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import {existsSync} from 'node:fs';
|
|
let declared = 0;
|
|
function test(name, action) { declared++; return nodeTest(name, action); }
|
|
|
|
const modulePath = new URL('../tools/recon/fidelity_viewer/viewer.mjs', import.meta.url);
|
|
const api = existsSync(modulePath) ? await import(modulePath) : {};
|
|
class Media extends EventTarget {
|
|
currentTime = 0; duration = 20; playbackRate = 1; muted = false; volume = 1;
|
|
readyState = 4; paused = true; ended = false; seeking = false; error = null;
|
|
failPlay = false;
|
|
pause() { this.paused = true; }
|
|
async play() { if (this.failPlay) throw Error('blocked'); this.paused = false; }
|
|
emit(name) { this.dispatchEvent(new Event(name)); }
|
|
}
|
|
function pair() {
|
|
assert.equal(typeof api.createPairController, 'function', 'paired media controller must exist');
|
|
const original = new Media(), port = new Media();
|
|
const controller = api.createPairController({original, port});
|
|
return {original, port, controller};
|
|
}
|
|
const marker = {name: 'landing', original: {media_seconds: 2, elapsed_seconds: 2, uncertainty_seconds: .02},
|
|
port: {media_seconds: 3, elapsed_seconds: 3.2, uncertainty_seconds: .03}};
|
|
test('event selection seeks independent observed times and waits for explicit play', async () => {
|
|
const {controller, original, port} = pair();
|
|
await controller.selectEvent(marker);
|
|
assert.equal(original.currentTime, 2); assert.equal(port.currentTime, 3);
|
|
assert.ok(original.paused && port.paused);
|
|
await controller.play();
|
|
assert.equal(original.playbackRate, 1); assert.equal(port.playbackRate, 1);
|
|
assert.ok(!original.paused && !port.paused);
|
|
});
|
|
test('invalid or unmatched event cannot seek either recording', async () => {
|
|
const {controller, original} = pair();
|
|
for (const invalid of [{...marker, port: null}, {...marker, original: {...marker.original, media_seconds: Infinity}},
|
|
{...marker, port: {...marker.port, media_seconds: 99}}]) {
|
|
await assert.rejects(controller.selectEvent(invalid));
|
|
assert.equal(original.currentTime, 0);
|
|
}
|
|
});
|
|
test('play rejection pauses both and names the cause', async () => {
|
|
const {controller, original, port} = pair(); port.failPlay = true;
|
|
assert.equal(await controller.play(), false);
|
|
assert.ok(original.paused && port.paused);
|
|
assert.match(controller.snapshot().problem, /play.*blocked/i);
|
|
});
|
|
test('relative artifact links reject remote and active URL schemes', () => {
|
|
assert.equal(typeof api.safeLocalURL, 'function');
|
|
assert.equal(api.safeLocalURL('sides/port/trace.json'), 'sides/port/trace.json');
|
|
for (const value of ['https://host/x', 'javascript:alert(1)', '//host/x', '../x', '/etc/passwd', '%2e%2e/x'])
|
|
assert.throws(() => api.safeLocalURL(value));
|
|
});
|
|
test('capability navigation is supplied through a renderer', () => {
|
|
assert.equal(typeof api.renderCapabilities, 'function');
|
|
});
|
|
test('suite executes a positive declared count', () => {
|
|
assert.ok(declared >= 6, 'runner must register a positive number of behavior tests');
|
|
});
|