Make sure buffer checks do not run after dispose()
Update a test case to verify that calls to fillBuffer() and drainBuffer() are not scheduled after the player has been disposed.
Showing
1 changed file
with
22 additions
and
4 deletions
... | @@ -26,6 +26,7 @@ var | ... | @@ -26,6 +26,7 @@ var |
26 | oldMediaSourceOpen, | 26 | oldMediaSourceOpen, |
27 | oldSegmentParser, | 27 | oldSegmentParser, |
28 | oldSetTimeout, | 28 | oldSetTimeout, |
29 | oldClearTimeout, | ||
29 | oldSourceBuffer, | 30 | oldSourceBuffer, |
30 | oldFlashSupported, | 31 | oldFlashSupported, |
31 | oldNativeHlsSupport, | 32 | oldNativeHlsSupport, |
... | @@ -146,6 +147,7 @@ module('HLS', { | ... | @@ -146,6 +147,7 @@ module('HLS', { |
146 | // store functionality that some tests need to mock | 147 | // store functionality that some tests need to mock |
147 | oldSegmentParser = videojs.Hls.SegmentParser; | 148 | oldSegmentParser = videojs.Hls.SegmentParser; |
148 | oldSetTimeout = window.setTimeout; | 149 | oldSetTimeout = window.setTimeout; |
150 | oldClearTimeout = window.clearTimeout; | ||
149 | 151 | ||
150 | oldNativeHlsSupport = videojs.Hls.supportsNativeHls; | 152 | oldNativeHlsSupport = videojs.Hls.supportsNativeHls; |
151 | 153 | ||
... | @@ -166,7 +168,6 @@ module('HLS', { | ... | @@ -166,7 +168,6 @@ module('HLS', { |
166 | }, | 168 | }, |
167 | 169 | ||
168 | teardown: function() { | 170 | teardown: function() { |
169 | player.dispose(); | ||
170 | videojs.Flash.isSupported = oldFlashSupported; | 171 | videojs.Flash.isSupported = oldFlashSupported; |
171 | videojs.MediaSource.open = oldMediaSourceOpen; | 172 | videojs.MediaSource.open = oldMediaSourceOpen; |
172 | videojs.Hls.SegmentParser = oldSegmentParser; | 173 | videojs.Hls.SegmentParser = oldSegmentParser; |
... | @@ -174,6 +175,8 @@ module('HLS', { | ... | @@ -174,6 +175,8 @@ module('HLS', { |
174 | videojs.Hls.decrypt = oldDecrypt; | 175 | videojs.Hls.decrypt = oldDecrypt; |
175 | videojs.SourceBuffer = oldSourceBuffer; | 176 | videojs.SourceBuffer = oldSourceBuffer; |
176 | window.setTimeout = oldSetTimeout; | 177 | window.setTimeout = oldSetTimeout; |
178 | window.clearTimeout = oldClearTimeout; | ||
179 | player.dispose(); | ||
177 | xhr.restore(); | 180 | xhr.restore(); |
178 | } | 181 | } |
179 | }); | 182 | }); |
... | @@ -463,10 +466,14 @@ test('dont downshift if bandwidth is low', function() { | ... | @@ -463,10 +466,14 @@ test('dont downshift if bandwidth is low', function() { |
463 | }); | 466 | }); |
464 | 467 | ||
465 | test('starts checking the buffer on init', function() { | 468 | test('starts checking the buffer on init', function() { |
466 | var player, i, length, callbacks = [], fills = 0, drains = 0; | 469 | var player, i, calls, callbacks = [], fills = 0, drains = 0; |
467 | // capture timeouts | 470 | // capture timeouts |
468 | window.setTimeout = function(callback) { | 471 | window.setTimeout = function(callback) { |
469 | callbacks.push(callback); | 472 | callbacks.push(callback); |
473 | return callbacks.length - 1; | ||
474 | }; | ||
475 | window.clearTimeout = function(index) { | ||
476 | callbacks[index] = Function.prototype; | ||
470 | }; | 477 | }; |
471 | 478 | ||
472 | player = createPlayer(); | 479 | player = createPlayer(); |
... | @@ -482,12 +489,23 @@ test('starts checking the buffer on init', function() { | ... | @@ -482,12 +489,23 @@ test('starts checking the buffer on init', function() { |
482 | }); | 489 | }); |
483 | ok(callbacks.length > 0, 'set timeouts'); | 490 | ok(callbacks.length > 0, 'set timeouts'); |
484 | 491 | ||
485 | for (i = 0, length = callbacks.length; i < length; i++) { | 492 | // run the initial set of callbacks. this should cause |
486 | callbacks[i](); | 493 | // fill/drainBuffer to be run |
494 | calls = callbacks.slice(); | ||
495 | for (i = 0; i < calls.length; i++) { | ||
496 | calls[i](); | ||
487 | } | 497 | } |
488 | equal(fills, 1, 'called fillBuffer'); | 498 | equal(fills, 1, 'called fillBuffer'); |
489 | equal(drains, 1, 'called drainBuffer'); | 499 | equal(drains, 1, 'called drainBuffer'); |
500 | |||
490 | player.dispose(); | 501 | player.dispose(); |
502 | // the remaining callbacks do not run any buffer checks | ||
503 | calls = callbacks.slice(); | ||
504 | for (i = 0; i < calls.length; i++) { | ||
505 | calls[i](); | ||
506 | } | ||
507 | equal(fills, 1, 'did not call fillBuffer again'); | ||
508 | equal(drains, 1, 'did not call drainBuffer again'); | ||
491 | }); | 509 | }); |
492 | 510 | ||
493 | test('buffer checks are noops until a media playlist is ready', function() { | 511 | test('buffer checks are noops until a media playlist is ready', function() { | ... | ... |
-
Please register or sign in to post a comment