Skip to content

Commit

Permalink
Update MediaSource tests with new cases from Blink.
Browse files Browse the repository at this point in the history
  • Loading branch information
acolwell committed Sep 9, 2014
1 parent 58df0e3 commit ab0ee7b
Show file tree
Hide file tree
Showing 11 changed files with 1,002 additions and 2 deletions.
63 changes: 63 additions & 0 deletions media-source/mediasource-addsourcebuffer.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@
<body>
<div id="log"></div>
<script>
mediasource_test(function(test, mediaElement, mediaSource)
{
mediaSource.endOfStream();
assert_throws("InvalidStateError",
function() { mediaSource.addSourceBuffer(MediaSourceUtil.AUDIO_VIDEO_TYPE); },
"addSourceBuffer() threw an exception when in 'ended' state.");
test.done();
}, "Test addSourceBuffer() in 'ended' state.");

mediasource_test(function(test, mediaElement, mediaSource)
{
assert_throws("InvalidAccessError",
Expand All @@ -17,6 +26,14 @@
test.done();
}, "Test addSourceBuffer() with empty type");

mediasource_test(function(test, mediaElement, mediaSource)
{
assert_throws("NotSupportedError",
function() { mediaSource.addSourceBuffer(null); },
"addSourceBuffer() threw an exception when passed null.");
test.done();
}, "Test addSourceBuffer() with null");

mediasource_test(function(test, mediaElement, mediaSource)
{
assert_throws("NotSupportedError",
Expand Down Expand Up @@ -56,6 +73,32 @@
test.done();
}, "Test addSourceBuffer() with Vorbis and VP8 in separate SourceBuffers");

mediasource_test(function(test, mediaElement, mediaSource)
{
var mimetype = MediaSourceUtil.VIDEO_ONLY_TYPE;

assert_true(MediaSource.isTypeSupported(mimetype), mimetype + " is supported");

var sourceBuffer = mediaSource.addSourceBuffer(mimetype);
assert_true(sourceBuffer != null, "New SourceBuffer returned");
assert_equals(mediaSource.sourceBuffers[0], sourceBuffer, "SourceBuffer is in mediaSource.sourceBuffers");
assert_equals(mediaSource.activeSourceBuffers.length, 0, "SourceBuffer is in mediaSource.activeSourceBuffers");
test.done();
}, "Test addSourceBuffer() video only");

mediasource_test(function(test, mediaElement, mediaSource)
{
var mimetype = MediaSourceUtil.AUDIO_ONLY_TYPE;

assert_true(MediaSource.isTypeSupported(mimetype), mimetype + " is supported");

var sourceBuffer = mediaSource.addSourceBuffer(mimetype);
assert_true(sourceBuffer != null, "New SourceBuffer returned");
assert_equals(mediaSource.sourceBuffers[0], sourceBuffer, "SourceBuffer is in mediaSource.sourceBuffers");
assert_equals(mediaSource.activeSourceBuffers.length, 0, "SourceBuffer is in mediaSource.activeSourceBuffers");
test.done();
}, "Test addSourceBuffer() audio only");

mediasource_test(function(test, mediaElement, mediaSource)
{
var mimetype = 'video/mp4;codecs="avc1.4D4001,mp4a.40.2"';
Expand Down Expand Up @@ -85,6 +128,26 @@
assert_equals(mediaSource.activeSourceBuffers.length, 0, "SourceBufferB is not in mediaSource.activeSourceBuffers");
test.done();
}, "Test addSourceBuffer() with AAC and H.264 in separate SourceBuffers");

mediasource_test(function(test, mediaElement, mediaSource)
{
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.");

</script>
</body>
</html>
287 changes: 287 additions & 0 deletions media-source/mediasource-append-buffer.html
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,45 @@
});
}, "Test SourceBuffer.appendBuffer() triggering an 'ended' to 'open' transition.");

mediasource_testafterdataloaded(function(test, mediaElement, mediaSource, segmentInfo, sourceBuffer, mediaData)
{
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(new Uint8Array(0));

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 zero byte SourceBuffer.appendBuffer() call triggering an 'ended' to 'open' transition.");

mediasource_testafterdataloaded(function(test, mediaElement, mediaSource, segmentInfo, sourceBuffer, mediaData)
{
test.failOnEvent(mediaElement, 'error');
Expand Down Expand Up @@ -227,6 +266,31 @@
});
}, "Test appending an empty ArrayBufferView.");

mediasource_testafterdataloaded(function(test, mediaElement, mediaSource, segmentInfo, sourceBuffer, mediaData)
{
test.expectEvent(sourceBuffer, "updatestart", "Append started.");
test.expectEvent(sourceBuffer, "update", "Append success.");
test.expectEvent(sourceBuffer, "updateend", "Append ended.");

var arrayBufferView = new Uint8Array(mediaData);

assert_equals(arrayBufferView.length, mediaData.length, "arrayBufferView.length before transfer.");

// Send the buffer as in a message so it gets neutered.
window.postMessage( "test", "*", [arrayBufferView.buffer]);

assert_equals(arrayBufferView.length, 0, "arrayBufferView.length after transfer.");

sourceBuffer.appendBuffer(arrayBufferView);

assert_true(sourceBuffer.updating, "updating attribute is true");

test.waitForExpectedEvents(function()
{
assert_false(sourceBuffer.updating, "updating attribute is false");
test.done();
});
}, "Test appending a neutered ArrayBufferView.");

