Skip to content

Commit

Permalink
Add audio track loading tests (video-dev#1969)
Browse files Browse the repository at this point in the history
* Put imports at the top of module body

* Add tests for AUDIO_TRACK_LOADING depending on track.url
  • Loading branch information
robwalch authored and johnBartos committed Nov 1, 2018
1 parent 1671c91 commit 3352ba5
Showing 1 changed file with 61 additions and 0 deletions.
61 changes: 61 additions & 0 deletions tests/unit/controller/audio-track-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import AudioTrackController from '../../../src/controller/audio-track-controller
import Hls from '../../../src/hls';

const assert = require('assert');
const sinon = require('sinon');

describe('AudioTrackController', () => {
const tracks = [{
Expand Down Expand Up @@ -187,6 +188,66 @@ describe('AudioTrackController', () => {
// name is still the same
assert.strictEqual(tracks[audioTrackController.audioTrack].name, audioTrackName);
});

it('should load audio tracks with a url', () => {
const needsTrackLoading = sinon.spy(audioTrackController, '_needsTrackLoading');
const audioTrackLoadingCallback = sinon.spy();
const trackWithUrl = {
groupId: '1',
id: 0,
name: 'A',
default: true,
url: './trackA.m3u8'
};

hls.on(Hls.Events.AUDIO_TRACK_LOADING, audioTrackLoadingCallback);

hls.levelController = {
levels: [{
urlId: 0,
audioGroupIds: ['1']
}]
};

audioTrackController.tracks = [trackWithUrl];

audioTrackController.onLevelLoaded({
level: 0
});

sinon.assert.calledOnce(needsTrackLoading);
sinon.assert.calledWith(needsTrackLoading, trackWithUrl);
assert.strictEqual(needsTrackLoading.firstCall.returnValue, true, 'expected _needsTrackLoading to return true');

sinon.assert.calledOnce(audioTrackLoadingCallback);
});

it('should not attempt to load audio tracks without a url', () => {
const needsTrackLoading = sinon.spy(audioTrackController, '_needsTrackLoading');
const audioTrackLoadingCallback = sinon.spy();
const trackWithOutUrl = tracks[0];

hls.on(Hls.Events.AUDIO_TRACK_LOADING, audioTrackLoadingCallback);

hls.levelController = {
levels: [{
urlId: 0,
audioGroupIds: ['1']
}]
};

audioTrackController.tracks = tracks;

audioTrackController.onLevelLoaded({
level: 0
});

sinon.assert.calledOnce(needsTrackLoading);
sinon.assert.calledWith(needsTrackLoading, trackWithOutUrl);
assert.strictEqual(needsTrackLoading.firstCall.returnValue, false, 'expected _needsTrackLoading to return false');

sinon.assert.notCalled(audioTrackLoadingCallback);
});
});

describe('onError', () => {
Expand Down

0 comments on commit 3352ba5

Please sign in to comment.