Skip to content

Commit

Permalink
Merge pull request web-platform-tests#3612 from wolenetz/tidoust-medi…
Browse files Browse the repository at this point in the history
…a-source-chromium

Some new media-source tests from Chromium
  • Loading branch information
wolenetz authored Aug 30, 2016
2 parents e9bb8c1 + b255ded commit bd1dc7b
Show file tree
Hide file tree
Showing 8 changed files with 708 additions and 0 deletions.
34 changes: 34 additions & 0 deletions media-source/mediasource-appendbuffer-quota-exceeded.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<!DOCTYPE html>
<!-- Copyright © 2016 Chromium authors and World Wide Web Consortium, (Massachusetts Institute of Technology, ERCIM, Keio University, Beihang). -->
<meta charset="utf-8">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="mediasource-util.js"></script>
<script>
// Fill up a given SourceBuffer by appending data repeatedly via doAppendDataFunc until
// an exception is thrown. The thrown exception is passed to onCaughtExceptionCallback.
function fillUpSourceBuffer(test, sourceBuffer, doAppendDataFunc, onCaughtExceptionCallback) {
// We are appending data repeatedly in sequence mode, there should be no gaps.
assert_false(sourceBuffer.buffered.length > 1, "unexpected gap in buffered ranges.");
try {
doAppendDataFunc();
} catch(ex) {
onCaughtExceptionCallback(ex);
}
test.expectEvent(sourceBuffer, 'updateend', 'append ended.');
test.waitForExpectedEvents(function() { fillUpSourceBuffer(test, sourceBuffer, doAppendDataFunc, onCaughtExceptionCallback); });
}

mediasource_testafterdataloaded(function(test, mediaElement, mediaSource, segmentInfo, sourceBuffer, mediaData)
{
sourceBuffer.mode = 'sequence';
fillUpSourceBuffer(test, sourceBuffer,
function () { // doAppendDataFunc
sourceBuffer.appendBuffer(mediaData);
},
function (ex) { // onCaughtExceptionCallback
assert_equals(ex.name, 'QuotaExceededError');
test.done();
});
}, 'Appending data repeatedly should fill up the buffer and throw a QuotaExceededError when buffer is full.');
</script>
124 changes: 124 additions & 0 deletions media-source/mediasource-avtracks.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
<!DOCTYPE html>
<!-- Copyright © 2016 Chromium authors and World Wide Web Consortium, (Massachusetts Institute of Technology, ERCIM, Keio University, Beihang). -->
<meta charset="utf-8">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="mediasource-util.js"></script>
<script>
mediasource_testafterdataloaded(function(test, mediaElement, mediaSource, segmentInfo, sourceBuffer, mediaData)
{
var initSegment = MediaSourceUtil.extractSegmentData(mediaData, segmentInfo.init);
sourceBuffer.appendBuffer(initSegment);
test.expectEvent(sourceBuffer.audioTracks, "addtrack", "sourceBuffer.audioTracks addtrack event");
test.expectEvent(sourceBuffer.videoTracks, "addtrack", "sourceBuffer.videoTracks addtrack event");
test.expectEvent(mediaElement.audioTracks, "addtrack", "mediaElement.audioTracks addtrack event");
test.expectEvent(mediaElement.videoTracks, "addtrack", "mediaElement.videoTracks addtrack event");
test.expectEvent(mediaElement, "loadedmetadata", "loadedmetadata done.");
test.expectEvent(sourceBuffer, "updateend", "initSegment append ended.");
test.waitForExpectedEvents(function()
{
assert_equals(sourceBuffer.videoTracks.length, 1, "videoTracks.length");
assert_equals(sourceBuffer.videoTracks[0].kind, "main", "videoTrack.kind");
assert_equals(sourceBuffer.videoTracks[0].label, "", "videoTrack.label");
assert_equals(sourceBuffer.videoTracks[0].language, "eng", "videoTrack.language");
assert_equals(sourceBuffer.videoTracks[0].sourceBuffer, sourceBuffer, "videoTrack.sourceBuffer");
// The first video track is selected by default.
assert_true(sourceBuffer.videoTracks[0].selected, "sourceBuffer.videoTracks[0].selected");

assert_equals(sourceBuffer.audioTracks.length, 1, "audioTracks.length");
assert_equals(sourceBuffer.audioTracks[0].kind, "main", "audioTrack.kind");
assert_equals(sourceBuffer.audioTracks[0].label, "", "audioTrack.label");
assert_equals(sourceBuffer.audioTracks[0].language, "eng", "audioTrack.language");
assert_equals(sourceBuffer.audioTracks[0].sourceBuffer, sourceBuffer, "audioTrack.sourceBuffer");
// The first audio track is enabled by default.
assert_true(sourceBuffer.audioTracks[0].enabled, "sourceBuffer.audioTracks[0].enabled");

assert_not_equals(sourceBuffer.audioTracks[0].id, sourceBuffer.videoTracks[0].id, "track ids must be unique");

assert_equals(mediaElement.videoTracks.length, 1, "videoTracks.length");
assert_equals(mediaElement.videoTracks[0], sourceBuffer.videoTracks[0], "mediaElement.videoTrack == sourceBuffer.videoTrack");

assert_equals(mediaElement.audioTracks.length, 1, "audioTracks.length");
assert_equals(mediaElement.audioTracks[0], sourceBuffer.audioTracks[0], "mediaElement.audioTrack == sourceBuffer.audioTrack");

test.done();
});
}, "Check that media tracks and their properties are populated properly");

