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'
>
12 function mediasource_detach_test(testFunction
, description
)
14 mediasource_test(function(test
, mediaElement
, mediaSource
)
16 var segmentInfo
= MediaSourceUtil
.SEGMENT_INFO
;
17 var sourceBuffer
= mediaSource
.addSourceBuffer(segmentInfo
.type
);
19 assert_equals(mediaElement
.readyState
, HTMLMediaElement
.HAVE_NOTHING
);
20 assert_equals(mediaSource
.readyState
, 'open');
22 mediaSource
.addEventListener('sourceclose', test
.step_func(function (event
)
24 assert_equals(mediaSource
.sourceBuffers
.length
, 0, 'sourceBuffers is empty');
25 assert_equals(mediaSource
.activeSourceBuffers
.length
, 0, 'activeSourceBuffers is empty');
26 assert_equals(mediaSource
.readyState
, 'closed', 'readyState is "closed"');
27 assert_true(Number
.isNaN(mediaSource
.duration
), 'duration is NaN');
31 MediaSourceUtil
.loadBinaryData(test
, segmentInfo
.url
, function(mediaData
)
33 testFunction(test
, mediaElement
, mediaSource
, sourceBuffer
, mediaData
);
38 mediasource_detach_test(function(test
, mediaElement
, mediaSource
, sourceBuffer
, mediaData
)
41 }, 'Test media.load() before appending data will trigger MediaSource detaching from a media element.');
43 mediasource_detach_test(function(test
, mediaElement
, mediaSource
, sourceBuffer
, mediaData
)
45 sourceBuffer
.addEventListener('updateend', test
.step_func(function (event
)
47 // FIXME: MediaElement.readyState could be HAVE_NOTHING when running multiple times.
48 // assert_greater_than(mediaElement.readyState, HTMLMediaElement.HAVE_NOTHING, 'media readyState is greater than "HAVE_NOTHING"')
49 assert_false(sourceBuffer
.updating
, 'updating attribute is false');
53 sourceBuffer
.appendBuffer(mediaData
);
54 }, 'Test media.load() after appending data will trigger MediaSource detaching from a media element.');