Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

first version for AbandonRequestsRule unit test #2074

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/streaming/rules/abr/AbandonRequestsRule.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,16 @@ function AbandonRequestsRule(config) {
}

function shouldAbandon(rulesContext) {
const switchRequest = SwitchRequest(context).create(SwitchRequest.NO_CHANGE, {name: AbandonRequestsRule.__dashjs_factory_name});

if (!rulesContext || !rulesContext.hasOwnProperty('getMediaInfo') || !rulesContext.hasOwnProperty('getMediaType') || !rulesContext.hasOwnProperty('getCurrentRequest') ||
!rulesContext.hasOwnProperty('getTrackInfo') || !rulesContext.hasOwnProperty('getAbrController')) {
return switchRequest;
}

const mediaInfo = rulesContext.getMediaInfo();
const mediaType = rulesContext.getMediaType();
const req = rulesContext.getCurrentRequest();
const switchRequest = SwitchRequest(context).create(SwitchRequest.NO_CHANGE, {name: AbandonRequestsRule.__dashjs_factory_name});

if (!isNaN(req.index)) {

Expand Down
76 changes: 76 additions & 0 deletions test/unit/streaming.rules.abr.AbandonRequestsRule.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import AbandonRequestsRule from '../../src/streaming/rules/abr/AbandonRequestsRule';
import FragmentRequest from '../../src/streaming/vo/FragmentRequest';

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

const context = {};

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() {};
}

class MetricsModelMock {
constructor() {
}

getReadOnlyMetricsFor(type) {
return null;
}
}

class DashMetricsMock {
constructor() {
}

getCurrentBufferLevel() {
return 15;
}
}

class MediaPlayerModelMock {
constructor() {
}

getStableBufferTime() {
return 10;
}

}

describe('AbandonRequestsRule', function () {
it("should return an empty switchRequest when shouldAbandon function is called with an empty parameter", function () {
const abandonRequestsRule = AbandonRequestsRule(context).create({});
const abandonRequest = abandonRequestsRule.shouldAbandon();

expect(abandonRequest.quality).to.be.equal(-1); // jshint ignore:line
});

it("should return an empty switchRequest when shouldAbandon function is called with a mock parameter", function () {
let rulesContextMock = new RulesContextMock();
let dashMetricsMock = new DashMetricsMock();
let metricsModelMock = new MetricsModelMock();
let mediaPlayerModelMock = new MediaPlayerModelMock();

const abandonRequestsRule = AbandonRequestsRule(context).create({metricsModel: metricsModelMock,
dashMetrics: dashMetricsMock,
mediaPlayerModel: mediaPlayerModelMock});


const abandonRequest = abandonRequestsRule.shouldAbandon(rulesContextMock);

expect(abandonRequest.quality).to.be.equal(-1); // jshint ignore:line
});
});