Skip to content

Commit

Permalink
test: Add a ClearKey integration test
Browse files Browse the repository at this point in the history
Will only run on devices which report ClearKey support.

Related to issue shaka-project#771 (ClearKey support on Tizen)

Change-Id: I1ca2458fc4bdc7b6de02a6e452bfd7e3bfe3f9a4
  • Loading branch information
joeyparrish committed Oct 7, 2021
1 parent b02ff27 commit 1bd954b
Showing 1 changed file with 86 additions and 2 deletions.
88 changes: 86 additions & 2 deletions test/media/drm_engine_integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ describe('DrmEngine', () => {
document.body.removeChild(video);
});

function checkSupport() {
function checkTrueDrmSupport() {
if (shaka.util.Platform.isXboxOne()) {
// Axinom won't issue a license for an Xbox One. The error message from
// the license server says "Your DRM client's security level is 150, but
Expand All @@ -174,7 +174,11 @@ describe('DrmEngine', () => {
return support['com.widevine.alpha'] || support['com.microsoft.playready'];
}

filterDescribe('basic flow', checkSupport, () => {
function checkClearKeySupport() {
return support['org.w3.clearkey'];
}

filterDescribe('basic flow', checkTrueDrmSupport, () => {
drmIt('gets a license and can play encrypted segments', async () => {
// The error callback should not be invoked.
onErrorSpy.and.callFake(fail);
Expand Down Expand Up @@ -274,4 +278,84 @@ describe('DrmEngine', () => {
expect(video.currentTime).toBeGreaterThan(0);
});
}); // describe('basic flow')

filterDescribe('ClearKey', checkClearKeySupport, () => {
drmIt('plays encrypted content with the ClearKey CDM', async () => {
// Configure DrmEngine for ClearKey playback.
const config = shaka.util.PlayerConfiguration.createDefault().drm;
config.clearKeys = {
// From https://github.com/Axinom/public-test-vectors/tree/conservative#v61-multidrm
'6e5a1d26275747d78046eaa5d1d34b5a': '197f26f572c864d2338b3ae5d114ea9c',
};
drmEngine.configure(config);

// The error callback should not be invoked.
onErrorSpy.and.callFake(fail);

/** @type {!shaka.util.PublicPromise} */
const encryptedEventSeen = new shaka.util.PublicPromise();
eventManager.listen(video, 'encrypted', () => {
encryptedEventSeen.resolve();
});
eventManager.listen(video, 'error', () => {
fail('MediaError code ' + video.error.code);
let extended = video.error.msExtendedCode;
if (extended) {
if (extended < 0) {
extended += Math.pow(2, 32);
}
fail('MediaError msExtendedCode ' + extended.toString(16));
}
});

/** @type {!shaka.util.PublicPromise} */
const keyStatusEventSeen = new shaka.util.PublicPromise();
onKeyStatusSpy.and.callFake(() => {
keyStatusEventSeen.resolve();
});

const variants = manifest.variants;

await drmEngine.initForPlayback(variants, manifest.offlineSessionIds);
await drmEngine.attach(video);
await mediaSourceEngine.appendBuffer(
ContentType.VIDEO, videoInitSegment, null, null,
/* hasClosedCaptions= */ false);
await mediaSourceEngine.appendBuffer(
ContentType.AUDIO, audioInitSegment, null, null,
/* hasClosedCaptions= */ false);
await encryptedEventSeen;

// Some platforms (notably 2017 Tizen TVs) do not fire key status
// events.
const keyStatusTimeout = shaka.test.Util.delay(5);
await Promise.race([keyStatusTimeout, keyStatusEventSeen]);

const call = onKeyStatusSpy.calls.mostRecent();
if (call) {
const map = /** @type {!Object} */ (call.args[0]);
expect(Object.keys(map).length).not.toBe(0);
for (const k in map) {
expect(map[k]).toBe('usable');
}
}

await mediaSourceEngine.appendBuffer(
ContentType.VIDEO, videoSegment, 0, 10,
/* hasClosedCaptions= */ false);
await mediaSourceEngine.appendBuffer(
ContentType.AUDIO, audioSegment, 0, 10,
/* hasClosedCaptions= */ false);

expect(video.buffered.end(0)).toBeGreaterThan(0);
video.play();

const waiter = new shaka.test.Waiter(eventManager).timeoutAfter(15);
await waiter.waitForMovement(video);

// Something should have played by now.
expect(video.readyState).toBeGreaterThan(1);
expect(video.currentTime).toBeGreaterThan(0);
});
}); // describe('ClearKey')
});

0 comments on commit 1bd954b

Please sign in to comment.