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 mediasource_test(function(test
, mediaElement
, mediaSource
)
15 test
.failOnEvent(mediaElement
, 'error');
16 test
.endOnEvent(mediaElement
, 'ended');
18 var sourceBuffer
= mediaSource
.addSourceBuffer(MediaSourceUtil
.AUDIO_ONLY_TYPE
);
20 assertSeekableEquals(mediaElement
, '{ }', 'mediaElement.seekable');
22 }, 'Get seekable time ranges when the sourcebuffer is empty.');
24 mediasource_testafterdataloaded(function(test
, mediaElement
, mediaSource
, segmentInfo
, sourceBuffer
, mediaData
)
26 var initSegment
= MediaSourceUtil
.extractSegmentData(mediaData
, segmentInfo
.init
);
27 test
.expectEvent(mediaElement
, 'durationchange', 'mediaElement got duration');
28 sourceBuffer
.appendBuffer(initSegment
);
29 test
.waitForExpectedEvents(function()
31 assert_equals(mediaElement
.duration
, 6.042);
32 assertSeekableEquals(mediaElement
, '{ [0.000, 6.042) }', 'mediaElement.seekable');
35 }, 'Get seekable time ranges after init segment received.');
37 mediasource_testafterdataloaded(function(test
, mediaElement
, mediaSource
, segmentInfo
, sourceBuffer
, mediaData
)
39 var initSegment
= MediaSourceUtil
.extractSegmentData(mediaData
, segmentInfo
.init
);
40 test
.expectEvent(mediaElement
, 'durationchange', 'mediaElement got duration after initsegment');
41 sourceBuffer
.appendBuffer(initSegment
);
42 test
.waitForExpectedEvents(function()
44 test
.expectEvent(mediaElement
, 'durationchange', 'mediaElement got infinity duration');
45 mediaSource
.duration
= Infinity
;
46 test
.waitForExpectedEvents(function()
48 assertSeekableEquals(mediaElement
, '{ }', 'mediaElement.seekable');
50 // Append a segment from the middle of the stream to make sure that seekable does not use buffered.start(0) or duration as first or last value
51 var midSegment
= MediaSourceUtil
.extractSegmentData(mediaData
, segmentInfo
.media
[2]);
52 test
.expectEvent(sourceBuffer
, 'update');
53 test
.expectEvent(sourceBuffer
, 'updateend');
54 sourceBuffer
.appendBuffer(midSegment
);
55 test
.waitForExpectedEvents(function()
57 assert_equals(mediaElement
.seekable
.length
, 1, 'mediaElement.seekable.length');
58 assert_equals(mediaElement
.buffered
.length
, 1, 'mediaElement.buffered.length');
59 assert_not_equals(mediaElement
.seekable
.start(0), mediaElement
.buffered
.start(0));
60 assert_equals(mediaElement
.seekable
.start(0), 0);
61 assert_not_equals(mediaElement
.seekable
.end(0), mediaElement
.duration
);
62 assert_not_equals(mediaElement
.seekable
.end(0), mediaElement
.buffered
.start(0));
63 assert_equals(mediaElement
.seekable
.end(0), mediaElement
.buffered
.end(0));
68 }, 'Get seekable time ranges on an infinite stream.');