Fix tests for playlist blacklisting feature
Showing
2 changed files
with
39 additions
and
49 deletions
... | @@ -180,7 +180,7 @@ videojs.HlsHandler.prototype.src = function(src) { | ... | @@ -180,7 +180,7 @@ videojs.HlsHandler.prototype.src = function(src) { |
180 | }.bind(this)); | 180 | }.bind(this)); |
181 | 181 | ||
182 | this.playlists.on('error', function() { | 182 | this.playlists.on('error', function() { |
183 | this.blacklistCurrentPlaylist_(this.playlists.error.code); | 183 | this.blacklistCurrentPlaylist_(this.playlists.error); |
184 | }.bind(this)); | 184 | }.bind(this)); |
185 | 185 | ||
186 | this.playlists.on('loadedplaylist', function() { | 186 | this.playlists.on('loadedplaylist', function() { |
... | @@ -910,16 +910,26 @@ videojs.HlsHandler.prototype.setBandwidth = function(xhr) { | ... | @@ -910,16 +910,26 @@ videojs.HlsHandler.prototype.setBandwidth = function(xhr) { |
910 | }; | 910 | }; |
911 | 911 | ||
912 | videojs.HlsHandler.prototype.blacklistCurrentPlaylist_ = function(error) { | 912 | videojs.HlsHandler.prototype.blacklistCurrentPlaylist_ = function(error) { |
913 | var nextPlaylist; | 913 | var currentPlaylist, nextPlaylist; |
914 | 914 | ||
915 | // Blacklist this playlist | 915 | currentPlaylist = this.playlists.media(); |
916 | this.playlists.media().excludeUntil = Date.now() + blacklistDuration; | 916 | |
917 | // If there is no current playlist, then an error occurred while we were | ||
918 | // trying to load the master OR while we were disposing of the tech | ||
919 | if (!currentPlaylist) { | ||
920 | this.error = error; | ||
921 | return this.mediaSource.endOfStream('network'); | ||
922 | } | ||
917 | 923 | ||
918 | // Select a new playlist | 924 | // Select a new playlist |
919 | nextPlaylist = this.selectPlaylist(); | 925 | nextPlaylist = this.selectPlaylist(); |
920 | 926 | ||
921 | if (nextPlaylist) { | 927 | if (nextPlaylist) { |
922 | videojs.log.warn('Problem encountered with the current HLS playlist. Switching to another playlist.'); | 928 | videojs.log.warn('Problem encountered with the current HLS playlist. Switching to another playlist.'); |
929 | |||
930 | // Blacklist this playlist | ||
931 | currentPlaylist.excludeUntil = Date.now() + blacklistDuration; | ||
932 | |||
923 | return this.playlists.media(nextPlaylist); | 933 | return this.playlists.media(nextPlaylist); |
924 | } else { | 934 | } else { |
925 | videojs.log.warn('Problem encountered with the current HLS playlist. No suitable alternatives found.'); | 935 | videojs.log.warn('Problem encountered with the current HLS playlist. No suitable alternatives found.'); | ... | ... |
... | @@ -831,21 +831,6 @@ test('selects a playlist after segment downloads', function() { | ... | @@ -831,21 +831,6 @@ test('selects a playlist after segment downloads', function() { |
831 | strictEqual(calls, 3, 'selects after additional segments'); | 831 | strictEqual(calls, 3, 'selects after additional segments'); |
832 | }); | 832 | }); |
833 | 833 | ||
834 | test('reports an error if a segment is unreachable', function() { | ||
835 | player.src({ | ||
836 | src: 'manifest/master.m3u8', | ||
837 | type: 'application/vnd.apple.mpegurl' | ||
838 | }); | ||
839 | openMediaSource(player); | ||
840 | |||
841 | player.tech_.hls.bandwidth = 20000; | ||
842 | standardXHRResponse(requests[0]); // master | ||
843 | standardXHRResponse(requests[1]); // media | ||
844 | |||
845 | requests[2].respond(400); // segment | ||
846 | strictEqual(player.tech_.hls.mediaSource.error_, 'network', 'network error is triggered'); | ||
847 | }); | ||
848 | |||
849 | test('updates the duration after switching playlists', function() { | 834 | test('updates the duration after switching playlists', function() { |
850 | var selectedPlaylist = false; | 835 | var selectedPlaylist = false; |
851 | player.src({ | 836 | player.src({ |
... | @@ -1510,32 +1495,23 @@ test('playlist 404 should end stream with a network error', function() { | ... | @@ -1510,32 +1495,23 @@ test('playlist 404 should end stream with a network error', function() { |
1510 | equal(player.tech_.hls.mediaSource.error_, 'network', 'set a network error'); | 1495 | equal(player.tech_.hls.mediaSource.error_, 'network', 'set a network error'); |
1511 | }); | 1496 | }); |
1512 | 1497 | ||
1513 | test('segment 404 should trigger MEDIA_ERR_NETWORK', function () { | 1498 | test('segment 404 should trigger blacklisting of media', function () { |
1499 | var media; | ||
1500 | |||
1514 | player.src({ | 1501 | player.src({ |
1515 | src: 'manifest/media.m3u8', | 1502 | src: 'manifest/master.m3u8', |
1516 | type: 'application/vnd.apple.mpegurl' | 1503 | type: 'application/vnd.apple.mpegurl' |
1517 | }); | 1504 | }); |
1518 | |||
1519 | openMediaSource(player); | 1505 | openMediaSource(player); |
1520 | 1506 | ||
1521 | standardXHRResponse(requests[0]); | 1507 | player.tech_.hls.bandwidth = 20000; |
1522 | requests[1].respond(404); | 1508 | standardXHRResponse(requests[0]); // master |
1523 | ok(player.tech_.hls.error.message, 'an error message is available'); | 1509 | standardXHRResponse(requests[1]); // media |
1524 | equal(2, player.tech_.hls.error.code, 'Player error code should be set to MediaError.MEDIA_ERR_NETWORK'); | ||
1525 | }); | ||
1526 | |||
1527 | test('segment 500 should trigger MEDIA_ERR_ABORTED', function () { | ||
1528 | player.src({ | ||
1529 | src: 'manifest/media.m3u8', | ||
1530 | type: 'application/vnd.apple.mpegurl' | ||
1531 | }); | ||
1532 | 1510 | ||
1533 | openMediaSource(player); | 1511 | media = player.tech_.hls.playlists.media_; |
1534 | 1512 | ||
1535 | standardXHRResponse(requests[0]); | 1513 | requests[2].respond(400); // segment |
1536 | requests[1].respond(500); | 1514 | ok(media.excludeUntil > 0, 'original media blacklisted for some time'); |
1537 | ok(player.tech_.hls.error.message, 'an error message is available'); | ||
1538 | equal(4, player.tech_.hls.error.code, 'Player error code should be set to MediaError.MEDIA_ERR_ABORTED'); | ||
1539 | }); | 1515 | }); |
1540 | 1516 | ||
1541 | test('seeking in an empty playlist is a non-erroring noop', function() { | 1517 | test('seeking in an empty playlist is a non-erroring noop', function() { |
... | @@ -2458,8 +2434,8 @@ test('retries key requests once upon failure', function() { | ... | @@ -2458,8 +2434,8 @@ test('retries key requests once upon failure', function() { |
2458 | equal(requests.length, 2, 'gives up after one retry'); | 2434 | equal(requests.length, 2, 'gives up after one retry'); |
2459 | }); | 2435 | }); |
2460 | 2436 | ||
2461 | test('errors if key requests fail more than once', function() { | 2437 | test('blacklists playlist if key requests fail more than once', function() { |
2462 | var bytes = []; | 2438 | var bytes = [], media; |
2463 | 2439 | ||
2464 | player.src({ | 2440 | player.src({ |
2465 | src: 'https://example.com/encrypted-media.m3u8', | 2441 | src: 'https://example.com/encrypted-media.m3u8', |
... | @@ -2479,14 +2455,16 @@ test('errors if key requests fail more than once', function() { | ... | @@ -2479,14 +2455,16 @@ test('errors if key requests fail more than once', function() { |
2479 | player.tech_.hls.sourceBuffer.appendBuffer = function(chunk) { | 2455 | player.tech_.hls.sourceBuffer.appendBuffer = function(chunk) { |
2480 | bytes.push(chunk); | 2456 | bytes.push(chunk); |
2481 | }; | 2457 | }; |
2458 | |||
2459 | media = player.tech_.hls.playlists.media_; | ||
2460 | |||
2482 | standardXHRResponse(requests.pop()); // segment 1 | 2461 | standardXHRResponse(requests.pop()); // segment 1 |
2483 | requests.shift().respond(404); // fail key | 2462 | requests.shift().respond(404); // fail key |
2484 | requests.shift().respond(404); // fail key, again | 2463 | requests.shift().respond(404); // fail key, again |
2485 | player.tech_.hls.checkBuffer_(); | 2464 | player.tech_.hls.checkBuffer_(); |
2486 | 2465 | ||
2487 | equal(player.tech_.hls.mediaSource.error_, | 2466 | ok(media.excludeUntil > 0, |
2488 | 'network', | 2467 | 'playlist blacklisted'); |
2489 | 'triggered a network error'); | ||
2490 | }); | 2468 | }); |
2491 | 2469 | ||
2492 | test('the key is supplied to the decrypter in the correct format', function() { | 2470 | test('the key is supplied to the decrypter in the correct format', function() { |
... | @@ -2624,8 +2602,9 @@ test('resolves relative key URLs against the playlist', function() { | ... | @@ -2624,8 +2602,9 @@ test('resolves relative key URLs against the playlist', function() { |
2624 | equal(requests[0].url, 'https://example.com/key.php?r=52', 'resolves the key URL'); | 2602 | equal(requests[0].url, 'https://example.com/key.php?r=52', 'resolves the key URL'); |
2625 | }); | 2603 | }); |
2626 | 2604 | ||
2627 | test('treats invalid keys as a key request failure', function() { | 2605 | test('treats invalid keys as a key request failure and blacklists playlist', function() { |
2628 | var bytes = []; | 2606 | var bytes = [], media; |
2607 | |||
2629 | player.src({ | 2608 | player.src({ |
2630 | src: 'https://example.com/media.m3u8', | 2609 | src: 'https://example.com/media.m3u8', |
2631 | type: 'application/vnd.apple.mpegurl' | 2610 | type: 'application/vnd.apple.mpegurl' |
... | @@ -2644,6 +2623,8 @@ test('treats invalid keys as a key request failure', function() { | ... | @@ -2644,6 +2623,8 @@ test('treats invalid keys as a key request failure', function() { |
2644 | player.tech_.hls.sourceBuffer.appendBuffer = function(chunk) { | 2623 | player.tech_.hls.sourceBuffer.appendBuffer = function(chunk) { |
2645 | bytes.push(chunk); | 2624 | bytes.push(chunk); |
2646 | }; | 2625 | }; |
2626 | |||
2627 | media = player.tech_.hls.playlists.media_; | ||
2647 | // segment request | 2628 | // segment request |
2648 | standardXHRResponse(requests.pop()); | 2629 | standardXHRResponse(requests.pop()); |
2649 | // keys should be 16 bytes long | 2630 | // keys should be 16 bytes long |
... | @@ -2657,10 +2638,9 @@ test('treats invalid keys as a key request failure', function() { | ... | @@ -2657,10 +2638,9 @@ test('treats invalid keys as a key request failure', function() { |
2657 | requests.shift().respond(200, null, ''); | 2638 | requests.shift().respond(200, null, ''); |
2658 | player.tech_.hls.checkBuffer_(); | 2639 | player.tech_.hls.checkBuffer_(); |
2659 | 2640 | ||
2660 | // two failed attempts is a network error | 2641 | // two failed attempts is an error - blacklist this playlist |
2661 | equal(player.tech_.hls.mediaSource.error_, | 2642 | ok(media.excludeUntil > 0, |
2662 | 'network', | 2643 | 'blacklisted playlist'); |
2663 | 'triggered a network error'); | ||
2664 | }); | 2644 | }); |
2665 | 2645 | ||
2666 | test('live stream should not call endOfStream', function(){ | 2646 | test('live stream should not call endOfStream', function(){ | ... | ... |
-
Please register or sign in to post a comment