diff --git a/html/semantics/embedded-content/the-img-element/naturalWidth-naturalHeight-width-height.tentative.html b/html/semantics/embedded-content/the-img-element/naturalWidth-naturalHeight-width-height.html
similarity index 81%
rename from html/semantics/embedded-content/the-img-element/naturalWidth-naturalHeight-width-height.tentative.html
rename to html/semantics/embedded-content/the-img-element/naturalWidth-naturalHeight-width-height.html
index 2b6936012eabd6..86355292fa857f 100644
--- a/html/semantics/embedded-content/the-img-element/naturalWidth-naturalHeight-width-height.tentative.html
+++ b/html/semantics/embedded-content/the-img-element/naturalWidth-naturalHeight-width-height.html
@@ -2,17 +2,6 @@
HTMLImageElement attributes naturalWidth, naturalHeight, width, height
-
-
@@ -55,6 +44,11 @@
not correct, we provide the actual expected value in the
"data-{width,height}" attributes (as distinguished from
data-natural-{width,height}).
+ * The "data-density" attribute indicates which natural dimensions are
+ SVG-intrinsic (and thus should be density-corrected): "both" (default for
+ raster), "width", "height", or "none". Default dimensions (300x150) and
+ dimensions derived from fitting an aspect ratio into the default object
+ size are not density-corrected.
* The "title" attribute is a description of the scenario being tested, and
it must be unique to satisfy the test harness requirements. -->
@@ -85,52 +79,64 @@
root svg element in a SVG image. -->
@@ -181,48 +196,88 @@
cases; it should have no impact. -->
-
+ determine the natural dimensions, with no impact from viewBox. ---->
+
+
+
+
+
+
+
@@ -258,15 +313,21 @@
img.setAttribute("title",
`${img.getAttribute("title")} (with srcset/${density}x)`);
- const isUsingConcreteObjectWidth = (img.dataset.naturalWidth == "300");
- const isUsingConcreteObjectHeight = (img.dataset.naturalHeight == "150");
+ // Determine which dimensions are density-corrected. For raster images
+ // (no data-density attribute), both dimensions are always corrected.
+ // For SVG images, only intrinsic (non-default) dimensions are corrected.
+ const densityAttr = img.dataset.density || "both";
+ const validDensityValues = ["none", "both", "width", "height"];
+ if (!validDensityValues.includes(densityAttr)) {
+ throw new Error(`test error: data-density="${densityAttr}" on "${img.getAttribute("title")}" is not a recognized value (expected one of: ${validDensityValues})`);
+ }
+ const scaleWidth = (densityAttr === "both" || densityAttr === "width");
+ const scaleHeight = (densityAttr === "both" || densityAttr === "height");
- // Scale our 'data-natural-{width,height}' expectations by the density.
- // But also:
- // * Preserve the original 'data-natural-{width,height}' as the
- // 'data-{width,height}' expectation if it's just the concrete object size
- // (which doesn't actually get scaled by the density in practice when
- // the image actually renders).
+ // Scale our 'data-natural-{width,height}' expectations by the density,
+ // but only for dimensions that are density-corrected (i.e., derived from
+ // the image's own intrinsic dimensions, not from the default object size).
+ // Also:
// * Preserve the original 'data-natural-{width,height}' as the
// 'data-not-rendered-{width,height}' expectation (if we don't already have
// one) since browsers don't do density-correction on .width and .height when
@@ -276,16 +337,12 @@
if (name.startsWith("natural")) {
let origExpectation = img.dataset[name];
- // Scale our img.natural{Width,Height} expectation:
- img.dataset[name] = origExpectation / density;
-
let isWidthAxis = (name == "naturalWidth");
- let nameWithoutNatural = (isWidthAxis ? "width" : "height");
+ let shouldScale = isWidthAxis ? scaleWidth : scaleHeight;
- let isConcreteObjectSize =
- (isWidthAxis ? isUsingConcreteObjectWidth : isUsingConcreteObjectHeight);
- if (isConcreteObjectSize && !(nameWithoutNatural in img.dataset)) {
- img.dataset[nameWithoutNatural] = origExpectation;
+ // Scale our img.natural{Width,Height} expectation:
+ if (shouldScale) {
+ img.dataset[name] = origExpectation / density;
}
// Construct a string for "data-not-rendered-{width,height}" for
diff --git a/html/semantics/embedded-content/the-img-element/naturalWidth-naturalHeight.html b/html/semantics/embedded-content/the-img-element/naturalWidth-naturalHeight.html
deleted file mode 100644
index 19aa4b9344f904..00000000000000
--- a/html/semantics/embedded-content/the-img-element/naturalWidth-naturalHeight.html
+++ /dev/null
@@ -1,42 +0,0 @@
-
-HTMLImageElement.prototype.naturalWidth/naturalHeight
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-