Skip to content

Commit

Permalink
dummy eme: fix find_key_system unit test mocks
Browse files Browse the repository at this point in the history
  • Loading branch information
peaBerberian committed Dec 23, 2024
1 parent ba08296 commit 021309d
Showing 1 changed file with 25 additions and 3 deletions.
28 changes: 25 additions & 3 deletions src/main_thread/decrypt/__tests__/find_key_system.test.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,35 @@
import type { MockInstance } from "vitest";
import { describe, beforeEach, it, expect, vi } from "vitest";
import eme from "../../../compat/eme";
import { describe, beforeEach, it, expect, vi, afterEach } from "vitest";
import type { IEmeApiImplementation } from "../../../compat/eme";
import getEmeApiImplementation from "../../../compat/eme";
import type { IKeySystemOption } from "../../../public_types";
import TaskCanceller from "../../../utils/task_canceller";
import getMediaKeySystemAccess from "../find_key_system";
import LoadedSessionsStore from "../utils/loaded_sessions_store";
import mediaKeysAttacher from "../utils/media_keys_attacher";

describe("find_key_systems - ", () => {
// eslint-disable-next-line @typescript-eslint/unbound-method
const oldRequestMediaKeySystemAccess = navigator.requestMediaKeySystemAccess;
let eme: IEmeApiImplementation;
let requestMediaKeySystemAccessMock: MockInstance;

beforeEach(() => {
// NOTE: We prefer resetting `navigator.requestMediaKeySystemAccess` as DOM
// implementations often forget to implement it.
navigator.requestMediaKeySystemAccess = vi.fn();
requestMediaKeySystemAccessMock = vi.spyOn(navigator, "requestMediaKeySystemAccess");
const implem = getEmeApiImplementation("auto");
if (implem === null) {
throw new Error("Could not initialize EME implementation");
}
eme = implem;
});

afterEach(() => {
navigator.requestMediaKeySystemAccess = oldRequestMediaKeySystemAccess;
vi.resetModules();
vi.restoreAllMocks();
requestMediaKeySystemAccessMock = vi.spyOn(eme, "requestMediaKeySystemAccess");
});

const baseEmeConfiguration: MediaKeySystemConfiguration = {
Expand Down Expand Up @@ -172,6 +188,7 @@ describe("find_key_systems - ", () => {

const taskCanceller = new TaskCanceller();
const event1 = await getMediaKeySystemAccess(
eme,
mediaElement,
keySystemOptionsA,
taskCanceller.signal,
Expand All @@ -190,6 +207,7 @@ describe("find_key_systems - ", () => {
});

const event2 = await getMediaKeySystemAccess(
eme,
mediaElement,
keySystemOptionsA,
taskCanceller.signal,
Expand Down Expand Up @@ -222,6 +240,7 @@ describe("find_key_systems - ", () => {

const taskCanceller = new TaskCanceller();
const event1 = await getMediaKeySystemAccess(
eme,
mediaElement,
keySystemOptionsA,
taskCanceller.signal,
Expand All @@ -248,6 +267,7 @@ describe("find_key_systems - ", () => {
];

const event2 = await getMediaKeySystemAccess(
eme,
mediaElement,
keySystemOptionsB,
taskCanceller.signal,
Expand Down Expand Up @@ -283,6 +303,7 @@ describe("find_key_systems - ", () => {

const taskCanceller = new TaskCanceller();
const event1 = await getMediaKeySystemAccess(
eme,
mediaElement,
keySystemOptionsA,
taskCanceller.signal,
Expand Down Expand Up @@ -313,6 +334,7 @@ describe("find_key_systems - ", () => {
];

const event2 = await getMediaKeySystemAccess(
eme,
mediaElement,
keySystemOptionsB,
taskCanceller.signal,
Expand Down

0 comments on commit 021309d

Please sign in to comment.