[skip ci] onkeyevent test for player

This commit is contained in:
Brahim Hadriche committed 2026-07-30 14:00:20 -04:00
1 parent a07d92eaa9
commit f29b0f0af8
6 files changed
+206 -5

No files matched your search

@@ -1,8 +1,9 @@
# VideoPlayerDev
The custom video player intended to replace `components/VideoPlayer` — a stock-OS-trickplay replica plus a
control button row. It is selected at **compile time** by `#const USE_DEV_PLAYER` in `VideoQueue.bs` (default
`false`). Build with the flag `true` to run it (and the integration suite).
The custom video player that replaced `components/VideoPlayer` — a stock-OS-trickplay replica plus a control
button row. It is selected at **compile time** by `#const USE_DEV_PLAYER` in `VideoQueue.bs`, currently `true`:
this is the player that ships. Build with the flag `false` to fall back to the stock `VideoPlayer` (the
integration suite asserts the dev player, so it only passes with the flag on).
## Architecture
@@ -418,7 +418,7 @@ function TrySponsorBlockSkip() as boolean
end function
' OK/Select — the one shared key. Priority (after the SponsorBlock skip, handled in OnKeyEvent): commit (if a
' transport is active) -> chrome/pause toggle. OK is the VOD pause key (there is no separate ECP Pause). So
' transport is active) -> chrome/pause toggle. OK is the VOD pause key. So
' while idle: VOD = play/pause toggle (reveals chrome + LargePause); live = chrome toggle only (no pause).
function OnOkPress() as boolean
' commit an active transport.
@@ -84,6 +84,14 @@ function TestSetup() as void
m.top.unobserveField(deviceField)
end for
' The mock node is shared across tests and `duration` is not alwaysNotify, so a leftover duration=100
' swallows the next test's identical write and OnDuration never fires. Reset with the observers off.
m.top.state = VideoState.None
m.top.control = VideoControl.None
m.top.position = 0
m.top.duration = 0
m.top.seek = 0
OnNodeReady()
end function
@@ -118,6 +126,13 @@ function TestSetLive(edgeMs as integer) as void
m.transport.OnPosition(edgeMs)
end function
' TestSeedSponsorBlock — the segments job's result, minus the job. Writing m.top.position afterwards runs the
' REAL OnPosition, which is what arms the manual notice.
function TestSeedSponsorBlock(segments as object) as void
m.sponsorblock.enabled = true
m.sponsorblock.segments = segments
end function
' TestFireLiveBadgeHold — fire the liveBadgeHold timer's handler now (the spec can't wait out the real timer).
function TestFireLiveBadgeHold() as void
OnLiveBadgeHoldFire()
@@ -214,6 +229,7 @@ function TestSnapshot() as object
focusTarget: m.focusTarget
focusedButton: m.focusedButton
nudgeCount: m.top.nudgeCount
sponsorNoticeShown: SponsorBlock.GetCurrentNotification(m.notifications) <> invalid
forceLiveBadge: m.trickPlayBar.forceLiveBadge
liveBadgeShown: m.trickPlayBar.findNode("liveLabel").visible
barRemainingText: m.trickPlayBar.findNode("remainingLabel").text
@@ -52,6 +52,7 @@
<function name="TestWireQueueClose" />
<function name="TestSetControl" />
<function name="TestSetLive" />
<function name="TestSeedSponsorBlock" />
<function name="TestFireLiveBadgeHold" />
<function name="TestKillAutoHide" />
<function name="TestFinishChromeFadeOut" />
@@ -216,11 +216,18 @@ namespace Tests
end function
' Up/Down reveal the chrome when it is hidden in idle (they otherwise do nothing).
@it("Up reveals the chrome when it is hidden in idle")
@it("Up and Down each reveal the chrome when it is hidden in idle")
function _()
m.assertFalse(m.Snap().chromeShown) ' starts hidden after setup
m.top.callFunc("TestKey", RemoteKeys.Up, true)
m.assertTrue(m.Snap().chromeShown, "Up revealed the chrome")
' back to fully hidden: the reveal only fires from Hidden, not mid fade-out.
m.top.callFunc("TestKey", RemoteKeys.Back, true)
m.top.callFunc("TestFinishChromeFadeOut")
m.assertFalse(m.Snap().chromeShown)
m.top.callFunc("TestKey", RemoteKeys.Down, true)
m.assertTrue(m.Snap().chromeShown, "Down revealed the chrome")
end function
' =========================================================================================
@@ -349,6 +356,121 @@ namespace Tests
m.assertTrue(m.top.videoQueue.closePlayer, "rung 4: Back closes")
end function
' =========================================================================================
' Key router — the branches that decide WHICH handler runs.
' =========================================================================================
' The segment shape SponsorBlockSegmentsJob returns.
function ManualSegment(startS as float, endS as float) as object
return [{ start: startS, end: endS, option: "manual_skip", title: "Sponsor", shortTitle: "Sponsor", actionText: "Press OK to skip", showNotification: true, UUID: "seg-manual", category: "sponsor" }]
end function
' Minimize is the discriminator: activating it would have hidden the chrome.
@it("an armed SponsorBlock notice outranks the buttons tier: OK skips instead of activating the button")
function _()
m.top.duration = 100
m.top.callFunc("TestSeedSponsorBlock", m.ManualSegment(10.0, 40.0))
m.top.position = 12.0 ' the REAL OnPosition arms the manual notice
m.assertTrue(m.Snap().sponsorNoticeShown, "the notice is up")
m.top.callFunc("TestKey", RemoteKeys.Up, true) ' reveal -> bar tier
m.top.callFunc("TestKey", RemoteKeys.Up, true) ' bar -> buttons tier
m.top.callFunc("TestKey", RemoteKeys.Right, true) ' highlight minimize
m.assertEqual(m.Snap().focusedButton, 1)
m.top.callFunc("TestKey", RemoteKeys.Ok, true)
after = m.Snap()
m.assertEqual(Int(m.top.seek * 1000), 40000, "OK skipped to the segment end, not into the focused button")
m.assertFalse(after.sponsorNoticeShown, "the skip took the notice down")
m.assertTrue(after.chromeShown, "minimize never ran -- it would have hidden the chrome")
end function
@it("an armed SponsorBlock notice outranks the Back ladder: Back dismisses the notice, not the player")
function _()
m.top.duration = 100
m.top.callFunc("TestSeedSponsorBlock", m.ManualSegment(10.0, 40.0))
m.top.position = 12.0
m.assertTrue(m.Snap().sponsorNoticeShown)
m.assertFalse(m.Snap().chromeShown, "chrome hidden: an unrouted Back here would CLOSE the player")
seekBefore = m.top.seek
m.top.callFunc("TestKey", RemoteKeys.Back, true)
after = m.Snap()
m.assertFalse(after.sponsorNoticeShown, "Back took the notice down")
m.assertFalse(m.top.videoQueue.closePlayer, "Back acted on the notice, NOT on the player")
m.assertEqual(m.top.seek, seekBefore, "dismissing is not skipping")
' one-shot: with the notice gone the next Back is the ordinary ladder again (rung 4 -> close).
m.top.callFunc("TestKey", RemoteKeys.Back, true)
m.assertTrue(m.top.videoQueue.closePlayer, "the notice consumed one Back, not every Back")
end function
@it("an armed notice on a segment at the video end finishes playback instead of seeking")
function _()
m.top.duration = 100
m.top.callFunc("TestSeedSponsorBlock", m.ManualSegment(90.0, 99.5)) ' ends within 2s of duration
m.top.position = 92.0
m.assertTrue(m.Snap().sponsorNoticeShown)
seekBefore = m.top.seek
m.top.callFunc("TestKey", RemoteKeys.Ok, true)
m.assertEqual(m.top.seek, seekBefore, "no seek was issued: the skip resolved to finish")
m.assertTrue(m.top.videoQueue.closePlayer, "no next video -> the finish closed the player")
end function
@it("the non-transport keys act on the key-DOWN edge only")
function _()
' Back goes first: only from the start state does its DOWN edge close the player.
m.assertFalse(m.top.callFunc("TestKey", RemoteKeys.Back, false), "the Back key-up is not consumed")
m.assertFalse(m.top.videoQueue.closePlayer, "the Back key-up must not close the player")
m.top.callFunc("TestKey", RemoteKeys.Ok, true) ' reveal
m.top.callFunc("TestKey", RemoteKeys.Ok, true) ' pause
m.top.callFunc("TestSetState", VideoState.Paused)
m.assertEqual(m.Snap().control, VideoControl.Pause)
m.assertFalse(m.top.callFunc("TestKey", RemoteKeys.Ok, false), "the OK key-up is not consumed")
m.assertFalse(m.top.callFunc("TestKey", RemoteKeys.Play, false), "the Play key-up is not consumed")
m.assertFalse(m.top.callFunc("TestKey", RemoteKeys.PlayOnly, false), "the PlayOnly key-up is not consumed")
m.assertFalse(m.top.callFunc("TestKey", RemoteKeys.Pause, false), "the Pause key-up is not consumed")
m.assertEqual(m.Snap().control, VideoControl.Pause, "no key-up toggled the pause back to playing")
end function
@it("Play commits an active transport, like OK")
function _()
m.top.callFunc("TestKey", RemoteKeys.Left, true)
m.top.callFunc("TestKey", RemoteKeys.Left, false)
m.assertEqual(m.Snap().transportMode, TransportController.Mode.Scrub)
m.top.callFunc("TestKey", RemoteKeys.Play, true)
after = m.Snap()
m.assertEqual(after.transportMode, TransportController.Mode.Idle, "Play committed the scrub")
m.assertTrue(after.seekSettling, "the commit emitted a play-through seek, not a play/pause toggle")
end function
@it("PlayOnly toggles play/pause, like Play")
function _()
m.top.callFunc("TestKey", RemoteKeys.PlayOnly, true)
m.assertEqual(m.Snap().control, VideoControl.Pause, "PlayOnly paused the playing video")
m.top.callFunc("TestSetState", VideoState.Paused)
m.top.callFunc("TestKey", RemoteKeys.PlayOnly, true)
m.assertEqual(m.Snap().control, VideoControl.Resume, "PlayOnly resumed the paused video")
end function
@it("the transport keys fall through the buttons tier to the transport")
function _()
m.top.callFunc("TestKey", RemoteKeys.Up, true) ' reveal -> bar tier
m.top.callFunc("TestKey", RemoteKeys.Up, true) ' bar -> buttons tier
m.assertEqual(m.Snap().focusTarget, PlayerCoordinatorLogic.FocusTarget.Buttons)
m.top.callFunc("TestKey", RemoteKeys.Rewind, true)
m.top.callFunc("TestKey", RemoteKeys.Rewind, false)
after = m.Snap()
m.assertEqual(after.transportMode, TransportController.Mode.Scan, "Rev started the scan from the buttons tier")
m.assertEqual(after.focusTarget, PlayerCoordinatorLogic.FocusTarget.Bar, "a transport key moves focus to the bar")
m.assertEqual(after.nudgeCount, 0, "the row did not treat it as one of its own keys")
end function
' The point of the bar-default: Left/Right seek and OK pauses with no navigation at all, straight off a
' fresh reveal. Pinned as its own test rather than left as a side effect of the tier round-trip tests.
@it("a fresh idle reveal defaults focus to the bar: Left/Right seek and OK pauses with no navigation")
@@ -555,6 +677,61 @@ namespace Tests
m.assertEqual(snap.focusedButton, 1, "the highlight is untouched")
end function
' Each arm is asserted: a state that silently failed to arm makes every row that follows vacuous.
function ArmRouterState(state as string) as void
m.top.callFunc("TestSetup")
m.top.callFunc("TestSetState", VideoState.Playing) ' opens the brain's ready-gate, as beforeEach does
if state = "idle hidden"
m.assertFalse(m.Snap().chromeShown, "armed: " + state)
else if state = "chrome/bar"
m.top.callFunc("TestKey", RemoteKeys.Up, true)
snap = m.Snap()
m.assertTrue(snap.chromeShown, "armed: " + state)
m.assertEqual(snap.focusTarget, PlayerCoordinatorLogic.FocusTarget.Bar, "armed: " + state)
else if state = "chrome/buttons"
m.top.callFunc("TestKey", RemoteKeys.Up, true)
m.top.callFunc("TestKey", RemoteKeys.Up, true)
snap = m.Snap()
m.assertTrue(snap.chromeShown, "armed: " + state)
m.assertEqual(snap.focusTarget, PlayerCoordinatorLogic.FocusTarget.Buttons, "armed: " + state)
else if state = "transport"
m.top.callFunc("TestKey", RemoteKeys.Left, true)
m.top.callFunc("TestKey", RemoteKeys.Left, false)
m.assertEqual(m.Snap().transportMode, TransportController.Mode.Scrub, "armed: " + state)
end if
end function
' BrighterScript enums are compile-time constants with no runtime form, so a new RemoteKeys member
' cannot fail this until someone lists it below — these lists are the decision record, not reflection.
@it("every remote key's disposition is pinned in every router state")
function _()
ownedEverywhere = [RemoteKeys.Left, RemoteKeys.Right, RemoteKeys.Rewind, RemoteKeys.FastForward, RemoteKeys.Replay, RemoteKeys.Ok, RemoteKeys.Back, RemoteKeys.Play, RemoteKeys.PlayOnly]
' AppController's, not the player's.
passedEverywhere = [RemoteKeys.Options, RemoteKeys.Pause, RemoteKeys.OkLongPress, RemoteKeys.OptionsLongPress]
' the tier keys are owned only while there is a tier to move through or a chrome to reveal.
tierKeys = [RemoteKeys.Up, RemoteKeys.Down]
for each state in ["idle hidden", "chrome/bar", "chrome/buttons", "transport"]
for each key in ownedEverywhere
m.ArmRouterState(state)
m.assertTrue(m.top.callFunc("TestKey", key, true), "'" + key + "' must be consumed in state " + state)
end for
for each key in passedEverywhere
m.ArmRouterState(state)
m.assertFalse(m.top.callFunc("TestKey", key, true), "'" + key + "' must pass to the parent in state " + state)
end for
for each key in tierKeys
m.ArmRouterState(state)
consumed = m.top.callFunc("TestKey", key, true)
if state = "transport"
m.assertFalse(consumed, "'" + key + "' has nothing to do under a transport -- it passes to the parent")
else
m.assertTrue(consumed, "'" + key + "' moves focus or reveals the chrome in state " + state)
end if
end for
end for
end function
' The coordinator twin of the brain's unmodeled-axis meta-test: every m.* field on the coordinator must
' be consciously classified here. A NEW coordinator field fails this until someone decides what it is —
' a state axis needs transition coverage, a flag needs its consuming path tested.
@@ -35,6 +35,12 @@ namespace Tests
m.assertEqual(PlayerCoordinatorLogic.KeyToCommand(RemoteKeys.Ok), TransportController.Command.None)
m.assertEqual(PlayerCoordinatorLogic.KeyToCommand(RemoteKeys.Back), TransportController.Command.None)
m.assertEqual(PlayerCoordinatorLogic.KeyToCommand(RemoteKeys.Down), TransportController.Command.None)
m.assertEqual(PlayerCoordinatorLogic.KeyToCommand(RemoteKeys.Up), TransportController.Command.None)
m.assertEqual(PlayerCoordinatorLogic.KeyToCommand(RemoteKeys.Options), TransportController.Command.None)
' the play cluster: play-state keys, and a transport command here would make them seek instead.
m.assertEqual(PlayerCoordinatorLogic.KeyToCommand(RemoteKeys.Play), TransportController.Command.None)
m.assertEqual(PlayerCoordinatorLogic.KeyToCommand(RemoteKeys.PlayOnly), TransportController.Command.None)
m.assertEqual(PlayerCoordinatorLogic.KeyToCommand(RemoteKeys.Pause), TransportController.Command.None)
m.assertEqual(PlayerCoordinatorLogic.KeyToCommand("bogus"), TransportController.Command.None)
end function