Skip to content

Commit

Permalink
test: Consolidate probeSupport in one place (shaka-project#6667)
Browse files Browse the repository at this point in the history
  • Loading branch information
avelad committed May 24, 2024
1 parent 894c2f9 commit 6a8dbf7
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 41 deletions.
8 changes: 3 additions & 5 deletions test/cast/cast_receiver_integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,6 @@ filterDescribe('CastReceiver', castReceiverIntegrationSupport, () => {
let toRestore;
let pendingWaitWrapperCalls = 0;

/** @type {!Object.<string, ?shaka.extern.DrmSupportType>} */
let support = {};

let fakeInitState;

beforeAll(async () => {
Expand All @@ -62,7 +59,6 @@ filterDescribe('CastReceiver', castReceiverIntegrationSupport, () => {
shaka.test.TestScheme.ManifestParser.factory);

await shaka.test.TestScheme.createManifests(shaka, '');
support = await shaka.media.DrmEngine.probeSupport();
});

beforeEach(async () => {
Expand Down Expand Up @@ -247,7 +243,9 @@ filterDescribe('CastReceiver', castReceiverIntegrationSupport, () => {
});
});

filterDescribe('with drm', () => support['com.widevine.alpha'], () => {
const widevineSupport =
() => window['shakaSupport'].drm['com.widevine.alpha'];
filterDescribe('with drm', widevineSupport, () => {
drmIt('sends reasonably-sized updates', async () => {
// Use an encrypted asset, to make sure DRM info doesn't balloon the size.
fakeInitState.manifest = 'test:sintel-enc';
Expand Down
6 changes: 1 addition & 5 deletions test/hls/hls_parser_integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
describe('HlsParser', () => {
const Util = shaka.test.Util;

/** @type {!Object.<string, ?shaka.extern.DrmSupportType>} */
let support = {};

/** @type {!jasmine.Spy} */
let onErrorSpy;

Expand All @@ -26,7 +23,7 @@ describe('HlsParser', () => {
let waiter;

function checkClearKeySupport() {
const clearKeySupport = support['org.w3.clearkey'];
const clearKeySupport = window['shakaSupport'].drm['org.w3.clearkey'];
if (!clearKeySupport) {
return false;
}
Expand All @@ -38,7 +35,6 @@ describe('HlsParser', () => {
document.body.appendChild(video);
compiledShaka =
await shaka.test.Loader.loadShaka(getClientArg('uncompiled'));
support = await shaka.media.DrmEngine.probeSupport();
});

beforeEach(async () => {
Expand Down
18 changes: 7 additions & 11 deletions test/media/drm_engine_integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ describe('DrmEngine', () => {
const audioInitSegmentUri = '/base/test/test/assets/multidrm-audio-init.mp4';
const audioSegmentUri = '/base/test/test/assets/multidrm-audio-segment.mp4';

/** @type {!Object.<string, ?shaka.extern.DrmSupportType>} */
let support = {};

/** @type {!HTMLVideoElement} */
let video;
/** @type {shaka.extern.Manifest} */
Expand Down Expand Up @@ -56,17 +53,15 @@ describe('DrmEngine', () => {
document.body.appendChild(video);

const responses = await Promise.all([
shaka.media.DrmEngine.probeSupport(),
shaka.test.Util.fetch(videoInitSegmentUri),
shaka.test.Util.fetch(videoSegmentUri),
shaka.test.Util.fetch(audioInitSegmentUri),
shaka.test.Util.fetch(audioSegmentUri),
]);
support = responses[0];
videoInitSegment = responses[1];
videoSegment = responses[2];
audioInitSegment = responses[3];
audioSegment = responses[4];
videoInitSegment = responses[0];
videoSegment = responses[1];
audioInitSegment = responses[2];
audioSegment = responses[3];
});

beforeEach(async () => {
Expand Down Expand Up @@ -151,11 +146,12 @@ describe('DrmEngine', () => {
// https://testweb.playready.microsoft.com/Server/ServiceQueryStringSyntax
return false;
}
return support['com.widevine.alpha'] || support['com.microsoft.playready'];
return window['shakaSupport'].drm['com.widevine.alpha'] ||
window['shakaSupport'].drm['com.microsoft.playready'];
}

function checkClearKeySupport() {
return support['org.w3.clearkey'];
return window['shakaSupport'].drm['org.w3.clearkey'];
}

filterDescribe('basic flow', checkTrueDrmSupport, () => {
Expand Down
9 changes: 3 additions & 6 deletions test/mss/mss_player_integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
describe('MSS Player', () => {
const Util = shaka.test.Util;

/** @type {!Object.<string, ?shaka.extern.DrmSupportType>} */
let support = {};

/** @type {!jasmine.Spy} */
let onErrorSpy;

Expand All @@ -35,8 +32,9 @@ describe('MSS Player', () => {
const playreadyLicenseUrl = 'https://test.playready.microsoft.com/service/rightsmanager.asmx?cfg=(persist:false,sl:150)';

function checkPlayReadySupport() {
const playReadySupport = support['com.microsoft.playready'] ||
support['com.chromecast.playready'];
const playReadySupport =
window['shakaSupport'].drm['com.microsoft.playready'] ||
window['shakaSupport'].drm['com.chromecast.playready'];
if (!playReadySupport) {
return false;
}
Expand All @@ -48,7 +46,6 @@ describe('MSS Player', () => {
document.body.appendChild(video);
compiledShaka =
await shaka.test.Loader.loadShaka(getClientArg('uncompiled'));
support = await shaka.media.DrmEngine.probeSupport();
});

beforeEach(async () => {
Expand Down
9 changes: 4 additions & 5 deletions test/offline/offline_integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,13 @@ filterDescribe('Offline', supportsStorage, () => {
/** @type {?shaka.extern.DrmSupportType} */
let playreadySupport;

beforeAll(async () => {
beforeAll(() => {
video = shaka.test.UiUtils.createVideoElement();
document.body.appendChild(video);

const support = await shaka.media.DrmEngine.probeSupport();
widevineSupport = support['com.widevine.alpha'];
playreadySupport = support['com.microsoft.playready'] ||
support['com.chromecast.playready'];
widevineSupport = window['shakaSupport'].drm['com.widevine.alpha'];
playreadySupport = window['shakaSupport'].drm['com.microsoft.playready'] ||
window['shakaSupport'].drm['com.chromecast.playready'];
});

afterAll(() => {
Expand Down
7 changes: 3 additions & 4 deletions test/offline/storage_integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,13 @@ function storageSupport() {
return shaka.offline.Storage.support();
}

/** @return {!Promise.<boolean>} */
async function drmStorageSupport() {
/** @return {boolean} */
function drmStorageSupport() {
if (!shaka.offline.Storage.support()) {
return false;
}

const support = await shaka.Player.probeSupport();
const widevineSupport = support.drm['com.widevine.alpha'];
const widevineSupport = window['shakaSupport'].drm['com.widevine.alpha'];
return !!(widevineSupport && widevineSupport.persistentState);
}

Expand Down
8 changes: 3 additions & 5 deletions test/player_external.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ describe('Player', () => {
/** @type {!jasmine.Spy} */
let onErrorSpy;

/** @type {shaka.extern.SupportType} */
let support;
/** @type {!HTMLVideoElement} */
let video;
/** @type {shaka.Player} */
Expand All @@ -30,7 +28,6 @@ describe('Player', () => {
document.body.appendChild(video);
compiledShaka =
await shaka.test.Loader.loadShaka(getClientArg('uncompiled'));
support = await compiledShaka.Player.probeSupport();
});

beforeEach(async () => {
Expand Down Expand Up @@ -93,7 +90,8 @@ describe('Player', () => {
!asset.drm.some((keySystem) => {
// Demo assets use an enum here, which we look up in idFor.
// Command-line assets use a direct key system ID.
return support.drm[idFor(keySystem)] || support.drm[keySystem];
return window['shakaSupport'].drm[idFor(keySystem)] ||
window['shakaSupport'].drm[keySystem];
})) {
pending('None of the required key systems are supported.');
}
Expand All @@ -107,7 +105,7 @@ describe('Player', () => {
mimeTypes.push('video/mp4');
}
if (mimeTypes.length &&
!mimeTypes.some((type) => support.media[type])) {
!mimeTypes.some((type) => window['shakaSupport'].media[type])) {
pending('None of the required MIME types are supported.');
}
}
Expand Down
1 change: 1 addition & 0 deletions test/test/boot.js
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,7 @@ async function logSupport() {
const support = await shaka.Player.probeSupport();
// Bypass Karma's log settings and dump this to the console.
window.dump('Platform support:' + JSON.stringify(support, null, 2));
window['shakaSupport'] = support;
// eslint-disable-next-line no-restricted-syntax
} catch (error) {
console.error('Support check failed at boot!', error);
Expand Down

0 comments on commit 6a8dbf7

Please sign in to comment.