-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
152 additions
and
120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,170 +1,179 @@ | ||
import DashAdapter from '../../src/dash/DashAdapter'; | ||
import MediaInfo from '../../src/streaming/vo/MediaInfo'; | ||
|
||
import MediaInfo from '../../src/dash/vo/MediaInfo'; | ||
import Constants from '../../src/streaming/constants/Constants'; | ||
import DashManifestModel from '../../src/dash/models/DashManifestModel'; | ||
|
||
import DashManifestModelMock from './mocks/DashManifestModelMock'; | ||
import VoHelper from './helpers/VOHelper'; | ||
|
||
const expect = require('chai').expect; | ||
|
||
const context = {}; | ||
const dashManifestModelMock = new DashManifestModelMock(); | ||
const voHelper = new VoHelper(); | ||
const dashAdapter = DashAdapter(context).getInstance(); | ||
dashAdapter.setConfig({ | ||
dashManifestModel: dashManifestModelMock | ||
}); | ||
|
||
describe('DashAdapter', function () { | ||
describe('SetConfig not previously called', function () { | ||
|
||
it('should return the first adaptation when getAdaptationForType is called and streamInfo is undefined', () => { | ||
const manifest = { Period_asArray: [{ AdaptationSet_asArray: [{ id: 0, mimeType: 'video' }, { id: 1, mimeType: 'video' }] }] }; | ||
const adaptation = dashAdapter.getAdaptationForType(manifest, 0, 'video'); | ||
it('should throw an exception when attempting to call getStreamsInfo While the setConfig function was not called, and externalManifest parameter is defined', function () { | ||
expect(dashAdapter.getStreamsInfo.bind(dashAdapter,{})).to.throw('setConfig function has to be called previously'); | ||
}); | ||
|
||
expect(adaptation.id).to.equal(0); // jshint ignore:line | ||
}); | ||
it('should throw an exception when attempting to call getAllMediaInfoForType While the setConfig function was not called, and externalManifest parameter is defined', function () { | ||
expect(dashAdapter.getAllMediaInfoForType.bind(dashAdapter, null, null, {})).to.throw('setConfig function has to be called previously'); | ||
}); | ||
|
||
it('should return the correct adaptation when getAdaptationForType is called', () => { | ||
const manifest = { Period_asArray: [{ AdaptationSet_asArray: [{ id: undefined, mimeType: 'audio', lang: 'eng', Role_asArray: [{ value: 'main' }] }, { id: undefined, mimeType: 'audio', lang: 'deu', Role_asArray: [{ value: 'main' }] }] }] }; | ||
it('should return an empty array when getEventsFor is called and voPeriods is an empty array', function () { | ||
dashAdapter.reset(); | ||
const eventsArray = dashAdapter.getEventsFor(); | ||
|
||
const streamInfo = { | ||
id: 'id' | ||
}; | ||
expect(eventsArray).to.be.instanceOf(Array); // jshint ignore:line | ||
expect(eventsArray).to.be.empty; // jshint ignore:line | ||
}); | ||
|
||
const track = new MediaInfo(); | ||
it('should return an empty array when getAllMediaInfoForType is called and voPeriods is an empty array', function () { | ||
const mediaInfoArray = dashAdapter.getAllMediaInfoForType(); | ||
|
||
track.id = undefined; | ||
track.index = 1; | ||
track.streamInfo = streamInfo; | ||
track.representationCount = 0; | ||
track.lang = 'deu'; | ||
track.roles = ['main']; | ||
track.codec = 'audio/mp4;codecs="mp4a.40.2"'; | ||
track.mimeType = 'audio/mp4'; | ||
expect(mediaInfoArray).to.be.instanceOf(Array); // jshint ignore:line | ||
expect(mediaInfoArray).to.be.empty; // jshint ignore:line | ||
}); | ||
|
||
dashAdapter.setCurrentMediaInfo(streamInfo.id, 'audio', track); | ||
it('should return null when updatePeriods is called and newManifest is undefined', function () { | ||
const returnValue = dashAdapter.updatePeriods(); | ||
|
||
const adaptation = dashAdapter.getAdaptationForType(manifest, 0, 'audio', streamInfo); | ||
expect(returnValue).to.be.null; // jshint ignore:line | ||
}); | ||
|
||
expect(adaptation.lang).to.equal('eng'); // jshint ignore:line | ||
}); | ||
it('should throw an error when updatePeriods is called and newManifest parameter is defined, while setConfig has not been called', function () { | ||
expect(dashAdapter.updatePeriods.bind(dashAdapter,{})).to.be.throw('setConfig function has to be called previously'); | ||
}); | ||
|
||
it('should throw an exception when attempting to call getStreamsInfo While the setConfig function was not called, and externalManifest parameter is defined', function () { | ||
expect(dashAdapter.getStreamsInfo.bind(dashAdapter,{})).to.throw('setConfig function has to be called previously'); | ||
}); | ||
it('should return null when getMediaInfoForType is called and voPeriods is an empty array', function () { | ||
const mediaInfo = dashAdapter.getMediaInfoForType(); | ||
|
||
it('should throw an exception when attempting to call getAllMediaInfoForType While the setConfig function was not called, and externalManifest parameter is defined', function () { | ||
expect(dashAdapter.getAllMediaInfoForType.bind(dashAdapter, null, null, {})).to.throw('setConfig function has to be called previously'); | ||
}); | ||
expect(mediaInfo).to.be.null; // jshint ignore:line | ||
}); | ||
|
||
it('should return an empty array when getEventsFor is called and voPeriods is an empty array', function () { | ||
dashAdapter.reset(); | ||
const eventsArray = dashAdapter.getEventsFor(); | ||
it('should return null when getDataForMedia is called and voPeriods is an empty array, mediaInfo parameter is undefined', function () { | ||
const adaptation = dashAdapter.getDataForMedia(); | ||
|
||
expect(eventsArray).to.be.instanceOf(Array); // jshint ignore:line | ||
expect(eventsArray).to.be.empty; // jshint ignore:line | ||
}); | ||
expect(adaptation).to.be.null; // jshint ignore:line | ||
}); | ||
|
||
it('should return an empty array when getAllMediaInfoForType is called and voPeriods is an empty array', function () { | ||
const mediaInfoArray = dashAdapter.getAllMediaInfoForType(); | ||
it('should return null when getDataForMedia is called and voPeriods is an empty array, mediaInfo parameter is an empty object', function () { | ||
const adaptation = dashAdapter.getDataForMedia({}); | ||
|
||
expect(mediaInfoArray).to.be.instanceOf(Array); // jshint ignore:line | ||
expect(mediaInfoArray).to.be.empty; // jshint ignore:line | ||
}); | ||
expect(adaptation).to.be.null; // jshint ignore:line | ||
}); | ||
|
||
it('should return null when updatePeriods is called and newManifest is undefined', function () { | ||
const returnValue = dashAdapter.updatePeriods(); | ||
it('should return null when getEvent is called and no parameter is set', function () { | ||
const event = dashAdapter.getEvent(); | ||
|
||
expect(returnValue).to.be.null; // jshint ignore:line | ||
}); | ||
expect(event).to.be.null; // jshint ignore:line | ||
}); | ||
|
||
it('should throw an error when updatePeriods is called and newManifest parameter is defined, while setConfig has not been called', function () { | ||
expect(dashAdapter.updatePeriods.bind(dashAdapter,{})).to.be.throw('setConfig function has to be called previously'); | ||
}); | ||
it('should return null when getEvent is called and an empty eventBox parameter is set and eventStreams is undefined', function () { | ||
const event = dashAdapter.getEvent({}); | ||
|
||
it('should return null when getMediaInfoForType is called and voPeriods is an empty array', function () { | ||
const mediaInfo = dashAdapter.getMediaInfoForType(); | ||
expect(event).to.be.null; // jshint ignore:line | ||
}); | ||
|
||
expect(mediaInfo).to.be.null; // jshint ignore:line | ||
}); | ||
it('should return null when getEvent is called and an empty eventBox and eventStreams parameters are set', function () { | ||
const event = dashAdapter.getEvent({}, []); | ||
|
||
it('should return null when getDataForMedia is called and voPeriods is an empty array, mediaInfo parameter is undefined', function () { | ||
const adaptation = dashAdapter.getDataForMedia(); | ||
expect(event).to.be.null; // jshint ignore:line | ||
}); | ||
|
||
expect(adaptation).to.be.null; // jshint ignore:line | ||
}); | ||
it('should return an empty event object when getEvent is called and eventBox and eventStreams parameters are set', function () { | ||
const event = dashAdapter.getEvent({scheme_id_uri: 'id', value: 'value'}, {'id/value': {}}); | ||
|
||
it('should return null when getDataForMedia is called and voPeriods is an empty array, mediaInfo parameter is an empty object', function () { | ||
const adaptation = dashAdapter.getDataForMedia({}); | ||
expect(event).to.be.an('object'); | ||
}); | ||
|
||
expect(adaptation).to.be.null; // jshint ignore:line | ||
}); | ||
|
||
it('should return null when getEvent is called and no parameter is set', function () { | ||
const event = dashAdapter.getEvent(); | ||
it('should return undefined when getRealAdaptation is called and streamInfo parameter is null or undefined', function () { | ||
const realAdaptation = dashAdapter.getRealAdaptation(null,voHelper.getDummyMediaInfo('video')); | ||
|
||
expect(event).to.be.null; // jshint ignore:line | ||
}); | ||
expect(realAdaptation).to.be.undefined; // jshint ignore:line | ||
}); | ||
|
||
it('should return null when getEvent is called and an empty eventBox parameter is set and eventStreams is undefined', function () { | ||
const event = dashAdapter.getEvent({}); | ||
it('should return undefined when getRealAdaptation is called and mediaInfo parameter is null or undefined', function () { | ||
const realAdaptation = dashAdapter.getRealAdaptation(voHelper.getDummyStreamInfo(), null); | ||
|
||
expect(event).to.be.null; // jshint ignore:line | ||
expect(realAdaptation).to.be.undefined; // jshint ignore:line | ||
}); | ||
}); | ||
|
||
it('should return null when getEvent is called and an empty eventBox and eventStreams parameters are set', function () { | ||
const event = dashAdapter.getEvent({}, []); | ||
describe('SetConfig previously called', function () { | ||
it('should return undefined when getVoRepresentations is called and mediaInfo parameter is null or undefined', function () { | ||
dashAdapter.setConfig({dashManifestModel: new DashManifestModelMock()}); | ||
const voRepresentations = dashAdapter.getVoRepresentations(); | ||
|
||
expect(event).to.be.null; // jshint ignore:line | ||
}); | ||
expect(voRepresentations).to.be.instanceOf(Array); // jshint ignore:line | ||
expect(voRepresentations).to.be.empty; // jshint ignore:line | ||
}); | ||
|
||
it('should return an empty event object when getEvent is called and eventBox and eventStreams parameters are set', function () { | ||
const event = dashAdapter.getEvent({scheme_id_uri: 'id', value: 'value'}, {'id/value': {}}); | ||
it('should return null when getBandwidthForRepresentation is called and representationId and periodId are undefined', () => { | ||
dashAdapter.setConfig({dashManifestModel: new DashManifestModelMock()}); | ||
dashAdapter.updatePeriods({}); | ||
const bdwth = dashAdapter.getBandwidthForRepresentation(); | ||
|
||
expect(event).to.be.an('object'); | ||
}); | ||
expect(bdwth).to.be.null; // jshint ignore:line | ||
}); | ||
|
||
it('should return undefined when getRealAdaptation is called and streamInfo parameter is null or undefined', function () { | ||
const realAdaptation = dashAdapter.getRealAdaptation(null,voHelper.getDummyMediaInfo('video')); | ||
it('should return -1 when getIndexForRepresentation is called and representationId and periodIdx are undefined', () => { | ||
dashAdapter.setConfig({dashManifestModel: new DashManifestModelMock()}); | ||
dashAdapter.updatePeriods({}); | ||
const index = dashAdapter.getIndexForRepresentation(); | ||
|
||
expect(realAdaptation).to.be.undefined; // jshint ignore:line | ||
}); | ||
expect(index).to.be.equal(-1); // jshint ignore:line | ||
}); | ||
|
||
it('should return undefined when getRealAdaptation is called and mediaInfo parameter is null or undefined', function () { | ||
const realAdaptation = dashAdapter.getRealAdaptation(voHelper.getDummyStreamInfo(), null); | ||
it('should return -1 when getMaxIndexForBufferType is called and bufferType and periodIdx are undefined', () => { | ||
dashAdapter.setConfig({dashManifestModel: new DashManifestModelMock()}); | ||
dashAdapter.updatePeriods({}); | ||
const index = dashAdapter.getMaxIndexForBufferType(); | ||
|
||
expect(realAdaptation).to.be.undefined; // jshint ignore:line | ||
}); | ||
expect(index).to.be.equal(-1); // jshint ignore:line | ||
}); | ||
|
||
it('should return undefined when getVoRepresentations is called and mediaInfo parameter is null or undefined', function () { | ||
dashAdapter.setConfig({dashManifestModel: new DashManifestModelMock()}); | ||
const voRepresentations = dashAdapter.getVoRepresentations(); | ||
it('should return the first adaptation when getAdaptationForType is called and streamInfo is undefined', () => { | ||
dashAdapter.setConfig({ | ||
dashManifestModel: DashManifestModel(context).getInstance(), | ||
constants: Constants | ||
}); | ||
const manifest = { loadedTime: new Date(), mediaPresentationDuration: 10, Period_asArray: [{ AdaptationSet_asArray: [{ id: 0, mimeType: 'video' }, { id: 1, mimeType: 'video' }] }] }; | ||
dashAdapter.updatePeriods(manifest); | ||
const adaptation = dashAdapter.getAdaptationForType(0, 'video'); | ||
|
||
expect(voRepresentations).to.be.instanceOf(Array); // jshint ignore:line | ||
expect(voRepresentations).to.be.empty; // jshint ignore:line | ||
}); | ||
expect(adaptation.id).to.equal(0); // jshint ignore:line | ||
}); | ||
|
||
it('should return null when getBandwidthForRepresentation is called and representationId and periodId are undefined', () => { | ||
dashAdapter.setConfig({dashManifestModel: new DashManifestModelMock()}); | ||
dashAdapter.updatePeriods({}); | ||
const bdwth = dashAdapter.getBandwidthForRepresentation(); | ||
it('should return the correct adaptation when getAdaptationForType is called', () => { | ||
const manifest = { loadedTime: new Date(), mediaPresentationDuration: 10, Period_asArray: [{ AdaptationSet_asArray: [{ id: undefined, mimeType: 'audio', lang: 'eng', Role_asArray: [{ value: 'main' }] }, { id: undefined, mimeType: 'audio', lang: 'deu', Role_asArray: [{ value: 'main' }] }] }] }; | ||
dashAdapter.setConfig({ | ||
dashManifestModel: DashManifestModel(context).getInstance(), | ||
constants: Constants | ||
}); | ||
const streamInfo = { | ||
id: 'id' | ||
}; | ||
|
||
expect(bdwth).to.be.null; // jshint ignore:line | ||
}); | ||
const track = new MediaInfo(); | ||
|
||
it('should return -1 when getIndexForRepresentation is called and representationId and periodIdx are undefined', () => { | ||
dashAdapter.setConfig({dashManifestModel: new DashManifestModelMock()}); | ||
dashAdapter.updatePeriods({}); | ||
const index = dashAdapter.getIndexForRepresentation(); | ||
|
||
expect(index).to.be.equal(-1); // jshint ignore:line | ||
}); | ||
track.id = undefined; | ||
track.index = 1; | ||
track.streamInfo = streamInfo; | ||
track.representationCount = 0; | ||
track.lang = 'deu'; | ||
track.roles = ['main']; | ||
track.codec = 'audio/mp4;codecs="mp4a.40.2"'; | ||
track.mimeType = 'audio/mp4'; | ||
|
||
it('should return -1 when getMaxIndexForBufferType is called and bufferType and periodIdx are undefined', () => { | ||
dashAdapter.setConfig({dashManifestModel: new DashManifestModelMock()}); | ||
dashAdapter.updatePeriods({}); | ||
const index = dashAdapter.getMaxIndexForBufferType(); | ||
dashAdapter.setCurrentMediaInfo(streamInfo.id, 'audio', track); | ||
dashAdapter.updatePeriods(manifest); | ||
const adaptation = dashAdapter.getAdaptationForType(0, 'audio', streamInfo); | ||
|
||
expect(index).to.be.equal(-1); // jshint ignore:line | ||
expect(adaptation.lang).to.equal('eng'); // jshint ignore:line | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters