Skip to content

Commit

Permalink
Tests: verify behaviour of Stream.getProcessors
Browse files Browse the repository at this point in the history
- existing test verifies that empty array of stream processors exists
when stream is not activated
- additional tests check that text and fragmented text processors are
returned by Stream.getProcessors _only_ when text is enabled via the
TextController
  • Loading branch information
03k64 committed Jul 29, 2020
1 parent 43e2f43 commit 1cb20c6
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 6 deletions.
3 changes: 2 additions & 1 deletion test/unit/helpers/ObjectsHelper.js
Expand Up @@ -44,7 +44,8 @@ class ObjectsHelper {
calcSegmentAvailabilityRange: () => { return {start: start, end: end};},
isTimeSyncCompleted: () => {return true;},
setExpectedLiveEdge: () => {},
setRange: (range) => {start = range.start; end = range.end;}
setRange: (range) => {start = range.start; end = range.end;},
setTimeSyncCompleted: () => {}
};
}

Expand Down
4 changes: 3 additions & 1 deletion test/unit/mocks/AbrControllerMock.js
Expand Up @@ -43,7 +43,9 @@ function AbrControllerMock () {

this.getAbandonmentStateFor = function () {};

this.getQualityForBitrate = function () {};
this.getQualityForBitrate = function () {
return this.QUALITY_DEFAULT();
};

this.getBitrateList = function () {
return [];
Expand Down
3 changes: 2 additions & 1 deletion test/unit/mocks/AdapterMock.js
Expand Up @@ -21,7 +21,8 @@ function AdapterMock () {

this.getAllMediaInfoForType = function () {
return [{codec: 'audio/mp4;codecs="mp4a.40.2"', id: undefined, index: 0, isText: false, lang: 'eng',mimeType: 'audio/mp4', roles: ['main']},
{codec: 'audio/mp4;codecs="mp4a.40.2"', id: undefined, index: 1, isText: false, lang: 'deu',mimeType: 'audio/mp4', roles: ['main']}];
{codec: 'audio/mp4;codecs="mp4a.40.2"', id: undefined, index: 1, isText: false, lang: 'deu',mimeType: 'audio/mp4', roles: ['main']},
{codec: 'audio/mp4;codecs="mp4a.40.2"', id: undefined, index: 2, isText: true, lang: 'eng',mimeType: 'audio/mp4', roles: ['main']}];
};

this.getDataForMedia = function () {
Expand Down
4 changes: 2 additions & 2 deletions test/unit/mocks/MediaControllerMock.js
Expand Up @@ -22,8 +22,8 @@ class MediaControllerMock {
return this.tracks;
}

getCurrentTrackFor() {
return this.track;
getCurrentTrackFor(type) {
return this.track === undefined || this.track === null ? { codec: '', type } : this.track;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion test/unit/mocks/TextControllerMock.js
Expand Up @@ -15,7 +15,7 @@ class TextControllerMock {
this.textEnabled = state;
}
getTextDefaultEnabled() {
return true;
return false;
}
addEmbeddedTrack() {}
}
Expand Down
57 changes: 57 additions & 0 deletions test/unit/streaming.Stream.js
Expand Up @@ -9,6 +9,7 @@ import Errors from '../../src/core/errors/Errors';
import Settings from '../../src/core/Settings';

import AdapterMock from './mocks/AdapterMock';
import BaseURLControllerMock from './mocks/BaseURLControllerMock';
import ManifestModelMock from './mocks/ManifestModelMock';
import ErrorHandlerMock from './mocks/ErrorHandlerMock';
import AbrControllerMock from './mocks/AbrControllerMock';
Expand Down Expand Up @@ -45,6 +46,7 @@ describe('Stream', function () {
const dashMetricsMock = new DashMetricsMock();
const textControllerMock = new TextControllerMock();
const videoModelMock = new VideoModelMock();
const baseURLControllerMock = new BaseURLControllerMock();
const timelineConverter = objectsHelper.getDummyTimelineConverter();
const streamInfo = {
id: 'id',
Expand All @@ -70,6 +72,7 @@ describe('Stream', function () {
dashMetrics: dashMetricsMock,
textController: textControllerMock,
videoModel: videoModelMock,
baseURLController: baseURLControllerMock,
settings: settings});
});

Expand All @@ -90,6 +93,60 @@ describe('Stream', function () {
expect(processors).to.be.empty; // jshint ignore:line
});

it('should return an array that does not include the streamProcessors for text and fragmented text when getProcessors is called and text is disabled', () => {
// test-specific setup
adapterMock.setRepresentation({
adaptation: { period: { mpd: { manifest: { type: 'bar' } } } },
hasInitialization: () => false,
hasSegments: () => true,
id: 'foo'
});

stream.initialize(streamInfo, {});
stream.activate(
null,
null
);

// check textControllerMock is in correct state
expect(textControllerMock.isTextEnabled()).to.be.false; // jshint ignore:line

// check assertions
const processors = stream.getProcessors();
expect(processors.length).to.be.equal(2); // jshint ignore:line
expect(processors[0].getType()).to.be.equal('video'); // jshint ignore:line
expect(processors[1].getType()).to.be.equal('audio'); // jshint ignore:line
});

it('should return an array that includes the streamProcessors for text and fragmented text when getProcessors is called and text is enabled', () => {
// test-specific setup
adapterMock.setRepresentation({
adaptation: { period: { mpd: { manifest: { type: 'bar' } } } },
hasInitialization: () => false,
hasSegments: () => true,
id: 'foo'
});

textControllerMock.enableText(true);

stream.initialize(streamInfo, {});
stream.activate(
null,
null
);

// check textControllerMock is in correct state
expect(textControllerMock.isTextEnabled()).to.be.true; // jshint ignore:line

// check assertions
const processors = stream.getProcessors();
expect(processors.length).to.be.equal(4); // jshint ignore:line
expect(processors[0].getType()).to.be.equal('video'); // jshint ignore:line
expect(processors[1].getType()).to.be.equal('audio'); // jshint ignore:line
expect(processors[2].getType()).to.be.equal('text'); // jshint ignore:line
expect(processors[3].getType()).to.be.equal('fragmentedText'); // jshint ignore:line
});

it('should trigger MANIFEST_ERROR_ID_NOSTREAMS_CODE error when setMediaSource is called but streamProcessors array is empty', () => {
stream.setMediaSource();
expect(errHandlerMock.errorCode).to.be.equal(Errors.MANIFEST_ERROR_ID_NOSTREAMS_CODE); // jshint ignore:line
Expand Down

0 comments on commit 1cb20c6

Please sign in to comment.