// Tests only the new input boundary; the original Controller listener is unchanged. async (page) => page.evaluate(async () => { const { Controller } = await import('/node_modules/@netless/app-plyr/dist/main.es.js'); let writable = true; let subscriptions = 0; const writes = []; const state = { src: 'POq5FCnwCbI', provider: 'youtube', youtubeInteractionMode: 'overlay', playTimeState: [true, 90000, 100000] }; const room = { isWritable: true, phase: 'connected', calibrationTimestamp: 100000, callbacks: { on() {}, off() {} } }; const context = { storage: { state, setState(data) { writes.push(data); Object.assign(state, data); }, addStateChangedListener() { subscriptions++; return () => subscriptions--; } }, emitter: { on() { subscriptions++; return () => subscriptions--; } }, getIsWritable: () => writable, getRoom: () => room }; const c = new Controller(context, { info() {}, warn() {}, error() {} }); const engine = { ready: true, duration: 300, paused: true, get currentTime() { return 40; }, set currentTime(v) { throw Error('Input must not seek: ' + v); }, play() { throw Error('Input must not directly play'); }, pause() { throw Error('Input must not directly pause'); }, destroy() {} }; c.player = engine; c.youtubePlayerReady = true; c.play = c.pause = () => { throw Error('Overlay must not invoke Controller.play/pause'); }; document.body.appendChild(c.playerContainer); const assert = (v, m) => { if (!v) throw Error(m); }; const checks = []; try { c.submitYouTubePlaybackToggle(); assert(writes.length === 1 && JSON.stringify(state.playTimeState) === '[false,90000]', 'Play target incorrect'); checks.push('writable click only writes shared play target; no Controller/engine play/pause/seek'); room.calibrationTimestamp = 101000; c.submitYouTubePlaybackToggle(); assert(writes.length === 2 && JSON.stringify(state.playTimeState) === '[true,90000,101000]', 'Pause target incorrect'); checks.push('pause freezes shared logical position without touching the engine'); room.isWritable = false; c.submitYouTubePlaybackToggle(); room.isWritable = true; writable = false; c.submitYouTubePlaybackToggle(); writable = true; room.phase = 'reconnecting'; c.submitYouTubePlaybackToggle(); room.phase = 'connected'; c.youtubePlayerReady = false; c.submitYouTubePlaybackToggle(); assert(writes.length === 2, 'Permission/readiness guard failed'); checks.push('room/App read-only, disconnected and not-ready inputs are blocked'); await c.destroy(); c.submitYouTubePlaybackToggle(); assert(subscriptions === 0 && !c.playerContainer.isConnected && writes.length === 2, 'Overlay cleanup failed'); checks.push('overlay subscriptions and DOM released; destroyed input blocked'); return { passed: true, checks }; } finally { if (c.player) await c.destroy(); } })