LibWeb: Partially implement MediaSource.isTypeSupported()
This commit is contained in:
parent
0adf261c32
commit
24069d55bf
Notes:
github-actions[bot]
2024-11-26 22:51:58 +00:00
Author: https://github.com/gmta Commit: https://github.com/LadybirdBrowser/ladybird/commit/24069d55bf6 Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/2588 Reviewed-by: https://github.com/shannonbooth
5 changed files with 200 additions and 1 deletions
|
@ -8,6 +8,7 @@
|
|||
#include <LibWeb/Bindings/MediaSourcePrototype.h>
|
||||
#include <LibWeb/MediaSourceExtensions/EventNames.h>
|
||||
#include <LibWeb/MediaSourceExtensions/MediaSource.h>
|
||||
#include <LibWeb/MimeSniff/MimeType.h>
|
||||
|
||||
namespace Web::MediaSourceExtensions {
|
||||
|
||||
|
@ -67,4 +68,28 @@ GC::Ptr<WebIDL::CallbackType> MediaSource::onsourceclose()
|
|||
return event_handler_attribute(EventNames::sourceclose);
|
||||
}
|
||||
|
||||
// https://w3c.github.io/media-source/#dom-mediasource-istypesupported
|
||||
bool MediaSource::is_type_supported(JS::VM&, String const& type)
|
||||
{
|
||||
// 1. If type is an empty string, then return false.
|
||||
if (type.is_empty())
|
||||
return false;
|
||||
|
||||
// 2. If type does not contain a valid MIME type string, then return false.
|
||||
auto mime_type = MimeSniff::MimeType::parse(type);
|
||||
if (!mime_type.has_value())
|
||||
return false;
|
||||
|
||||
// FIXME: 3. If type contains a media type or media subtype that the MediaSource does not support, then
|
||||
// return false.
|
||||
|
||||
// FIXME: 4. If type contains a codec that the MediaSource does not support, then return false.
|
||||
|
||||
// FIXME: 5. If the MediaSource does not support the specified combination of media type, media
|
||||
// subtype, and codecs then return false.
|
||||
|
||||
// 6. Return true.
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -30,6 +30,8 @@ public:
|
|||
void set_onsourceclose(GC::Ptr<WebIDL::CallbackType>);
|
||||
GC::Ptr<WebIDL::CallbackType> onsourceclose();
|
||||
|
||||
static bool is_type_supported(JS::VM&, String const&);
|
||||
|
||||
protected:
|
||||
MediaSource(JS::Realm&);
|
||||
|
||||
|
|
|
@ -38,5 +38,5 @@ interface MediaSource : EventTarget {
|
|||
[FIXME] undefined endOfStream(optional EndOfStreamError error);
|
||||
[FIXME] undefined setLiveSeekableRange(double start, double end);
|
||||
[FIXME] undefined clearLiveSeekableRange();
|
||||
[FIXME] static boolean isTypeSupported(DOMString type);
|
||||
static boolean isTypeSupported(DOMString type);
|
||||
};
|
||||
|
|
|
@ -0,0 +1,66 @@
|
|||
Summary
|
||||
|
||||
Harness status: OK
|
||||
|
||||
Rerun
|
||||
|
||||
Found 55 tests
|
||||
|
||||
28 Pass
|
||||
27 Fail
|
||||
Details
|
||||
Result Test Name MessagePass Test invalid MIME format "video"
|
||||
Pass Test invalid MIME format "video/"
|
||||
Fail Test invalid MIME format "video/webm"
|
||||
Fail Test invalid MIME format "video/webm;"
|
||||
Fail Test invalid MIME format "video/webm;codecs"
|
||||
Fail Test invalid MIME format "video/webm;codecs="
|
||||
Fail Test invalid MIME format "video/webm;codecs=""
|
||||
Fail Test invalid MIME format "video/webm;codecs="""
|
||||
Fail Test invalid MIME format "video/webm;codecs=",""
|
||||
Fail Test invalid MIME format "audio/webm;aaacodecsbbb=opus"
|
||||
Pass Test invalid MIME format "unsupported_mediatype"
|
||||
Pass Test invalid MIME format ""
|
||||
Pass Test invalid MIME format "null"
|
||||
Pass Test invalid MSE MIME media type "xxx"
|
||||
Fail Test invalid MSE MIME media type "text/html"
|
||||
Fail Test invalid MSE MIME media type "image/jpeg"
|
||||
Fail Test invalid mismatch between MIME type and codec ID "audio/webm;codecs="vp8""
|
||||
Fail Test invalid mismatch between MIME type and codec ID "audio/mp4;codecs="avc1.4d001e""
|
||||
Fail Test invalid mismatch between MIME type and codec ID "audio/mp4;codecs="vorbis""
|
||||
Fail Test invalid mismatch between MIME type and codec ID "audio/webm;codecs="mp4a.40.2""
|
||||
Fail Test invalid mismatch between MIME type and codec ID "video/mp4;codecs="vp8""
|
||||
Fail Test invalid mismatch between MIME type and codec ID "video/mp4;codecs="vorbis""
|
||||
Fail Test invalid mismatch between MIME type and codec ID "video/webm;codecs="mp4a.40.2""
|
||||
Fail Test invalid inclusion of codecs parameter for mpeg audio types "audio/mpeg;codecs="mp3""
|
||||
Fail Test invalid inclusion of codecs parameter for mpeg audio types "audio/mpeg;codecs="mp4a.69""
|
||||
Fail Test invalid inclusion of codecs parameter for mpeg audio types "audio/mpeg;codecs="mp4a.6B""
|
||||
Fail Test invalid inclusion of codecs parameter for mpeg audio types "audio/aac;codecs="aac""
|
||||
Fail Test invalid inclusion of codecs parameter for mpeg audio types "audio/aac;codecs="adts""
|
||||
Fail Test invalid inclusion of codecs parameter for mpeg audio types "audio/aac;codecs="mp4a.40""
|
||||
Fail Test invalid codec ID "audio/mp4;codecs="mp4a""
|
||||
Fail Test invalid codec ID "audio/mp4;codecs="mp4a.40""
|
||||
Fail Test invalid codec ID "audio/mp4;codecs="mp4a.40.""
|
||||
Fail Test invalid codec ID "audio/mp4;codecs="mp4a.67.3""
|
||||
Pass Test valid WebM type "video/webm;codecs="vp8""
|
||||
Pass Test valid WebM type "video/webm;codecs="vorbis""
|
||||
Pass Test valid WebM type "video/webm;codecs="vp8,vorbis""
|
||||
Pass Test valid WebM type "video/webm;codecs="vorbis, vp8""
|
||||
Pass Test valid WebM type "audio/webm;codecs="vorbis""
|
||||
Pass Test valid WebM type "AUDIO/WEBM;CODECS="vorbis""
|
||||
Pass Test valid WebM type "audio/webm;codecs=vorbis;test="6""
|
||||
Pass Test valid WebM type "audio/webm;codecs="opus""
|
||||
Pass Test valid WebM type "video/webm;codecs="opus""
|
||||
Pass Test valid MP4 type "video/mp4;codecs="avc1.4d001e""
|
||||
Pass Test valid MP4 type "video/mp4;codecs="avc1.42001e""
|
||||
Pass Test valid MP4 type "audio/mp4;codecs="mp4a.40.2""
|
||||
Pass Test valid MP4 type "audio/mp4;codecs="mp4a.40.5""
|
||||
Pass Test valid MP4 type "audio/mp4;codecs="mp4a.67""
|
||||
Pass Test valid MP4 type "video/mp4;codecs="mp4a.40.2""
|
||||
Pass Test valid MP4 type "video/mp4;codecs="avc1.4d001e,mp4a.40.2""
|
||||
Pass Test valid MP4 type "video/mp4;codecs="mp4a.40.2 , avc1.4d001e ""
|
||||
Pass Test valid MP4 type "video/mp4;codecs="avc1.4d001e,mp4a.40.5""
|
||||
Pass Test valid MP4 type "audio/mp4;codecs="Opus""
|
||||
Pass Test valid MP4 type "video/mp4;codecs="Opus""
|
||||
Pass Test valid MP4 type "audio/mp4;codecs="fLaC""
|
||||
Pass Test valid MP4 type "video/mp4;codecs="fLaC""
|
|
@ -0,0 +1,106 @@
|
|||
<!DOCTYPE html>
|
||||
<!-- Copyright © 2016 Chromium authors and World Wide Web Consortium, (Massachusetts Institute of Technology, ERCIM, Keio University, Beihang). -->
|
||||
<html>
|
||||
<head>
|
||||
<title>MediaSource.isTypeSupported() test cases.</title>
|
||||
<script src="../resources/testharness.js"></script>
|
||||
<script src="../resources/testharnessreport.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<div id="log"></div>
|
||||
<script>
|
||||
// Generate a distinct test for each type in types
|
||||
function test_type_support(types, expectation, description)
|
||||
{
|
||||
for (var i = 0; i < types.length; ++i) {
|
||||
test(function()
|
||||
{
|
||||
assert_equals(MediaSource.isTypeSupported(types[i]),
|
||||
expectation, 'supported');
|
||||
}, description + ' "' + types[i] + '"');
|
||||
}
|
||||
};
|
||||
|
||||
test_type_support([
|
||||
'video',
|
||||
'video/',
|
||||
'video/webm',
|
||||
'video/webm;',
|
||||
'video/webm;codecs',
|
||||
'video/webm;codecs=',
|
||||
'video/webm;codecs="',
|
||||
'video/webm;codecs=""',
|
||||
'video/webm;codecs=","',
|
||||
'audio/webm;aaacodecsbbb=opus',
|
||||
'unsupported_mediatype',
|
||||
'',
|
||||
null
|
||||
], false, 'Test invalid MIME format');
|
||||
|
||||
test_type_support([
|
||||
'xxx',
|
||||
'text/html',
|
||||
'image/jpeg'
|
||||
], false, 'Test invalid MSE MIME media type');
|
||||
|
||||
test_type_support([
|
||||
'audio/webm;codecs="vp8"',
|
||||
'audio/mp4;codecs="avc1.4d001e"',
|
||||
'audio/mp4;codecs="vorbis"',
|
||||
'audio/webm;codecs="mp4a.40.2"',
|
||||
'video/mp4;codecs="vp8"',
|
||||
'video/mp4;codecs="vorbis"',
|
||||
'video/webm;codecs="mp4a.40.2"',
|
||||
], false, 'Test invalid mismatch between MIME type and codec ID');
|
||||
|
||||
// Note that, though the user agent might support some subset of
|
||||
// these for progressive non-MSE playback, the MSE mpeg audio
|
||||
// bytestream format specification requires there to be no codecs
|
||||
// parameter.
|
||||
test_type_support([
|
||||
'audio/mpeg;codecs="mp3"',
|
||||
'audio/mpeg;codecs="mp4a.69"',
|
||||
'audio/mpeg;codecs="mp4a.6B"',
|
||||
'audio/aac;codecs="aac"',
|
||||
'audio/aac;codecs="adts"',
|
||||
'audio/aac;codecs="mp4a.40"',
|
||||
], false, 'Test invalid inclusion of codecs parameter for mpeg audio types');
|
||||
|
||||
test_type_support([
|
||||
'audio/mp4;codecs="mp4a"',
|
||||
'audio/mp4;codecs="mp4a.40"',
|
||||
'audio/mp4;codecs="mp4a.40."',
|
||||
'audio/mp4;codecs="mp4a.67.3"'
|
||||
], false, 'Test invalid codec ID');
|
||||
|
||||
test_type_support([
|
||||
'video/webm;codecs="vp8"',
|
||||
'video/webm;codecs="vorbis"',
|
||||
'video/webm;codecs="vp8,vorbis"',
|
||||
'video/webm;codecs="vorbis, vp8"',
|
||||
'audio/webm;codecs="vorbis"',
|
||||
'AUDIO/WEBM;CODECS="vorbis"',
|
||||
'audio/webm;codecs=vorbis;test="6"',
|
||||
'audio/webm;codecs="opus"',
|
||||
'video/webm;codecs="opus"'
|
||||
], true, 'Test valid WebM type');
|
||||
|
||||
test_type_support([
|
||||
'video/mp4;codecs="avc1.4d001e"', // H.264 Main Profile level 3.0
|
||||
'video/mp4;codecs="avc1.42001e"', // H.264 Baseline Profile level 3.0
|
||||
'audio/mp4;codecs="mp4a.40.2"', // MPEG4 AAC-LC
|
||||
'audio/mp4;codecs="mp4a.40.5"', // MPEG4 HE-AAC
|
||||
'audio/mp4;codecs="mp4a.67"', // MPEG2 AAC-LC
|
||||
'video/mp4;codecs="mp4a.40.2"',
|
||||
'video/mp4;codecs="avc1.4d001e,mp4a.40.2"',
|
||||
'video/mp4;codecs="mp4a.40.2 , avc1.4d001e "',
|
||||
'video/mp4;codecs="avc1.4d001e,mp4a.40.5"',
|
||||
'audio/mp4;codecs="Opus"',
|
||||
'video/mp4;codecs="Opus"',
|
||||
'audio/mp4;codecs="fLaC"',
|
||||
'video/mp4;codecs="fLaC"'
|
||||
], true, 'Test valid MP4 type');
|
||||
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
Loading…
Add table
Reference in a new issue