4 <script src=
"/w3c/resources/testharness.js"></script>
5 <script src=
"/w3c/resources/testharnessreport.js"></script>
6 <script src=
"mediasource-util.js"></script>
8 <link rel='stylesheet' href='/w3c/resources/testharness.css'
>
13 mediasource_test(function(test
, mediaElement
, mediaSource
)
15 mediaSource
.endOfStream();
16 assert_throws("InvalidStateError",
17 function() { mediaSource
.addSourceBuffer(MediaSourceUtil
.AUDIO_VIDEO_TYPE
); },
18 "addSourceBuffer() threw an exception when in 'ended' state.");
20 }, "Test addSourceBuffer() in 'ended' state.");
22 mediasource_test(function(test
, mediaElement
, mediaSource
)
24 assert_throws("InvalidAccessError",
25 function() { mediaSource
.addSourceBuffer(""); },
26 "addSourceBuffer() threw an exception when passed an empty string.");
28 }, "Test addSourceBuffer() with empty type");
30 mediasource_test(function(test
, mediaElement
, mediaSource
)
32 assert_throws("NotSupportedError",
33 function() { mediaSource
.addSourceBuffer(null); },
34 "addSourceBuffer() threw an exception when passed null.");
36 }, "Test addSourceBuffer() with null");
38 mediasource_test(function(test
, mediaElement
, mediaSource
)
40 assert_throws("NotSupportedError",
41 function() { mediaSource
.addSourceBuffer("invalidType"); },
42 "addSourceBuffer() threw an exception for an unsupported type.");
44 }, "Test addSourceBuffer() with unsupported type");
46 mediasource_test(function(test
, mediaElement
, mediaSource
)
48 var mimetype
= 'video/webm;codecs="vp8,vorbis"';
50 assert_true(MediaSource
.isTypeSupported(mimetype
), mimetype
+ " is supported");
52 var sourceBuffer
= mediaSource
.addSourceBuffer(mimetype
);
53 assert_true(sourceBuffer
!= null, "New SourceBuffer returned");
54 assert_equals(mediaSource
.sourceBuffers
[0], sourceBuffer
, "SourceBuffer is in mediaSource.sourceBuffers");
55 assert_equals(mediaSource
.activeSourceBuffers
.length
, 0, "SourceBuffer is not in mediaSource.activeSourceBuffers");
57 }, "Test addSourceBuffer() with Vorbis and VP8");
59 mediasource_test(function(test
, mediaElement
, mediaSource
)
61 var videoMimetype
= 'video/webm;codecs="vp8"';
62 var audioMimetype
= 'audio/webm;codecs="vorbis"';
64 assert_true(MediaSource
.isTypeSupported(videoMimetype
), videoMimetype
+ " is supported");
65 assert_true(MediaSource
.isTypeSupported(audioMimetype
), audioMimetype
+ " is supported");
67 var sourceBufferA
= mediaSource
.addSourceBuffer(videoMimetype
);
68 var sourceBufferB
= mediaSource
.addSourceBuffer(audioMimetype
);
69 assert_equals(mediaSource
.sourceBuffers
[0], sourceBufferA
, "sourceBufferA is in mediaSource.sourceBuffers");
70 assert_equals(mediaSource
.activeSourceBuffers
.length
, 0, "SourceBufferA is not in mediaSource.activeSourceBuffers");
71 assert_equals(mediaSource
.sourceBuffers
[1], sourceBufferB
, "sourceBufferB is in mediaSource.sourceBuffers");
72 assert_equals(mediaSource
.activeSourceBuffers
.length
, 0, "SourceBufferB is not in mediaSource.activeSourceBuffers");
74 }, "Test addSourceBuffer() with Vorbis and VP8 in separate SourceBuffers");
76 mediasource_test(function(test
, mediaElement
, mediaSource
)
78 var mimetype
= MediaSourceUtil
.VIDEO_ONLY_TYPE
;
80 assert_true(MediaSource
.isTypeSupported(mimetype
), mimetype
+ " is supported");
82 var sourceBuffer
= mediaSource
.addSourceBuffer(mimetype
);
83 assert_true(sourceBuffer
!= null, "New SourceBuffer returned");
84 assert_equals(mediaSource
.sourceBuffers
[0], sourceBuffer
, "SourceBuffer is in mediaSource.sourceBuffers");
85 assert_equals(mediaSource
.activeSourceBuffers
.length
, 0, "SourceBuffer is not in mediaSource.activeSourceBuffers");
87 }, "Test addSourceBuffer() video only");
89 mediasource_test(function(test
, mediaElement
, mediaSource
)
91 var mimetype
= MediaSourceUtil
.AUDIO_ONLY_TYPE
;
93 assert_true(MediaSource
.isTypeSupported(mimetype
), mimetype
+ " is supported");
95 var sourceBuffer
= mediaSource
.addSourceBuffer(mimetype
);
96 assert_true(sourceBuffer
!= null, "New SourceBuffer returned");
97 assert_equals(mediaSource
.sourceBuffers
[0], sourceBuffer
, "SourceBuffer is in mediaSource.sourceBuffers");
98 assert_equals(mediaSource
.activeSourceBuffers
.length
, 0, "SourceBuffer is not in mediaSource.activeSourceBuffers");
100 }, "Test addSourceBuffer() audio only");
102 mediasource_test(function(test
, mediaElement
, mediaSource
)
104 var mimetype
= 'video/mp4;codecs="avc1.4D4001,mp4a.40.2"';
106 assert_true(MediaSource
.isTypeSupported(mimetype
), mimetype
+ " is supported");
108 var sourceBuffer
= mediaSource
.addSourceBuffer(mimetype
);
109 assert_true(sourceBuffer
!= null, "New SourceBuffer returned");
110 assert_equals(mediaSource
.sourceBuffers
[0], sourceBuffer
, "SourceBuffer is in mediaSource.sourceBuffers");
111 assert_equals(mediaSource
.activeSourceBuffers
.length
, 0, "SourceBuffer is not in mediaSource.activeSourceBuffers");
113 }, "Test addSourceBuffer() with AAC and H.264");
115 mediasource_test(function(test
, mediaElement
, mediaSource
)
117 var videoMimetype
= 'video/mp4;codecs="avc1.4D4001"';
118 var audioMimetype
= 'audio/mp4;codecs="mp4a.40.2"';
120 assert_true(MediaSource
.isTypeSupported(videoMimetype
), videoMimetype
+ " is supported");
121 assert_true(MediaSource
.isTypeSupported(audioMimetype
), audioMimetype
+ " is supported");
123 var sourceBufferA
= mediaSource
.addSourceBuffer(videoMimetype
);
124 var sourceBufferB
= mediaSource
.addSourceBuffer(audioMimetype
);
125 assert_equals(mediaSource
.sourceBuffers
[0], sourceBufferA
, "sourceBufferA is in mediaSource.sourceBuffers");
126 assert_equals(mediaSource
.activeSourceBuffers
.length
, 0, "SourceBufferA is not in mediaSource.activeSourceBuffers");
127 assert_equals(mediaSource
.sourceBuffers
[1], sourceBufferB
, "sourceBufferB is in mediaSource.sourceBuffers");
128 assert_equals(mediaSource
.activeSourceBuffers
.length
, 0, "SourceBufferB is not in mediaSource.activeSourceBuffers");
130 }, "Test addSourceBuffer() with AAC and H.264 in separate SourceBuffers");
132 mediasource_test(function(test
, mediaElement
, mediaSource
)
134 var reachedLimit
= false;
136 // The 20 here is an arbitrary upper limit to make sure the test terminates. This test
137 // assumes that implementations won't support more than 20 SourceBuffers simultaneously.
138 for (var i
= 0; i
< 20; ++i
) {
140 mediaSource
.addSourceBuffer(MediaSourceUtil
.AUDIO_VIDEO_TYPE
);
142 assert_equals(e
.name
, "QuotaExceededError");
147 assert_true(reachedLimit
, "Reached SourceBuffer limit.");
149 }, "Test addSourceBuffer() QuotaExceededError.");