Skip to content

Commit

Permalink
Merge pull request #2138 from Orange-OpenSource/UpdateUnitTests
Browse files Browse the repository at this point in the history
Update unit tests
  • Loading branch information
Dan Sparacio committed Aug 18, 2017
2 parents 6f0e8ef + f468fdb commit eb6c694
Show file tree
Hide file tree
Showing 38 changed files with 709 additions and 813 deletions.
13 changes: 13 additions & 0 deletions src/dash/utils/TimelineSegmentsGetter.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,21 @@ function TimelineSegmentsGetter(config, isDynamic) {

let instance;

function checkConfig() {
if (!timelineConverter || !timelineConverter.hasOwnProperty('calcMediaTimeFromPresentationTime') || !timelineConverter.hasOwnProperty('calcSegmentAvailabilityRange') ||
!timelineConverter.hasOwnProperty('calcMediaTimeFromPresentationTime')) {
throw new Error('Missing config parameter(s)');
}
}

function getSegmentsFromTimeline(representation, requestedTime, index, availabilityUpperLimit) {

checkConfig();

if (!representation) {
throw new Error('no representation');
}

if (requestedTime === undefined) {
requestedTime = null;
}
Expand Down
2 changes: 1 addition & 1 deletion src/streaming/text/TextBufferController.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ function TextBufferController(config) {
});
} else {

// in this case, internal buffer controller is a not fragmented text controller object
// in this case, internal buffer controller is a not fragmented text controller object
_BufferControllerImpl = NotFragmentedTextBufferController(context).create({
type: config.type,
errHandler: config.errHandler,
Expand Down
20 changes: 20 additions & 0 deletions test/unit/dash.utils.TimelineSegmentsGetter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import TimelineSegmentsGetter from '../../src/dash/utils/TimelineSegmentsGetter';
import TimelineConverter from '../../src/dash/utils/TimelineConverter';

const expect = require('chai').expect;

describe("TimelineSegmentsGetter", function () {
const context = {};
let timelineSegmentsGetter = TimelineSegmentsGetter(context).create({});

it("should throw an error if config object has not been properly passed", function () {
expect(timelineSegmentsGetter.getSegments.bind(timelineSegmentsGetter)).to.be.throw('Missing config parameter(s)');
});

it("should throw an error if representation parameter has not been properly set", function () {
let timelineConverter = TimelineConverter(context).getInstance();
timelineSegmentsGetter = TimelineSegmentsGetter(context).create({timelineConverter: timelineConverter});

expect(timelineSegmentsGetter.getSegments.bind(timelineSegmentsGetter)).to.be.throw('no representation');
});
});
33 changes: 33 additions & 0 deletions test/unit/data/subtitles/vttSample.vtt
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
WEBVTT
1
00:00:15.042 --> 00:00:18.042
At the <c.red.caps>left</c> we can see...

2
00:00:18.167 --> 00:00:20.083
<c.red.caps>At the right we can see the...</c>

3
00:00:20.083 --> 00:00:22.000
...the head-snarlers.

4
00:00:22.000 --> 00:00:24.417
Everything is safe. Perfectly safe.

5
00:00:24.583 --> 00:00:27.083
Emo ? Emo!

6
00:00:28.208 --> 00:00:30.042
Watch out!

7
00:00:46.642 --> 00:00:48.250
Are you hurt?

8
00:00:52.000 --> 00:00:54.000
I don't think so. You?
12 changes: 12 additions & 0 deletions test/unit/mocks/AdapterMock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class AdapterMock {
constructor() {
this.metricsList = {
BUFFER_STATE: 'BUFFER_STATE'
};
}
getEventsFor() {
return null;
}
}

export default AdapterMock;
10 changes: 10 additions & 0 deletions test/unit/mocks/DashManifestModelMock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class DashManifestModelMock {

constructor() {}

getIsTextTrack() {
return false;
}
}

export default DashManifestModelMock;
14 changes: 14 additions & 0 deletions test/unit/mocks/DashMetricsMock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class DashMetricsMock {
constructor() {
}

getCurrentDVRInfo() {
return null;
}

getCurrentBufferLevel() {
return 15;
}
}

export default DashMetricsMock;
26 changes: 26 additions & 0 deletions test/unit/mocks/DomStorageMock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
class DomStorageMock {
constructor() {
this.mediaSettings = {};
}

getSavedMediaSettings(type) {
if (this.mediaSettings[type]) {
return this.mediaSettings[type];
}
return null;
}

setSavedMediaSettings(type, settings) {

if (!settings) {
return;
}
if (!this.mediaSettings[type]) {
this.mediaSettings[type] = {};
}

this.mediaSettings[type] = settings;
}
}

export default DomStorageMock;
13 changes: 13 additions & 0 deletions test/unit/mocks/ErrorHandlerMock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
function ErrorHandlerMock() {
this.error = undefined;

this.manifestError = function(error) {
this.error = error;
};

this.mediaSourceError = function(error) {
this.error = error;
};
}

export default ErrorHandlerMock;
11 changes: 11 additions & 0 deletions test/unit/mocks/ManifestModelMock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class ManifestModelMock {
constructor() {
this.manifestValue = 0;
}

getValue() {
return this.manifestValue;
}
}

export default ManifestModelMock;
25 changes: 25 additions & 0 deletions test/unit/mocks/ManifestUpdaterMock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
class ManifestLoaderMock {
constructor() {
this.loadManifest = false;
}

getLoadManifest() {
return false;
}

load() {
this.loadManifest = true;
}
}

class ManifestUpdaterMock {
constructor() {
this.manifestLoader = new ManifestLoaderMock();
}

getManifestLoader() {
return this.manifestLoader;
}
}

export default ManifestUpdaterMock;
56 changes: 56 additions & 0 deletions test/unit/mocks/MediaSourceBufferMock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
class TimeRangesMock {
constructor() {
this.ranges = [];
this.length = this.ranges.length;
}

start(index) {
return this.ranges[index] ? this.ranges[index].start : null;
}
end(index) {
return this.ranges[index] ? this.ranges[index].end : null;
}

addRange(range) {
this.ranges.push(range);
this.length = this.ranges.length;
}
}
class MediaSourceBufferMock {
constructor() {
this.buffered = new TimeRangesMock();
this.updating = false;
this.chunk = null;
this.aborted = false;
}

addRange(range) {
this.buffered.addRange(range);
}

remove() {
this.updating = true;
this.chunk = null;

let that = this;
setTimeout(function() {
that.updating = false;
}, 500);
}

append(chunk) {
this.updating = true;
this.chunk = chunk;

let that = this;
setTimeout(function() {
that.updating = false;
}, 500);
}

abort() {
this.aborted = true;
}
}

export default MediaSourceBufferMock;
34 changes: 34 additions & 0 deletions test/unit/mocks/MediaSourceMock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import MediaSourceBufferMock from './MediaSourceBufferMock';

class MediaSourceMock {
constructor() {
this.buffers = [];
this.readyState = 'open';
}

addSourceBuffer(codec) {
if (codec.match(/text/i)) {
throw new Error('not really supported');
}

if (codec.match(/unknown/i)) {
throw new Error('unknown');
}

let buffer = new MediaSourceBufferMock();
this.buffers.push(buffer);
return buffer;
}

removeSourceBuffer(buffer) {
let index = this.buffers.indexOf(buffer);

if (index === -1) {
return;
}

this.buffers.splice(index, 1);
}
}

export default MediaSourceMock;
19 changes: 19 additions & 0 deletions test/unit/mocks/MetricsModelMock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
class MetricsModelMock {
constructor() {
this.bufferState = 0;
this.bufferLevel = 0;
}
addBufferState(type, bufferState, bufferTarget) {
this.bufferState = bufferState;
}

addBufferLevel(type, date, bufferLevel ) {
this.bufferState = bufferLevel;
}

getReadOnlyMetricsFor() {
return null;
}
}

export default MetricsModelMock;
20 changes: 20 additions & 0 deletions test/unit/mocks/RulesContextMock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import FragmentRequest from '../../../src/streaming/vo/FragmentRequest';

function RulesContextMock () {
this.getMediaInfo = function() {

};
this.getMediaType = function() {
return 'video';
};
this.getCurrentRequest = function() {
let fragRequest = new FragmentRequest();
fragRequest.index = 1;

return fragRequest;
};
this.getTrackInfo = function() {};
this.getAbrController = function() {};
}

export default RulesContextMock;
Loading

0 comments on commit eb6c694

Please sign in to comment.