/
Streaming.StreamProcessor.js
96 lines (78 loc) · 3.77 KB
/
Streaming.StreamProcessor.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import StreamProcessor from '../../src/streaming/StreamProcessor';
import Constants from '../../src/streaming/constants/Constants';
import EventBus from '../../src/core/EventBus';
import Events from '../../src/core/events/Events';
import ObjectsHelper from './helpers/ObjectsHelper';
import DashMetricsMock from './mocks/DashMetricsMock';
import ManifestModelMock from './mocks/ManifestModelMock';
import PlaybackControllerMock from './mocks/PlaybackControllerMock';
import AbrControllerMock from './mocks/AbrControllerMock';
import AdapterMock from './mocks/AdapterMock';
const expect = require('chai').expect;
const testType = 'video';
const objectsHelper = new ObjectsHelper();
const context = {};
const dashMetricsMock = new DashMetricsMock();
const manifestModelMock = new ManifestModelMock();
const timelineConverterMock = objectsHelper.getDummyTimelineConverter();
const playbackControllerMock = new PlaybackControllerMock();
const abrControllerMock = new AbrControllerMock();
const adapterMock = new AdapterMock();
const eventBus = EventBus(context).getInstance();
const streamInfo = {
id: 'streamId',
manifestInfo: {
isDynamic: true
}
};
describe('StreamProcessor', function () {
describe('StreamProcessor not initialized', function () {
let streamProcessor = null;
beforeEach(function () {
streamProcessor = StreamProcessor(context).create({});
});
afterEach(function () {
streamProcessor.reset();
});
it('getIndexHandlerTime should return NaN', function () {
const time = streamProcessor.getIndexHandlerTime();
expect(time).to.be.NaN; // jshint ignore:line
});
it('setIndexHandlerTime should not throw an error', function () {
expect(streamProcessor.setIndexHandlerTime.bind(streamProcessor)).to.not.throw();
});
it('getInitRequest should return null', function () {
const initRequest = streamProcessor.getInitRequest(0);
expect(initRequest).to.be.null; // jshint ignore:line
});
it('getInitRequest should throw an error when quality is not a number', function () {
expect(streamProcessor.getInitRequest.bind(streamProcessor, {})).to.be.throw(Constants.BAD_ARGUMENT_ERROR + ' : argument is not an integer');
});
it('getFragmentRequest should return null', function () {
const nextFragRequest = streamProcessor.getFragmentRequest();
expect(nextFragRequest).to.be.null; // jshint ignore:line
});
it('getRepresentationInfo should throw an error when quality is not a number', function () {
expect(streamProcessor.getRepresentationInfo.bind(streamProcessor, {})).to.be.throw(Constants.BAD_ARGUMENT_ERROR + ' : argument is not an integer');
});
});
it('when a BUFFER_LEVEL_UPDATED event occurs, should update dvr info metrics', function () {
const streamProcessor = StreamProcessor(context).create({
streamInfo: streamInfo,
type: testType,
dashMetrics: dashMetricsMock,
manifestModel: manifestModelMock,
playbackController: playbackControllerMock,
timelineConverter: timelineConverterMock,
abrController: abrControllerMock,
adapter: adapterMock
});
streamProcessor.initialize();
let dvrInfo = dashMetricsMock.getCurrentDVRInfo();
expect(dvrInfo).to.be.null; // jshint ignore:line
eventBus.trigger(Events.BUFFER_LEVEL_UPDATED, { streamId: streamInfo.id, mediaType: testType, bufferLevel: 50 });
dvrInfo = dashMetricsMock.getCurrentDVRInfo();
expect(dvrInfo).not.to.be.null; // jshint ignore:line
expect(dvrInfo.type).to.equal(testType); // jshint ignore:line
});
});