haikuwebkit/LayoutTests/media/video-poster-not-found.html

36 lines
1.3 KiB
HTML
Raw Permalink Normal View History

HTMLVideoElement with a broken poster image will take square dimension https://bugs.webkit.org/show_bug.cgi?id=174122 <rdar://problem/33121806> Patch by Peng Liu <peng.liu6@apple.com> on 2019-09-19 Reviewed by Daniel Bates. Source/WebCore: For a video element, if only the width attribute is given and the height attribute is missing, an invalid poster image will make its aspect ratio to be 1, which is the historical WebKit behavior if we're painting alt text and/or a broken image. This fix prevents that behavior to impact video elements. We add a virtual function shouldDisplayBrokenImageIcon() to RenderImage and it will return true only when the image source is given but cannot be downloaded. RenderMedia overrides this virtual function and always return false because it never shows the broken image icon. RenderVideo inherits that behavior from RenderMedia. Then, in RenderImage::computeIntrinsicRatioInformation(), we only set the aspect ratio to 1 when we need to show the broken image icon. It is the historical WebKit behavior that we want to keep for image element, but we also want to avoid its impact (this bug) on video elements. We also replace the imageResource().errorOccurred() with shouldDisplayBrokenImageIcon() in TreeBuilder::createLayoutBox() for the same reason. The logic to display the broken image icon in RenderImage::renderReplaced() is also cleaned up. Test: media/video-poster-not-found.html * layout/layouttree/LayoutTreeBuilder.cpp: (WebCore::Layout::TreeBuilder::createLayoutBox): * rendering/RenderImage.cpp: (WebCore::RenderImage::shouldDisplayBrokenImageIcon const): (WebCore::RenderImage::paintReplaced): (WebCore::RenderImage::computeIntrinsicRatioInformation const): * rendering/RenderImage.h: * rendering/RenderMedia.h: LayoutTests: When only the width (no height) attribute of a video element is given and the the poster image is missing (cannot be downloaded), the aspect ratio of the video element should not be 1, which is the default behavior of WebKit to paint a broken image. Instead, it should be the aspect ratio of the video content. * media/video-poster-not-found-expected.txt: Added. * media/video-poster-not-found.html: Added. Canonical link: https://commits.webkit.org/215615@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@250100 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2019-09-19 19:19:37 +00:00
<!DOCTYPE html>
<html>
<head>
<title>video-poster-not-found</title>
<script src=video-test.js></script>
<script src="media-file.js"></script>
<script>
function go()
{
findMediaElement();
run('video.src = findMediaFile("video", "content/test")');
waitForEventOnce('canplaythrough', canplaythrough);
}
function canplaythrough()
{
// When only the width attribute is given and the height attribute is missing,
// for an image element, if it cannot download the image (a broken url?),
// the historical WebKit behavior is to set the aspect ratio of the element to 1.
// However, for a video element, if the poster image cannot be downloaded,
// the aspect ratio of the element should not be hardcoded 1, instead, it must be decided by the video content.
testExpected("video.clientWidth", 320);
testExpected("video.clientHeight", 240);
endTest();
}
</script>
</head>
<body onload="go()">
<video width=320 poster="notfound.jpg"></video>
<p>Test &lt;video&gt; element with only width attribute and the poster is missing (cannot be downloaded).</p>
</body>
</html>