Commit 1032d69a authored by acolwell@chromium.org's avatar acolwell@chromium.org

Fix SourceBuffer.timestampOffset setter behavior for invalid values.

This patch adds logic to SourceBuffer::setTimestampOffset() to reject
invalid values. A LayoutTest to verify proper behavior for a variety of
values was also added.

BUG=353245
TEST=LayoutTests/http/tests/media/media-source/mediasource-timestamp-offset.html

Review URL: https://codereview.chromium.org/202423002

git-svn-id: svn://svn.chromium.org/blink/trunk@169773 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent e137f062
PASS Test setting SourceBuffer.timestampOffset to a positive number.
PASS Test setting SourceBuffer.timestampOffset to a negative number.
PASS Test setting SourceBuffer.timestampOffset to zero.
PASS Test setting SourceBuffer.timestampOffset to positive infinity.
PASS Test setting SourceBuffer.timestampOffset to negative infinity.
PASS Test setting SourceBuffer.timestampOffset to NaN.
PASS Test setting SourceBuffer.timestampOffset to undefined.
PASS Test setting SourceBuffer.timestampOffset to null.
PASS Test setting SourceBuffer.timestampOffset to false.
PASS Test setting SourceBuffer.timestampOffset to true.
PASS Test setting SourceBuffer.timestampOffset to a number string.
PASS Test setting SourceBuffer.timestampOffset to an empty string.
<!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>
function simpleTimestampOffsetTest(value, expected, description)
{
mediasource_test(function(test, mediaElement, mediaSource)
{
var segmentInfo = MediaSourceUtil.SEGMENT_INFO;
var sourceBuffer = mediaSource.addSourceBuffer(segmentInfo.type);
if (expected == 'TypeMismatchError') {
assert_throws('TypeMismatchError',
function() { sourceBuffer.timestampOffset = value; },
'setting timestampOffset to ' + description + ' throws an exception.');
} else {
sourceBuffer.timestampOffset = value;
assert_equals(sourceBuffer.timestampOffset, expected);
}
test.done();
}, 'Test setting SourceBuffer.timestampOffset to ' + description + '.');
}
simpleTimestampOffsetTest(10.5, 10.5, 'a positive number');
simpleTimestampOffsetTest(-10.4, -10.4, 'a negative number');
simpleTimestampOffsetTest(0, 0, 'zero');
simpleTimestampOffsetTest(Number.POSITIVE_INFINITY, 'TypeMismatchError', 'positive infinity');
simpleTimestampOffsetTest(Number.NEGATIVE_INFINITY, 'TypeMismatchError', 'negative infinity');
simpleTimestampOffsetTest(Number.NaN, 'TypeMismatchError', 'NaN');
simpleTimestampOffsetTest(undefined, 'TypeMismatchError', 'undefined');
simpleTimestampOffsetTest(null, 0, 'null');
simpleTimestampOffsetTest(false, 0, 'false');
simpleTimestampOffsetTest(true, 1, 'true');
simpleTimestampOffsetTest('10.5', 10.5, 'a number string');
simpleTimestampOffsetTest('', 0, 'an empty string');
</script>
</body>
</html>
......@@ -175,6 +175,12 @@ double SourceBuffer::timestampOffset() const
void SourceBuffer::setTimestampOffset(double offset, ExceptionState& exceptionState)
{
// Enforce throwing an exception on restricted double values.
if (!std::isfinite(offset)) {
exceptionState.throwDOMException(TypeMismatchError, ExceptionMessages::notAFiniteNumber(offset));
return;
}
// Section 3.1 timestampOffset attribute setter steps.
// 1. Let new timestamp offset equal the new value being assigned to this attribute.
// 2. If this object has been removed from the sourceBuffers attribute of the parent media source, then throw an
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment