81a1caac by bc-bbay

Updates for unit tests

1 parent 6da9fd14
......@@ -248,6 +248,10 @@ videojs.Hls.prototype.src = function(src) {
the current time to go along with it.
*/
videojs.Hls.getMediaIndexForLive = function(selectedPlaylist) {
if (!selectedPlaylist.segments) {
return 0;
}
var tailIterator = selectedPlaylist.segments.length,
tailDuration = 0,
targetTail = (selectedPlaylist.targetDuration || 10) * 3;
......@@ -287,7 +291,7 @@ videojs.Hls.prototype.play = function() {
this.mediaIndex = 0;
}
if (this.playlists.media() && !this.player_.hasClass('vjs-has-started')) {
if (this.playlists.media() && !this.player().hasClass('vjs-has-started')) {
this.mediaIndex = videojs.Hls.getMediaIndexForLive(this.playlists.media());
this.setCurrentTime(this.getCurrentTimeByMediaIndex(this.playlists.media(), this.mediaIndex));
}
......
......@@ -1259,9 +1259,13 @@ test('live playlist starts with correct currentTime value', function() {
standardXHRResponse(requests[0]);
player.hls.playlists.trigger('loadedmetadata');
player.hasClass = function(classname) {
return player.el().classList.contains(classname);
}
player.hls.play();
strictEqual(player.currentTime(), 60, 'currentTime is updated at playback');
strictEqual(player.currentTime(), 70, 'currentTime is updated at playback');
});
test('mediaIndex is zero before the first segment loads', function() {
......@@ -1735,6 +1739,11 @@ test('calling play() at the end of a video resets the media index', function() {
player.hls.ended = function() {
return true;
};
player.hasClass = function(classname) {
return player.el().classList.contains(classname);
}
player.play();
strictEqual(player.hls.mediaIndex, 0, 'index is 1 after the first segment');
});
......