function verifyTrackRemoval(test, mediaElement, mediaSource, sourceBuffer, trackRemovalAction, successCallback) {
assert_equals(sourceBuffer.audioTracks.length, 1, "audioTracks.length");
assert_true(sourceBuffer.audioTracks[0].enabled, "sourceBuffer.audioTracks[0].enabled");
assert_equals(sourceBuffer.videoTracks.length, 1, "videoTracks.length");
assert_true(sourceBuffer.videoTracks[0].selected, "sourceBuffer.videoTracks[0].selected");

var audioTrack = sourceBuffer.audioTracks[0];
var videoTrack = sourceBuffer.videoTracks[0];

// Verify removetrack events.
test.expectEvent(sourceBuffer.audioTracks, "removetrack", "sourceBuffer.audioTracks removetrack event");
test.expectEvent(sourceBuffer.videoTracks, "removetrack", "sourceBuffer.videoTracks removetrack event");
test.expectEvent(mediaElement.audioTracks, "removetrack", "mediaElement.audioTracks removetrack event");
test.expectEvent(mediaElement.videoTracks, "removetrack", "mediaElement.videoTracks removetrack event");

// Removing enabled audio track and selected video track should fire "change" events on mediaElement track lists.
test.expectEvent(mediaElement.audioTracks, "change", "mediaElement.audioTracks changed.");
test.expectEvent(mediaElement.videoTracks, "change", "mediaElement.videoTracks changed.");

trackRemovalAction();

test.waitForExpectedEvents(function()
{
assert_equals(mediaSource.sourceBuffers.length, 0, "mediaSource.sourceBuffers.length");
assert_equals(mediaElement.videoTracks.length, 0, "videoTracks.length");
assert_equals(mediaElement.audioTracks.length, 0, "audioTracks.length");
assert_equals(sourceBuffer.videoTracks.length, 0, "videoTracks.length");
assert_equals(sourceBuffer.audioTracks.length, 0, "audioTracks.length");
// Since audio and video tracks have been removed, their .sourceBuffer property should be null now.
assert_equals(audioTrack.sourceBuffer, null, "audioTrack.sourceBuffer");
assert_equals(videoTrack.sourceBuffer, null, "videoTrack.sourceBuffer");
test.done();
});
}

