Add seek field to player

This commit is contained in:
Brahim Hadriche committed 2026-10-09 14:09:58 -04:00
1 parent 3bb7746d50
commit 810ef60770
16 files changed
+685 -52

No files matched your search

+22 -1
View File
@@ -4,7 +4,7 @@
//
// cd references/playlet-legacy && npx tsx ./integration-tests/vpd-player-adversarial.ts
import { Key, odc, launchVod, finish, group, pressChecked, assertPlayerInvariants } from './vpd-player-harness';
import { Key, odc, launchVod, finish, group, pressChecked, assertPlayerInvariants, waitFor } from './vpd-player-harness';
const CONTENT_ID = 'aqz-KE-bpKQ'; // Big Buck Bunny — 10min, has storyboards
@@ -42,6 +42,27 @@ const CONTENT_ID = 'aqz-KE-bpKQ'; // Big Buck Bunny — 10min, has storyboards
await pressChecked(Key.Replay, 'replay-from-scrub');
await pressChecked(Key.Ok, 'settle');
// A seek from outside the player (Lounge sets setSeek): it takes over any transport and keeps the play state.
group('external seek (setSeek) under every transport, mid-seek, and paused');
const externalSeek = async (seconds: number, label: string) => {
await odc.setValue({ base: 'scene', keyPath: '#VideoPlayer.setSeek', value: seconds });
await assertPlayerInvariants(label);
};
await pressChecked(Key.Left, 'scrub-for-setSeek');
await externalSeek(200, 'setSeek under scrub');
await pressChecked(Key.Forward, 'scan-for-setSeek');
await externalSeek(150, 'setSeek under scan');
await pressChecked(Key.Left, 'scrub-for-commit');
await pressChecked(Key.Ok, 'commit-then-setSeek');
await externalSeek(250, 'setSeek while the commit settles');
await pressChecked(Key.Replay, 'replay-then-setSeek');
await externalSeek(300, 'setSeek with a replay in flight');
await waitFor('#VideoPlayer.state', (v) => v === 'playing', 'settle before pausing');
await pressChecked(Key.Play, 'pause-then-setSeek');
await externalSeek(100, 'setSeek while paused');
await waitFor('#VideoPlayer.state', (v) => v === 'paused', 'setSeek keeps the pause', 8000);
await pressChecked(Key.Play, 'resume-after-setSeek');
group('double-OK + scan-to-scrub');
await pressChecked(Key.Rewind, 'scan');
await pressChecked(Key.Ok, 'commit-scan');
+12 -1
View File
@@ -5,7 +5,7 @@
// cd references/playlet-legacy && npx tsx ./integration-tests/vpd-player-live.ts
// PLAYER_LIVE_ID=<id> npx tsx ./integration-tests/vpd-player-live.ts # override the stream
import { Key, Mode, Glyph, press, launch, finish, group, field, expectField, expectSoft, waitFor, frames } from './vpd-player-harness';
import { Key, Mode, Glyph, odc, press, launch, finish, group, field, expectField, expectSoft, waitFor, frames } from './vpd-player-harness';
import { getLiveVideoId } from './live-id';
(async () => {
@@ -50,6 +50,17 @@ import { getLiveVideoId } from './live-id';
await press(Key.Ok);
await expectField('#trickPlayBar.transportMode', Mode.idle);
group('an external seek (setSeek) takes over the live-DVR ladder and resumes behind the edge');
await waitFor('#VideoPlayer.state', (v) => v === 'playing', 'settle the commit before rewinding again');
await press(Key.Rewind);
await expectField('#trickPlayBar.transportMode', Mode.liveDvr);
const behindS = Number(await field('#VideoPlayer.position')) - 60;
await odc.setValue({ base: 'scene', keyPath: '#VideoPlayer.setSeek', value: behindS });
await expectField('#trickPlayBar.transportMode', Mode.idle);
await expectField('#bifDisplay.visible', false);
await waitFor('#VideoPlayer.state', (v) => v === 'playing', 'plays from the setSeek target');
await expectSoft('#trickPlayBar.atLiveEdge', (v) => v === false, 'behind the edge after the setSeek');
// Pause a live stream, let the edge run on, resume -> you're behind the edge, so the badge swaps "● LIVE" for
// the time-behind offset. The brain drops off the edge the moment the device reports the user pause
// (pausing live IS falling behind); the offset reads out once the post-resume duration catch-up lands.
+2 -2
View File
@@ -41,8 +41,8 @@ async function snap(label: string): Promise<Record<string, unknown>> {
const duration = await odcN('#VideoPlayer.duration');
console.log(` BBB duration=${duration}s -> outro skip 618.7 is ${duration > 620.7 ? 'a REAL in-flight SEEK' : 'FINISH (near EOF)'}`);
group('fixture: fast-forward to just before the outro (idle ODC seek)');
await odc.setValue({ base: 'scene', keyPath: '#VideoPlayer.seek', value: FF_SEEK_S });
group('fixture: fast-forward to just before the outro (setSeek over ODC)');
await odc.setValue({ base: 'scene', keyPath: '#VideoPlayer.setSeek', value: FF_SEEK_S });
for (let i = 0; i < 30; i++) { if ((await odcN('#VideoPlayer.position')) >= FF_SEEK_S - 3) break; await ecp.sleep(250); }
await snap('fast-forward landing');
@@ -474,7 +474,7 @@ class LoungeApi
seekTo = Val(commandArgs[FIELD_NEW_TIME])
LogInfo("Seeking to:", seekTo)
player.seek = seekTo
player.setSeek = seekTo
end function
function HandleSetPlaybackSpeed(_commandId as integer, _commandType as string, commandArgs as object, messagesToSend as object) as void
@@ -408,6 +408,10 @@ function OnPositionChangeMarkWatchTime(event as object) as void
m.markVideoWatchedJob.watchTime = m.watchTimeMarker
end function
function OnSetSeek() as void
m.top.seek = m.top.setSeek
end function
function OnClose()
m.onCloseCalled = true
@@ -17,6 +17,7 @@
<field id="chapter" type="string" alias="chapterLabel.text" />
<field id="showFullScreenHint" type="boolean" alwaysNotify="true" onChange="OnShowFullScreenHint" />
<field id="close" type="boolean" alwaysNotify="true" onChange="OnClose" />
<field id="setSeek" type="float" alwaysNotify="true" onChange="OnSetSeek" />
<function name="PlayWithContent" />
</interface>
<children>
@@ -100,6 +100,13 @@ the playing edge; the device auto-resumes on any seek).
## Lounge takeover
A transport freezes the video, so an external resume from the linked phone (Lounge sets `control=resume` on the
player) is caught in `OnControlChange` and takes over: cancel the transport, hide the bif/chrome, and play from
the phone-seeked position. VPD itself only ever resumes at idle, so a resume under a transport is unambiguously
external.
player) is caught in `OnControlChange` and takes over: cancel the transport, hide the bif/chrome, and play. VPD
itself only ever resumes at idle, so a resume under a transport is unambiguously external.
## Seeks
`ApplySeek` is the one writer of the device's `seek`. Anything outside the player seeks through the `setSeek`
field: `OnSetSeek` routes it through the transport (`ForceIdleSeek`). It keeps the play state, as the
YouTube receiver does (the device resumes on any seek, so a paused video is re-paused on landing); a seek under a
transport takes over like the resume above, cancelling it and resuming from the target. One that arrives while
the content loads becomes the content-load seek.
@@ -417,7 +417,7 @@ namespace TransportController
if firstEnter
if m.transportMode = TransportController.Mode.Idle
m.FreezeForTransport() ' the video FREEZES (deferred if a play-through seek is still settling)
m.cursorMs = m.SnapToGrid(m.positionMs, m.storyboardStepMs)
m.cursorMs = m.SnapToGrid(m.cursorMs, m.storyboardStepMs)
end if
m.transportMode = TransportController.Mode.Scrub
m.scanLevel = 0
@@ -467,7 +467,6 @@ namespace TransportController
if m.transportMode <> TransportController.Mode.Scan
if m.transportMode = TransportController.Mode.Idle
m.FreezeForTransport()
m.cursorMs = m.positionMs
end if
m.transportMode = TransportController.Mode.Scan
m.scrubHeldDir = 0
@@ -506,7 +505,6 @@ namespace TransportController
if m.transportMode = TransportController.Mode.LiveDvr
return false
end if
m.cursorMs = m.positionMs
m.transportMode = TransportController.Mode.LiveDvr
m.scanLevel = 0
m.scanDir = 0
@@ -692,17 +690,15 @@ namespace TransportController
' ------------------------------------------------------------------------------------------------
function Replay() as void
' InstantReplay works from ANY state. From a transport (frozen) it cancels it and RESUMES from
' cursor-20s; from idle it just seeks -20s and keeps the play state. Reference is the cursor (= position
' while idle).
' cursor-20s; from idle it just seeks -20s and keeps the play state. Reference is the cursor (while idle,
' the playhead, or a seek target that has not landed yet).
wasTransport = (m.transportMode <> TransportController.Mode.Idle)
' spamming InstantReplay must ACCUMULATE: while a prior replay seek is still in flight, base off the
' LAST target so each press goes another -20s, not off the stale position (all presses landing together).
if m.replayPending
base = m.replayTargetMs
else if wasTransport
base = m.cursorMs ' was frozen -> resume from where the cursor sits
else
base = m.positionMs
base = m.cursorMs
end if
control = TransportController.Control.None ' from idle: keep playing, no state change
if wasTransport
@@ -757,11 +753,26 @@ namespace TransportController
end if
end function
' An EXTERNAL authority (SponsorBlock skip) seeks while a transport may be active. Route it THROUGH the
' brain so the device never diverges: reset to idle and emit the seek as a normal intent. keepPlaying
' preserves the current play state (control=none); else resume.
' An EXTERNAL authority seeks while a transport may be active. The cursor goes to the target before the
' seek lands, so the idle bar, a Replay, and a transport entered meanwhile all start from it. On live, a
' target at or past the effective edge seeks to the edge, as a commit there does.
function ForceIdleSeek(targetMs as integer, keepPlaying as boolean) as void
m.ResetToIdle()
m.replayPending = false
if m.isLive
if TransportController.IsLiveEdgeSentinelMs(targetMs) or (m.edgeMs > 0 and targetMs >= m.LiveEdgeMs())
targetMs = TransportController.LIVE_EDGE_SEEK_MS
m.cursorMs = m.LiveEdgeMs()
else
targetMs = m.ClampToTimeline(targetMs, m.LiveFloorMs(), m.edgeMs)
m.cursorMs = targetMs
end if
m.RecomputeLive()
else
targetMs = m.ClampToTimeline(targetMs, 0, m.durationMs)
m.positionMs = targetMs ' the idle VOD bar reads positionMs
m.cursorMs = targetMs
end if
control = TransportController.Control.Resume
if keepPlaying
control = TransportController.Control.None
@@ -866,6 +877,15 @@ namespace TransportController
m.timerCmdRepeat = false
end function
' Clamp to [lo, hi]; hi <= 0 is a timeline end not known yet, so only the floor applies. An external seek
' can arrive while the content loads; transport input is dropped until the first frame, when it is known.
function ClampToTimeline(value as integer, lo as integer, hi as integer) as integer
if hi <= 0
hi = -1
end if
return m.Clamp(value, lo, hi)
end function
function Clamp(value as integer, lo as integer, hi as integer) as integer
if value < lo
return lo
@@ -56,6 +56,8 @@ function Initialize()
m.reportWatchTime = false
m.onCloseCalled = false
m.seekToPercent = invalid
' a setSeek that arrived while the content loads (ms, -1 = none): the content-load seek goes there instead.
m.loadingSetSeekMs = -1
m.errorDialogNode = invalid
m.ignoreNextFinished = false ' a retry replay -> swallow the next "finished" edge
@@ -70,9 +72,9 @@ function Initialize()
m.armedTimerId = TransportController.Timer.None ' which module timer the single transportTimer holds
m.lastCommitSeq = 0
m.lastFinishSeq = 0
' a keep-playing seek (SponsorBlock skip / InstantReplay) was issued while the device was PAUSED. The
' device auto-resumes on any seek (autoplayAfterSeek only governs resume-after-REBUFFER per the Video
' docs), so the paused state is preserved by re-pausing on the next playing edge.
' a keep-playing seek was issued while the device was PAUSED. The device auto-resumes on any seek
' (autoplayAfterSeek only governs resume-after-REBUFFER per the Video docs), so the paused state is preserved
' by re-pausing on the next playing edge.
m.repauseAfterSeek = false
' live edge clock anchor: the manifest's availabilityStartTime (Playlet generates it), as epoch seconds.
' The edge is then wallClock - anchor — continuous through pauses/rebuffers/startup. The fallback pair
@@ -166,6 +168,7 @@ function OnNodeReady()
m.top.ObserveField("thumbnailTiles", FuncName(OnThumbnailTiles))
' an external resume/play (the linked phone via Lounge) under an active transport must take over.
m.top.ObserveField("control", FuncName(OnControlChange))
m.top.ObserveField("setSeek", FuncName(OnSetSeek))
m.top.ObserveField("bufferingStatus", FuncName(OnBufferingStatus))
m.top.ObserveField("playStartInfo", FuncName(OnPlayStartInfo))
@@ -186,10 +189,10 @@ end function
'===============================================================================
function ApplyTransport() as void
' A transport freezes the video. While one is active, disable auto-resume-after-rebuffer so an in-flight or
' pending seek (a replay that kept playing, a SponsorBlock skip) can't un-pause the freeze when it completes;
' restored to the default at idle so commit's resume + the normal seek-resume behave. But NOT while a
' play-through seek is still settling: that seek must still reach "playing" so EnforceTransportFreeze can
' freeze it cleanly — disabling autoplay here would strand it buffering. seekSettling clears at state=playing.
' pending keep-playing seek can't un-pause the freeze when it completes; restored to the default at idle so
' commit's resume + the normal seek-resume behave. But NOT while a play-through seek is still settling: that
' seek must still reach "playing" so EnforceTransportFreeze can freeze it cleanly — disabling autoplay here
' would strand it buffering. seekSettling clears at state=playing.
' Write-guarded: this runs on every position tick, and most ticks don't change the value.
autoplayAfterSeek = (m.transport.transportMode = TransportController.Mode.Idle) or m.transport.seekSettling
if m.top.autoplayAfterSeek <> autoplayAfterSeek
@@ -307,7 +310,8 @@ function PushTransportToRenderers() as void
end if
end function
' Apply a seek (ms). The live "jump to edge" sentinel maps to the live-end seek the OS understands.
' Apply a seek (ms): the one writer of the device's `seek`. The live "jump to edge" sentinel maps to the
' live-end seek the OS understands.
function ApplySeek(seekMs as integer) as void
if TransportController.IsLiveEdgeSentinelMs(seekMs)
m.top.seek = 999999
@@ -1035,8 +1039,8 @@ function OnFullScreenHintTimer() as void
end function
' A resume/play arriving while a transport is active is necessarily external: VPD only ever resumes/plays at
' idle, so this is the linked phone (Lounge) seeking + resuming. The phone action wins — cancel the scrub/scan
' (the bif + chrome clear) and let the video play from where the phone seeked.
' idle, so this is the linked phone (Lounge) resuming. The phone action wins — cancel the scrub/scan (the bif +
' chrome clear) and let the video play.
function OnControlChange(event as object) as void
if m.onCloseCalled = true
return
@@ -1053,6 +1057,26 @@ function OnControlChange(event as object) as void
end if
end function
' Keeps the play state; a frozen transport resumes, as its commit would.
function OnSetSeek(event as object) as void
if m.onCloseCalled = true
return
end if
seekMs = Int(event.getData() * 1000)
LogDebug("external seek ->", seekMs)
if m.videoContentJob <> invalid
m.loadingSetSeekMs = seekMs
return
end if
m.seekToPercent = invalid
wasTransport = (m.transport.transportMode <> TransportController.Mode.Idle)
m.transport.ForceIdleSeek(seekMs, not wasTransport)
ApplyTransport()
if wasTransport
HideChromeNow()
end if
end function
'===============================================================================
' Content load, initial seek, previous-player handoff, close.
'===============================================================================
@@ -1250,15 +1274,21 @@ function SeekToInitialPosition(content as object) as void
if content = invalid
return
end if
if m.loadingSetSeekMs <> -1
LogDebug("seeking to the setSeek that arrived while loading:", m.loadingSetSeekMs)
ApplySeek(m.loadingSetSeekMs)
m.loadingSetSeekMs = -1
return
end if
if content.Live = true
LogDebug("seeking to end of live stream")
m.top.seek = 999999
ApplySeek(TransportController.LIVE_EDGE_SEEK_MS)
return
end if
timestamp = ValidInt(content.timestamp)
if timestamp > 0
LogDebug("seeking to timestamp:", timestamp)
m.top.seek = content.timestamp
ApplySeek(timestamp * 1000)
return
end if
percentDurationWatched = ValidFloat(content.percentDurationWatched)
@@ -1285,7 +1315,7 @@ function SeekToPercentOfDuration() as void
seek = (MathUtils.Clamp(seekToPercent, 0, 100) / 100.0) * duration
if seek > 0
LogDebug("seeking to percent watched ->", seek)
m.top.seek = seek
ApplySeek(Int(seek * 1000))
end if
end function
@@ -1474,6 +1504,7 @@ function OnClose() as void
m.top.unobserveField("duration")
m.top.unobserveField("thumbnailTiles")
m.top.unobserveField("control")
m.top.unobserveField("setSeek")
m.top.unobserveField("bufferingStatus")
m.top.unobserveField("playStartInfo")
m.top.unobserveField("close")
@@ -30,6 +30,7 @@
<field id="minRect" type="rect2D" value="[834,460,426,240]" />
<field id="maxRect" type="rect2D" value="[0,0,1280,720]" />
<field id="close" type="boolean" alwaysNotify="true" />
<field id="setSeek" type="float" alwaysNotify="true" />
<function name="PlayWithContent" />
</interface>
<!-- Init() lives in its own file so VideoPlayerDev.bs (the coordinator logic) has no Init and is importable by
@@ -70,7 +70,7 @@ function TestSetup() as void
' nudge counter above — stacked observers fire a handler once per prior TestSetup on every write,
' and OnPosition's latency learning reads two identical fires as a CONFIRMED min-gap, poisoning
' LiveEdgeMs for any live test that runs after another test in the suite.
for each deviceField in ["state", "position", "duration", "close", "thumbnailTiles", "control", "bufferingStatus", "playStartInfo"]
for each deviceField in ["state", "position", "duration", "close", "thumbnailTiles", "control", "setSeek", "bufferingStatus", "playStartInfo"]
m.top.unobserveField(deviceField)
end for
@@ -81,8 +81,14 @@ function TestSetup() as void
m.top.position = 0
m.top.duration = 0
m.top.seek = 0
m.top.suppressCaptions = false ' a test that minimized leaves it set; the container below starts fullscreen
m.top.autoplayAfterSeek = true
OnNodeReady()
' the children survive across tests too: clear what a previous test's transport or live content left.
m.transportTimer.control = "none"
m.trickPlayBar.isLive = false
end function
function OnTestNudge() as void
@@ -122,6 +128,21 @@ function TestSeedSponsorBlock(segments as object) as void
m.sponsorblock.segments = segments
end function
' TestSeekToInitialPosition — the content-load seek (live edge / resume timestamp / percent watched), minus the
' content job.
function TestSeekToInitialPosition(content as object) as void
SeekToInitialPosition(content)
end function
' TestSetContentLoading — a VideoContentJob in flight (or not), minus the job.
function TestSetContentLoading(loading as boolean) as void
if loading
m.videoContentJob = CreateObject("roSGNode", "Node")
else
m.videoContentJob = invalid
end if
end function
' TestFireLiveBadgeHold — fire the liveBadgeHold timer's handler now (the spec can't wait out the real timer).
function TestFireLiveBadgeHold() as void
OnLiveBadgeHoldFire()
@@ -235,6 +256,35 @@ function TestSnapshot() as object
forceLiveBadge: m.trickPlayBar.forceLiveBadge
liveBadgeShown: m.trickPlayBar.findNode("liveLabel").visible
barRemainingText: m.trickPlayBar.findNode("remainingLabel").text
replayPending: m.transport.replayPending
transportTimerControl: m.transportTimer.control
buttonRowVisible: m.buttonRow.visible
barPositionMs: m.trickPlayBar.positionMs
spinnerMode: m.spinner.mode
brain: TestBrainSnapshot()
}
end function
' The brain's output fields in the shape PlayerInvariants.CheckBrain expects.
function TestBrainSnapshot() as object
t = m.transport
return {
transportMode: t.transportMode
glyph: t.glyph
scanLevel: t.scanLevel
scanDir: t.scanDir
scrubHeldDir: t.scrubHeldDir
scrubHoldTicks: t.scrubHoldTicks
scrubStepMs: t.scrubStepMs
storyboardStepMs: t.storyboardStepMs
cursorMs: t.cursorMs
positionMs: t.positionMs
durationMs: t.durationMs
edgeMs: t.edgeMs
liveOffsetMs: t.liveOffsetMs
atLiveEdge: t.atLiveEdge
isLive: t.isLive
replayPending: t.replayPending
}
end function
@@ -43,6 +43,7 @@
<field id="minRect" type="rect2D" value="[834,460,426,240]" />
<field id="maxRect" type="rect2D" value="[0,0,1280,720]" />
<field id="close" type="boolean" alwaysNotify="true" />
<field id="setSeek" type="float" alwaysNotify="true" />
<!-- test-only probe: how many times the coordinator pulsed ButtonRow.nudge (TestSetup observes it). -->
<field id="nudgeCount" type="integer" />
<!-- the Video-only method Initialize calls, plus the spec's drivers (callFunc reaches only interface funcs). -->
@@ -56,6 +57,8 @@
<function name="TestSetControl" />
<function name="TestSetLive" />
<function name="TestSeedSponsorBlock" />
<function name="TestSeekToInitialPosition" />
<function name="TestSetContentLoading" />
<function name="TestFireLiveBadgeHold" />
<function name="TestKillAutoHide" />
<function name="TestFinishChromeFadeOut" />
@@ -5,6 +5,8 @@
import "pkg:/components/VideoPlayerDev/PlayerCoordinatorLogic.bs"
import "pkg:/components/VideoPlayerDev/TransportController.bs"
import "pkg:/components/VideoPlayerDev/VideoNode.bs"
import "pkg:/source/tests/VideoPlayerDev/PlayerInvariants.bs"
import "pkg:/source/utils/ArrayUtils.bs"
import "pkg:/source/utils/RemoteKeys.bs"
namespace Tests
@@ -133,7 +135,7 @@ namespace Tests
m.assertEqual(mid.transportMode, TransportController.Mode.Scrub)
m.assertEqual(mid.control, VideoControl.Pause)
' the phone seeks + resumes: Lounge sets control=resume directly on the player node.
' the phone resumes: Lounge sets control=resume directly on the player node.
m.top.callFunc("TestSetControl", VideoControl.Resume)
after = m.Snap()
m.assertEqual(after.transportMode, TransportController.Mode.Idle, "the external resume cancels the transport")
@@ -141,6 +143,230 @@ namespace Tests
m.assertTrue(after.autoplay, "autoplay restored so a settling seek won't re-freeze the takeover")
end function
' --- external seek (setSeek) ---
' Each arm is asserted: a state that silently failed to arm makes its row vacuous.
function ArmSeekState(state as string) as void
m.top.callFunc("TestSetup")
if state = "first load"
m.top.callFunc("TestSetState", VideoState.Buffering)
m.assertEqual(m.Snap().spinnerMode, SpinMode.Loading, "armed: " + state)
return
end if
m.top.callFunc("TestSetState", VideoState.Playing)
if Left(state, 4) = "live"
m.top.callFunc("TestSetLive", 43200000) ' 12h edge, 4h window: floor 8h
else
m.top.duration = 600.0
m.top.position = 300.0
end if
if state = "idle paused"
m.top.callFunc("TestKey", RemoteKeys.Play, true)
m.top.callFunc("TestSetState", VideoState.Paused)
else if state = "idle buffering"
m.top.callFunc("TestSetState", VideoState.Buffering)
else if state = "repause pending"
m.top.callFunc("TestKey", RemoteKeys.Play, true)
m.top.callFunc("TestSetState", VideoState.Paused)
m.top.callFunc("TestKey", RemoteKeys.Replay, true)
m.top.callFunc("TestSetState", VideoState.Buffering)
else if state = "replay in flight"
m.top.callFunc("TestKey", RemoteKeys.Replay, true)
m.assertTrue(m.Snap().replayPending, "armed: " + state)
else if state = "chrome/bar"
m.top.callFunc("TestKey", RemoteKeys.Up, true)
m.assertTrue(m.Snap().chromeShown, "armed: " + state)
else if state = "chrome fading"
m.top.callFunc("TestKey", RemoteKeys.Up, true)
m.top.callFunc("TestKey", RemoteKeys.Back, true)
m.assertTrue(m.Snap().chromeFadingOut, "armed: " + state)
else if state = "minimized"
m.top.container.fullscreen = false
m.assertTrue(m.Snap().suppressCaptions, "armed: " + state)
else if state = "scrub" or state = "live dvr"
m.top.callFunc("TestKey", RemoteKeys.Left, true)
m.top.callFunc("TestKey", RemoteKeys.Left, false)
m.top.callFunc("TestSetState", VideoState.Paused)
else if state = "scrub held"
m.top.callFunc("TestKey", RemoteKeys.Left, true)
m.top.callFunc("TestSetState", VideoState.Paused)
else if state = "scan"
m.top.callFunc("TestKey", RemoteKeys.FastForward, true)
m.top.callFunc("TestSetState", VideoState.Paused)
else if state = "live scan"
m.top.callFunc("TestKey", RemoteKeys.Rewind, true)
m.top.callFunc("TestKey", RemoteKeys.Rewind, false)
m.top.callFunc("TestSetState", VideoState.Paused)
else if state = "deferred freeze"
' commit, then an immediate re-scrub while the commit's seek is still settling: no freeze sent.
m.top.callFunc("TestKey", RemoteKeys.Left, true)
m.top.callFunc("TestKey", RemoteKeys.Left, false)
m.top.callFunc("TestSetState", VideoState.Paused)
m.top.callFunc("TestKey", RemoteKeys.Ok, true)
m.top.callFunc("TestSetState", VideoState.Buffering)
m.top.callFunc("TestKey", RemoteKeys.Left, true)
m.assertTrue(m.Snap().seekSettling, "armed: " + state)
end if
snap = m.Snap()
mode = snap.transportMode
m.assertEqual(snap.brain.isLive, Left(state, 4) = "live", "armed: " + state)
if state = "scrub" or state = "scrub held" or state = "deferred freeze"
m.assertEqual(mode, TransportController.Mode.Scrub, "armed: " + state)
else if state = "scan"
m.assertEqual(mode, TransportController.Mode.Scan, "armed: " + state)
else if state = "live dvr"
m.assertEqual(mode, TransportController.Mode.LiveDvr, "armed: " + state)
m.assertEqual(snap.brain.scanLevel, 0, "armed: " + state)
else if state = "live scan"
m.assertEqual(mode, TransportController.Mode.LiveDvr, "armed: " + state)
m.assertTrue(snap.brain.scanLevel >= 1, "armed: " + state)
else
m.assertEqual(mode, TransportController.Mode.Idle, "armed: " + state)
end if
end function
' Every state a seek from outside the player (setSeek) can arrive in. It lands idle at the target with the
' brain consistent; it keeps the play state (a paused video is re-paused on landing), and out of a
' transport it resumes, the chrome cleared.
@it("setSeek in every reachable player state lands idle at the target, keeping the play state")
function _()
transports = ["scrub", "scrub held", "scan", "deferred freeze", "live dvr", "live scan"]
paused = ["idle paused", "repause pending"]
states = ["idle playing", "idle buffering", "replay in flight", "chrome/bar", "chrome fading", "minimized", "first load", "live idle"]
states.Append(paused)
states.Append(transports)
for each state in states
m.ArmSeekState(state)
wasTransport = ArrayUtils.IndexOfString(transports, state) <> -1
targetS = 30.5
if Left(state, 4) = "live"
targetS = 40000.0 ' inside the live window
end if
before = m.Snap()
m.top.callFunc("TestSetControl", VideoControl.None) ' so a control write below is the seek's
m.top.seek = -1
m.top.setSeek = targetS
snap = m.Snap()
where = " — " + state
m.assertEqual(snap.transportMode, TransportController.Mode.Idle, "idle" + where)
m.assertFalse(snap.bifVisible, "no bif" + where)
m.assertEqual(Int(m.top.seek * 1000), Int(targetS * 1000), "seeked to the target" + where)
m.assertTrue(snap.autoplay, "autoplay restored" + where)
m.assertFalse(snap.replayPending, "no replay chain" + where)
m.assertEqual(snap.transportTimerControl, "stop", "transport timer stopped" + where)
brainCheck = PlayerInvariants.CheckBrain(snap.brain)
m.assertTrue(brainCheck.ok, brainCheck.failed + where)
if wasTransport
m.assertEqual(snap.control, VideoControl.Resume, "the transport resumes from the target" + where)
m.assertFalse(snap.chromeShown, "the chrome cleared" + where)
else
m.assertEqual(snap.control, VideoControl.None, "no control write: the play state is kept" + where)
m.assertEqual(snap.spinnerMode, before.spinnerMode, "spinner untouched" + where)
m.assertEqual(snap.chromeShown, before.chromeShown, "chrome untouched" + where)
m.assertEqual(snap.chromeFadingOut, before.chromeFadingOut, "chrome fade untouched" + where)
end if
if state = "chrome/bar"
m.assertEqual(snap.barPositionMs, Int(targetS * 1000), "the visible bar shows the target before it lands")
end if
' the device lands and (on any seek) plays.
m.top.callFunc("TestSetState", VideoState.Playing)
landed = m.Snap()
m.assertEqual(landed.transportMode, TransportController.Mode.Idle, "still idle on landing" + where)
if ArrayUtils.IndexOfString(paused, state) <> -1
m.assertEqual(landed.control, VideoControl.Pause, "re-paused on landing" + where)
else if wasTransport
m.assertEqual(landed.control, VideoControl.Resume, "not re-frozen on landing" + where)
else
m.assertEqual(landed.control, VideoControl.None, "untouched on landing" + where)
end if
end for
end function
@it("setSeek under a held scrub: the later key-up is a no-op at idle")
function _()
m.ArmSeekState("scrub held")
m.top.setSeek = 30.5
control = m.Snap().control
m.top.callFunc("TestKey", RemoteKeys.Left, false)
snap = m.Snap()
m.assertEqual(snap.transportMode, TransportController.Mode.Idle)
m.assertEqual(snap.control, control)
end function
@it("setSeek ends an InstantReplay chain: the next replay goes back from the setSeek target")
function _()
m.ArmSeekState("replay in flight")
m.top.setSeek = 100.0
m.top.callFunc("TestKey", RemoteKeys.Replay, true)
m.assertEqual(Int(m.top.seek * 1000), 80000)
end function
@it("setSeek seeks every time it is set, the same target included")
function _()
m.top.setSeek = 42.0
m.assertEqual(Int(m.top.seek * 1000), 42000)
m.top.seek = -1
m.top.setSeek = 42.0
m.assertEqual(Int(m.top.seek * 1000), 42000)
end function
@it("setSeek before the duration is known cancels the pending percent-watched seek")
function _()
m.ArmSeekState("first load")
content = CreateObject("roSGNode", "ContentNode")
content.AddFields({ percentDurationWatched: 50.0 })
m.top.callFunc("TestSeekToInitialPosition", content)
m.top.setSeek = 30.5
m.top.duration = 600.0
m.assertEqual(Int(m.top.seek * 1000), 30500, "the percent seek did not override the setSeek")
end function
@it("setSeek while the content loads becomes the content-load seek, over the resume timestamp")
function _()
m.top.callFunc("TestSetContentLoading", true)
m.top.seek = -1
m.top.setSeek = 30.5
m.assertEqual(m.top.seek, -1.0, "no seek while there is no content to seek")
m.top.callFunc("TestSetContentLoading", false)
content = CreateObject("roSGNode", "ContentNode")
content.AddFields({ timestamp: 42 })
m.top.callFunc("TestSeekToInitialPosition", content)
m.assertEqual(Int(m.top.seek * 1000), 30500)
' consumed: a later content-load seek (an error retry) goes back to the content's own start.
m.top.callFunc("TestSeekToInitialPosition", content)
m.assertEqual(Int(m.top.seek * 1000), 42000)
end function
' --- content-load seek ---
@it("the content-load seek goes to the live edge on live content")
function _()
content = CreateObject("roSGNode", "ContentNode")
content.Live = true
m.top.callFunc("TestSeekToInitialPosition", content)
m.assertEqual(m.top.seek, 999999.0)
end function
@it("the content-load seek goes to the resume timestamp")
function _()
content = CreateObject("roSGNode", "ContentNode")
content.AddFields({ timestamp: 42 })
m.top.callFunc("TestSeekToInitialPosition", content)
m.assertEqual(Int(m.top.seek * 1000), 42000)
end function
@it("the content-load seek goes to the percent watched once the duration is known")
function _()
content = CreateObject("roSGNode", "ContentNode")
content.AddFields({ percentDurationWatched: 25.0 })
m.top.callFunc("TestSeekToInitialPosition", content)
m.assertEqual(m.top.seek, 0.0, "no seek before the duration is known")
m.top.duration = 600.0
m.assertEqual(Int(m.top.seek * 1000), 150000)
end function
@it("the error dialog displays every captured error field, not just the category")
function _()
' Real Roku Video error captured on device (an http stream failure, 502 manifest).
@@ -742,7 +968,7 @@ namespace Tests
classified[name] = "axis"
end for
' flags / scratch — one-shot latches and counters with a single consuming path.
for each name in ["onCloseCalled", "ignoreNextFinished", "videoPlayedSuccessfully", "firstFrameSeen", "showFullScreenHint", "repauseAfterSeek", "seekToPercent", "watchTimeMarker", "reportWatchTime", "errorDialogNode", "lastCommitSeq", "lastFinishSeq", "liveAstSeconds", "liveFallbackEdgeMs", "liveFallbackAtSeconds", "liveBadgeHoldActive"]
for each name in ["onCloseCalled", "ignoreNextFinished", "videoPlayedSuccessfully", "firstFrameSeen", "showFullScreenHint", "repauseAfterSeek", "seekToPercent", "loadingSetSeekMs", "watchTimeMarker", "reportWatchTime", "errorDialogNode", "lastCommitSeq", "lastFinishSeq", "liveAstSeconds", "liveFallbackEdgeMs", "liveFallbackAtSeconds", "liveBadgeHoldActive"]
classified[name] = "flag"
end for
' NOT coordinator state — node-scope + test-environment entries, pinned EXPLICITLY (no hidden
@@ -802,7 +1028,7 @@ namespace Tests
container.fullscreen = true
' close the player (what the queue does when replacing the video), then throw every signal a dead
' player might still receive at it: fullscreen flips (the * key), device edges from the async stop,
' a stray control/seek write, late thumbnails and buffering/start info, a second close. OnClose unobserves them all.
' a stray control/seek/setSeek write, late thumbnails and buffering/start info, a second close. OnClose unobserves them all.
m.top.close = true
container.fullscreen = false
container.fullscreen = true
@@ -813,6 +1039,8 @@ namespace Tests
m.top.position = 12.0
m.top.duration = 99.0
m.top.seek = 5.0
m.top.setSeek = 7.0
m.assertEqual(m.top.seek, 5.0, "the closed player ignored the setSeek")
m.top.thumbnailTiles = { x: [{ htiles: 1 }] }
m.top.bufferingStatus = { isUnderrun: true, percentage: 0, prebufferDone: false, actualStart: 0 }
m.top.playStartInfo = { start_type: "cseek", total_dur: 0.1 }
@@ -8,6 +8,7 @@
' L1->2->3->1, reverse clamps at the DVR floor, forward auto-resumes at the edge; offset counts up frozen.
' - LIVE step<->ladder sub-mode transitions clear the other sub-mode's scratch (no stale-tick bleed).
' - InstantReplay from idle AND from any transport (scrub/scan/live), and the not-ready input drop.
' - External seek (ForceIdleSeek) from idle and from a transport: cursor on the target, clamped; replay chain dropped.
import "pkg:/components/VideoPlayerDev/TransportController.bs"
@@ -1066,18 +1067,158 @@ namespace Tests
m.assertEqual(t.liveOffsetMs, 0)
end function
' =========================================================================================
' EXTERNAL SEEK (ForceIdleSeek) — a seek from outside the brain, from any state: back to idle, the cursor
' on the target (clamped to the timeline), a seek intent.
' =========================================================================================
@describe("external seek")
@it("from idle: stays idle, moves the cursor + position to the target, and seeks keeping the play state")
function _()
m.t.ForceIdleSeek(150000, true)
m.assertEqual(m.t.transportMode, TransportController.Mode.Idle)
m.assertEqual(m.t.cursorMs, 150000)
m.assertEqual(m.t.positionMs, 150000)
intent = m.t.TakeVideoIntent()
m.assertEqual(intent.control, TransportController.Control.None)
m.assertTrue(intent.hasSeek)
m.assertEqual(intent.seekMs, 150000)
end function
@it("from a scrub: back to idle with the scratch cleared, and resumes at the target")
function _()
m.t.HandleKey(TransportController.Command.Left, true)
m.t.TakeVideoIntent()
m.t.ForceIdleSeek(150000, false)
m.assertEqual(m.t.transportMode, TransportController.Mode.Idle)
m.assertEqual(m.t.glyph, TransportController.Glyph.None)
m.assertEqual(m.t.scrubHeldDir, 0)
m.assertEqual(m.t.cursorMs, 150000)
intent = m.t.TakeVideoIntent()
m.assertEqual(intent.control, TransportController.Control.Resume)
m.assertEqual(intent.seekMs, 150000)
end function
@it("clamps a VOD target to [0, duration]")
function _()
m.t.ForceIdleSeek(500000, true)
m.assertEqual(m.t.cursorMs, 210000)
m.assertEqual(m.t.TakeVideoIntent().seekMs, 210000)
m.t.ForceIdleSeek(-5000, true)
m.assertEqual(m.t.cursorMs, 0)
m.assertEqual(m.t.TakeVideoIntent().seekMs, 0)
end function
@it("keeps the target when the duration is not known yet")
function _()
t = new TransportController.Controller()
t.SetContent(false, 2000, true)
t.ForceIdleSeek(150000, true)
m.assertEqual(t.cursorMs, 150000)
m.assertEqual(t.TakeVideoIntent().seekMs, 150000)
end function
@it("drops a pending InstantReplay: the next replay goes back from the external target")
function _()
m.t.HandleCommand(TransportController.Command.Replay)
m.assertTrue(m.t.replayPending)
m.t.ForceIdleSeek(150000, true)
m.assertFalse(m.t.replayPending)
m.t.TakeVideoIntent()
m.t.HandleCommand(TransportController.Command.Replay)
m.assertEqual(m.t.TakeVideoIntent().seekMs, 130000)
end function
' a live brain 5s behind its raw edge (learned latency): edge 300s, effective edge 295s, window 60s ->
' floor 240s. Tells the raw edge, the effective edge and the playhead apart.
function LiveLagging() as object
t = new TransportController.Controller()
t.SetContent(true, 0, false)
t.SetLiveDvrWindow(60000)
t.OnLiveEdge(300000)
t.OnPosition(295000)
t.OnPosition(295000) ' confirmed latency floor: 5s
t.OnReady()
return t
end function
@it("on live, moves the cursor to the target clamped to the floor and recomputes the offset")
function _()
t = m.LiveLagging()
m.assertEqual(t.LiveEdgeMs(), 295000)
t.ForceIdleSeek(270000, true)
m.assertEqual(t.cursorMs, 270000)
m.assertEqual(t.positionMs, 295000, "the live playhead stays the last real sample")
m.assertEqual(t.liveOffsetMs, 25000) ' (300 - 270) - 5 latency
m.assertFalse(t.atLiveEdge)
m.assertEqual(t.TakeVideoIntent().seekMs, 270000)
t.ForceIdleSeek(100000, true)
m.assertEqual(t.cursorMs, 240000)
m.assertEqual(t.TakeVideoIntent().seekMs, 240000)
end function
@it("on live, a target at or past the effective edge seeks to the edge, as a commit there does")
function _()
t = m.LiveLagging()
t.ForceIdleSeek(297000, true) ' between the effective (295s) and the raw (300s) edge
m.assertEqual(t.cursorMs, 295000)
m.assertTrue(t.atLiveEdge)
m.assertEqual(t.TakeVideoIntent().seekMs, TransportController.LIVE_EDGE_SEEK_MS)
t.ForceIdleSeek(295000, true)
m.assertEqual(t.TakeVideoIntent().seekMs, TransportController.LIVE_EDGE_SEEK_MS)
end function
@it("on live, the edge sentinel puts the cursor at the effective edge and seeks with the sentinel")
function _()
t = m.LiveLagging()
t.HandleCommand(TransportController.Command.Left)
t.ForceIdleSeek(TransportController.LIVE_EDGE_SEEK_MS, false)
m.assertEqual(t.transportMode, TransportController.Mode.Idle)
m.assertEqual(t.cursorMs, 295000)
m.assertTrue(t.atLiveEdge)
m.assertEqual(t.TakeVideoIntent().seekMs, TransportController.LIVE_EDGE_SEEK_MS)
end function
@it("before the seek lands, a scrub, a scan and a Replay start from the target (VOD)")
function _()
m.t.ForceIdleSeek(150000, true)
m.t.HandleCommand(TransportController.Command.Left)
m.assertEqual(m.t.cursorMs, 148000)
m.t.ForceIdleSeek(150000, true)
m.t.HandleCommand(TransportController.Command.Fwd)
m.t.Tick(TransportController.Timer.Scan)
m.assertTrue(m.t.cursorMs > 150000, "the scan runs on from the target")
m.t.ForceIdleSeek(150000, true)
m.t.TakeVideoIntent()
m.t.HandleCommand(TransportController.Command.Replay)
m.assertEqual(m.t.TakeVideoIntent().seekMs, 130000)
end function
@it("before the seek lands, a live rewind and a Replay start from the target")
function _()
t = m.LiveLagging()
t.ForceIdleSeek(270000, true)
t.HandleCommand(TransportController.Command.Left)
m.assertEqual(t.transportMode, TransportController.Mode.LiveDvr)
m.assertEqual(t.cursorMs, 265000)
t.ForceIdleSeek(270000, true)
t.TakeVideoIntent()
t.HandleCommand(TransportController.Command.Replay)
m.assertEqual(t.TakeVideoIntent().seekMs, 250000)
end function
' =========================================================================================
' SEEK-SETTLING FREEZE DEFER (INV-B12) — a transport entered while a play-through seek (commit /
' SponsorBlock skip / replay) is still in flight must NOT slam control=pause: that pause lands mid-seek
' external seek / replay) is still in flight must NOT slam control=pause: that pause lands mid-seek
' and wedges the device (the reported bif-over-black bug). Defer the freeze; the coordinator's
' EnforceTransportFreeze re-pauses once the seek reaches "playing". seekSettling models the in-flight seek.
' =========================================================================================
@describe("seek-settling freeze defer")
@it("a non-pause seek (SponsorBlock skip / commit / replay) marks seekSettling; pause+no-seek do not")
@it("a non-pause seek (external / commit / replay) marks seekSettling; pause+no-seek do not")
function _()
m.assertFalse(m.t.seekSettling)
m.t.ForceIdleSeek(120000, true) ' SponsorBlock skip, keep playing -> in flight
m.t.ForceIdleSeek(120000, true) ' an external seek, keep playing -> in flight
m.assertTrue(m.t.seekSettling)
m.t.MarkSeekSettled()
m.assertFalse(m.t.seekSettling)
@@ -1097,9 +1238,9 @@ namespace Tests
m.t.HandleCommand(TransportController.Command.Right)
m.assertEqual(m.t.transportMode, TransportController.Mode.Scrub) ' still enters scrub
m.assertInvalid(m.t.TakeVideoIntent()) ' but the FREEZE was deferred (no pause)
' the scrub still snaps + steps off the LAST KNOWN position (60000) — the seek to 120000 hasn't
' landed yet (that IS the "press Right immediately" race), so cursor = 60000 grid + 2000 step.
m.assertEqual(m.t.cursorMs, 62000)
' the scrub steps off the seek target, not the stale position (60000): the seek to 120000 hasn't
' landed yet (that IS the "press Right immediately" race), so cursor = 120000 + 2000 step.
m.assertEqual(m.t.cursorMs, 122000)
end function
@it("entering scan while a seek is settling DEFERS the freeze")
@@ -16,11 +16,13 @@ namespace Tests
' a fresh brain at rest (idle, ready) with realistic content facts. windowMs = the live DVR window
' (0 = unknown), the axis that decides the rewind floor.
function Fresh(isLive as boolean, windowMs = 0 as integer) as object
function Fresh(isLive as boolean, windowMs = 0 as integer, ready = true as boolean) as object
t = new TransportController.Controller()
t.SetContent(isLive, 2000, true)
t.SetLiveDvrWindow(windowMs)
t.OnReady()
if ready
t.OnReady()
end if
if isLive
t.OnLiveEdge(600000) ' clock-anchored live edge
else
@@ -71,11 +73,11 @@ namespace Tests
' reachable-state labels — each built by DRIVING the brain (only reachable states are tested). On live
' the same label reaches a live mode (left -> liveDvr step, fwd -> liveDvr ladder).
function Labels() as object
return ["idle", "scrub", "scrubHeld", "scan1", "scan2", "replay"]
return ["idle", "scrub", "scrubHeld", "scan1", "scan2", "replay", "committed", "notReady"]
end function
function Build(label as string, isLive as boolean, windowMs = 0 as integer) as object
t = m.Fresh(isLive, windowMs)
t = m.Fresh(isLive, windowMs, label <> "notReady")
if label = "scrub"
t.HandleKey(TransportController.Command.Left, true)
t.HandleKey(TransportController.Command.Left, false) ' release -> frozen, glyph cleared
@@ -88,6 +90,10 @@ namespace Tests
t.HandleCommand(TransportController.Command.Fwd)
else if label = "replay"
t.HandleCommand(TransportController.Command.Replay)
else if label = "committed"
' a scrub committed: its play-through seek is still settling.
t.HandleCommand(TransportController.Command.Left)
t.HandleCommand(TransportController.Command.Commit)
end if
return t
end function
@@ -141,14 +147,60 @@ namespace Tests
t.OnDuration(d)
m.AssertInv(t, label + tag + "+dur=" + d.ToStr())
end for
' an external seek from any state, to any target: back to idle on the clamped target, the replay
' chain and any armed timer dropped, the seek in flight.
for each target in [0, 120000, 599000, 900000, -5000, TransportController.LIVE_EDGE_SEEK_MS]
for each keepPlaying in [true, false]
t = m.Build(label, v.isLive, v.windowMs)
t.TakeTimerCmd()
expected = m.ExpectedExternalSeek(t, target)
t.ForceIdleSeek(target, keepPlaying)
where = label + tag + "+externalSeek=" + target.ToStr() + "/" + keepPlaying.ToStr()
m.AssertInv(t, where)
m.assertEqual(t.transportMode, TransportController.Mode.Idle, where)
m.assertFalse(t.replayPending, where)
m.assertTrue(t.seekSettling, where)
m.assertEqual(t.cursorMs, expected.cursorMs, where)
intent = t.TakeVideoIntent()
m.assertTrue(intent.hasSeek, where)
m.assertEqual(intent.seekMs, expected.seekMs, where)
if keepPlaying
m.assertEqual(intent.control, TransportController.Control.None, where)
else
m.assertEqual(intent.control, TransportController.Control.Resume, where)
end if
m.assertEqual(t.TakeTimerCmd().action, TransportController.TimerAction.Stop, where)
end for
end for
end for
end for
end function
' Where an external seek must land, from the brain's bounds before it: VOD clamps to [0, duration]; live
' clamps to the DVR floor, and at or past the effective edge goes to the edge (the sentinel).
function ExpectedExternalSeek(t as object, target as integer) as object
if t.isLive
if TransportController.IsLiveEdgeSentinelMs(target) or target >= t.LiveEdgeMs()
return { cursorMs: t.LiveEdgeMs(), seekMs: TransportController.LIVE_EDGE_SEEK_MS }
end if
floor = t.LiveFloorMs()
if target < floor
target = floor
end if
return { cursorMs: target, seekMs: target }
end if
if target < 0
target = 0
else if target > t.durationMs
target = t.durationMs
end if
return { cursorMs: target, seekMs: target }
end function
' ---------- seeded fuzz with shrink ----------
' a 16-bit LCG (ZX-Spectrum constants): s*25173 < 2^31 so it never overflows Integer; deterministic +
' reproducible (NOT Rnd, which is clock-seeded). Token = s mod 14 -> one input.
' reproducible (NOT Rnd, which is clock-seeded). Token = s mod 19 -> one input.
function Lcg(s as integer) as integer
return (s * 25173 + 13849) and 65535
end function
@@ -158,7 +210,7 @@ namespace Tests
s = seed
for i = 0 to n - 1
s = m.Lcg(s)
seq.Push(s mod 14)
seq.Push(s mod 19)
end for
return seq
end function
@@ -192,6 +244,16 @@ namespace Tests
t.OnLiveEdge(t.edgeMs + 50000) ' a big edge jump (long pause's catch-up)
else if tok = 13
t.ResolveLiveTail() ' the coordinator's tail-overtake resolution (no-op outside LiveDvr)
else if tok = 14
t.ForceIdleSeek(300000, true) ' an external seek keeping the play state (SponsorBlock skip, setSeek)
else if tok = 15
t.ForceIdleSeek(300000, false) ' an external seek out of a transport (setSeek resumes)
else if tok = 16
t.ForceIdleSeek(-5000, true) ' below the start / the DVR floor
else if tok = 17
t.ForceIdleSeek(900000, false) ' past the end / the edge
else if tok = 18
t.ForceIdleSeek(TransportController.LIVE_EDGE_SEEK_MS, true)
end if
end function
@@ -1,8 +1,11 @@
' Pins the test mock's node tree to the real component's. VideoPlayerDevMock.xml is a hand-mirrored copy of
' VideoPlayerDev.xml (same child ids so the coordinator's findNode()s resolve); silent drift between the two
' weakens every seam test built on the mock. This suite parses both XMLs from pkg and asserts:
' Pins the test mock's node tree and interface to the real component's. VideoPlayerDevMock.xml is a hand-mirrored
' copy of VideoPlayerDev.xml (same child ids so the coordinator's findNode()s resolve, same interface fields so
' the spec drives them as the outside world does); silent drift between the two weakens every seam test built on
' the mock. This suite parses both XMLs from pkg and asserts:
' - every real child id exists in the mock (minus the documented omissions) and vice versa;
' - same-id duration attributes (Timers/Animations) match.
' - same-id duration attributes (Timers/Animations) match;
' - every real interface field exists in the mock (minus the documented omissions) with the same type and
' alwaysNotify. The mock's extra fields (the Video fields it fakes, test probes) are its own.
' Element TYPES may differ (the mock substitutes simpler nodes with the same field surface, e.g. Label for
' ScrollingLabel), so type parity is intentionally not checked.
@@ -50,8 +53,58 @@ namespace Tests
end for
end function
' real interface fields the mock omits: profilesService is read only by the content-job paths the seam never
' runs; bindings + binding_done are the AutoBind include's plumbing, which TestSetup does by hand.
function MockFieldOmissions() as object
return { profilesService: true, bindings: true, binding_done: true }
end function
' Parse a component XML from pkg and index its <interface> fields: id -> { type, alwaysNotify }.
function FieldIndex(path as string) as object
text = ReadAsciiFile(path)
xml = CreateObject("roXMLElement")
parsed = (text <> "") and xml.Parse(text)
index = {}
if parsed
for each section in xml.GetChildElements()
if LCase(section.GetName()) = "interface"
for each field in section.GetChildElements()
if LCase(field.GetName()) = "field"
attrs = field.GetAttributes()
index[ValidString(attrs.id)] = { type: LCase(ValidString(attrs.type)), alwaysNotify: LCase(ValidString(attrs.alwaysNotify)) = "true" }
end if
end for
end if
end for
end if
return { parsed: parsed, index: index }
end function
@describe("mock parity")
@it("the mock declares every real interface field with the same type and alwaysNotify")
function _()
real = m.FieldIndex("pkg:/components/VideoPlayerDev/VideoPlayerDev.xml")
mock = m.FieldIndex("pkg:/components/VideoPlayerDev/tests/VideoPlayerDevMock.xml")
m.assertTrue(real.parsed, "VideoPlayerDev.xml read + parsed")
m.assertTrue(mock.parsed, "VideoPlayerDevMock.xml read + parsed")
m.assertTrue(real.index.Count() > 10, "real fields found (sanity: the walker isn't vacuous)")
omissions = m.MockFieldOmissions()
for each id in real.index
if not omissions.DoesExist(id)
m.assertTrue(mock.index.DoesExist(id), "mock is missing interface field '" + id + "' — mirror it (or add a documented omission)")
if mock.index.DoesExist(id)
m.assertEqual(mock.index[id].type, real.index[id].type, "type drift on field '" + id + "'")
m.assertEqual(mock.index[id].alwaysNotify, real.index[id].alwaysNotify, "alwaysNotify drift on field '" + id + "'")
end if
end if
end for
for each id in omissions
m.assertTrue(real.index.DoesExist(id), "stale field omission '" + id + "' — it left VideoPlayerDev.xml")
end for
end function
@it("the mock mirrors the real component's children (ids + timer/animation durations)")
function _()
real = m.ChildIndex("pkg:/components/VideoPlayerDev/VideoPlayerDev.xml")