c51f8a1b by bc-bbay Committed by Brandon Bay

Updates for unit tests

1 parent be19a03e
...@@ -248,6 +248,10 @@ videojs.Hls.prototype.src = function(src) { ...@@ -248,6 +248,10 @@ videojs.Hls.prototype.src = function(src) {
248 the current time to go along with it. 248 the current time to go along with it.
249 */ 249 */
250 videojs.Hls.getMediaIndexForLive = function(selectedPlaylist) { 250 videojs.Hls.getMediaIndexForLive = function(selectedPlaylist) {
251 if (!selectedPlaylist.segments) {
252 return 0;
253 }
254
251 var tailIterator = selectedPlaylist.segments.length, 255 var tailIterator = selectedPlaylist.segments.length,
252 tailDuration = 0, 256 tailDuration = 0,
253 targetTail = (selectedPlaylist.targetDuration || 10) * 3; 257 targetTail = (selectedPlaylist.targetDuration || 10) * 3;
...@@ -287,7 +291,7 @@ videojs.Hls.prototype.play = function() { ...@@ -287,7 +291,7 @@ videojs.Hls.prototype.play = function() {
287 this.mediaIndex = 0; 291 this.mediaIndex = 0;
288 } 292 }
289 293
290 if (this.playlists.media() && !this.player_.hasClass('vjs-has-started')) { 294 if (this.playlists.media() && !this.player().hasClass('vjs-has-started')) {
291 this.mediaIndex = videojs.Hls.getMediaIndexForLive(this.playlists.media()); 295 this.mediaIndex = videojs.Hls.getMediaIndexForLive(this.playlists.media());
292 this.setCurrentTime(this.getCurrentTimeByMediaIndex(this.playlists.media(), this.mediaIndex)); 296 this.setCurrentTime(this.getCurrentTimeByMediaIndex(this.playlists.media(), this.mediaIndex));
293 } 297 }
......
...@@ -1259,9 +1259,13 @@ test('live playlist starts with correct currentTime value', function() { ...@@ -1259,9 +1259,13 @@ test('live playlist starts with correct currentTime value', function() {
1259 standardXHRResponse(requests[0]); 1259 standardXHRResponse(requests[0]);
1260 1260
1261 player.hls.playlists.trigger('loadedmetadata'); 1261 player.hls.playlists.trigger('loadedmetadata');
1262 player.hasClass = function(classname) {
1263 return player.el().classList.contains(classname);
1264 }
1265
1262 player.hls.play(); 1266 player.hls.play();
1263 1267
1264 strictEqual(player.currentTime(), 60, 'currentTime is updated at playback'); 1268 strictEqual(player.currentTime(), 70, 'currentTime is updated at playback');
1265 }); 1269 });
1266 1270
1267 test('mediaIndex is zero before the first segment loads', function() { 1271 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() { ...@@ -1735,6 +1739,11 @@ test('calling play() at the end of a video resets the media index', function() {
1735 player.hls.ended = function() { 1739 player.hls.ended = function() {
1736 return true; 1740 return true;
1737 }; 1741 };
1742
1743 player.hasClass = function(classname) {
1744 return player.el().classList.contains(classname);
1745 }
1746
1738 player.play(); 1747 player.play();
1739 strictEqual(player.hls.mediaIndex, 0, 'index is 1 after the first segment'); 1748 strictEqual(player.hls.mediaIndex, 0, 'index is 1 after the first segment');
1740 }); 1749 });
......