Skip to content

Commit

Permalink
DRM: Add MediaKeySystemAccess Cache reusage basic tests
Browse files Browse the repository at this point in the history
  • Loading branch information
peaBerberian committed Dec 12, 2024
1 parent 075f9b3 commit c2a0d34
Showing 1 changed file with 197 additions and 1 deletion.
198 changes: 197 additions & 1 deletion tests/integration/scenarios/drm_requestMediaKeySystemAccess.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { describe, beforeEach, afterEach, it, expect } from "vitest";
import { describe, beforeEach, afterEach, it, expect, vi } from "vitest";
import { manifestInfos } from "../../contents/DASH_DRM_static_SegmentTemplate";
import DummyMediaElement from "../../../dist/es2017/experimental/tools/DummyMediaElement";
import RxPlayer from "../../../dist/es2017";
Expand Down Expand Up @@ -1342,4 +1342,200 @@ describe("DRM: requestMediaKeySystemAcces use cases", function () {
expect(checkNumber).toEqual(1);
}
});

describe("MediaKeySystemAccess cache", () => {
const loadVideoAndWaitForLoaded = async (player, keySystemConfigs) => {
player.loadVideo({
url,
transport,
autoPlay: false,
textTrackMode: "html",
textTrackElement: document.createElement("div"),
keySystems: keySystemConfigs.map((keySystemConfig) => ({
getLicense: generateGetLicenseForFakeLicense({}),
...keySystemConfig,
})),
});
await waitForPlayerState(player, "LOADED", ["LOADING"]);
};

it("should reuse a MediaKeySystemAccess if the exact same config was asked before", async () => {
for (const keySystem of [
"widevine",
"com.widevine.alpha",
"playready",
"com.microsoft.playready",
"com.microsoft.playready.recommendation",
]) {
const someConfig = [
{
type: keySystem,
audioCapabilitiesConfig: {
type: "robustness",
value: ["foo", "bar"],
},
videoCapabilitiesConfig: {
type: "robustness",
value: ["Waka", "Flocka"],
},
},
];
dummy = new DummyMediaElement({
drmOptions: {
requestMediaKeySystemAccessConfig: {
isKeySystemSupported: () => true,
},
},
});
const spy = vi.spyOn(dummy.FORCED_EME_API, "requestMediaKeySystemAccess");
player = new RxPlayer({ videoElement: dummy });
lockLowestBitrates(player);

await loadVideoAndWaitForLoaded(player, someConfig);
expect(spy).toHaveBeenCalledOnce();
await loadVideoAndWaitForLoaded(player, someConfig);
expect(spy).toHaveBeenCalledOnce();
spy.mockRestore();
player.dispose();
await sleep(10);
}
});

it("should NOT reuse a MediaKeySystemAccess if the type is different", async () => {
dummy = new DummyMediaElement({
drmOptions: {
requestMediaKeySystemAccessConfig: {
isKeySystemSupported: () => true,
},
},
});
const spy = vi.spyOn(dummy.FORCED_EME_API, "requestMediaKeySystemAccess");
player = new RxPlayer({ videoElement: dummy });
lockLowestBitrates(player);

await loadVideoAndWaitForLoaded(player, [
{
type: "playready",
},
]);
expect(spy).toHaveBeenCalledOnce();
await loadVideoAndWaitForLoaded(player, [
{
type: "widevine",
},
]);
expect(spy).toHaveBeenCalledTimes(2);
spy.mockRestore();
player.dispose();
await sleep(10);
});

it("should NOT reuse a MediaKeySystemAccess if distinctiveIdentifier is different", async () => {
dummy = new DummyMediaElement({
drmOptions: {
requestMediaKeySystemAccessConfig: {
isKeySystemSupported: () => true,
},
},
});
const spy = vi.spyOn(dummy.FORCED_EME_API, "requestMediaKeySystemAccess");
player = new RxPlayer({ videoElement: dummy });
lockLowestBitrates(player);

await loadVideoAndWaitForLoaded(player, [
{
type: "playready",
distinctiveIdentifier: "not-allowed",
},
]);
expect(spy).toHaveBeenCalledOnce();
await loadVideoAndWaitForLoaded(player, [
{
type: "playready",
distinctiveIdentifier: "required",
},
]);
expect(spy).toHaveBeenCalledTimes(2);
await loadVideoAndWaitForLoaded(player, [
{
type: "playready",
distinctiveIdentifier: "optional",
},
]);
// TODO: It should perhaps be `3` here?
expect(spy).toHaveBeenCalledTimes(2);

// Now just check that it's reused when they are the same
await loadVideoAndWaitForLoaded(player, [
{
type: "playready",
distinctiveIdentifier: "optional",
},
]);
expect(spy).toHaveBeenCalledTimes(2);
await loadVideoAndWaitForLoaded(player, [
{
type: "playready",
},
]);
expect(spy).toHaveBeenCalledTimes(2);
spy.mockRestore();
player.dispose();
await sleep(10);
});

it("should NOT reuse a MediaKeySystemAccess if persistentState is different", async () => {
dummy = new DummyMediaElement({
drmOptions: {
requestMediaKeySystemAccessConfig: {
isKeySystemSupported: () => true,
},
},
});
const spy = vi.spyOn(dummy.FORCED_EME_API, "requestMediaKeySystemAccess");
player = new RxPlayer({ videoElement: dummy });
lockLowestBitrates(player);

await loadVideoAndWaitForLoaded(player, [
{
type: "playready",
persistentState: "not-allowed",
},
]);
expect(spy).toHaveBeenCalledOnce();
await loadVideoAndWaitForLoaded(player, [
{
type: "playready",
persistentState: "required",
},
]);
expect(spy).toHaveBeenCalledTimes(2);
await loadVideoAndWaitForLoaded(player, [
{
type: "playready",
persistentState: "optional",
},
]);
// TODO: It should perhaps be `3` here?
expect(spy).toHaveBeenCalledTimes(2);

// Now just check that it's reused when they are the same
await loadVideoAndWaitForLoaded(player, [
{
type: "playready",
persistentState: "optional",
},
]);
expect(spy).toHaveBeenCalledTimes(2);
await loadVideoAndWaitForLoaded(player, [
{
type: "playready",
},
]);
expect(spy).toHaveBeenCalledTimes(2);
spy.mockRestore();
player.dispose();
await sleep(10);
});
});
});

0 comments on commit c2a0d34

Please sign in to comment.