1
0

more refactors
All checks were successful
Test / test (push) Successful in 9m32s

This commit is contained in:
Aiden
2026-06-10 12:37:48 +10:00
parent d9a5ec9018
commit 24a166046e
9 changed files with 238 additions and 62 deletions

View File

@@ -0,0 +1,93 @@
import test from 'node:test';
import assert from 'node:assert/strict';
import {
createMediaAdapter,
VideoMediaAdapter
} from '../vr180player/media/media-adapter.js';
function createVideo({
ended = false,
paused = false,
source = 'https://cdn.example.com/videos/demo-video.mp4',
title = ''
} = {}) {
return {
classList: {
values: [],
add(value) {
this.values.push(value);
}
},
ended,
loadCount: 0,
paused,
style: { display: '' },
getAttribute(name) {
return name === 'title' ? title : '';
},
load() {
this.loadCount += 1;
},
querySelector(selector) {
if (selector !== 'source' || !source) {
return null;
}
return { src: source };
}
};
}
test('VideoMediaAdapter exposes video capabilities and lifecycle helpers', () => {
const video = createVideo({ title: 'Demo Title' });
const adapter = new VideoMediaAdapter(video);
assert.deepEqual(adapter.capabilities, {
audio: true,
dynamicTexture: true,
playback: true,
timeline: true
});
assert.equal(adapter.element, video);
assert.equal(adapter.textureSource, video);
assert.equal(adapter.getTitle(), 'Demo Title');
adapter.hideElement();
assert.equal(video.style.display, 'none');
adapter.showElement();
assert.equal(video.style.display, '');
adapter.load();
assert.equal(video.loadCount, 1);
});
test('VideoMediaAdapter falls back to source filename and tracks texture update state', () => {
const video = createVideo({ source: 'https://cdn.example.com/media/flat-sbs-demo.mp4' });
const adapter = new VideoMediaAdapter(video);
assert.equal(adapter.getTitle(), 'flat sbs demo');
assert.equal(adapter.shouldUpdateTexture(), true);
video.paused = true;
assert.equal(adapter.shouldUpdateTexture(), false);
video.paused = false;
video.ended = true;
assert.equal(adapter.shouldUpdateTexture(), false);
});
test('createMediaAdapter finds and marks the supported video element', () => {
const video = createVideo();
const playerContainer = {
querySelector(selector) {
return selector === 'video' ? video : null;
}
};
const adapter = createMediaAdapter(playerContainer);
assert.ok(adapter instanceof VideoMediaAdapter);
assert.equal(adapter.element, video);
assert.deepEqual(video.classList.values, ['vrwp-video']);
});

View File

@@ -1,6 +1,6 @@
import test from 'node:test';
import assert from 'node:assert/strict';
import { VideoTextureManager } from '../vr180player/rendering/texture-manager.js';
import { MediaTextureManager } from '../vr180player/rendering/texture-manager.js';
function createTexture(name) {
return {
@@ -17,13 +17,13 @@ function createVideo({ paused = false, ended = false } = {}) {
return { ended, paused };
}
test('VideoTextureManager replaces the previous texture when creating a new one', () => {
test('MediaTextureManager replaces the previous texture when creating a new one', () => {
const created = [];
const manager = new VideoTextureManager(createVideo(), () => {
const manager = new MediaTextureManager(createVideo(), () => {
const texture = createTexture(`texture-${created.length}`);
created.push(texture);
return texture;
});
}, () => true);
const first = manager.create();
const second = manager.create();
@@ -34,9 +34,9 @@ test('VideoTextureManager replaces the previous texture when creating a new one'
assert.equal(created.length, 2);
});
test('VideoTextureManager assigns and clears material maps', () => {
test('MediaTextureManager assigns and clears material maps', () => {
const material = { map: null, needsUpdate: false };
const manager = new VideoTextureManager(createVideo(), () => createTexture('assigned'));
const manager = new MediaTextureManager(createVideo(), () => createTexture('assigned'), () => true);
const texture = manager.assignToMaterial(material);
@@ -53,21 +53,25 @@ test('VideoTextureManager assigns and clears material maps', () => {
assert.equal(manager.current, null);
});
test('VideoTextureManager only marks textures dirty while playback is active', () => {
test('MediaTextureManager only marks textures dirty when the update predicate allows it', () => {
const video = createVideo();
const manager = new VideoTextureManager(video, () => createTexture('playing'));
const manager = new MediaTextureManager(
video,
() => createTexture('playing'),
() => !video.paused && !video.ended
);
const texture = manager.create();
manager.updateIfPlaying();
manager.updateIfNeeded();
assert.equal(texture.needsUpdate, true);
texture.needsUpdate = false;
video.paused = true;
manager.updateIfPlaying();
manager.updateIfNeeded();
assert.equal(texture.needsUpdate, false);
video.paused = false;
video.ended = true;
manager.updateIfPlaying();
manager.updateIfNeeded();
assert.equal(texture.needsUpdate, false);
});