forked from Dash-Industry-Forum/dash.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstreaming.AbrControllerSpec.js
92 lines (71 loc) · 4 KB
/
streaming.AbrControllerSpec.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
import SpecHelper from './helpers/SpecHelper';
import VoHelper from './helpers/VOHelper';
import AbrController from '../src/streaming/controllers/AbrController';
const expect = require('chai').expect;
describe("AbrController", function () {
const context = {};
const testType = 'video';
const voHelper = new VoHelper();
const defaultQuality = AbrController.QUALITY_DEFAULT;
const abrCtrl = AbrController(context).getInstance();
const dummyMediaInfo = voHelper.getDummyMediaInfo('video');
const representationCount = dummyMediaInfo.representationCount;
it("should update top quality index", function () {
const expectedTopQuality = representationCount - 1;
let actualTopQuality;
actualTopQuality = abrCtrl.updateTopQualityIndex(dummyMediaInfo);
expect(actualTopQuality).to.be.equal(expectedTopQuality);
});
it("should set a quality in a range between zero and a top quality index", function () {
const testQuality = 1;
let newQuality;
abrCtrl.setPlaybackQuality(testType, dummyMediaInfo.streamInfo, testQuality);
newQuality = abrCtrl.getQualityFor(testType, dummyMediaInfo.streamInfo);
expect(newQuality).to.be.equal(testQuality);
});
it("should throw an exception when attempting to set not a number value for a quality", function () {
let testQuality = 'a';
expect(abrCtrl.setPlaybackQuality.bind(abrCtrl, testType, dummyMediaInfo.streamInfo, testQuality)).to.throw("argument is not an integer");
testQuality = null;
expect(abrCtrl.setPlaybackQuality.bind(abrCtrl, testType, dummyMediaInfo.streamInfo, testQuality)).to.throw("argument is not an integer");
testQuality = 2.5;
expect(abrCtrl.setPlaybackQuality.bind(abrCtrl, testType, dummyMediaInfo.streamInfo, testQuality)).to.throw("argument is not an integer");
testQuality = {};
expect(abrCtrl.setPlaybackQuality.bind(abrCtrl, testType, dummyMediaInfo.streamInfo, testQuality)).to.throw("argument is not an integer");
});
it("should ignore an attempt to set a negative quality value", function () {
const negativeQuality = -1;
const oldQuality = abrCtrl.getQualityFor(testType, dummyMediaInfo.streamInfo);
let newQuality;
abrCtrl.setPlaybackQuality(testType, dummyMediaInfo.streamInfo, negativeQuality);
newQuality = abrCtrl.getQualityFor(testType, dummyMediaInfo.streamInfo);
expect(newQuality).to.be.equal(oldQuality);
});
it("should ignore an attempt to set a quality greater than top quality index", function () {
const greaterThanTopQualityValue = representationCount;
const oldQuality = abrCtrl.getQualityFor(testType, dummyMediaInfo.streamInfo);
let newQuality;
abrCtrl.setPlaybackQuality(testType, dummyMediaInfo.streamInfo, greaterThanTopQualityValue);
newQuality = abrCtrl.getQualityFor(testType, dummyMediaInfo.streamInfo);
expect(newQuality).to.be.equal(oldQuality);
});
it("should restore a default quality value after reset", function () {
const testQuality = 1;
let newQuality;
abrCtrl.setPlaybackQuality(testType, dummyMediaInfo.streamInfo, testQuality);
abrCtrl.reset();
newQuality = abrCtrl.getQualityFor(testType, dummyMediaInfo.streamInfo);
expect(newQuality).to.be.equal(defaultQuality);
});
it("should compose a list of available bitrates", function () {
const expectedBitrates = dummyMediaInfo.bitrateList;
const actualBitrates = abrCtrl.getBitrateList(dummyMediaInfo);
let item,
match;
match = expectedBitrates.filter(function(val, idx) {
item = actualBitrates[idx];
return (item && (item.qualityIndex === idx) && (item.bitrate === val.bandwidth) && (item.mediaType === dummyMediaInfo.type) && (item.width === val.width) && (item.height === val.height));
});
expect(match.length).to.be.equal(expectedBitrates.length);
});
});