Capture additional fields to investigate DRM errors

This commit is contained in:
Brahim Hadriche committed 2026-10-16 17:13:40 -04:00
1 parent 555665488d
commit 9eac1aac04
14 files changed
+251 -47

No files matched your search

@@ -0,0 +1,89 @@
import "pkg:/components/Services/Innertube/DrmLicenseRequests.bs"
import "pkg:/components/Services/Innertube/GetDrmLicenseEndpoint.bs"
namespace Tests
@suite
class DrmLicenseTests extends Rooibos.BaseTestSuite
protected override function afterEach()
DeleteFile(DRM_LICENSE_REQUESTS_PATH)
end function
function Requests(videoLoadId as string) as object
return VideoLoadHandoff.Read(DRM_LICENSE_REQUESTS_PATH, videoLoadId)
end function
@describe("Innertube.ParseGetDrmLicenseResponse")
@it("decodes the web-safe base64 license and keeps the rest of the response")
function _()
authorizedFormats = [{ "trackType": "DRM_TRACK_TYPE_HD", "keyId": "a" }]
responseContext = { "serviceTrackingParams": [{ "service": "GFEEDBACK", "params": [{ "key": "logged_in", "value": "1" }] }] }
parsed = Innertube.ParseGetDrmLicenseResponse({
"responseContext": responseContext
"status": "LICENSE_STATUS_OK"
"license": "AQID-_8="
"authorizedFormats": authorizedFormats
"canRenew": false
})
m.assertEqual(parsed.license.ToHexString(), "010203FBFF")
m.assertEqual(parsed.payload, { "responseContext": responseContext, "status": "LICENSE_STATUS_OK", "authorizedFormats": authorizedFormats, "canRenew": false })
end function
@it("a license that decodes to no bytes is an error, with the response as sent")
function _()
' Roku decodes a length that isn't a multiple of 4 to nothing.
parsed = Innertube.ParseGetDrmLicenseResponse({ "status": "LICENSE_STATUS_OK", "license": "AQI" })
m.assertEqual(parsed.error, "DRM license decodes to no bytes")
m.assertEqual(parsed.payload, { "status": "LICENSE_STATUS_OK", "license": "AQI" })
end function
@it("a status other than OK is an error, with the response as sent")
function _()
parsed = Innertube.ParseGetDrmLicenseResponse({ "status": "LICENSE_STATUS_DENIED", "license": "AQID", "reason": "r" })
m.assertEqual(parsed.error, "DRM license request failed with status: LICENSE_STATUS_DENIED")
m.assertEqual(parsed.payload, { "status": "LICENSE_STATUS_DENIED", "license": "AQID", "reason": "r" })
end function
@describe("DrmLicenseRequests")
@it("counts the video load's requests and keeps each response in order")
function _()
DrmLicenseRequests.RecordSent("load1")
DrmLicenseRequests.RecordResponse("load1", { payload: { "status": "LICENSE_STATUS_OK" } })
DrmLicenseRequests.RecordSent("load1")
DrmLicenseRequests.RecordResponse("load1", { error: "timeout" })
DrmLicenseRequests.RecordSent("load1")
m.assertEqual(m.Requests("load1"), {
"sent": 3
"responses": [
{ "payload": { "status": "LICENSE_STATUS_OK" } }
{ "error": "timeout" }
]
})
end function
@it("keeps the first responses, counting every request")
function _()
for i = 1 to DRM_LICENSE_RESPONSE_SAMPLE_CAP + 2
DrmLicenseRequests.RecordSent("load1")
DrmLicenseRequests.RecordResponse("load1", { error: `e${i}` })
end for
requests = m.Requests("load1")
m.assertEqual(requests["sent"], DRM_LICENSE_RESPONSE_SAMPLE_CAP + 2)
m.assertEqual(requests["responses"].Count(), DRM_LICENSE_RESPONSE_SAMPLE_CAP)
m.assertEqual(requests["responses"][0], { "error": "e1" })
end function
@it("a new video load starts over")
function _()
DrmLicenseRequests.RecordSent("load1")
DrmLicenseRequests.RecordSent("load2")
m.assertInvalid(m.Requests("load1"))
m.assertEqual(m.Requests("load2"), { "sent": 1, "responses": [] })
end function
end class
end namespace
@@ -38,6 +38,11 @@ namespace Tests
m.recorder = new PlaybackTelemetry.Recorder({ playerTimer: m.playerClock, transport: m.fakeTransport, top: m.fakeTop })
end function
protected override function afterEach()
DeleteFile(LIVE_LOAD_COUNTS_PATH)
DeleteFile(DRM_LICENSE_REQUESTS_PATH)
end function
function At(ms as integer) as void
m.playerClock.ms = ms
end function
@@ -292,6 +297,27 @@ namespace Tests
m.assertEqual(summary.stream_url_index, 1)
end function
@it("DRM content: the video load's license requests, read once")
function _()
m.fakeTop.content = { videoId: "vid1", videoLoadId: "load1", backend: "playlet", playletStreamSource: "adaptiveFormats", drmParams: { keySystem: "Widevine" } }
requests = { "sent": 2, "responses": [{ "error": "timeout" }, { "payload": { "status": "LICENSE_STATUS_OK", "authorizedFormats": [{ "trackType": "DRM_TRACK_TYPE_SD", "keyId": "a" }] } }] }
VideoLoadHandoff.Write(DRM_LICENSE_REQUESTS_PATH, "load1", requests)
summary = m.SendAt(1000)
m.assertEqual(summary.drm_license_requests, requests)
m.assertEqual(summary.widevine_security_level, CreateObject("roDeviceInfo").GetDrmInfoEx().Widevine.securityLevel)
m.assertFalse(m.SendAt(2000).DoesExist("drm_license_requests"), "read once")
end function
@it("content without DRM sends no DRM fields")
function _()
m.fakeTop.content.videoLoadId = "load1"
VideoLoadHandoff.Write(DRM_LICENSE_REQUESTS_PATH, "load1", { "sent": 1, "responses": [] })
summary = m.SendAt(1000)
for each field in ["drm", "drm_license_requests", "widevine_security_level", "hdcp_version"]
m.assertFalse(summary.DoesExist(field), field)
end for
end function
@it("content that never loaded sends no stream fields")
function _()
m.fakeTop.content = { videoId: "vid1", backend: "playlet" }
@@ -392,25 +418,22 @@ namespace Tests
function _()
m.fakeTransport.isLive = true
m.fakeTop.content.videoLoadId = "live1"
WriteAsciiFile(LIVE_LOAD_COUNTS_PATH, FormatJson({
"video_load_id": "live1"
VideoLoadHandoff.Write(LIVE_LOAD_COUNTS_PATH, "live1", {
"live_head": { "checks_sent": 6, "answered_after_wait": 1, "timed_out": 0 }
"live_timeline": { "timed_checks": 3, "corrections": 1, "stall_corrections": 0, "drift_ms_min": -3425, "drift_ms_max": 0, "duration_runs_max": 2 }
}))
})
summary = m.SendAt(1000)
m.assertEqual(summary.live_head, { "checks_sent": 6, "answered_after_wait": 1 })
m.assertEqual(summary.live_timeline, { "timed_checks": 3, "corrections": 1, "drift_ms_min": -3425, "duration_runs_max": 2 })
m.assertFalse(CreateObject("roFileSystem").Exists(LIVE_LOAD_COUNTS_PATH), "read once")
summary = m.SendAt(2000)
m.assertFalse(summary.DoesExist("live_head"))
m.assertFalse(summary.DoesExist("live_timeline"))
m.assertFalse(summary.DoesExist("live_head"), "read once")
m.assertFalse(summary.DoesExist("live_timeline"), "read once")
end function
@it("a live play without live load counts has none")
function _()
m.fakeTransport.isLive = true
m.fakeTop.content.videoLoadId = "live1"
DeleteFile(LIVE_LOAD_COUNTS_PATH)
summary = m.SendAt(1000)
m.assertFalse(summary.DoesExist("live_head"))
m.assertFalse(summary.DoesExist("live_timeline"))
@@ -420,13 +443,12 @@ namespace Tests
function _()
m.fakeTransport.isLive = true
m.fakeTop.content.videoLoadId = "live1"
handoff = FormatJson({ "video_load_id": "live2", "live_head": { "checks_sent": 6 }, "live_timeline": { "corrections": 1 } })
WriteAsciiFile(LIVE_LOAD_COUNTS_PATH, handoff)
counts = { "live_head": { "checks_sent": 6 }, "live_timeline": { "corrections": 1 } }
VideoLoadHandoff.Write(LIVE_LOAD_COUNTS_PATH, "live2", counts)
summary = m.SendAt(1000)
m.assertFalse(summary.DoesExist("live_head"))
m.assertFalse(summary.DoesExist("live_timeline"))
m.assertEqual(ReadAsciiFile(LIVE_LOAD_COUNTS_PATH), handoff)
DeleteFile(LIVE_LOAD_COUNTS_PATH)
m.assertEqual(VideoLoadHandoff.Read(LIVE_LOAD_COUNTS_PATH, "live2"), counts)
end function
@it("a live play: the first video segment's bitrate and the network's at the first playing")
@@ -176,14 +176,12 @@ namespace Tests
function _()
m.LoadLive([{ seqnum: 10, timeMs: 18630 }, { seqnum: -1, timeMs: invalid }])
m.RefreshDue()
handoff = StringUtils.ParseJsonSafe(ReadAsciiFile(LIVE_LOAD_COUNTS_PATH))
m.assertEqual(handoff["live_timeline"]["corrections"], 1)
m.assertEqual(VideoLoadHandoff.Read(LIVE_LOAD_COUNTS_PATH, "live1")["live_timeline"]["corrections"], 1)
m.RefreshDue()
handoff = StringUtils.ParseJsonSafe(ReadAsciiFile(LIVE_LOAD_COUNTS_PATH))
m.assertEqual(handoff["video_load_id"], "live1")
m.assertEqual(handoff["live_head"]["checks_sent"], 2)
m.assertEqual(handoff["live_head"]["answered_without_head"], 1)
m.assertEqual(handoff["live_timeline"], m.router.liveTimelineCounts)
counts = VideoLoadHandoff.Read(LIVE_LOAD_COUNTS_PATH, "live1")
m.assertEqual(counts["live_head"]["checks_sent"], 2)
m.assertEqual(counts["live_head"]["answered_without_head"], 1)
m.assertEqual(counts["live_timeline"], m.router.liveTimelineCounts)
end function
@it("gives a list behind the head the cadence since load; the load head ended where the list stays ahead")