Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add unit tests and integration test #448

Merged
merged 5 commits into from
Mar 29, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/segment-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -347,8 +347,6 @@ export default class SegmentLoader extends videojs.EventTarget {
const id = initSegmentId(map);
let storedMap = this.initSegments_[id];

// TODO: We should use the HTTP Expires header to invalidate our cache per
// https://tools.ietf.org/html/draft-pantos-http-live-streaming-23#section-6.2.3
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lol oops

if (set && !storedMap && map.bytes) {
this.initSegments_[id] = storedMap = {
resolvedUri: map.resolvedUri,
Expand Down Expand Up @@ -380,6 +378,8 @@ export default class SegmentLoader extends videojs.EventTarget {
const id = segmentKeyId(key);
let storedKey = this.keyCache_[id];

// TODO: We should use the HTTP Expires header to invalidate our cache per
// https://tools.ietf.org/html/draft-pantos-http-live-streaming-23#section-6.2.3
if (this.cacheEncryptionKeys_ && set && !storedKey && key.bytes) {
this.keyCache_[id] = storedKey = {
resolvedUri: key.resolvedUri,
Expand Down
38 changes: 37 additions & 1 deletion test/segment-loader.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ QUnit.module('SegmentLoader: M2TS', function(hooks) {
'segment end time not shifted by mp4 start time');
});

QUnit.test('segmentKey will cache new encrypted keys', function(assert) {
QUnit.test('segmentKey will cache new encrypted keys with cacheEncryptionKeys true', function(assert) {
const newLoader = new SegmentLoader(LoaderCommonSettings.call(this, {
loaderType: 'main',
segmentMetadataTrack: this.segmentMetadataTrack,
Expand Down Expand Up @@ -296,6 +296,40 @@ QUnit.module('SegmentLoader: M2TS', function(hooks) {
);
});

QUnit.test('segmentKey will not cache encrypted keys with cacheEncryptionKeys false', function(assert) {
const newLoader = new SegmentLoader(LoaderCommonSettings.call(this, {
loaderType: 'main',
segmentMetadataTrack: this.segmentMetadataTrack,
cacheEncryptionKeys: false
}), {});

newLoader.playlist(playlistWithDuration(10), { isEncrypted: true });
newLoader.mimeType(this.mimeType);
newLoader.load();
this.clock.tick(1);

assert.strictEqual(
Object.keys(newLoader.keyCache_).length,
0,
'no keys have been cached'
);

newLoader.segmentKey(
{
resolvedUri: 'key.php',
bytes: new Uint32Array([1, 2, 3, 4])
},
// set = true
true
);

assert.strictEqual(
Object.keys(newLoader.keyCache_).length,
0,
'no keys have been cached since cacheEncryptionKeys is false'
);
});

QUnit.test('new segment requests will use cached keys', function(assert) {
const done = assert.async();
const newLoader = new SegmentLoader(LoaderCommonSettings.call(this, {
Expand Down Expand Up @@ -326,6 +360,8 @@ QUnit.module('SegmentLoader: M2TS', function(hooks) {
standardXHRResponse(this.requests.shift(), new Uint32Array([1, 5, 0, 1]));
this.clock.tick(1);

// As the Decrypter is in a web worker, the last function in SegmentLoader is
// the easiest way to listen for the decrypted response
const origHandleSegment = newLoader.handleSegment_.bind(newLoader);

newLoader.handleSegment_ = () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I must be missing something, but how/when does this function get called?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

answer, decrypt worker runs in webworker so its async

Expand Down
2 changes: 2 additions & 0 deletions test/videojs-http-streaming.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2315,6 +2315,8 @@ QUnit.test('keys are not requested when cached key available', function(assert)
this.standardXHRResponse(this.requests.shift());
this.clock.tick(1);

// As the Decrypter is in a web worker, the last function in SegmentLoader is
// the easiest way to listen for the decrypted response
const mainSegmentLoader = this.player.vhs.masterPlaylistController_.mainSegmentLoader_;
const origHandleSegment = mainSegmentLoader.handleSegment_;

Expand Down