blob: a030cf2db1af9e2bb6c69192019c9cc3c52e09e4 [file] [log] [blame]
<!DOCTYPE html>
<html>
<head>
<script src="/w3c/resources/testharness.js"></script>
<script src="/w3c/resources/testharnessreport.js"></script>
<script src="mediasource-util.js"></script>
<link rel='stylesheet' href='/w3c/resources/testharness.css'>
</head>
<body>
<div id="log"></div>
<script>
mediasource_test(function(test, mediaElement, mediaSource)
{
var sourceBuffer = mediaSource.addSourceBuffer(MediaSourceUtil.AUDIO_VIDEO_TYPE);
mediaSource.duration = 10;
assert_throws_js(TypeError, function()
{
sourceBuffer.remove(-1, 2);
}, "remove");
test.done();
}, "Test remove with a negative start.");
mediasource_test(function(test, mediaElement, mediaSource)
{
var sourceBuffer = mediaSource.addSourceBuffer(MediaSourceUtil.AUDIO_VIDEO_TYPE);
mediaSource.duration = 10;
[ undefined, NaN, Infinity, -Infinity ].forEach(function(item)
{
assert_throws_js(TypeError, function()
{
sourceBuffer.remove(item, 2);
}, "remove");
});
test.done();
}, "Test remove with non-finite start.");
mediasource_test(function(test, mediaElement, mediaSource)
{
var sourceBuffer = mediaSource.addSourceBuffer(MediaSourceUtil.AUDIO_VIDEO_TYPE);
mediaSource.duration = 10;
assert_throws_js(TypeError, function()
{
sourceBuffer.remove(11, 12);
}, "remove");
test.done();
}, "Test remove with a start beyond the duration.");
mediasource_test(function(test, mediaElement, mediaSource)
{
var sourceBuffer = mediaSource.addSourceBuffer(MediaSourceUtil.AUDIO_VIDEO_TYPE);
mediaSource.duration = 10;
assert_throws_js(TypeError, function()
{
sourceBuffer.remove(2, 1);
}, "remove");
test.done();
}, "Test remove with a start larger than the end.");
mediasource_test(function(test, mediaElement, mediaSource)
{
var sourceBuffer = mediaSource.addSourceBuffer(MediaSourceUtil.AUDIO_VIDEO_TYPE);
mediaSource.duration = 10;
assert_throws_js(TypeError, function()
{
sourceBuffer.remove(0, Number.NEGATIVE_INFINITY);
}, "remove");
test.done();
}, "Test remove with a NEGATIVE_INFINITY end.");
mediasource_test(function(test, mediaElement, mediaSource)
{
var sourceBuffer = mediaSource.addSourceBuffer(MediaSourceUtil.AUDIO_VIDEO_TYPE);
mediaSource.duration = 10;
assert_throws_js(TypeError, function()
{
sourceBuffer.remove(0, Number.NaN);
}, "remove");
test.done();
}, "Test remove with a NaN end.");
mediasource_test(function(test, mediaElement, mediaSource)
{
var sourceBuffer = mediaSource.addSourceBuffer(MediaSourceUtil.AUDIO_VIDEO_TYPE);
mediaSource.duration = 10;
mediaSource.removeSourceBuffer(sourceBuffer);
assert_throws_dom("InvalidStateError", function()
{
sourceBuffer.remove(1, 2);
}, "remove");
test.done();
}, "Test remove after SourceBuffer removed from mediaSource.");
mediasource_test(function(test, mediaElement, mediaSource)
{
var sourceBuffer = mediaSource.addSourceBuffer(MediaSourceUtil.AUDIO_VIDEO_TYPE);
mediaSource.duration = 10;
test.expectEvent(sourceBuffer, "updatestart");
test.expectEvent(sourceBuffer, "update");
test.expectEvent(sourceBuffer, "updateend");
sourceBuffer.remove(1, 2);
assert_true(sourceBuffer.updating, "updating");
assert_throws_dom("InvalidStateError", function()
{
sourceBuffer.remove(3, 4);
}, "remove");
test.waitForExpectedEvents(function()
{
test.done();
});
}, "Test remove while update pending.");
mediasource_test(function(test, mediaElement, mediaSource)
{
var sourceBuffer = mediaSource.addSourceBuffer(MediaSourceUtil.AUDIO_VIDEO_TYPE);
mediaSource.duration = 10;
test.expectEvent(sourceBuffer, "updatestart");
test.expectEvent(sourceBuffer, "updateend");
sourceBuffer.remove(1, 2);
assert_true(sourceBuffer.updating, "updating");
assert_throws_dom('InvalidStateError',
function() { sourceBuffer.abort(); },
'abort() of remove() throws an exception');
assert_true(sourceBuffer.updating, "updating");
test.waitForExpectedEvents(function()
{
test.done();
});
}, "Test aborting a remove operation throws exception.");
mediasource_testafterdataloaded(function(test, mediaElement, mediaSource, segmentInfo, sourceBuffer, mediaData)
{
sourceBuffer.appendBuffer(mediaData);
test.expectEvent(sourceBuffer, "updatestart");
test.expectEvent(sourceBuffer, "update");
test.expectEvent(sourceBuffer, "updateend");
test.waitForExpectedEvents(function()
{
assert_less_than(mediaSource.duration, 10)
mediaSource.duration = 10;
sourceBuffer.remove(mediaSource.duration, mediaSource.duration + 2);
assert_true(sourceBuffer.updating, "updating");
test.expectEvent(sourceBuffer, "updatestart");
test.expectEvent(sourceBuffer, "update");
test.expectEvent(sourceBuffer, "updateend");
});
test.waitForExpectedEvents(function()
{
test.done();
});
}, "Test remove with a start at the duration.");
mediasource_testafterdataloaded(function(test, mediaElement, mediaSource, segmentInfo, sourceBuffer, mediaData)
{
test.expectEvent(sourceBuffer, "updatestart");
test.expectEvent(sourceBuffer, "update");
test.expectEvent(sourceBuffer, "updateend");
sourceBuffer.appendBuffer(mediaData);
test.waitForExpectedEvents(function()
{
mediaSource.endOfStream();
assert_equals(mediaSource.readyState, "ended");
test.expectEvent(sourceBuffer, "updatestart");
test.expectEvent(sourceBuffer, "update");
test.expectEvent(sourceBuffer, "updateend");
sourceBuffer.remove(1, 2);
assert_true(sourceBuffer.updating, "updating");
assert_equals(mediaSource.readyState, "open");
});
test.waitForExpectedEvents(function()
{
assert_false(sourceBuffer.updating, "updating");
test.done();
});
}, "Test remove transitioning readyState from 'ended' to 'open'.");
function removeAppendedDataTests(callback, description)
{
mediasource_testafterdataloaded(function(test, mediaElement, mediaSource, segmentInfo, sourceBuffer, mediaData)
{
test.expectEvent(sourceBuffer, "updatestart");
test.expectEvent(sourceBuffer, "update");
test.expectEvent(sourceBuffer, "updateend");
sourceBuffer.appendBuffer(mediaData);
test.waitForExpectedEvents(function()
{
var bufferedRangeEnd = segmentInfo.bufferedRangeEndBeforeEndOfStream.toFixed(3);
var subType = MediaSourceUtil.getSubType(segmentInfo.type);
assertBufferedEquals(sourceBuffer, "{ [0.000, " + bufferedRangeEnd + ") }", "Initial buffered range.");
callback(test, sourceBuffer, bufferedRangeEnd, subType);
});
}, description);
};
function removeAndCheckBufferedRanges(test, sourceBuffer, start, end, expected)
{
test.expectEvent(sourceBuffer, "updatestart");
test.expectEvent(sourceBuffer, "update");
test.expectEvent(sourceBuffer, "updateend");
sourceBuffer.remove(start, end);
test.waitForExpectedEvents(function()
{
assertBufferedEquals(sourceBuffer, expected, "Buffered ranges after remove().");
test.done();
});
}
removeAppendedDataTests(function(test, sourceBuffer, bufferedRangeEnd, subType)
{
removeAndCheckBufferedRanges(test, sourceBuffer, 0, Number.POSITIVE_INFINITY, "{ }");
}, "Test removing all appended data.");
removeAppendedDataTests(function(test, sourceBuffer, bufferedRangeEnd, subType)
{
var expectations = {
webm: ("{ [3.187, " + bufferedRangeEnd + ") }"),
mp4: ("{ [3.021, " + bufferedRangeEnd + ") }"),
};
// Note: Range doesn't start exactly at the end of the remove range because there isn't
// a keyframe there. The resulting range starts at the first keyframe >= the end time.
removeAndCheckBufferedRanges(test, sourceBuffer, 0, 3, expectations[subType]);
}, "Test removing beginning of appended data.");
removeAppendedDataTests(function(test, sourceBuffer, bufferedRangeEnd, subType)
{
var expectations = {
webm: ("{ [0.000, 1.012) [3.187, " + bufferedRangeEnd + ") }"),
mp4: ("{ [0.000, 1.022) [3.021, " + bufferedRangeEnd + ") }"),
};
// Note: The first resulting range ends slightly after start because the removal algorithm only removes
// frames with a timestamp >= the start time. If a frame starts before and ends after the remove() start
// timestamp, then it stays in the buffer.
removeAndCheckBufferedRanges(test, sourceBuffer, 1, 3, expectations[subType]);
}, "Test removing the middle of appended data.");
removeAppendedDataTests(function(test, sourceBuffer, bufferedRangeEnd, subType)
{
var expectations = {
webm: "{ [0.000, 1.012) }",
mp4: "{ [0.000, 1.022) }",
};
// Using MAX_VALUE rather than POSITIVE_INFINITY here due to lack
// of 'unrestricted' on end parameter. (See comment in SourceBuffer.idl)
removeAndCheckBufferedRanges(test, sourceBuffer, 1, Number.MAX_VALUE, expectations[subType]);
}, "Test removing the end of appended data.");
</script>
</body>
</html>