mediasource-seek-beyond-duration.html (5220B)
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 seeking beyond the duration of the clip.</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 14 function seekToSpecifiedTimeSetEOSAndVerifyDone(test, mediaElement, mediaSource, seekToTime) 15 { 16 assert_less_than(mediaElement.currentTime, mediaElement.duration, 'Not at the end yet.'); 17 test.expectEvent(mediaElement, 'seeking', 'mediaElement seeking'); 18 // Seek to specified time. 19 mediaElement.currentTime = seekToTime; 20 if (seekToTime >= mediaSource.duration) { 21 assert_equals(mediaElement.currentTime, mediaSource.duration, 'Current time equals duration.'); 22 } else { 23 assert_equals(mediaElement.currentTime, seekToTime, 'Current time equals specified seek time.'); 24 } 25 26 test.waitForExpectedEvents(function() 27 { 28 test.expectEvent(mediaElement, 'timeupdate', 'mediaElement time updated.'); 29 test.expectEvent(mediaElement, 'seeked', 'mediaElement seeked'); 30 test.expectEvent(mediaElement, 'ended', 'mediaElement ended.'); 31 test.expectEvent(mediaSource, 'sourceended', 'mediaSource ended.'); 32 mediaSource.endOfStream(); 33 assert_true(mediaElement.seeking, 'mediaElement seeking.'); 34 }); 35 36 test.waitForExpectedEvents(function() 37 { 38 assert_equals(mediaElement.currentTime, mediaSource.duration, 'Current time equals duration.'); 39 test.done(); 40 }); 41 }; 42 43 mediasource_testafterdataloaded(function(test, mediaElement, mediaSource, segmentInfo, sourceBuffer, mediaData) 44 { 45 mediaElement.play(); 46 var initSegment = MediaSourceUtil.extractSegmentData(mediaData, segmentInfo.init); 47 48 // Append the initialization segment to trigger a transition to HAVE_METADATA. 49 test.expectEvent(sourceBuffer, 'updateend', 'sourceBuffer end update.'); 50 test.expectEvent(mediaElement, 'loadedmetadata', 'Reached HAVE_METADATA'); 51 sourceBuffer.appendBuffer(initSegment); 52 53 test.waitForExpectedEvents(function() 54 { 55 // Add sufficient segments to have at least 2s of play-time. 56 var playbackData = MediaSourceUtil.getMediaDataForPlaybackTime(mediaData, segmentInfo, 2.0); 57 test.expectEvent(sourceBuffer, 'updateend', 'sourceBuffer'); 58 test.expectEvent(mediaElement, 'playing', 'Playing media.'); 59 sourceBuffer.appendBuffer(playbackData); 60 }); 61 62 test.waitForExpectedEvents(function() 63 { 64 assert_equals(mediaElement.duration, segmentInfo.duration); 65 assert_greater_than_equal(mediaElement.duration, 2.0, 'Duration is >2.0s.'); 66 67 test.expectEvent(sourceBuffer, "updateend"); 68 sourceBuffer.remove(1.5, Infinity); 69 assert_true(sourceBuffer.updating, "updating"); 70 }); 71 72 test.waitForExpectedEvents(function() 73 { 74 assert_false(sourceBuffer.updating, "updating"); 75 test.waitForCurrentTimeChange(mediaElement, function() 76 { 77 // Update duration. 78 mediaSource.duration = 1.5; 79 seekToSpecifiedTimeSetEOSAndVerifyDone(test, mediaElement, mediaSource, 1.8); 80 }); 81 }); 82 }, 'Test seeking beyond updated media duration.'); 83 84 mediasource_testafterdataloaded(function(test, mediaElement, mediaSource, segmentInfo, sourceBuffer, mediaData) 85 { 86 mediaElement.play(); 87 88 // Append all media data for complete playback. 89 test.expectEvent(sourceBuffer, 'updateend', 'sourceBuffer end update.'); 90 test.expectEvent(mediaElement, 'loadedmetadata', 'Reached HAVE_METADATA'); 91 test.expectEvent(mediaElement, 'playing', 'Playing media.'); 92 sourceBuffer.appendBuffer(mediaData); 93 94 test.waitForExpectedEvents(function() 95 { 96 test.waitForCurrentTimeChange(mediaElement, function() 97 { 98 seekToSpecifiedTimeSetEOSAndVerifyDone(test, mediaElement, mediaSource, mediaSource.duration, mediaSource.duration + 0.1); 99 }); 100 }); 101 102 }, 'Test seeking beyond media duration.'); 103 </script> 104 </body> 105 </html>