tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

mediasource-endofstream.html (3544B)


      1 <!DOCTYPE html>
      2 <meta charset="utf-8">
      3 <title>Calls to MediaSource.endOfStream() without error</title>
      4 <script src="/resources/testharness.js"></script>
      5 <script src="/resources/testharnessreport.js"></script>
      6 <script src="mediasource-util.js"></script>
      7 <script>
      8    mediasource_test(function(test, mediaElement, mediaSource)
      9    {
     10        mediaSource.duration = 2;
     11        mediaSource.endOfStream();
     12        assert_equals(mediaSource.duration, 0);
     13        test.done();
     14    }, 'MediaSource.endOfStream(): duration truncated to 0 when there are no buffered coded frames');
     15 
     16    mediasource_testafterdataloaded(function(test, mediaElement, mediaSource, segmentInfo, sourceBuffer, mediaData)
     17    {
     18        sourceBuffer.appendBuffer(mediaData);
     19        test.expectEvent(sourceBuffer, 'updateend',
     20          'Media buffer appended to SourceBuffer');
     21        test.waitForExpectedEvents(function()
     22        {
     23            mediaSource.endOfStream();
     24            test.expectEvent(mediaElement, 'canplaythrough',
     25              'Media element may render the media content until the end');
     26        });
     27 
     28        test.waitForExpectedEvents(function()
     29        {
     30            assert_equals(mediaElement.readyState, HTMLMediaElement.HAVE_ENOUGH_DATA,
     31              'Media element has enough data to render the content');
     32            test.done();
     33        });
     34    }, 'MediaSource.endOfStream(): media element notified that it now has all of the media data');
     35 
     36    mediasource_testafterdataloaded(function(test, mediaElement, mediaSource, segmentInfo, sourceBuffer, mediaData)
     37    {
     38        sourceBuffer.appendBuffer(mediaData);
     39        test.expectEvent(sourceBuffer, 'updateend',
     40          'Media buffer appended to SourceBuffer');
     41        test.waitForExpectedEvents(function()
     42        {
     43            assert_equals(sourceBuffer.buffered.length, 1,
     44              'Media data properly buffered');
     45            var highestEndTime = sourceBuffer.buffered.end(0);
     46 
     47            // Note that segmentInfo.duration is expected to also be the
     48            // highest track buffer range end time. Therefore, endOfStream() should
     49            // not change duration with this media.
     50            assert_approx_equals(segmentInfo.duration, mediaSource.duration, 0.001,
     51                'SegmentInfo duration should initially roughly match mediaSource duration');
     52            assert_less_than_equal(highestEndTime, mediaSource.duration,
     53                'Media duration may be slightly longer than intersected track buffered ranges');
     54 
     55            // Set the duration even higher, then confirm that endOfStream() drops it back to be
     56            // the highest track buffer range end time.
     57            mediaSource.duration += 10;
     58            mediaSource.endOfStream();
     59 
     60            assert_equals(sourceBuffer.buffered.length, 1,
     61              'Media data properly buffered after endOfStream');
     62 
     63            assert_approx_equals(segmentInfo.duration, mediaSource.duration, 0.001,
     64                'SegmentInfo duration should still roughly match mediaSource duration');
     65            assert_less_than_equal(highestEndTime, mediaSource.duration,
     66                'Media duration may be slightly longer than intersected track buffered ranges');
     67            assert_equals(sourceBuffer.buffered.end(0), mediaSource.duration,
     68                'After endOfStream(), highest buffered range end time must be the highest track buffer range end time');
     69 
     70            test.done();
     71        });
     72    }, 'MediaSource.endOfStream(): duration and buffered range end time before and after endOfStream');
     73 </script>