https://github.com/web-platform-tests/wpt
Tip revision: 8e253afd467510fd23201bd9086920eb06ce920a authored by Hallvord R. M. Steen on 19 October 2014, 21:58:51 UTC
making it clearer what events are firing, in what order and what the state of the request is at each step
making it clearer what events are firing, in what order and what the state of the request is at each step
Tip revision: 8e253af
mediasource-append-buffer.html
<!DOCTYPE html>
<html>
<head>
<title>SourceBuffer.appendBuffer() test cases</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="mediasource-util.js"></script>
</head>
<body>
<div id="log"></div>
<script>
mediasource_testafterdataloaded(function(test, mediaElement, mediaSource, segmentInfo, sourceBuffer, mediaData)
{
test.failOnEvent(mediaElement, 'error');
test.expectEvent(sourceBuffer, "updatestart", "Append started.");
test.expectEvent(sourceBuffer, "update", "Append success.");
test.expectEvent(sourceBuffer, "updateend", "Append ended.");
sourceBuffer.appendBuffer(mediaData);
assert_true(sourceBuffer.updating, "updating attribute is true");
test.waitForExpectedEvents(function()
{
assert_false(sourceBuffer.updating, "updating attribute is false");
test.done();
});
}, "Test SourceBuffer.appendBuffer() event dispatching.");
mediasource_testafterdataloaded(function(test, mediaElement, mediaSource, segmentInfo, sourceBuffer, mediaData)
{
test.failOnEvent(mediaElement, 'error');
test.expectEvent(sourceBuffer, "updatestart", "Append started.");
test.expectEvent(sourceBuffer, "update", "Append success.");
test.expectEvent(sourceBuffer, "updateend", "Append ended.");
sourceBuffer.appendBuffer(mediaData);
assert_true(sourceBuffer.updating, "updating attribute is true");
assert_throws("InvalidStateError",
function() { sourceBuffer.appendBuffer(mediaData); },
"appendBuffer() throws an exception there is a pending append.");
assert_true(sourceBuffer.updating, "updating attribute is true");
test.waitForExpectedEvents(function()
{
assert_false(sourceBuffer.updating, "updating attribute is false");
test.done();
});
}, "Test SourceBuffer.appendBuffer() call during a pending appendBuffer().");
mediasource_testafterdataloaded(function(test, mediaElement, mediaSource, segmentInfo, sourceBuffer, mediaData)
{
test.failOnEvent(mediaElement, 'error');
test.expectEvent(sourceBuffer, "updatestart", "Append started.");
test.expectEvent(sourceBuffer, "abort", "Append aborted.");
test.expectEvent(sourceBuffer, "updateend", "Append ended.");
sourceBuffer.appendBuffer(mediaData);
assert_true(sourceBuffer.updating, "updating attribute is true");
sourceBuffer.abort();
assert_false(sourceBuffer.updating, "updating attribute is false");
test.waitForExpectedEvents(function()
{
assert_false(sourceBuffer.updating, "updating attribute is false");
test.done();
});
}, "Test SourceBuffer.abort() call during a pending appendBuffer().");
mediasource_testafterdataloaded(function(test, mediaElement, mediaSource, segmentInfo, sourceBuffer, mediaData)
{
test.failOnEvent(mediaElement, 'error');
test.expectEvent(sourceBuffer, "updatestart", "Append started.");
test.expectEvent(sourceBuffer, "update", "Append success.");
test.expectEvent(sourceBuffer, "updateend", "Append ended.");
sourceBuffer.appendBuffer(mediaData);
assert_true(sourceBuffer.updating, "updating attribute is true");
test.waitForExpectedEvents(function()
{
assert_false(sourceBuffer.updating, "updating attribute is false");
test.expectEvent(mediaSource, "sourceended", "MediaSource sourceended event");
mediaSource.endOfStream();
assert_equals(mediaSource.readyState, "ended", "MediaSource readyState is 'ended'");
});
test.waitForExpectedEvents(function()
{
assert_equals(mediaSource.readyState, "ended", "MediaSource readyState is 'ended'");
test.expectEvent(mediaSource, "sourceopen", "MediaSource sourceopen event");
test.expectEvent(sourceBuffer, "updatestart", "Append started.");
test.expectEvent(sourceBuffer, "update", "Append success.");
test.expectEvent(sourceBuffer, "updateend", "Append ended.");
sourceBuffer.appendBuffer(mediaData);
assert_equals(mediaSource.readyState, "open", "MediaSource readyState is 'open'");
assert_true(sourceBuffer.updating, "updating attribute is true");
});
test.waitForExpectedEvents(function()
{
assert_equals(mediaSource.readyState, "open", "MediaSource readyState is 'open'");
assert_false(sourceBuffer.updating, "updating attribute is false");
test.done();
});
}, "Test SourceBuffer.appendBuffer() triggering an 'ended' to 'open' transition.");
mediasource_testafterdataloaded(function(test, mediaElement, mediaSource, segmentInfo, sourceBuffer, mediaData)
{
test.failOnEvent(mediaElement, 'error');
test.expectEvent(sourceBuffer, "updatestart", "Append started.");
test.expectEvent(sourceBuffer, "abort", "Append aborted.");
test.expectEvent(sourceBuffer, "updateend", "Append ended.");
sourceBuffer.appendBuffer(mediaData);
assert_true(sourceBuffer.updating, "updating attribute is true");
assert_equals(mediaSource.activeSourceBuffers.length, 0, "activeSourceBuffers.length");
test.expectEvent(mediaSource.sourceBuffers, "removesourcebuffer", "sourceBuffers");
mediaSource.removeSourceBuffer(sourceBuffer);
assert_false(sourceBuffer.updating, "updating attribute is false");
assert_throws("InvalidStateError",
function() { sourceBuffer.appendBuffer(mediaData); },
"appendBuffer() throws an exception because it isn't attached to the mediaSource anymore.");
test.waitForExpectedEvents(function()
{
assert_false(sourceBuffer.updating, "updating attribute is false");
test.done();
});
}, "Test MediaSource.removeSourceBuffer() call during a pending appendBuffer().");
mediasource_testafterdataloaded(function(test, mediaElement, mediaSource, segmentInfo, sourceBuffer, mediaData)
{
test.failOnEvent(mediaElement, 'error');
test.expectEvent(sourceBuffer, "updatestart", "Append started.");
test.expectEvent(sourceBuffer, "updateend", "Append ended.");
sourceBuffer.appendBuffer(mediaData);
assert_true(sourceBuffer.updating, "updating attribute is true");
assert_throws("InvalidStateError",
function() { mediaSource.duration = 1.0; },
"set duration throws an exception when updating attribute is true.");
test.waitForExpectedEvents(function()
{
assert_false(sourceBuffer.updating, "updating attribute is false");
test.done();
});
}, "Test set MediaSource.duration during a pending appendBuffer() for one of its SourceBuffers.");
mediasource_testafterdataloaded(function(test, mediaElement, mediaSource, segmentInfo, sourceBuffer, mediaData)
{
test.failOnEvent(mediaElement, "error");
test.failOnEvent(mediaSource, "sourceended");
test.expectEvent(sourceBuffer, "updatestart", "Append started.");
test.expectEvent(sourceBuffer, "updateend", "Append ended.");
sourceBuffer.appendBuffer(mediaData);
assert_true(sourceBuffer.updating, "updating attribute is true");
assert_throws("InvalidStateError",
function() { mediaSource.endOfStream(); },
"endOfStream() throws an exception when updating attribute is true.");
assert_equals(mediaSource.readyState, "open");
test.waitForExpectedEvents(function()
{
assert_false(sourceBuffer.updating, "updating attribute is false");
assert_equals(mediaSource.readyState, "open");
test.done();
});
}, "Test MediaSource.endOfStream() during a pending appendBuffer() for one of its SourceBuffers.");
mediasource_testafterdataloaded(function(test, mediaElement, mediaSource, segmentInfo, sourceBuffer, mediaData)
{
test.failOnEvent(mediaElement, 'error');
test.expectEvent(sourceBuffer, "updatestart", "Append started.");
test.expectEvent(sourceBuffer, "updateend", "Append ended.");
sourceBuffer.appendBuffer(mediaData);
assert_true(sourceBuffer.updating, "updating attribute is true");
assert_throws("InvalidStateError",
function() { sourceBuffer.timestampOffset = 10.0; },
"set timestampOffset throws an exception when updating attribute is true.");
test.waitForExpectedEvents(function()
{
assert_false(sourceBuffer.updating, "updating attribute is false");
test.done();
});
}, "Test set SourceBuffer.timestampOffset during a pending appendBuffer().");
mediasource_test(function(test, mediaElement, mediaSource)
{
var sourceBuffer = mediaSource.addSourceBuffer(MediaSourceUtil.VIDEO_ONLY_TYPE);
test.expectEvent(sourceBuffer, "updatestart", "Append started.");
test.expectEvent(sourceBuffer, "update", "Append success.");
test.expectEvent(sourceBuffer, "updateend", "Append ended.");
sourceBuffer.appendBuffer(new Uint8Array(0));
assert_true(sourceBuffer.updating, "updating attribute is true");
test.waitForExpectedEvents(function()
{
assert_false(sourceBuffer.updating, "updating attribute is false");
test.done();
});
}, "Test appending an empty ArrayBufferView.");
mediasource_test(function(test, mediaElement, mediaSource)
{
var sourceBuffer = mediaSource.addSourceBuffer(MediaSourceUtil.VIDEO_ONLY_TYPE);
test.expectEvent(sourceBuffer, "updatestart", "Append started.");
test.expectEvent(sourceBuffer, "update", "Append success.");
test.expectEvent(sourceBuffer, "updateend", "Append ended.");
sourceBuffer.appendBuffer(new ArrayBuffer(0));
assert_true(sourceBuffer.updating, "updating attribute is true");
test.waitForExpectedEvents(function()
{
assert_false(sourceBuffer.updating, "updating attribute is false");
test.done();
});
}, "Test appending an empty ArrayBuffer.");
</script>
</body>
</html>