Add test and null segementXhr in dispose
Showing
2 changed files
with
36 additions
and
0 deletions
... | @@ -237,6 +237,7 @@ videojs.Hls.prototype.dispose = function() { | ... | @@ -237,6 +237,7 @@ videojs.Hls.prototype.dispose = function() { |
237 | if (this.segmentXhr_) { | 237 | if (this.segmentXhr_) { |
238 | this.segmentXhr_.onreadystatechange = null; | 238 | this.segmentXhr_.onreadystatechange = null; |
239 | this.segmentXhr_.abort(); | 239 | this.segmentXhr_.abort(); |
240 | this.segmentXhr_ = null; | ||
240 | } | 241 | } |
241 | if (keyXhr) { | 242 | if (keyXhr) { |
242 | keyXhr.onreadystatechange = null; | 243 | keyXhr.onreadystatechange = null; | ... | ... |
... | @@ -710,6 +710,41 @@ test('cancels outstanding XHRs when seeking', function() { | ... | @@ -710,6 +710,41 @@ test('cancels outstanding XHRs when seeking', function() { |
710 | strictEqual(requests.length, 3, 'opened new XHR'); | 710 | strictEqual(requests.length, 3, 'opened new XHR'); |
711 | }); | 711 | }); |
712 | 712 | ||
713 | test('when outstanding XHRs are cancelled, they get aborted properly', function() { | ||
714 | var readystatechanges = 0; | ||
715 | |||
716 | player.src({ | ||
717 | src: 'manifest/media.m3u8', | ||
718 | type: 'application/vnd.apple.mpegurl' | ||
719 | }); | ||
720 | openMediaSource(player); | ||
721 | standardXHRResponse(requests[0]); | ||
722 | player.hls.media = { | ||
723 | segments: [{ | ||
724 | uri: '0.ts', | ||
725 | duration: 10 | ||
726 | }, { | ||
727 | uri: '1.ts', | ||
728 | duration: 10 | ||
729 | }] | ||
730 | }; | ||
731 | |||
732 | // trigger a segment download request | ||
733 | player.trigger('timeupdate'); | ||
734 | |||
735 | player.hls.segmentXhr_.onreadystatechange = function() { | ||
736 | readystatechanges++; | ||
737 | }; | ||
738 | |||
739 | // attempt to seek while the download is in progress | ||
740 | player.currentTime(12); | ||
741 | |||
742 | ok(requests[1].aborted, 'XHR aborted'); | ||
743 | strictEqual(requests.length, 3, 'opened new XHR'); | ||
744 | notEqual(player.hls.segmentXhr_.url, requests[1].url, 'the segment xhr is nulled out'); | ||
745 | strictEqual(readystatechanges, 0, 'onreadystatechange was not called'); | ||
746 | }); | ||
747 | |||
713 | test('flushes the parser after each segment', function() { | 748 | test('flushes the parser after each segment', function() { |
714 | var flushes = 0; | 749 | var flushes = 0; |
715 | // mock out the segment parser | 750 | // mock out the segment parser | ... | ... |
-
Please register or sign in to post a comment