Skip to content

Commit

Permalink
Add unit tests for getAverageThroughput
Browse files Browse the repository at this point in the history
  • Loading branch information
Axel Delmas committed Jun 28, 2017
1 parent bb9dea9 commit 6a3973c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
5 changes: 5 additions & 0 deletions test/unit/mocks/AbrControllerMock.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class AbrControllerMock{
this.limitBitrateByPortal = false;
this.usePixelRatioInLimitBitrateByPortal = false;
this.autoSwitchBitrate = {video: true, audio: true};
this.throughputHistory = undefined;
}

initialize() {}
Expand Down Expand Up @@ -164,6 +165,10 @@ class AbrControllerMock{

}

getThroughputHistory() {
return this.throughputHistory;
}

updateTopQualityIndex() {}

isPlayingAtTopQuality() {}
Expand Down
18 changes: 17 additions & 1 deletion test/unit/streaming.MediaPlayerSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ describe("MediaPlayer", function () {

});

describe("AutoBitrate Functions", function () {
describe("AbrController Functions", function () {
afterEach(function () {
abrControllerMock.reset();
})
Expand Down Expand Up @@ -457,6 +457,22 @@ describe("MediaPlayer", function () {
expect(AutoSwitchBitrateFor).to.be.false;
});

it("Method getAverageThroughput should return 0 when throughputHistory is not set up", function() {
const averageThroughput = player.getAverageThroughput('video');
expect(averageThroughput).to.equal(0);
});

it("Method getAverageThroughput should value computed from ThroughputHistory", function() {
const AVERAGE_THROUGHPUT = 2000;
abrControllerMock.throughputHistory = {
getAverageThroughput: function() {
return AVERAGE_THROUGHPUT;
}
};
const averageThroughput = player.getAverageThroughput('video');
expect(averageThroughput).to.equal(AVERAGE_THROUGHPUT);
});

describe("When it is not initialized", function () {
it("Method getQualityFor should throw an exception", function () {
expect(player.getQualityFor).to.throw(PLAYBACK_NOT_INITIALIZED_ERROR);
Expand Down

0 comments on commit 6a3973c

Please sign in to comment.