Truly independent web browser
LibWeb: Skip a media source whose type attribute can’t be played
sideshowbarker0d4937e8dd2f
diff --git a/Libraries/LibWeb/HTML/HTMLMediaElement.cpp b/Libraries/LibWeb/HTML/HTMLMediaElement.cppindex 67bc45630ac..ac63efae713 100644--- a/Libraries/LibWeb/HTML/HTMLMediaElement.cpp+++ b/Libraries/LibWeb/HTML/HTMLMediaElement.cpp@@ -1073,9 +1073,16 @@ public:return;}- // FIXME: 6. ⌛ If candidate has a type attribute whose value, when parsed as a MIME type (including any codecs described- // by the codecs parameter, for types that define that parameter), represents a type that the user agent knows- // it cannot render, then end the synchronous section, and jump down to the failed with elements step below.+ // 6. ⌛ If candidate has a type attribute whose value, when parsed as a MIME type (including any codecs described by+ // the codecs parameter, for types that define that parameter), represents a type that the user agent knows it+ // cannot render, then end the synchronous section, and jump down to the failed with elements step below.+ // NB: An empty type attribute names no type, so unlike an unparseable one, it doesn't rule the source out.+ if (auto type = m_candidate->get_attribute(HTML::AttributeNames::type); type.has_value() && !type->is_empty()) {+ if (m_media_element->can_play_type(*type) == Bindings::CanPlayTypeResult::Empty) {+ failed_with_elements();+ return;+ }+ }// 7. ⌛ Set the currentSrc attribute to the result of applying the URL serializer to urlRecord.m_media_element->m_current_src = utf16_string_from_url_ascii(url_record->serialize());diff --git a/Tests/LibWeb/Text/expected/HTML/HTMLMediaElement-source-type-attribute.txt b/Tests/LibWeb/Text/expected/HTML/HTMLMediaElement-source-type-attribute.txtnew file mode 100644index 00000000000..fd1e0e2403e--- /dev/null+++ b/Tests/LibWeb/Text/expected/HTML/HTMLMediaElement-source-type-attribute.txt@@ -0,0 +1,8 @@+unsupported type: currentSrc=(none)+supported type: currentSrc=a.mp4+empty type: currentSrc=a.mp4+unparseable type: currentSrc=(none)+application/octet-stream: currentSrc=(none)+unsupported codec: currentSrc=(none)+unsupported type, then a supported one: currentSrc=b.mp4+unsupported type, then no type: currentSrc=b.mp4diff --git a/Tests/LibWeb/Text/input/HTML/HTMLMediaElement-source-type-attribute.html b/Tests/LibWeb/Text/input/HTML/HTMLMediaElement-source-type-attribute.htmlnew file mode 100644index 00000000000..be4d58b9235--- /dev/null+++ b/Tests/LibWeb/Text/input/HTML/HTMLMediaElement-source-type-attribute.html@@ -0,0 +1,39 @@+<!DOCTYPE html>+<script src="../include.js"></script>+<body>+<script>+ // A source whose type can't be played is skipped without being fetched, so it never becomes the current+ // source, and selection moves on to the next one. An empty type rules nothing out.+ const cases = [+ ["unsupported type", [["a.bin", "video/x-unsupported"]]],+ ["supported type", [["a.mp4", "video/mp4"]]],+ ["empty type", [["a.mp4", ""]]],+ ["unparseable type", [["a.mp4", "not a mime type"]]],+ ["application/octet-stream", [["a.bin", "application/octet-stream"]]],+ ["unsupported codec", [["a.mp4", 'video/mp4; codecs="nope.1"']]],+ ["unsupported type, then a supported one", [["a.m3u8", "application/x-mpegURL"], ["b.mp4", "video/mp4"]]],+ ["unsupported type, then no type", [["a.bin", "video/x-unsupported"], ["b.mp4", null]]],+ ];+ const videos = cases.map(([name, sources]) => {+ const video = document.createElement("video");+ for (const [file, type] of sources) {+ const source = document.createElement("source");+ source.src = `file:///nonexistent-media-file-${file}`;+ if (type !== null)+ source.type = type;+ video.append(source);+ }+ document.body.append(video);+ return [name, video];+ });++ asyncTest(done => {+ window.addEventListener("load", () => {+ for (const [name, video] of videos) {+ const current = video.currentSrc ? video.currentSrc.replace("file:///nonexistent-media-file-", "") : "(none)";+ println(`${name}: currentSrc=${current}`);+ }+ done();+ });+ });+</script>