mediasource-liveseekable.html (6252B)
1 <!DOCTYPE html> 2 <!-- Copyright © 2016 Chromium authors and World Wide Web Consortium, (Massachusetts Institute of Technology, ERCIM, Keio University, Beihang). --> 3 <meta charset="utf-8"> 4 <title>Checks setting/clearing the live seekable range and HTMLMediaElement.seekable</title> 5 <script src="/resources/testharness.js"></script> 6 <script src="/resources/testharnessreport.js"></script> 7 <script src="mediasource-util.js"></script> 8 <script> 9 test(function(test) 10 { 11 var mediaSource = new MediaSource(); 12 assert_equals(mediaSource.readyState, "closed", "media source is closed."); 13 assert_throws_dom("InvalidStateError", function() { mediaSource.setLiveSeekableRange(0, 1); }); 14 }, "setLiveSeekableRange throws an InvalidStateError exception if the readyState attribute is not 'open'"); 15 16 17 test(function(test) 18 { 19 var mediaSource = new MediaSource(); 20 assert_equals(mediaSource.readyState, "closed", "media source is closed."); 21 assert_throws_dom("InvalidStateError", function() { mediaSource.clearLiveSeekableRange(); }); 22 }, "clearLiveSeekableRange throws an InvalidStateError exception if the readyState attribute is not 'open'"); 23 24 25 mediasource_test(function(test, mediaElement, mediaSource) 26 { 27 mediaElement.addEventListener('error', test.unreached_func("Unexpected event 'error'")); 28 var mimetype = MediaSourceUtil.AUDIO_VIDEO_TYPE; 29 var sourceBuffer = mediaSource.addSourceBuffer(mimetype); 30 sourceBuffer.appendBuffer(new Uint8Array(0)); 31 assert_true(sourceBuffer.updating, "Updating set when a buffer is appended."); 32 mediaSource.setLiveSeekableRange(0, 1); 33 test.done(); 34 }, "setLiveSeekableRange does not restrict to not currently updating"); 35 36 37 mediasource_test(function(test, mediaElement, mediaSource) 38 { 39 mediaElement.addEventListener('error', test.unreached_func("Unexpected event 'error'")); 40 var mimetype = MediaSourceUtil.AUDIO_VIDEO_TYPE; 41 var sourceBuffer = mediaSource.addSourceBuffer(mimetype); 42 sourceBuffer.appendBuffer(new Uint8Array(0)); 43 assert_true(sourceBuffer.updating, "Updating set when a buffer is appended."); 44 mediaSource.clearLiveSeekableRange(); 45 test.done(); 46 }, "clearLiveSeekableRange does not restrict to not currently updating"); 47 48 49 mediasource_test(function(test, mediaElement, mediaSource) 50 { 51 mediaElement.addEventListener('error', test.unreached_func("Unexpected event 'error'")); 52 assert_throws_js(TypeError, function() { mediaSource.setLiveSeekableRange(-1, 1); }); 53 test.done(); 54 }, "setLiveSeekableRange throws a TypeError if start is negative"); 55 56 57 mediasource_test(function(test, mediaElement, mediaSource) 58 { 59 mediaElement.addEventListener('error', test.unreached_func("Unexpected event 'error'")); 60 assert_throws_js(TypeError, function() { mediaSource.setLiveSeekableRange(2, 1); }); 61 test.done(); 62 }, "setLiveSeekableRange throws a TypeError if start is greater than end"); 63 64 65 mediasource_test(function(test, mediaElement, mediaSource) 66 { 67 mediaElement.addEventListener('error', test.unreached_func("Unexpected event 'error'")); 68 mediaSource.setLiveSeekableRange(0, 1); 69 test.done(); 70 }, "setLiveSeekableRange returns with no error when conditions are correct"); 71 72 73 mediasource_test(function(test, mediaElement, mediaSource) 74 { 75 mediaElement.addEventListener('error', test.unreached_func("Unexpected event 'error'")); 76 mediaSource.clearLiveSeekableRange(); 77 test.done(); 78 }, "clearLiveSeekableRange returns with no error when conditions are correct"); 79 80 81 mediasource_test(function(test, mediaElement, mediaSource) 82 { 83 mediaSource.duration = +Infinity; 84 mediaSource.setLiveSeekableRange(1, 2); 85 assert_equals(mediaElement.seekable.length, 1, 86 'The seekable attribute contains a single range.'); 87 assertSeekableEquals(mediaElement, '{ [1.000, 2.000) }', 88 'The seekable attribute returns the correct range.'); 89 90 mediaSource.clearLiveSeekableRange(); 91 assertSeekableEquals(mediaElement, '{ }', 92 'The seekable attribute now returns an empty range.'); 93 test.done(); 94 }, "HTMLMediaElement.seekable returns the live seekable range or an empty range if that range was cleared when nothing is buffered"); 95 96 97 mediasource_testafterdataloaded(function(test, mediaElement, mediaSource, segmentInfo, sourceBuffer, mediaData) 98 { 99 var initSegment = MediaSourceUtil.extractSegmentData(mediaData, segmentInfo.init); 100 test.expectEvent(sourceBuffer, 'updateend', 'Init segment appended to SourceBuffer.'); 101 sourceBuffer.appendBuffer(initSegment); 102 test.waitForExpectedEvents(function() 103 { 104 mediaSource.duration = +Infinity; 105 mediaSource.setLiveSeekableRange(40, 42); 106 107 // Append a segment that starts after 1s to ensure seekable 108 // won't use 0 as starting point. 109 var midSegment = MediaSourceUtil.extractSegmentData(mediaData, segmentInfo.media[5]); 110 test.expectEvent(sourceBuffer, 'updateend'); 111 sourceBuffer.appendBuffer(midSegment); 112 test.waitForExpectedEvents(function() 113 { 114 assert_equals(mediaElement.seekable.length, 1, 115 'The seekable attribute contains a single range.'); 116 assert_equals(mediaElement.buffered.length, 1, 117 'The buffered attribute contains a single range.'); 118 assert_not_equals(mediaElement.seekable.start(0), 0, 119 'The range starts after 0.'); 120 assert_equals(mediaElement.seekable.start(0), mediaElement.buffered.start(0), 121 'The start time is the start time of the buffered range.'); 122 assert_equals(mediaElement.seekable.end(0), 42, 123 'The end time is the end time of the seekable range.'); 124 125 mediaSource.clearLiveSeekableRange(); 126 assert_equals(mediaElement.seekable.length, 1, 127 'The seekable attribute contains a single range.'); 128 assert_equals(mediaElement.seekable.start(0), 0, 129 'The start time is now 0.'); 130 assert_equals(mediaElement.seekable.end(0), mediaElement.buffered.end(0), 131 'The end time is now the end time of the buffered range.'); 132 133 test.done(); 134 }); 135 }); 136 }, 'HTMLMediaElement.seekable returns the union of the buffered range and the live seekable range, when set'); 137 </script>