Commit 4cbeb826 authored by Matt Wolenetz's avatar Matt Wolenetz Committed by Commit Bot

MSE: Add SourceBuffer.changeType() web-platform-tests

Adds external/wpt tests for the SourceBuffer.changeType() method being
incubated in WICG/media-source spec repo's codec-switching branch.

BUG=605134

Change-Id: I52879fdff07473fbec6f5b44296dedd42619455c
Reviewed-on: https://chromium-review.googlesource.com/1111275
Commit-Queue: Matthew Wolenetz <wolenetz@chromium.org>
Reviewed-by: default avatarDan Sanders <sandersd@chromium.org>
Cr-Commit-Position: refs/heads/master@{#569812}
parent f5726ed5
This is a testharness.js-based test. This is a testharness.js-based test.
Found 143 tests; 140 PASS, 3 FAIL, 0 TIMEOUT, 0 NOTRUN. Found 147 tests; 144 PASS, 3 FAIL, 0 TIMEOUT, 0 NOTRUN.
PASS Partial interface URL: original interface defined PASS Partial interface URL: original interface defined
PASS Partial interface URL: valid exposure set PASS Partial interface URL: valid exposure set
PASS Partial interface AudioTrack: original interface defined PASS Partial interface AudioTrack: original interface defined
...@@ -103,6 +103,8 @@ PASS SourceBuffer interface: operation appendBuffer(BufferSource) ...@@ -103,6 +103,8 @@ PASS SourceBuffer interface: operation appendBuffer(BufferSource)
PASS Unscopable handled correctly for appendBuffer(BufferSource) on SourceBuffer PASS Unscopable handled correctly for appendBuffer(BufferSource) on SourceBuffer
PASS SourceBuffer interface: operation abort() PASS SourceBuffer interface: operation abort()
PASS Unscopable handled correctly for abort() on SourceBuffer PASS Unscopable handled correctly for abort() on SourceBuffer
PASS SourceBuffer interface: operation changeType(DOMString)
PASS Unscopable handled correctly for changeType(DOMString) on SourceBuffer
PASS SourceBuffer interface: operation remove(double, unrestricted double) PASS SourceBuffer interface: operation remove(double, unrestricted double)
PASS Unscopable handled correctly for remove(double, unrestricted double) on SourceBuffer PASS Unscopable handled correctly for remove(double, unrestricted double) on SourceBuffer
PASS SourceBuffer must be primary interface of sourceBuffer PASS SourceBuffer must be primary interface of sourceBuffer
...@@ -124,6 +126,8 @@ PASS SourceBuffer interface: sourceBuffer must inherit property "onabort" with t ...@@ -124,6 +126,8 @@ PASS SourceBuffer interface: sourceBuffer must inherit property "onabort" with t
PASS SourceBuffer interface: sourceBuffer must inherit property "appendBuffer(BufferSource)" with the proper type PASS SourceBuffer interface: sourceBuffer must inherit property "appendBuffer(BufferSource)" with the proper type
PASS SourceBuffer interface: calling appendBuffer(BufferSource) on sourceBuffer with too few arguments must throw TypeError PASS SourceBuffer interface: calling appendBuffer(BufferSource) on sourceBuffer with too few arguments must throw TypeError
PASS SourceBuffer interface: sourceBuffer must inherit property "abort()" with the proper type PASS SourceBuffer interface: sourceBuffer must inherit property "abort()" with the proper type
PASS SourceBuffer interface: sourceBuffer must inherit property "changeType(DOMString)" with the proper type
PASS SourceBuffer interface: calling changeType(DOMString) on sourceBuffer with too few arguments must throw TypeError
PASS SourceBuffer interface: sourceBuffer must inherit property "remove(double, unrestricted double)" with the proper type PASS SourceBuffer interface: sourceBuffer must inherit property "remove(double, unrestricted double)" with the proper type
PASS SourceBuffer interface: calling remove(double, unrestricted double) on sourceBuffer with too few arguments must throw TypeError PASS SourceBuffer interface: calling remove(double, unrestricted double) on sourceBuffer with too few arguments must throw TypeError
PASS SourceBufferList interface: existence and properties of interface object PASS SourceBufferList interface: existence and properties of interface object
......
...@@ -59,6 +59,7 @@ interface SourceBuffer : EventTarget { ...@@ -59,6 +59,7 @@ interface SourceBuffer : EventTarget {
attribute EventHandler onabort; attribute EventHandler onabort;
void appendBuffer(BufferSource data); void appendBuffer(BufferSource data);
void abort(); void abort();
void changeType(DOMString type);
void remove(double start, unrestricted double end); void remove(double start, unrestricted double end);
}; };
......
<!DOCTYPE html>
<!-- Copyright © 2018 Chromium authors and World Wide Web Consortium, (Massachusetts Institute of Technology, ERCIM, Keio University, Beihang). -->
<html>
<head>
<title>Exercise changeType for supported test types.</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="mediasource-util.js"></script>
<script src="mediasource-changetype-util.js"></script>
</head>
<body>
<div id="log"></div>
<script>
function generateChangeTypeTests(audio_types, video_types)
{
async_test(function(test) {
assert_true(audio_types.length > 1, "Browser doesn't support at least 2 types of audio test media" + audio_types);
assert_true(video_types.length > 1, "Browser doesn't support at least 2 types of video test media");
test.done();
}, "Check if browser supports enough test media types");
// Generate audio-only changeType tests
for (let audio1 of audio_types) {
for (let audio2 of audio_types) {
mediaSourceChangeTypeTest(audio1, audio2, "Test audio-only changeType for " + audio1.type + " <-> " + audio2.type);
}
}
// Generate video-only changeType tests
for (let video1 of video_types) {
for (let video2 of video_types) {
mediaSourceChangeTypeTest(video1, video2, "Test video-only changeType for " + video1.type + " <-> " + video2.type);
}
}
}
findSupportedChangeTypeTestTypes(generateChangeTypeTests);
</script>
</body>
</html>
// Copyright © 2018 Chromium authors and World Wide Web Consortium, (Massachusetts Institute of Technology, ERCIM, Keio University, Beihang).
function findSupportedChangeTypeTestTypes(cb)
{
var CHANGE_TYPE_MEDIA_LIST = [
{
type: 'video/webm; codecs="vp8"',
is_video: true,
url: 'webm/test-v-128k-320x240-24fps-8kfr.webm'
},
{
type: 'video/webm; codecs="vp9"',
is_video: true,
url: 'webm/test-vp9.webm'
},
{
type: 'video/mp4; codecs="avc1.4D4001"',
is_video: true,
url: 'mp4/test-v-128k-320x240-24fps-8kfr.mp4'
},
{
type: 'video/webm; codecs="vorbis"',
is_video: false,
url: 'webm/test-a-128k-44100Hz-1ch.webm'
},
{
type: 'video/mp4; codecs="mp4a.40.2"',
is_video: false,
url: 'mp4/test-a-128k-44100Hz-1ch.mp4'
},
{
type: 'audio/mpeg',
is_video: false,
url: 'mp3/sound_5.mp3'
}
];
var audio_result = [];
var video_result = [];
for (var i = 0; i < CHANGE_TYPE_MEDIA_LIST.length; ++i) {
var media = CHANGE_TYPE_MEDIA_LIST[i];
if (window.MediaSource && MediaSource.isTypeSupported(media.type)) {
if (media.is_video === true) {
video_result.push(media);
} else {
audio_result.push(media);
}
}
}
cb(audio_result, video_result);
}
function appendBuffer(test, sourceBuffer, data)
{
test.expectEvent(sourceBuffer, "update");
test.expectEvent(sourceBuffer, "updateend");
sourceBuffer.appendBuffer(data);
}
function trimBuffered(test, mediaElement, sourceBuffer, minimumPreviousDuration, newDuration)
{
assert_less_than(newDuration, minimumPreviousDuration);
assert_less_than(minimumPreviousDuration, mediaElement.duration);
test.expectEvent(sourceBuffer, "update");
test.expectEvent(sourceBuffer, "updateend");
sourceBuffer.remove(newDuration, Infinity);
}
function trimDuration(test, mediaElement, mediaSource, newDuration)
{
assert_less_than(newDuration, mediaElement.duration);
test.expectEvent(mediaElement, "durationchange");
mediaSource.duration = newDuration;
}
function runChangeTypeTest(test, mediaElement, mediaSource, typeA, dataA, typeB, dataB)
{
var sourceBuffer = mediaSource.addSourceBuffer(typeA);
appendBuffer(test, sourceBuffer, dataA);
// changeType A->B and append B starting at 0.5 seconds.
test.waitForExpectedEvents(function()
{
sourceBuffer.changeType(typeB);
sourceBuffer.timestampOffset = 0.5;
appendBuffer(test, sourceBuffer, dataB);
});
// changeType B->B and append B starting at 1.0 seconds.
test.waitForExpectedEvents(function()
{
sourceBuffer.changeType(typeB);
sourceBuffer.timestampOffset = 1.0;
appendBuffer(test, sourceBuffer, dataB);
});
// changeType B->A and append A starting at 1.5 seconds.
test.waitForExpectedEvents(function()
{
sourceBuffer.changeType(typeA);
sourceBuffer.timestampOffset = 1.5;
appendBuffer(test, sourceBuffer, dataA);
});
// changeTypoe A->A and append A starting at 1.3 seconds.
test.waitForExpectedEvents(function()
{
sourceBuffer.changeType(typeA);
sourceBuffer.timestampOffset = 1.3;
appendBuffer(test, sourceBuffer, dataA);
});
// Trim duration to 2 seconds, then play through to end.
test.waitForExpectedEvents(function()
{
trimBuffered(test, mediaElement, sourceBuffer, 2.1, 2);
});
test.waitForExpectedEvents(function()
{
trimDuration(test, mediaElement, mediaSource, 2);
});
test.waitForExpectedEvents(function()
{
assert_equals(mediaElement.currentTime, 0);
test.expectEvent(mediaSource, "sourceended");
test.expectEvent(mediaElement, "play");
test.expectEvent(mediaElement, "ended");
mediaSource.endOfStream();
mediaElement.play();
});
test.waitForExpectedEvents(function() {
test.done();
});
}
function mediaSourceChangeTypeTest(metadataA, metadataB, description)
{
mediasource_test(function(test, mediaElement, mediaSource)
{
mediaElement.pause();
mediaElement.addEventListener('error', test.unreached_func("Unexpected event 'error'"));
MediaSourceUtil.loadBinaryData(test, metadataA.url, function(dataA) {
MediaSourceUtil.loadBinaryData(test, metadataB.url, function(dataB) {
runChangeTypeTest(test, mediaElement, mediaSource, metadataA.type, dataA, metadataB.type, dataB);
});
});
}, description);
}
<!DOCTYPE html>
<!-- Copyright © 2018 Chromium authors and World Wide Web Consortium, (Massachusetts Institute of Technology, ERCIM, Keio University, Beihang). -->
<html>
<head>
<meta charset="utf-8">
<title>SourceBuffer.changeType() test cases.</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="mediasource-util.js"></script>
</head>
<body>
<div id="log"></div>
<script>
mediasource_test(function(test, mediaElement, mediaSource)
{
var sourceBuffer = mediaSource.addSourceBuffer(MediaSourceUtil.AUDIO_VIDEO_TYPE);
assert_throws(new TypeError(), function()
{
sourceBuffer.changeType("");
}, "changeType");
test.done();
}, "Test changeType with an empty type.");
mediasource_test(function(test, mediaElement, mediaSource)
{
var sourceBuffer = mediaSource.addSourceBuffer(MediaSourceUtil.AUDIO_VIDEO_TYPE);
mediaSource.removeSourceBuffer(sourceBuffer);
assert_throws("InvalidStateError", function()
{
sourceBuffer.changeType(MediaSourceUtil.AUDIO_VIDEO_TYPE);
}, "changeType");
test.done();
}, "Test changeType after SourceBuffer removed from mediaSource.");
mediasource_test(function(test, mediaElement, mediaSource)
{
var sourceBuffer = mediaSource.addSourceBuffer(MediaSourceUtil.AUDIO_VIDEO_TYPE);
sourceBuffer.appendBuffer(new Uint8Array(0));
assert_true(sourceBuffer.updating, "Updating flag set when a buffer is appended.");
assert_throws("InvalidStateError", function()
{
sourceBuffer.changeType(MediaSourceUtil.AUDIO_VIDEO_TYPE);
}, "changeType");
test.done();
}, "Test changeType while update pending.");
mediasource_test(function(test, mediaElement, mediaSource)
{
var sourceBuffer = mediaSource.addSourceBuffer(MediaSourceUtil.AUDIO_VIDEO_TYPE);
var unsupported_type = null;
assert_false(MediaSource.isTypeSupported(unsupported_type), "null MIME type is not expected to be supported.");
assert_throws("NotSupportedError", function()
{
sourceBuffer.changeType(unsupported_type);
}, "changeType");
test.done();
}, "Test changeType with null type.");
mediasource_test(function(test, mediaElement, mediaSource)
{
var sourceBuffer = mediaSource.addSourceBuffer(MediaSourceUtil.AUDIO_VIDEO_TYPE);
var unsupported_type = 'invalidType';
assert_false(MediaSource.isTypeSupported(unsupported_type), unsupported_type + " is not expected to be supported.");
assert_throws("NotSupportedError", function()
{
sourceBuffer.changeType(unsupported_type);
}, "changeType");
test.done();
}, "Test changeType with unsupported type.");
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(mediaSource, "sourceopen");
sourceBuffer.changeType(MediaSourceUtil.AUDIO_VIDEO_TYPE);
assert_equals(mediaSource.readyState, "open");
});
test.waitForExpectedEvents(function()
{
test.done();
});
}, "Test changeType transitioning readyState from 'ended' to 'open'.");
mediasource_test(function(test, mediaElement, mediaSource) {
var sequenceType = "audio/aac";
if (!MediaSource.isTypeSupported(sequenceType)) {
sequenceType = "audio/mpeg";
assert_true(MediaSource.isTypeSupported(sequenceType),
"No bytestream that generates timestamps is supported, aborting test");
}
assert_not_equals(MediaSourceUtil.AUDIO_ONLY_TYPE, sequenceType,
"This test requires distinct audio-only types");
var sourceBuffer = mediaSource.addSourceBuffer(MediaSourceUtil.AUDIO_ONLY_TYPE);
assert_equals(sourceBuffer.mode, "segments",
"None of the audioOnlyTypes in the test util generate timestamps, but mode is incorrectly set");
sourceBuffer.changeType(sequenceType);
assert_equals(sourceBuffer.mode, "sequence",
"Mode is not updated correctly for a bytestream that generates timestamps");
test.done();
}, "Test changeType sets mode to sequence for change to type that generates timestamps");
mediasource_test(function(test, mediaElement, mediaSource) {
var sourceBuffer = mediaSource.addSourceBuffer(MediaSourceUtil.AUDIO_ONLY_TYPE);
assert_equals(sourceBuffer.mode, "segments",
"None of the audioOnlyTypes in the test util generate timestamps, but mode is incorrectly set");
sourceBuffer.changeType(MediaSourceUtil.AUDIO_ONLY_TYPE);
assert_equals(sourceBuffer.mode, "segments",
"Previous segments mode is not retained correctly for changeType to one that doesn't generate timestamps");
sourceBuffer.mode = "sequence";
assert_equals(sourceBuffer.mode, "sequence", "mode should be sequence now");
sourceBuffer.changeType(MediaSourceUtil.AUDIO_ONLY_TYPE);
assert_equals(sourceBuffer.mode, "sequence",
"Previous sequence mode is not retained correctly for changeType to one that doesn't generate timestamps");
test.done();
}, "Test changeType retains previous mode when changing to type that doesn't generate timestamps");
</script>
</body>
</html>
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