commit 0946e78ab1023584e50a0cd4149a7d387ab778f4
parent 75101d5ffba3ee8c1fdbbf0e14de496755257eac
Author: Fredrik Söderquist <fs@opera.com>
Date: Thu, 6 Nov 2025 21:31:46 +0000
Bug 1997352 [wpt PR 55765] - Keep natural size for LayoutImage as 0x0 before the image is available, a=testonly
Automatic update from web-platform-tests
Keep natural size for LayoutImage as 0x0 before the image is available
We were using the LayoutImageResource::HasImage() predicate to guard
reading the natural size. In the case where we've received a small part
of the image data, but not enough to yet determine the size, we would
set a natural size of "none", which would then yield a layout using the
default size of 300x150.
Add LayoutImageResource::IsSizeAvailable() and use that instead.
Fixed: 454152420
Change-Id: I4b73af4fba5a0b9cc037813889bc1028a3b35b82
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/7088855
Commit-Queue: Fredrik Söderquist <fs@opera.com>
Reviewed-by: Ian Kilpatrick <ikilpatrick@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1537960}
--
wpt-commits: 0a1941ab9e47a706507a15195fe366587e0df066
wpt-pr: 55765
Diffstat:
1 file changed, 40 insertions(+), 0 deletions(-)
diff --git a/testing/web-platform/tests/html/rendering/replaced-elements/images/img-represents-image-size-before-partially-available.html b/testing/web-platform/tests/html/rendering/replaced-elements/images/img-represents-image-size-before-partially-available.html
@@ -0,0 +1,40 @@
+<!DOCTYPE html>
+<title><img> representing image: Natural size before partially available</title>
+<link rel="help" href="https://html.spec.whatwg.org/multipage/rendering.html#images-3">
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<body>
+<script>
+ function check_sizes(img, rendered_expected, natural_expected) {
+ const rect = img.getBoundingClientRect();
+ const rendered_actual = [rect.width, rect.height];
+ const natural_actual = [img.naturalWidth, img.naturalHeight];
+ assert_array_equals(rendered_actual, rendered_expected, 'rendered');
+ assert_array_equals(natural_actual, natural_expected, 'natural');
+ }
+
+ promise_test(async (t) => {
+ const img = new Image();
+ img.src = "/images/green-256x256.png?pipe=trickle(8:d0.25)";
+
+ // Approximate a TTFB delay using another request for the same image
+ // resource but with a shorter trickle delay.
+ await new Promise(resolve => {
+ const timingImg = new Image();
+ timingImg.src = "/images/green-256x256.png?pipe=trickle(8:d0.05)";
+ timingImg.onload = resolve;
+ });
+
+ document.body.appendChild(img);
+
+ const observer = new ResizeObserver(
+ () => img.dispatchEvent(new Event('resized')));
+ observer.observe(img);
+
+ const watcher = new EventWatcher(t, img, 'resized');
+ await watcher.wait_for('resized');
+ check_sizes(img, [0, 0], [0 ,0]);
+ await watcher.wait_for('resized');
+ check_sizes(img, [256, 256], [256 ,256]);
+ });
+</script>