Index: third_party/WebKit/LayoutTests/http/tests/media/media-source/mediasource-addsourcebuffer.html |
diff --git a/third_party/WebKit/LayoutTests/http/tests/media/media-source/mediasource-addsourcebuffer.html b/third_party/WebKit/LayoutTests/http/tests/media/media-source/mediasource-addsourcebuffer.html |
index 2fe975473577e630e711e79848d6ac0d7b5f6045..dc2bfd0052a7b1aa6c17151e9658efd3daf721c8 100644 |
--- a/third_party/WebKit/LayoutTests/http/tests/media/media-source/mediasource-addsourcebuffer.html |
+++ b/third_party/WebKit/LayoutTests/http/tests/media/media-source/mediasource-addsourcebuffer.html |
@@ -39,7 +39,7 @@ |
"addSourceBuffer() threw an exception when passed null."); |
test.done(); |
}, "Test addSourceBuffer() with null"); |
- |
+ |
mediasource_test(function(test, mediaElement, mediaSource) |
{ |
assert_throws("NotSupportedError", |
@@ -90,7 +90,7 @@ |
assert_equals(mediaSource.activeSourceBuffers.length, 0, "SourceBuffer is not in mediaSource.activeSourceBuffers"); |
test.done(); |
}, "Test addSourceBuffer() video only"); |
- |
+ |
mediasource_test(function(test, mediaElement, mediaSource) |
{ |
var mimetype = MediaSourceUtil.AUDIO_ONLY_TYPE; |
@@ -134,24 +134,48 @@ |
test.done(); |
}, "Test addSourceBuffer() with AAC and H.264 in separate SourceBuffers"); |
- mediasource_test(function(test, mediaElement, mediaSource) |
+ mediasource_testafterdataloaded(function(test, mediaElement, mediaSource, segmentInfo, sourceBuffer, mediaData) |
+ { |
+ test.expectEvent(sourceBuffer, "updateend"); |
+ sourceBuffer.appendBuffer(mediaData); |
+ test.waitForExpectedEvents(function() |
+ { |
+ assert_throws({name: "QuotaExceededError"}, |
+ function() { mediaSource.addSourceBuffer(MediaSourceUtil.AUDIO_VIDEO_TYPE); }, |
+ "addSourceBuffer must throw an exception if the MediaSource has already received init segments for all sourcebuffers added at the time"); |
+ test.done(); |
+ }); |
+ }, "Test addSourceBuffer() throws QuotaExceededError after MediaSource has completed init."); |
+ |
+ mediasource_testafterdataloaded(function(test, mediaElement, mediaSource, segmentInfo, sourceBuffer, mediaData) |
{ |
- var reachedLimit = false; |
- |
- // The 20 here is an arbitrary upper limit to make sure the test terminates. This test |
- // assumes that implementations won't support more than 20 SourceBuffers simultaneously. |
- for (var i = 0; i < 20; ++i) { |
- try { |
- mediaSource.addSourceBuffer(MediaSourceUtil.AUDIO_VIDEO_TYPE); |
- } catch(e) { |
- assert_equals(e.name, "QuotaExceededError"); |
- reachedLimit = true; |
- break; |
- } |
- } |
- assert_true(reachedLimit, "Reached SourceBuffer limit."); |
- test.done(); |
- }, "Test addSourceBuffer() QuotaExceededError."); |
+ var initSegment = MediaSourceUtil.extractSegmentData(mediaData, segmentInfo.init); |
+ test.expectEvent(sourceBuffer, "updateend"); |
+ // Append incomplete init segment to the first SourceBuffer. |
+ sourceBuffer.appendBuffer(initSegment.slice(0, initSegment.length - 1)); |
+ test.waitForExpectedEvents(function() |
+ { |
+ // We have not added a full init segment for the first SourceBuffer yet, so MediaSource init is not yet |
+ // finished and we should be able to add/remove one more SourceBuffer. |
+ var sourceBuffer2 = mediaSource.addSourceBuffer(MediaSourceUtil.AUDIO_VIDEO_TYPE); |
+ mediaSource.removeSourceBuffer(sourceBuffer2); |
+ |
+ // Now append the rest of the init segment, this should complete the initialization of the MediaSource. |
+ test.expectEvent(sourceBuffer, "updateend"); |
+ test.expectEvent(mediaElement, "loadedmetadata", "mediaElement metadata."); |
+ sourceBuffer.appendBuffer(initSegment.slice(initSegment.length - 1)); |
+ }); |
+ |
+ test.waitForExpectedEvents(function() |
+ { |
+ // MediaSource is fully initialized now, so adding new SourceBuffers is no longer possible. |
+ assert_equals(mediaElement.readyState, HTMLMediaElement.HAVE_METADATA); |
+ assert_throws({name: "QuotaExceededError"}, |
+ function() { mediaSource.addSourceBuffer(MediaSourceUtil.AUDIO_VIDEO_TYPE); }, |
+ "addSourceBuffer must throw an exception if the media element has already reached HAVE_METADATA"); |
+ test.done(); |
+ }); |
+ }, "Test addSourceBuffer() succeeds while incomplete init segment is appended, fails after MediaSource init completed."); |
</script> |
</body> |
</html> |