Skip to content

Commit

Permalink
new tests
Browse files Browse the repository at this point in the history
  • Loading branch information
joeyparrish committed Sep 13, 2022
1 parent 7773f6c commit 4288e48
Show file tree
Hide file tree
Showing 2 changed files with 105 additions and 0 deletions.
68 changes: 68 additions & 0 deletions test/hls/hls_live_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,74 @@ describe('HlsParser live', () => {
// Wait for stop to complete.
await stopPromise;
});

it('calls notifySegments on each update', async () => {
const manifest = await testInitialManifest(master, media);
const notifySegmentsSpy = spyOn(
manifest.presentationTimeline, 'notifySegments').and.callThrough();

// Trigger an update.
await delayForUpdatePeriod();

expect(notifySegmentsSpy).toHaveBeenCalled();
notifySegmentsSpy.calls.reset();

// Trigger another update.
await delayForUpdatePeriod();

expect(notifySegmentsSpy).toHaveBeenCalled();
});

it('converts to VOD only after all playlists end', async () => {
const master = [
'#EXTM3U\n',
'#EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID="aud1",LANGUAGE="eng",',
'URI="audio"\n',
'#EXT-X-STREAM-INF:BANDWIDTH=200,CODECS="avc1",AUDIO="aud1",',
'RESOLUTION=960x540,FRAME-RATE=60\n',
'video\n',
].join('');

const mediaWithEndList = media + '#EXT-X-ENDLIST';

const manifest = await testInitialManifest(master, media);
expect(manifest.presentationTimeline.isLive()).toBe(true);

// Update video only.
fakeNetEngine.setResponseText('test:/video', mediaWithEndList);
await delayForUpdatePeriod();

// Audio hasn't "ended" yet, so we're still live.
expect(manifest.presentationTimeline.isLive()).toBe(true);

// Update audio.
fakeNetEngine.setResponseText('test:/audio', mediaWithEndList);
await delayForUpdatePeriod();

// Now both have "ended", so we're no longer live.
expect(manifest.presentationTimeline.isLive()).toBe(false);
});

it('stops updating after all playlists end', async () => {
const manifest = await testInitialManifest(master, media);
expect(manifest.presentationTimeline.isLive()).toBe(true);

fakeNetEngine.request.calls.reset();
await testUpdate(
manifest, mediaWithAdditionalSegment + '#EXT-X-ENDLIST\n');

// We saw one request for the video playlist, which signalled "ENDLIST".
fakeNetEngine.expectRequest(
'test:/video',
shaka.net.NetworkingEngine.RequestType.MANIFEST);
expect(manifest.presentationTimeline.isLive()).toBe(false);

fakeNetEngine.request.calls.reset();
await delayForUpdatePeriod();

// No new updates were requested.
expect(fakeNetEngine.request).toHaveBeenCalledTimes(0);
});
}); // describe('update')
}); // describe('playlist type EVENT')

Expand Down
37 changes: 37 additions & 0 deletions test/media/media_source_engine_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -1003,6 +1003,43 @@ describe('MediaSourceEngine', () => {
expect(audioSourceBuffer.appendBuffer).toHaveBeenCalledWith(buffer);
audioSourceBuffer.updateend();
});

it('allows duration to be shrunk', async () => {
// Pretend the initial duration was 100.
mockMediaSource.durationGetter.and.returnValue(100);

// When duration is shrunk, 'updateend' events are generated. This is
// because reducing the duration triggers the MSE removal algorithm to
// run.
mockMediaSource.durationSetter.and.callFake((duration) => {
expect(duration).toBe(50);
videoSourceBuffer.updateend();
audioSourceBuffer.updateend();
});

audioSourceBuffer.appendBuffer.and.callFake(() => {
audioSourceBuffer.updateend();
});
videoSourceBuffer.appendBuffer.and.callFake(() => {
videoSourceBuffer.updateend();
});

/** @type {!Promise} */
const p1 = mediaSourceEngine.setDuration(50);
expect(mockMediaSource.durationSetter).not.toHaveBeenCalled();

// These operations should be blocked until after duration is shrunk.
// This is tested because shrinking duration generates 'updateend'
// events, and we want to show that the queue still operates correctly.
const a1 = mediaSourceEngine.appendBuffer(ContentType.AUDIO, buffer, null,
/* hasClosedCaptions= */ false);
const a2 = mediaSourceEngine.appendBuffer(ContentType.VIDEO, buffer, null,
/* hasClosedCaptions= */ false);

await p1;
await a1;
await a2;
});
});

describe('destroy', () => {
Expand Down

0 comments on commit 4288e48

Please sign in to comment.