Skip to content

Commit

Permalink
test: Trigger RESTRICTIONS_CANNOT_BE_MET once from onKeyStatus error (#…
Browse files Browse the repository at this point in the history
…4205)

Adding tests for #4194 in order to ensure that, when `onKeyStatus({ kid: 'output-restricted'})` error is thrown **ONLY** one `RESTRICTIONS_CANNOT_BE_MET` error is triggered/thrown.
  • Loading branch information
albertdaurell authored and joeyparrish committed May 17, 2022
1 parent 4d418be commit 2720ee4
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions test/player_unit.js
Expand Up @@ -156,6 +156,7 @@ describe('Player', () => {
window.MediaSource.isTypeSupported = originalIsTypeSupported;
shaka.media.ManifestParser.unregisterParserByMime(fakeMimeType);
navigator.mediaCapabilities.decodingInfo = originalDecodingInfo;
onError.calls.reset();
}
});

Expand Down Expand Up @@ -2658,6 +2659,51 @@ describe('Player', () => {
expect(activeVariant.id).toBe(1);
});

// Regression test for https://github.com/shaka-project/shaka-player/issues/4190
it('throws only one RESTRICTIONS_CANNOT_BE_MET error', async () => {
manifest = shaka.test.ManifestGenerator.generate((manifest) => {
manifest.addVariant(0, (variant) => {
variant.addVideo(1, (stream) => {
stream.keyIds = new Set(['abc']);
});
});
});

// Check that error is RESTRICTIONS_CANNOT_BE_MET
onError.and.callFake((e) => {
const error = e.detail;
shaka.test.Util.expectToEqualError(
error,
new shaka.util.Error(
shaka.util.Error.Severity.CRITICAL,
shaka.util.Error.Category.MANIFEST,
shaka.util.Error.Code.RESTRICTIONS_CANNOT_BE_MET, {
hasAppRestrictions: false,
missingKeys: ['abc'],
restrictedKeyStatuses: [],
}));
});

await player.load(fakeManifestUri, 0, fakeMimeType);
const activeVariant = getActiveVariantTrack();
expect(activeVariant.id).toBe(0);

abrManager.chooseIndex = 0;
abrManager.chooseVariant.calls.reset();

onKeyStatus({'abc': 'output-restricted'});

// Ensure that RESTRICTIONS_CANNOT_BE_MET is thrown once
expect(onError).toHaveBeenCalledTimes(1);

// It does not call chooseVariant
expect(abrManager.chooseVariant).not.toHaveBeenCalled();

// The first variant is disallowed.
expect(manifest.variants[0].id).toBe(0);
expect(manifest.variants[0].allowedByKeySystem).toBe(false);
});

it('doesn\'t switch if the active stream isn\'t restricted', async () => {
manifest = shaka.test.ManifestGenerator.generate((manifest) => {
manifest.addVariant(0, (variant) => {
Expand Down

0 comments on commit 2720ee4

Please sign in to comment.