Skip to content

Commit 1cb20c6

Browse files
committed
Tests: verify behaviour of Stream.getProcessors
- 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
1 parent 43e2f43 commit 1cb20c6

File tree

6 files changed

+67
-6
lines changed

6 files changed

+67
-6
lines changed

test/unit/helpers/ObjectsHelper.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ class ObjectsHelper {
4444
calcSegmentAvailabilityRange: () => { return {start: start, end: end};},
4545
isTimeSyncCompleted: () => {return true;},
4646
setExpectedLiveEdge: () => {},
47-
setRange: (range) => {start = range.start; end = range.end;}
47+
setRange: (range) => {start = range.start; end = range.end;},
48+
setTimeSyncCompleted: () => {}
4849
};
4950
}
5051

test/unit/mocks/AbrControllerMock.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ function AbrControllerMock () {
4343

4444
this.getAbandonmentStateFor = function () {};
4545

46-
this.getQualityForBitrate = function () {};
46+
this.getQualityForBitrate = function () {
47+
return this.QUALITY_DEFAULT();
48+
};
4749

4850
this.getBitrateList = function () {
4951
return [];

test/unit/mocks/AdapterMock.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ function AdapterMock () {
2121

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

2728
this.getDataForMedia = function () {

test/unit/mocks/MediaControllerMock.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ class MediaControllerMock {
2222
return this.tracks;
2323
}
2424

25-
getCurrentTrackFor() {
26-
return this.track;
25+
getCurrentTrackFor(type) {
26+
return this.track === undefined || this.track === null ? { codec: '', type } : this.track;
2727
}
2828

2929
/**

test/unit/mocks/TextControllerMock.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class TextControllerMock {
1515
this.textEnabled = state;
1616
}
1717
getTextDefaultEnabled() {
18-
return true;
18+
return false;
1919
}
2020
addEmbeddedTrack() {}
2121
}

test/unit/streaming.Stream.js

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import Errors from '../../src/core/errors/Errors';
99
import Settings from '../../src/core/Settings';
1010

1111
import AdapterMock from './mocks/AdapterMock';
12+
import BaseURLControllerMock from './mocks/BaseURLControllerMock';
1213
import ManifestModelMock from './mocks/ManifestModelMock';
1314
import ErrorHandlerMock from './mocks/ErrorHandlerMock';
1415
import AbrControllerMock from './mocks/AbrControllerMock';
@@ -45,6 +46,7 @@ describe('Stream', function () {
4546
const dashMetricsMock = new DashMetricsMock();
4647
const textControllerMock = new TextControllerMock();
4748
const videoModelMock = new VideoModelMock();
49+
const baseURLControllerMock = new BaseURLControllerMock();
4850
const timelineConverter = objectsHelper.getDummyTimelineConverter();
4951
const streamInfo = {
5052
id: 'id',
@@ -70,6 +72,7 @@ describe('Stream', function () {
7072
dashMetrics: dashMetricsMock,
7173
textController: textControllerMock,
7274
videoModel: videoModelMock,
75+
baseURLController: baseURLControllerMock,
7376
settings: settings});
7477
});
7578

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

96+
it('should return an array that does not include the streamProcessors for text and fragmented text when getProcessors is called and text is disabled', () => {
97+
// test-specific setup
98+
adapterMock.setRepresentation({
99+
adaptation: { period: { mpd: { manifest: { type: 'bar' } } } },
100+
hasInitialization: () => false,
101+
hasSegments: () => true,
102+
id: 'foo'
103+
});
104+
105+
stream.initialize(streamInfo, {});
106+
stream.activate(
107+
null,
108+
null
109+
);
110+
111+
// check textControllerMock is in correct state
112+
expect(textControllerMock.isTextEnabled()).to.be.false; // jshint ignore:line
113+
114+
// check assertions
115+
const processors = stream.getProcessors();
116+
expect(processors.length).to.be.equal(2); // jshint ignore:line
117+
expect(processors[0].getType()).to.be.equal('video'); // jshint ignore:line
118+
expect(processors[1].getType()).to.be.equal('audio'); // jshint ignore:line
119+
});
120+
121+
it('should return an array that includes the streamProcessors for text and fragmented text when getProcessors is called and text is enabled', () => {
122+
// test-specific setup
123+
adapterMock.setRepresentation({
124+
adaptation: { period: { mpd: { manifest: { type: 'bar' } } } },
125+
hasInitialization: () => false,
126+
hasSegments: () => true,
127+
id: 'foo'
128+
});
129+
130+
textControllerMock.enableText(true);
131+
132+
stream.initialize(streamInfo, {});
133+
stream.activate(
134+
null,
135+
null
136+
);
137+
138+
// check textControllerMock is in correct state
139+
expect(textControllerMock.isTextEnabled()).to.be.true; // jshint ignore:line
140+
141+
// check assertions
142+
const processors = stream.getProcessors();
143+
expect(processors.length).to.be.equal(4); // jshint ignore:line
144+
expect(processors[0].getType()).to.be.equal('video'); // jshint ignore:line
145+
expect(processors[1].getType()).to.be.equal('audio'); // jshint ignore:line
146+
expect(processors[2].getType()).to.be.equal('text'); // jshint ignore:line
147+
expect(processors[3].getType()).to.be.equal('fragmentedText'); // jshint ignore:line
148+
});
149+
93150
it('should trigger MANIFEST_ERROR_ID_NOSTREAMS_CODE error when setMediaSource is called but streamProcessors array is empty', () => {
94151
stream.setMediaSource();
95152
expect(errHandlerMock.errorCode).to.be.equal(Errors.MANIFEST_ERROR_ID_NOSTREAMS_CODE); // jshint ignore:line

0 commit comments

Comments
 (0)