Bug 1362165: Add web platform test. r=gerald

readyState is supposed to be updated during MSE's Initialization Segment Received and Coded Frame Processing algorithm.
Only then would the appendBuffer operation terminates by queueing the update/updateend events.

These tests ensure that loadedmetadata and loadeddata are fired first.

MozReview-Commit-ID: BJ5gISQRA7B

--HG--
extra : rebase_source : 3b4956c360224caa50019a6286f0bc6c7f772f63
This commit is contained in:
Jean-Yves Avenard 2017-05-11 10:43:25 +02:00
parent 2dc6972be9
commit b1fcfd70be

View File

@ -411,6 +411,58 @@
});
}, "Test appendBuffer with partial media 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]);
assert_equals(mediaElement.readyState, mediaElement.HAVE_NOTHING);
assert_equals(mediaSource.duration, Number.NaN);
// readyState is changing as per the Initialization Segment Received algorithm.
var loadedmetadataCalled = false;
mediaElement.addEventListener("loadedmetadata", function metadata(e) {
loadedmetadataCalled = true;
e.target.removeEventListener(e.type, metadata);
});
sourceBuffer.addEventListener("updateend", function updateend(e) {
assert_true(loadedmetadataCalled);
assert_equals(mediaElement.readyState, mediaElement.HAVE_METADATA);
e.target.removeEventListener(e.type, updateend);
});
test.expectEvent(sourceBuffer, "updateend", "remainingInitSegment append ended.");
test.expectEvent(mediaElement, "loadedmetadata", "loadedmetadata event received.");
sourceBuffer.appendBuffer(initSegment);
test.waitForExpectedEvents(function()
{
assert_equals(mediaElement.readyState, mediaElement.HAVE_METADATA);
assert_equals(mediaSource.duration, segmentInfo.duration);
// readyState is changing as per the Coded Frame Processing algorithm.
var loadeddataCalled = false;
mediaElement.addEventListener("loadeddata", function loadeddata(e) {
loadeddataCalled = true;
e.target.removeEventListener(e.type, loadeddata);
});
sourceBuffer.addEventListener("updateend", function updateend(e) {
assert_true(loadeddataCalled);
assert_greater_than_equal(mediaElement.readyState, mediaElement.HAVE_CURRENT_DATA);
e.target.removeEventListener(e.type, updateend);
});
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 events order.");
mediasource_testafterdataloaded(function(test, mediaElement, mediaSource, segmentInfo, sourceBuffer, mediaData)
{
var initSegment = MediaSourceUtil.extractSegmentData(mediaData, segmentInfo.init);