255cb612 by David LaPalomento

Merge pull request #9 from videojs/bugfix/seek-test

Add a basic seek test case
2 parents 1c5e8c3e 652095a1
...@@ -24,6 +24,7 @@ var ...@@ -24,6 +24,7 @@ var
24 player, 24 player,
25 oldFlashSupported, 25 oldFlashSupported,
26 oldXhr, 26 oldXhr,
27 oldSegmentParser,
27 oldSourceBuffer, 28 oldSourceBuffer,
28 oldSupportsNativeHls, 29 oldSupportsNativeHls,
29 xhrUrls; 30 xhrUrls;
...@@ -58,6 +59,9 @@ module('HLS', { ...@@ -58,6 +59,9 @@ module('HLS', {
58 return videojs.createTimeRange(0, 0); 59 return videojs.createTimeRange(0, 0);
59 }; 60 };
60 61
62 // store the SegmentParser so it can be easily mocked
63 oldSegmentParser = videojs.hls.SegmentParser;
64
61 // make XHR synchronous 65 // make XHR synchronous
62 oldXhr = window.XMLHttpRequest; 66 oldXhr = window.XMLHttpRequest;
63 window.XMLHttpRequest = function() { 67 window.XMLHttpRequest = function() {
...@@ -83,7 +87,8 @@ module('HLS', { ...@@ -83,7 +87,8 @@ module('HLS', {
83 teardown: function() { 87 teardown: function() {
84 videojs.Flash.isSupported = oldFlashSupported; 88 videojs.Flash.isSupported = oldFlashSupported;
85 videojs.hls.supportsNativeHls = oldSupportsNativeHls; 89 videojs.hls.supportsNativeHls = oldSupportsNativeHls;
86 window.videojs.SourceBuffer = oldSourceBuffer; 90 videojs.hls.SegmentParser = oldSegmentParser;
91 videojs.SourceBuffer = oldSourceBuffer;
87 window.XMLHttpRequest = oldXhr; 92 window.XMLHttpRequest = oldXhr;
88 } 93 }
89 }); 94 });
...@@ -635,6 +640,80 @@ test('cancels outstanding XHRs when seeking', function() { ...@@ -635,6 +640,80 @@ test('cancels outstanding XHRs when seeking', function() {
635 strictEqual(1, opened, 'opened new XHR'); 640 strictEqual(1, opened, 'opened new XHR');
636 }); 641 });
637 642
643 test('flushes the parser after each segment', function() {
644 var flushes = 0;
645 // mock out the segment parser
646 videojs.hls.SegmentParser = function() {
647 this.getFlvHeader = function() {
648 return [];
649 };
650 this.parseSegmentBinaryData = function() {};
651 this.flushTags = function() {
652 flushes++;
653 };
654 this.tagsAvailable = function() {};
655 };
656
657 player.hls('manifest/media.m3u8');
658 videojs.mediaSources[player.currentSrc()].trigger({
659 type: 'sourceopen'
660 });
661
662 strictEqual(1, flushes, 'tags are flushed at the end of a segment');
663 });
664
665 test('drops tags before the target timestamp when seeking', function() {
666 var
667 i = 10,
668 segment = [],
669 tags = [],
670 bytes = [];
671
672 // mock out the parser and source buffer
673 videojs.hls.SegmentParser = function() {
674 this.getFlvHeader = function() {
675 return [];
676 };
677 this.parseSegmentBinaryData = function() {};
678 this.flushTags = function() {};
679 this.tagsAvailable = function() {
680 return tags.length;
681 };
682 this.getTags = function() {
683 return tags;
684 };
685 this.getNextTag = function() {
686 return tags.shift();
687 };
688 };
689 window.videojs.SourceBuffer = function() {
690 this.appendBuffer = function(chunk) {
691 bytes.push(chunk);
692 };
693 };
694
695 player.hls('manifest/media.m3u8');
696 videojs.mediaSources[player.currentSrc()].trigger({
697 type: 'sourceopen'
698 });
699
700 // build up some mock FLV tags
701 while (i--) {
702 segment.unshift({
703 pts: i * 1000,
704 bytes: i
705 });
706 }
707 tags = segment.slice();
708 bytes = [];
709 player.currentTime = function() {
710 return 7;
711 };
712 player.trigger('seeking');
713
714 deepEqual([7,8,9], bytes, 'three tags are appended');
715 });
716
638 test('playlist 404 should trigger MEDIA_ERR_NETWORK', function() { 717 test('playlist 404 should trigger MEDIA_ERR_NETWORK', function() {
639 var errorTriggered = false; 718 var errorTriggered = false;
640 719
......