tor-browser

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

mediasource-seek-during-pending-seek.html (9467B)


      1 <!DOCTYPE html>
      2 <!-- Copyright © 2016 Chromium authors and World Wide Web Consortium, (Massachusetts Institute of Technology, ERCIM, Keio University, Beihang). -->
      3 <html>
      4    <head>
      5        <title>Test MediaSource behavior when a seek is requested while another seek is pending.</title>
      6        <script src="/resources/testharness.js"></script>
      7        <script src="/resources/testharnessreport.js"></script>
      8        <script src="mediasource-util.js"></script>
      9    </head>
     10    <body>
     11        <div id="log"></div>
     12        <script>
     13          mediasource_testafterdataloaded(function(test, mediaElement, mediaSource, segmentInfo, sourceBuffer, mediaData)
     14          {
     15              mediaElement.play();
     16 
     17              var initSegment = MediaSourceUtil.extractSegmentData(mediaData, segmentInfo.init);
     18              var firstSegment = MediaSourceUtil.extractSegmentData(mediaData, segmentInfo.media[0]);
     19              var segmentIndex = 2;
     20              var secondSegmentInfo = segmentInfo.media[segmentIndex];
     21 
     22              // Append the initialization segment to trigger a transition to HAVE_METADATA.
     23              test.expectEvent(sourceBuffer, 'updateend', 'sourceBuffer');
     24              test.expectEvent(mediaElement, 'loadedmetadata', 'Reached HAVE_METADATA');
     25              sourceBuffer.appendBuffer(initSegment);
     26 
     27              test.waitForExpectedEvents(function()
     28              {
     29                  assert_false(mediaElement.seeking, 'mediaElement is not seeking');
     30                  assert_equals(mediaElement.readyState, mediaElement.HAVE_METADATA, 'Still in HAVE_METADATA');
     31 
     32                  // Seek to a new position before letting the initial seek to 0 completes.
     33                  test.expectEvent(mediaElement, 'seeking', 'mediaElement');
     34                  mediaElement.currentTime = Math.max(secondSegmentInfo.timev, secondSegmentInfo.timea);
     35                  assert_true(mediaElement.seeking, 'mediaElement is seeking');
     36 
     37                  // Append media data for time 0.
     38                  test.expectEvent(sourceBuffer, 'updateend', 'sourceBuffer');
     39                  sourceBuffer.appendBuffer(firstSegment);
     40              });
     41 
     42              test.waitForExpectedEvents(function()
     43              {
     44                  // Verify that the media data didn't trigger a 'seeking' event or a transition beyond HAVE_METADATA.
     45                  assert_true(mediaElement.seeking, 'mediaElement is still seeking');
     46                  assert_equals(mediaElement.readyState, mediaElement.HAVE_METADATA, 'Still in HAVE_METADATA');
     47 
     48                  // Append media data for the current position until the element starts playing.
     49                  test.expectEvent(mediaElement, 'seeked', 'mediaElement finished seek');
     50                  test.expectEvent(mediaElement, 'playing', 'mediaElement playing');
     51 
     52                  MediaSourceUtil.appendUntilEventFires(test, mediaElement, 'playing', sourceBuffer, mediaData, segmentInfo, segmentIndex);
     53              });
     54 
     55              test.waitForExpectedEvents(function()
     56              {
     57                  if (sourceBuffer.updating)
     58                  {
     59                      // The event playing was fired prior to the appendBuffer completing.
     60                      test.expectEvent(sourceBuffer, 'updateend', 'sourceBuffer');
     61                      test.waitForExpectedEvents(function()
     62                      {
     63                          assert_false(sourceBuffer.updating, 'append have compleded');
     64                          test.expectEvent(mediaSource, 'sourceended', 'mediaSource ended');
     65                          mediaSource.endOfStream();
     66                      });
     67                  }
     68                  else
     69                  {
     70                      test.expectEvent(mediaSource, 'sourceended', 'mediaSource ended');
     71                      mediaSource.endOfStream();
     72                  }
     73              });
     74 
     75              test.waitForExpectedEvents(function()
     76              {
     77              	  // Note: we just completed the seek. However, we only have less than a second worth of data to play. It is possible that
     78              	  // playback has reached the end since the seek completed.
     79              	  if (!mediaElement.paused)
     80              	  {
     81                      assert_greater_than_equal(mediaElement.readyState, mediaElement.HAVE_CURRENT_DATA, 'Greater or equal than HAVE_CURRENT_DATA');
     82                  }
     83                  else
     84                  {
     85                      assert_true(mediaElement.ended);
     86                  }
     87                  test.done();
     88              });
     89 
     90          }, 'Test seeking to a new location before transitioning beyond HAVE_METADATA.');
     91 
     92          mediasource_testafterdataloaded(function(test, mediaElement, mediaSource, segmentInfo, sourceBuffer, mediaData)
     93          {
     94              mediaElement.play();
     95 
     96              var initSegment = MediaSourceUtil.extractSegmentData(mediaData, segmentInfo.init);
     97              var firstSegment = MediaSourceUtil.extractSegmentData(mediaData, segmentInfo.media[0]);
     98              var secondSegmentInfo = segmentInfo.media[2];
     99              var secondSegment = MediaSourceUtil.extractSegmentData(mediaData, secondSegmentInfo);
    100              var segmentIndex = 4;
    101              var thirdSegmentInfo = segmentInfo.media[segmentIndex];
    102 
    103              // Append the initialization segment to trigger a transition to HAVE_METADATA.
    104              test.expectEvent(sourceBuffer, 'updateend', 'sourceBuffer');
    105              test.expectEvent(mediaElement, 'loadedmetadata', 'Reached HAVE_METADATA');
    106              sourceBuffer.appendBuffer(initSegment);
    107 
    108              test.waitForExpectedEvents(function()
    109              {
    110                  test.expectEvent(sourceBuffer, 'updateend', 'sourceBuffer');
    111                  test.expectEvent(mediaElement, 'playing', 'mediaElement playing');
    112                  sourceBuffer.appendBuffer(firstSegment);
    113              });
    114 
    115              test.waitForExpectedEvents(function()
    116              {
    117                  assert_greater_than(mediaElement.readyState, mediaElement.HAVE_CURRENT_DATA, 'Greater than HAVE_CURRENT_DATA');
    118 
    119                  // Seek to a new position.
    120                  test.expectEvent(mediaElement, 'seeking', 'mediaElement');
    121                  mediaElement.currentTime = Math.max(secondSegmentInfo.timev, secondSegmentInfo.timea);
    122                  assert_true(mediaElement.seeking, 'mediaElement is seeking');
    123 
    124              });
    125 
    126              test.waitForExpectedEvents(function()
    127              {
    128                  assert_true(mediaElement.seeking, 'mediaElement is still seeking');
    129 
    130                  // Seek to a second position while the first seek is still pending.
    131                  test.expectEvent(mediaElement, 'seeking', 'mediaElement');
    132                  mediaElement.currentTime = Math.max(thirdSegmentInfo.timev, thirdSegmentInfo.timea);
    133                  assert_true(mediaElement.seeking, 'mediaElement is seeking');
    134 
    135                  // Append media data for the first seek position.
    136                  test.expectEvent(sourceBuffer, 'updateend', 'sourceBuffer');
    137                  sourceBuffer.appendBuffer(secondSegment);
    138              });
    139 
    140              test.waitForExpectedEvents(function()
    141              {
    142                  // Note that we can't assume that the element is still seeking
    143                  // when the seeking event is fired as the operation is asynchronous.
    144 
    145                  // Append media data for the second seek position.
    146                  test.expectEvent(mediaElement, 'seeked', 'mediaElement finished seek');
    147                  MediaSourceUtil.appendUntilEventFires(test, mediaElement, 'seeked', sourceBuffer, mediaData, segmentInfo, segmentIndex);
    148              });
    149 
    150              test.waitForExpectedEvents(function()
    151              {
    152                  assert_false(mediaElement.seeking, 'mediaElement is no longer seeking');
    153 
    154                  if (sourceBuffer.updating)
    155                  {
    156                      // The event seeked was fired prior to the appendBuffer completing.
    157                      test.expectEvent(sourceBuffer, 'updateend', 'sourceBuffer');
    158                      test.waitForExpectedEvents(function()
    159                      {
    160                          assert_false(sourceBuffer.updating, 'append have compleded');
    161                          test.expectEvent(mediaSource, 'sourceended', 'mediaSource ended');
    162                          mediaSource.endOfStream();
    163                      });
    164                  }
    165                  else
    166                  {
    167                      test.expectEvent(mediaSource, 'sourceended', 'mediaSource ended');
    168                      mediaSource.endOfStream();
    169                  }
    170              });
    171 
    172              test.waitForExpectedEvents(function()
    173              {
    174              	  // Note: we just completed the seek. However, we only have less than a second worth of data to play. It is possible that
    175              	  // playback has reached the end since the seek completed.
    176              	  if (!mediaElement.paused)
    177              	  {
    178                      assert_greater_than_equal(mediaElement.readyState, mediaElement.HAVE_CURRENT_DATA, 'Greater or equal than HAVE_CURRENT_DATA');
    179                  }
    180                  else
    181                  {
    182                      assert_true(mediaElement.ended);
    183                  }
    184                  test.done();
    185              });
    186          }, 'Test seeking to a new location during a pending seek.');
    187        </script>
    188    </body>
    189 </html>