mediasource_test(function(test, mediaElement, mediaSource)
{
Expand All @@ -246,6 +310,229 @@
});
}, "Test appending an empty ArrayBuffer.");

mediasource_testafterdataloaded(function(test, mediaElement, mediaSource, segmentInfo, sourceBuffer, mediaData)
{
test.expectEvent(sourceBuffer, "updatestart", "Append started.");
test.expectEvent(sourceBuffer, "update", "Append success.");
test.expectEvent(sourceBuffer, "updateend", "Append ended.");

var arrayBuffer = mediaData.buffer.slice();

assert_equals(arrayBuffer.byteLength, mediaData.buffer.byteLength, "arrayBuffer.byteLength before transfer.");

// Send the buffer as in a message so it gets neutered.
window.postMessage( "test", "*", [arrayBuffer]);

assert_equals(arrayBuffer.byteLength, 0, "arrayBuffer.byteLength after transfer.");

sourceBuffer.appendBuffer(arrayBuffer);

assert_true(sourceBuffer.updating, "updating attribute is true");

test.waitForExpectedEvents(function()
{
assert_false(sourceBuffer.updating, "updating attribute is false");
test.done();
});
}, "Test appending a neutered ArrayBuffer.");

mediasource_testafterdataloaded(function(test, mediaElement, mediaSource, segmentInfo, sourceBuffer, mediaData)
{
var initSegment = MediaSourceUtil.extractSegmentData(mediaData, segmentInfo.init);
var halfIndex = (initSegment.length + 1) / 2;
var partialInitSegment = initSegment.subarray(0, halfIndex);
var remainingInitSegment = initSegment.subarray(halfIndex);
var mediaSegment = MediaSourceUtil.extractSegmentData(mediaData, segmentInfo.media[0]);

test.expectEvent(sourceBuffer, "updateend", "partialInitSegment append ended.");
sourceBuffer.appendBuffer(partialInitSegment);

test.waitForExpectedEvents(function()
{
assert_equals(mediaElement.readyState, mediaElement.HAVE_NOTHING);
assert_equals(mediaSource.duration, Number.NaN);
test.expectEvent(sourceBuffer, "updateend", "remainingInitSegment append ended.");
test.expectEvent(mediaElement, "loadedmetadata", "loadedmetadata event received.");
sourceBuffer.appendBuffer(remainingInitSegment);
});

test.waitForExpectedEvents(function()
{
assert_equals(mediaElement.readyState, mediaElement.HAVE_METADATA);
assert_equals(mediaSource.duration, segmentInfo.duration);
test.expectEvent(sourceBuffer, "updateend", "mediaSegment append ended.");
test.expectEvent(mediaElement, "loadeddata", "loadeddata fired.");
sourceBuffer.appendBuffer(mediaSegment);
});

test.waitForExpectedEvents(function()
{
assert_greater_than_equal(mediaElement.readyState, mediaElement.HAVE_CURRENT_DATA);
assert_equals(sourceBuffer.updating, false);
assert_equals(mediaSource.readyState, "open");
test.done();
});
}, "Test appendBuffer with partial init segments.");

mediasource_testafterdataloaded(function(test, mediaElement, mediaSource, segmentInfo, sourceBuffer, mediaData)
{
var initSegment = MediaSourceUtil.extractSegmentData(mediaData, segmentInfo.init);
var mediaSegment = MediaSourceUtil.extractSegmentData(mediaData, segmentInfo.media[0]);
var halfIndex = (mediaSegment.length + 1) / 2;
var partialMediaSegment = mediaSegment.subarray(0, halfIndex);
var remainingMediaSegment = mediaSegment.subarray(halfIndex);

test.expectEvent(sourceBuffer, "updateend", "InitSegment append ended.");
test.expectEvent(mediaElement, "loadedmetadata", "loadedmetadata done.");
sourceBuffer.appendBuffer(initSegment);

test.waitForExpectedEvents(function()
{
assert_equals(mediaElement.readyState, mediaElement.HAVE_METADATA);
assert_equals(mediaSource.duration, segmentInfo.duration);
test.expectEvent(sourceBuffer, "updateend", "partial media segment append ended.");
sourceBuffer.appendBuffer(partialMediaSegment);
});

test.waitForExpectedEvents(function()
{
test.expectEvent(sourceBuffer, "updateend", "mediaSegment append ended.");
test.expectEvent(mediaElement, "loadeddata", "loadeddata fired.");
sourceBuffer.appendBuffer(remainingMediaSegment);
});

test.waitForExpectedEvents(function()
{
assert_greater_than_equal(mediaElement.readyState, mediaElement.HAVE_CURRENT_DATA);
assert_equals(mediaSource.readyState, "open");
assert_equals(sourceBuffer.updating, false);
test.done();
});
}, "Test appendBuffer with partial media segments.");