mediasource_testafterdataloaded(function(test, mediaElement, mediaSource, segmentInfo, sourceBuffer, mediaData)
{
var initSegment = MediaSourceUtil.extractSegmentData(mediaData, segmentInfo.init);
sourceBuffer.appendBuffer(initSegment);
test.expectEvent(sourceBuffer, "updateend", "initSegment append ended.");
test.waitForExpectedEvents(function()
{
verifyTrackRemoval(test, mediaElement, mediaSource, sourceBuffer, test.step_func(function ()
{
mediaSource.removeSourceBuffer(sourceBuffer);
}));
});
}, "Media tracks must be removed when the SourceBuffer is removed from the MediaSource");

mediasource_testafterdataloaded(function(test, mediaElement, mediaSource, segmentInfo, sourceBuffer, mediaData)
{
var initSegment = MediaSourceUtil.extractSegmentData(mediaData, segmentInfo.init);
sourceBuffer.appendBuffer(initSegment);
test.expectEvent(sourceBuffer, "updateend", "initSegment append ended.");
test.waitForExpectedEvents(function()
{
verifyTrackRemoval(test, mediaElement, mediaSource, sourceBuffer, test.step_func(function ()
{
mediaElement.src = "";
}));
});
}, "Media tracks must be removed when the HTMLMediaElement.src is changed");

mediasource_testafterdataloaded(function(test, mediaElement, mediaSource, segmentInfo, sourceBuffer, mediaData)
{
var initSegment = MediaSourceUtil.extractSegmentData(mediaData, segmentInfo.init);
sourceBuffer.appendBuffer(initSegment);
test.expectEvent(sourceBuffer, "updateend", "initSegment append ended.");
test.waitForExpectedEvents(function()
{
verifyTrackRemoval(test, mediaElement, mediaSource, sourceBuffer, test.step_func(function ()
{
mediaElement.load();
}));
});
}, "Media tracks must be removed when HTMLMediaElement.load() is called");
</script>
50 changes: 50 additions & 0 deletions media-source/mediasource-detach.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<!DOCTYPE html>
<!-- Copyright © 2016 Chromium authors and World Wide Web Consortium, (Massachusetts Institute of Technology, ERCIM, Keio University, Beihang). -->
<meta charset="utf-8">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="mediasource-util.js"></script>
<script>
function mediasource_detach_test(testFunction, description)
{
mediasource_test(function(test, mediaElement, mediaSource)
{
var segmentInfo = MediaSourceUtil.SEGMENT_INFO;
var sourceBuffer = mediaSource.addSourceBuffer(segmentInfo.type);

assert_equals(mediaElement.readyState, HTMLMediaElement.HAVE_NOTHING);
assert_equals(mediaSource.readyState, 'open');

mediaSource.addEventListener('sourceclose', test.step_func(function (event)
{
assert_equals(mediaSource.sourceBuffers.length, 0, 'sourceBuffers is empty');
assert_equals(mediaSource.activeSourceBuffers.length, 0, 'activeSourceBuffers is empty');
assert_equals(mediaSource.readyState, 'closed', 'readyState is "closed"');
assert_true(Number.isNaN(mediaSource.duration), 'duration is NaN');
test.done();
}));

MediaSourceUtil.loadBinaryData(test, segmentInfo.url, function(mediaData)
{
testFunction(test, mediaElement, mediaSource, sourceBuffer, mediaData);
});
}, description);
}

mediasource_detach_test(function(test, mediaElement, mediaSource, sourceBuffer, mediaData)
{
mediaElement.load();
}, 'Test media.load() before appending data will trigger MediaSource detaching from a media element.');

mediasource_detach_test(function(test, mediaElement, mediaSource, sourceBuffer, mediaData)
{
sourceBuffer.addEventListener('updateend', test.step_func(function (event)
{
assert_greater_than(mediaElement.readyState, HTMLMediaElement.HAVE_NOTHING, 'media readyState is greater than "HAVE_NOTHING"')
assert_false(sourceBuffer.updating, 'updating attribute is false');
mediaElement.load();
}));

sourceBuffer.appendBuffer(mediaData);
}, 'Test media.load() after appending data will trigger MediaSource detaching from a media element.');
</script>
Loading

0 comments on commit bd1dc7b

Please sign in to comment.