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'
>
14 var mediaSource
= new MediaSource();
15 assert_equals(mediaSource
.sourceBuffers
.length
, 0, 'sourceBuffers is empty');
16 assert_equals(mediaSource
.activeSourceBuffers
.length
, 0, 'activeSourceBuffers is empty');
17 assert_equals(mediaSource
.readyState
, 'closed', 'readyState is "closed"');
18 assert_true(Number
.isNaN(mediaSource
.duration
), 'duration is NaN');
19 }, 'Test attribute values on a closed MediaSource object.');
23 var mediaSource
= new MediaSource();
24 assert_throws('InvalidStateError',
25 function() { mediaSource
.addSourceBuffer(MediaSourceUtil
.VIDEO_ONLY_TYPE
); },
26 'addSourceBuffer() throws an exception when closed.');
27 }, 'Test addSourceBuffer() while closed.');
29 mediasource_test(function(test
, mediaElement
, mediaSource
)
31 var sourceBuffer
= mediaSource
.addSourceBuffer(MediaSourceUtil
.AUDIO_ONLY_TYPE
);
33 // Setup a handler to run when the MediaSource closes.
34 mediaSource
.addEventListener('sourceclose', test
.step_func(function (event
)
36 assert_equals(mediaSource
.sourceBuffers
.length
, 0, 'sourceBuffers is empty');
37 assert_equals(mediaSource
.activeSourceBuffers
.length
, 0, 'activeSourceBuffers is empty');
38 assert_equals(mediaSource
.readyState
, 'closed', 'readyState is "closed"');
39 assert_true(Number
.isNaN(mediaSource
.duration
), 'duration is NaN');
40 assert_throws('NotFoundError',
41 function() { mediaSource
.removeSourceBuffer(sourceBuffer
); },
42 'removeSourceBuffer() throws an exception when closed.');
46 // Trigger the MediaSource to close.
47 mediaElement
.src
= '';
48 }, 'Test removeSourceBuffer() while closed.');
52 var mediaSource
= new MediaSource();
53 assert_throws('InvalidStateError',
54 function() { mediaSource
.endOfStream(); },
55 'endOfStream() throws an exception when closed.');
56 }, 'Test endOfStream() while closed.');
60 var mediaSource
= new MediaSource();
61 assert_throws('InvalidStateError',
62 function() { mediaSource
.endOfStream('decode'); },
63 'endOfStream(decode) throws an exception when closed.');
64 }, 'Test endOfStream(decode) while closed.');
68 var mediaSource
= new MediaSource();
69 assert_throws('InvalidStateError',
70 function() { mediaSource
.endOfStream('network'); },
71 'endOfStream(network) throws an exception when closed.');
72 }, 'Test endOfStream(network) while closed.');
77 var mediaSource
= new MediaSource();
78 assert_throws('InvalidStateError',
79 function() { mediaSource
.duration
= 10; },
80 'Setting duration throws an exception when closed.');
81 }, 'Test setting duration while closed.');
83 mediasource_test(function(test
, mediaElement
, mediaSource
)
85 var sourceBuffer
= mediaSource
.addSourceBuffer(MediaSourceUtil
.AUDIO_ONLY_TYPE
);
87 assert_equals(mediaSource
.readyState
, 'open', 'readyState is "open"');
88 // Setup a handler to run when the MediaSource closes.
89 mediaSource
.addEventListener('sourceclose', test
.step_func(function (event
)
91 assert_equals(mediaSource
.readyState
, 'closed', 'readyState is "closed"');
92 assert_throws('InvalidStateError',
93 function() { mediaSource
.duration
= 10; },
94 'Setting duration when closed throws an exception');
98 // Trigger the MediaSource to close.
99 mediaElement
.src
= '';
100 }, 'Test setting duration while open->closed.');
102 mediasource_test(function(test
, mediaElement
, mediaSource
)
104 var sourceBuffer
= mediaSource
.addSourceBuffer(MediaSourceUtil
.AUDIO_ONLY_TYPE
);
106 assert_equals(mediaSource
.readyState
, 'open', 'readyState is "open"');
107 // Setup a handler to run when the MediaSource closes.
108 mediaSource
.addEventListener('sourceclose', test
.step_func(function (event
)
110 assert_equals(mediaSource
.readyState
, 'closed', 'readyState is "closed"');
111 assert_true(Number
.isNaN(mediaSource
.duration
), 'duration is NaN');
115 // Trigger the MediaSource to close.
116 mediaElement
.src
= '';
117 }, 'Test getting duration while open->closed.');
119 mediasource_test(function(test
, mediaElement
, mediaSource
)
121 var sourceBuffer
= mediaSource
.addSourceBuffer(MediaSourceUtil
.AUDIO_ONLY_TYPE
);
123 assert_equals(mediaSource
.readyState
, 'open', 'readyState is open');
125 // Setup a handler to run when the MediaSource closes.
126 mediaSource
.addEventListener('sourceclose', test
.step_func(function (event
)
128 assert_equals(mediaSource
.readyState
, 'closed', 'readyState is closed');
129 assert_throws('InvalidStateError',
130 function() { sourceBuffer
.abort(); },
131 'sourceBuffer.abort() throws INVALID_STATE_ERROR');
135 // Trigger the MediaSource to close.
136 mediaElement
.src
= '';
137 }, 'Test sourcebuffer.abort when closed.');