mediasource_testafterdataloaded(function(test, mediaElement, mediaSource, segmentInfo, sourceBuffer, mediaData)
{
var initSegment = MediaSourceUtil.extractSegmentData(mediaData, segmentInfo.init);
var partialInitSegment = initSegment.subarray(0, initSegment.length / 2);
var mediaSegment = MediaSourceUtil.extractSegmentData(mediaData, segmentInfo.media[0]);

test.expectEvent(sourceBuffer, "updateend", "partialInitSegment append ended.");
sourceBuffer.appendBuffer(partialInitSegment);

test.waitForExpectedEvents(function()
{
// Call abort to reset the parser.
sourceBuffer.abort();

// Append the full intiialization segment.
test.expectEvent(sourceBuffer, "updateend", "initSegment append ended.");
sourceBuffer.appendBuffer(initSegment);
});

test.waitForExpectedEvents(function()
{
test.expectEvent(sourceBuffer, "updateend", "mediaSegment append ended.");
test.expectEvent(mediaElement, "loadeddata", "loadeddata fired.");
sourceBuffer.appendBuffer(mediaSegment);
});

test.waitForExpectedEvents(function()
{
test.done();
});
}, "Test abort in the middle of an initialization segment.");

mediasource_testafterdataloaded(function(test, mediaElement, mediaSource, segmentInfo, sourceBuffer, mediaData)
{
test.expectEvent(mediaSource.sourceBuffers, "removesourcebuffer", "SourceBuffer removed.");
mediaSource.removeSourceBuffer(sourceBuffer);
test.waitForExpectedEvents(function()
{
assert_throws("InvalidStateError",
function() { sourceBuffer.abort(); },
"sourceBuffer.abort() throws an exception for InvalidStateError.");

test.done();
});
}, "Test abort after removing sourcebuffer.");

mediasource_testafterdataloaded(function(test, mediaElement, mediaSource, segmentInfo, sourceBuffer, mediaData)
{
var initSegment = MediaSourceUtil.extractSegmentData(mediaData, segmentInfo.init);
var mediaSegment = MediaSourceUtil.extractSegmentData(mediaData, segmentInfo.media[0]);

test.expectEvent(sourceBuffer, "updateend", "initSegment append ended.");
sourceBuffer.appendBuffer(initSegment);

test.waitForExpectedEvents(function()
{
assert_equals(mediaSource.readyState, "open", "readyState is open after init segment appended.");
test.expectEvent(sourceBuffer, "updateend", "mediaSegment append ended.");
sourceBuffer.appendBuffer(mediaSegment);
});

test.waitForExpectedEvents(function()
{
assert_equals(sourceBuffer.buffered.length, 1, "sourceBuffer has a buffered range");
assert_equals(mediaSource.readyState, "open", "readyState is open after media segment appended.");
test.expectEvent(mediaSource, "sourceended", "source ended");
mediaSource.endOfStream();
});

test.waitForExpectedEvents(function()
{
assert_equals(mediaSource.readyState, "ended", "readyState is ended.");
assert_throws("InvalidStateError",
function() { sourceBuffer.abort(); },
"sourceBuffer.abort() throws an exception for InvalidStateError.");
test.done();
});

}, "Test abort after readyState is ended following init segment and media segment.");

mediasource_testafterdataloaded(function(test, mediaElement, mediaSource, segmentInfo, sourceBuffer, mediaData)
{
test.expectEvent(sourceBuffer, "updatestart", "Append started.");
test.expectEvent(sourceBuffer, "updateend", "Append ended.");
sourceBuffer.appendWindowStart = 1;
sourceBuffer.appendWindowEnd = 100;
sourceBuffer.appendBuffer(mediaData);

test.waitForExpectedEvents(function()
{
assert_false(sourceBuffer.updating, "updating attribute is false");
sourceBuffer.abort();
assert_equals(sourceBuffer.appendWindowStart, 0, "appendWindowStart is reset to 0");
assert_equals(sourceBuffer.appendWindowEnd, Number.POSITIVE_INFINITY,
"appendWindowEnd is reset to +INFINITY");
test.done();
});
}, "Test abort after appendBuffer update ends.");

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.");

assert_throws( { name: "TypeError"} ,
function() { sourceBuffer.appendBuffer(null); },
"appendBuffer(null) throws an exception.");
test.done();
}, "Test appending null.");

mediasource_testafterdataloaded(function(test, mediaElement, mediaSource, segmentInfo, sourceBuffer, mediaData)
{
mediaSource.removeSourceBuffer(sourceBuffer);

assert_throws( { name: "InvalidStateError"} ,
function() { sourceBuffer.appendBuffer(mediaData); },
"appendBuffer() throws an exception when called after removeSourceBuffer().");
test.done();
}, "Test appending after removeSourceBuffer().");

</script>
</body>
</html>
Loading

0 comments on commit ab0ee7b

Please sign in to comment.