4 <script src=
"/w3c/resources/testharness.js"></script>
5 <script src=
"/w3c/resources/testharnessreport.js"></script>
6 <script src=
"mediasource-util.js"></script>
7 <link rel=
"stylesheet" href=
"/w3c/resources/testharness.css">
13 function seekToSpecifiedTimeSetEOSAndVerifyDone(test
, mediaElement
, mediaSource
, seekToTime
)
15 assert_less_than(mediaElement
.currentTime
, mediaElement
.duration
, 'Not at the end yet.');
16 test
.expectEvent(mediaElement
, 'seeking', 'mediaElement seeking');
17 // Seek to specified time.
18 mediaElement
.currentTime
= seekToTime
;
19 if (seekToTime
>= mediaSource
.duration
) {
20 assert_equals(mediaElement
.currentTime
, mediaSource
.duration
, 'Current time equals duration.');
22 assert_equals(mediaElement
.currentTime
, seekToTime
, 'Current time equals specified seek time.');
25 test
.waitForExpectedEvents(function()
27 test
.expectEvent(mediaElement
, 'timeupdate', 'mediaElement time updated.');
28 test
.expectEvent(mediaElement
, 'seeked', 'mediaElement seeked');
29 test
.expectEvent(mediaElement
, 'ended', 'mediaElement ended.');
30 test
.expectEvent(mediaSource
, 'sourceended', 'mediaSource ended.');
31 mediaSource
.endOfStream();
32 assert_true(mediaElement
.seeking
, 'mediaElement seeking.');
35 test
.waitForExpectedEvents(function()
37 assert_equals(mediaElement
.currentTime
, mediaSource
.duration
, 'Current time equals duration.');
42 mediasource_testafterdataloaded(function(test
, mediaElement
, mediaSource
, segmentInfo
, sourceBuffer
, mediaData
)
45 var initSegment
= MediaSourceUtil
.extractSegmentData(mediaData
, segmentInfo
.init
);
47 // Append the initialization segment to trigger a transition to HAVE_METADATA.
48 test
.expectEvent(sourceBuffer
, 'updateend', 'sourceBuffer end update.');
49 test
.expectEvent(mediaElement
, 'loadedmetadata', 'Reached HAVE_METADATA');
50 sourceBuffer
.appendBuffer(initSegment
);
52 test
.waitForExpectedEvents(function()
54 // Add sufficient segments to have at least 2s of play-time.
55 var playbackData
= MediaSourceUtil
.getMediaDataForPlaybackTime(mediaData
, segmentInfo
, 2.0);
56 test
.expectEvent(sourceBuffer
, 'updateend', 'sourceBuffer');
57 test
.expectEvent(mediaElement
, 'playing', 'Playing media.');
58 sourceBuffer
.appendBuffer(playbackData
);
61 test
.waitForExpectedEvents(function()
63 assert_equals(mediaElement
.duration
, segmentInfo
.durationInInitSegment
);
64 assert_greater_than_equal(mediaElement
.duration
, 2.0, 'Duration is >2.0s.');
65 test
.waitForCurrentTimeChange(mediaElement
, function()
68 mediaSource
.duration
= 1.5;
69 seekToSpecifiedTimeSetEOSAndVerifyDone(test
, mediaElement
, mediaSource
, 1.8);
72 }, 'Test seeking beyond updated media duration.');
74 mediasource_testafterdataloaded(function(test
, mediaElement
, mediaSource
, segmentInfo
, sourceBuffer
, mediaData
)
78 // Append all media data for complete playback.
79 test
.expectEvent(sourceBuffer
, 'updateend', 'sourceBuffer end update.');
80 test
.expectEvent(mediaElement
, 'loadedmetadata', 'Reached HAVE_METADATA');
81 test
.expectEvent(mediaElement
, 'playing', 'Playing media.');
82 sourceBuffer
.appendBuffer(mediaData
);
84 test
.waitForExpectedEvents(function()
86 test
.waitForCurrentTimeChange(mediaElement
, function()
88 seekToSpecifiedTimeSetEOSAndVerifyDone(test
, mediaElement
, mediaSource
, mediaSource
.duration
, mediaSource
.duration
+ 0.1);
92 }, 'Test seeking beyond media duration.');