LayoutTests/ChangeLog

 12021-04-19 Cathie Chen <cathiechen@igalia.com>
 2
 3 Update html/rendering/replaced-elements/attributes-for-embedded-content-and-images/ tests from WPT
 4 https://bugs.webkit.org/show_bug.cgi?id=224748
 5
 6 Reviewed by Rob Buis.
 7
 8 picture-aspect-ratio.html is flaky.
 9
 10 * TestExpectations:
 11
1122021-04-19 Youenn Fablet <youenn@apple.com>
213
314 Migrate some WebRTC encoded transform tests to WPT

LayoutTests/imported/w3c/ChangeLog

 12021-04-19 Cathie Chen <cathiechen@igalia.com>
 2
 3 Update html/rendering/replaced-elements/attributes-for-embedded-content-and-images/ tests from WPT
 4 https://bugs.webkit.org/show_bug.cgi?id=224748
 5
 6 Reviewed by Rob Buis.
 7
 8 Update the tests for "mapping attribute width and height as the implicit aspect ratio" which are based on the latest agreement
 9 from WPT commit 19445e7b39.
 10
 11 * web-platform-tests/html/rendering/replaced-elements/attributes-for-embedded-content-and-images/canvas-aspect-ratio-expected.txt:
 12 * web-platform-tests/html/rendering/replaced-elements/attributes-for-embedded-content-and-images/canvas-aspect-ratio.html:
 13 * web-platform-tests/html/rendering/replaced-elements/attributes-for-embedded-content-and-images/img-aspect-ratio-expected.txt:
 14 * web-platform-tests/html/rendering/replaced-elements/attributes-for-embedded-content-and-images/img-aspect-ratio.html:
 15 * web-platform-tests/html/rendering/replaced-elements/attributes-for-embedded-content-and-images/number-placeholder-right-aligned-expected.html: Added.
 16 * web-platform-tests/html/rendering/replaced-elements/attributes-for-embedded-content-and-images/number-placeholder-right-aligned.html: Added.
 17 * web-platform-tests/html/rendering/replaced-elements/attributes-for-embedded-content-and-images/picture-aspect-ratio-expected.txt: Added.
 18 * web-platform-tests/html/rendering/replaced-elements/attributes-for-embedded-content-and-images/picture-aspect-ratio.html: Added.
 19 * web-platform-tests/html/rendering/replaced-elements/attributes-for-embedded-content-and-images/resources/aspect-ratio.js: Added.
 20 (test_computed_style_aspect_ratio):
 21 * web-platform-tests/html/rendering/replaced-elements/attributes-for-embedded-content-and-images/resources/w3c-import.log: Added.
 22 * web-platform-tests/html/rendering/replaced-elements/attributes-for-embedded-content-and-images/video-aspect-ratio-expected.txt:
 23 * web-platform-tests/html/rendering/replaced-elements/attributes-for-embedded-content-and-images/video-aspect-ratio.html:
 24 * web-platform-tests/html/rendering/replaced-elements/attributes-for-embedded-content-and-images/w3c-import.log:
 25
1262021-04-19 Youenn Fablet <youenn@apple.com>
227
328 Migrate some WebRTC encoded transform tests to WPT

LayoutTests/TestExpectations

@@imported/w3c/web-platform-tests/html/semantics/embedded-content/the-img-element/
14171417imported/w3c/web-platform-tests/html/semantics/embedded-content/the-img-element/sizes/parse-a-sizes-attribute-standards-mode.html [ Failure Pass ]
14181418imported/w3c/web-platform-tests/html/semantics/embedded-content/the-object-element/object-fallback-failed-cross-origin-navigation.sub.html [ Failure Pass ]
14191419
 1420# Newly importing aspect ratio test is flaky.
 1421imported/w3c/web-platform-tests/html/rendering/replaced-elements/attributes-for-embedded-content-and-images/picture-aspect-ratio.html [ Failure Pass ]
 1422
14201423# Newly importing W3C tests needed support for reftest-wait.
14211424webkit.org/b/186045 imported/w3c/web-platform-tests/html/semantics/embedded-content/media-elements/track/track-element/track-cue-rendering-after-controls-added.html [ Skip ]
14221425webkit.org/b/186045 imported/w3c/web-platform-tests/html/semantics/embedded-content/media-elements/track/track-element/track-cue-rendering-after-controls-removed.html [ Skip ]

LayoutTests/imported/w3c/web-platform-tests/html/rendering/replaced-elements/attributes-for-embedded-content-and-images/canvas-aspect-ratio-expected.txt

11
 2
 3PASS Canvas width and height attributes are used as the surface size with contain:size
24PASS Canvas width and height attributes are used as the surface size
 5FAIL canvas with {"width":"10","height":"20"} assert_equals: expected "auto 10 / 20" but got "auto"
 6PASS canvas with {"width":"0","height":"1"}
 7PASS canvas with {"width":"1","height":"0"}
 8PASS canvas with {"width":"0","height":"0"}
 9FAIL canvas with {"width":"0.5","height":"1.5"} assert_in_array: value "auto" not in array ["auto 0 / 1", "auto 0.5 / 1.5"]
 10PASS canvas with {"width":"10%","height":"20"}
 11PASS canvas with {"width":null,"height":null}
 12PASS canvas with {"width":"10","height":null}
 13PASS canvas with {"width":null,"height":"20"}
 14PASS canvas with {"width":"xx","height":"20"}
315

LayoutTests/imported/w3c/web-platform-tests/html/rendering/replaced-elements/attributes-for-embedded-content-and-images/canvas-aspect-ratio.html

11<!doctype html><!-- webkit-test-runner [ AspectRatioOfImgFromWidthAndHeightEnabled=true ] -->
2 <title>Canvas width and height attributes are used as the surface size</title>
 2<title>Canvas width and height attributes are used as the surface size, and also to infer aspect ratio</title>
33<script src="/resources/testharness.js"></script>
44<script src="/resources/testharnessreport.js"></script>
 5<script src="resources/aspect-ratio.js"></script>
56<style>
67 canvas {
78 width: 100%;

1011 }
1112</style>
1213<body>
 14<canvas id="contained" width="250" height="100" style="contain: size;"></canvas>
1315<script>
14 let t = async_test("Canvas width and height attributes are used as the surface size");
1516function assert_ratio(img, expected) {
1617 let epsilon = 0.001;
1718 assert_approx_equals(parseInt(getComputedStyle(img).width, 10) / parseInt(getComputedStyle(img).height, 10), expected, epsilon);
1819}
 20
 21function test_computed_style(width, height, expected) {
 22 test_computed_style_aspect_ratio("canvas", {width: width, height: height}, expected);
 23}
 24
 25test(function() {
 26 canvas = document.getElementById("contained");
 27 assert_ratio(canvas, 2.5);
 28}, "Canvas width and height attributes are used as the surface size with contain:size");
 29
1930// Create and append a new canvas and immediately check the ratio.
20 t.step(function() {
 31test(function() {
2132 var canvas = document.createElement("canvas");
2233 canvas.setAttribute("width", "250");
2334 canvas.setAttribute("height", "100");
2435 document.body.appendChild(canvas);
2536 // Canvases always use the aspect ratio from their surface size.
2637 assert_ratio(canvas, 2.5);
 38}, "Canvas width and height attributes are used as the surface size");
 39
 40test_computed_style("10", "20", "auto 10 / 20");
 41// These are invalid per spec, but see
 42// https://github.com/whatwg/html/issues/4961
 43test_computed_style("0", "1", ["auto", "auto 0 / 1"]);
 44test_computed_style("1", "0", ["auto", "auto 1 / 0"]);
 45test_computed_style("0", "0", ["auto", "auto 0 / 0"]);
 46
 47// See https://github.com/whatwg/html/issues/4961:
 48// https://html.spec.whatwg.org/#attr-canvas-width
 49// https://html.spec.whatwg.org/#rules-for-parsing-non-negative-integers
 50test_computed_style("0.5", "1.5", ["auto 0 / 1", "auto 0.5 / 1.5"]);
 51test_computed_style("10%", "20", ["auto", "auto 10 / 20"]);
 52
 53test_computed_style(null, null, "auto");
 54test_computed_style("10", null, "auto");
 55test_computed_style(null, "20", "auto");
 56test_computed_style("xx", "20", "auto");
2757
28  t.done();
29 });
3058</script>

LayoutTests/imported/w3c/web-platform-tests/html/rendering/replaced-elements/attributes-for-embedded-content-and-images/img-aspect-ratio-expected.txt

11
22
3 FAIL Image width and height attributes are used to infer aspect-ratio assert_approx_equals: expected 1.2547169811320755 +/- 0.001 but got 1.25
 3FAIL Image width and height attributes are used to infer aspect-ratio assert_approx_equals: aspect-ratio should override intrinsic size of images that don't have any src. expected 0.8 +/- 0.001 but got Infinity
 4FAIL img with {"width":"10","height":"20"} assert_equals: expected "auto 10 / 20" but got "auto"
 5FAIL input with {"type":"image","width":"10","height":"20"} assert_equals: expected "auto 10 / 20" but got "auto"
 6PASS input with {"type":"submit","width":"10","height":"20"}
 7FAIL img with {"width":"0","height":"1"} assert_equals: expected "auto 0 / 1" but got "auto"
 8FAIL input with {"type":"image","width":"0","height":"1"} assert_equals: expected "auto 0 / 1" but got "auto"
 9PASS input with {"type":"submit","width":"0","height":"1"}
 10FAIL img with {"width":"1","height":"0"} assert_equals: expected "auto 1 / 0" but got "auto"
 11FAIL input with {"type":"image","width":"1","height":"0"} assert_equals: expected "auto 1 / 0" but got "auto"
 12PASS input with {"type":"submit","width":"1","height":"0"}
 13FAIL img with {"width":"0","height":"0"} assert_equals: expected "auto 0 / 0" but got "auto"
 14FAIL input with {"type":"image","width":"0","height":"0"} assert_equals: expected "auto 0 / 0" but got "auto"
 15PASS input with {"type":"submit","width":"0","height":"0"}
 16FAIL img with {"width":"0.5","height":"1.5"} assert_equals: expected "auto 0.5 / 1.5" but got "auto"
 17FAIL input with {"type":"image","width":"0.5","height":"1.5"} assert_equals: expected "auto 0.5 / 1.5" but got "auto"
 18PASS input with {"type":"submit","width":"0.5","height":"1.5"}
 19PASS img with {"width":null,"height":null}
 20PASS input with {"type":"image","width":null,"height":null}
 21PASS input with {"type":"submit","width":null,"height":null}
 22PASS img with {"width":"10","height":null}
 23PASS input with {"type":"image","width":"10","height":null}
 24PASS input with {"type":"submit","width":"10","height":null}
 25PASS img with {"width":null,"height":"20"}
 26PASS input with {"type":"image","width":null,"height":"20"}
 27PASS input with {"type":"submit","width":null,"height":"20"}
 28PASS img with {"width":"xx","height":"20"}
 29PASS input with {"type":"image","width":"xx","height":"20"}
 30PASS input with {"type":"submit","width":"xx","height":"20"}
 31PASS img with {"width":"10%","height":"20"}
 32PASS input with {"type":"image","width":"10%","height":"20"}
 33PASS input with {"type":"submit","width":"10%","height":"20"}
434

LayoutTests/imported/w3c/web-platform-tests/html/rendering/replaced-elements/attributes-for-embedded-content-and-images/img-aspect-ratio.html

22<title>Image width and height attributes are used to infer aspect-ratio</title>
33<script src="/resources/testharness.js"></script>
44<script src="/resources/testharnessreport.js"></script>
 5<script src="resources/aspect-ratio.js"></script>
56<style>
67 img {
78 width: 100%;

1415<img src="" width=100 height=125>
1516<img src="error.png" width=100 height=125>
1617<img src="error.png">
 18<img src="error.png" alt="Alt text" width=100 height=500>
1719<script>
1820let t = async_test("Image width and height attributes are used to infer aspect-ratio");
19 function assert_ratio(img, expected) {
 21function assert_ratio(img, expected, description) {
2022 let epsilon = 0.001;
21  assert_approx_equals(parseFloat(getComputedStyle(img).width, 10) / parseFloat(getComputedStyle(img).height, 10), expected, epsilon);
 23 assert_approx_equals(parseFloat(getComputedStyle(img).width, 10) / parseFloat(getComputedStyle(img).height, 10),
 24 expected, epsilon, description);
2225}
 26
 27function test_computed_style(width, height, expected) {
 28 test_computed_style_aspect_ratio("img", {width: width, height: height}, expected);
 29 test_computed_style_aspect_ratio("input", {type: "image", width: width, height: height}, expected);
 30 // input type=submit should not do this mapping.
 31 test_computed_style_aspect_ratio("input", {type: "submit", width: width, height: height}, "auto");
 32}
 33
2334// Create and append a new image and immediately check the ratio.
2435// This is not racy because the spec requires the user agent to queue a task:
2536// https://html.spec.whatwg.org/multipage/images.html#updating-the-image-data

@@t.step(function() {
4960
5061onload = t.step_func_done(function() {
5162 let images = document.querySelectorAll("img");
52  assert_ratio(images[0], 2.0); // Loaded image's aspect ratio, at least by default, overrides width / height ratio.
53  assert_ratio(images[1], 2.0); // 2.0 is the original aspect ratio of green.png
54  assert_equals(getComputedStyle(images[2]).height, "0px"); // aspect-ratio doesn't override intrinsic size of images that don't have any src.
55  assert_equals(getComputedStyle(images[3]).height, getComputedStyle(images[4]).height); // aspect-ratio doesn't override intrinsic size of error images.
56  assert_ratio(images[5], 133/106); // The original aspect ratio of blue.png
 63 assert_ratio(images[0], 2.0, "2.0 is the original aspect ratio of green.png");
 64 assert_ratio(images[1], 2.0, "Loaded image's aspect ratio, at least by default, overrides width / height ratio.");
 65 assert_ratio(images[2], 100/125, "aspect-ratio should override intrinsic size of images that don't have any src.");
 66 assert_ratio(images[3], 100/125, "aspect-ratio should affect the size of error images.");
 67 assert_not_equals(images[5].offsetHeight, 500, "Images with alt text should be inline and ignore the aspect ratio");
 68 assert_ratio(images[6], 133/106, "The original aspect ratio of blue.png");
5769});
 70
 71test_computed_style("10", "20", "auto 10 / 20");
 72// These are invalid per spec, but see
 73// https://github.com/whatwg/html/issues/4961
 74test_computed_style("0", "1", "auto 0 / 1");
 75test_computed_style("1", "0", "auto 1 / 0");
 76test_computed_style("0", "0", "auto 0 / 0");
 77// https://html.spec.whatwg.org/#map-to-the-aspect-ratio-property
 78// https://html.spec.whatwg.org/#rules-for-parsing-non-zero-dimension-values
 79test_computed_style("0.5", "1.5", "auto 0.5 / 1.5");
 80
 81test_computed_style(null, null, "auto");
 82test_computed_style("10", null, "auto");
 83test_computed_style(null, "20", "auto");
 84test_computed_style("xx", "20", "auto");
 85test_computed_style("10%", "20", "auto");
 86
5887</script>

LayoutTests/imported/w3c/web-platform-tests/html/rendering/replaced-elements/attributes-for-embedded-content-and-images/number-placeholder-right-aligned-expected.html

 1<!doctype html>
 2<style>
 3input {
 4 color: black;
 5 text-align: right;
 6}
 7</style>
 8<input type=number value=0>

LayoutTests/imported/w3c/web-platform-tests/html/rendering/replaced-elements/attributes-for-embedded-content-and-images/number-placeholder-right-aligned.html

 1<!doctype html>
 2<link rel="author" title="Emilio Cobos Álvarez" href="mailto:emilio@crisal.io">
 3<link rel="author" title="Mozilla" href="https://mozilla.org">
 4<link rel="help" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1698043">
 5<link rel="match" href="number-placeholder-right-aligned-ref.html">
 6<style>
 7input {
 8 color: black;
 9 text-align: right;
 10}
 11input::placeholder {
 12 color: inherit;
 13 opacity: 1;
 14}
 15</style>
 16<input type=number placeholder=0>

LayoutTests/imported/w3c/web-platform-tests/html/rendering/replaced-elements/attributes-for-embedded-content-and-images/picture-aspect-ratio-expected.txt

 1
 2
 3
 4
 5FAIL source width and height attributes are used to infer aspect-ratio in <picture> assert_equals: expected "auto 100 / 100" but got "auto"
 6FAIL Computed style for width/height/aspect-ratio assert_approx_equals: expected 1 +/- 0.001 but got Infinity
 7FAIL Source width/height should take precedence over img attributes. assert_approx_equals: expected 2 +/- 0.001 but got 5
 8FAIL Make sure style gets invalidated correctly when the source gets removed. assert_equals: expected "auto 250 / 50" but got "auto"
 9FAIL If the <source> has only one of width/height, we don't get an aspect ratio, even if the <img> has both. assert_equals: expected "100px" but got "200px"
 10FAIL If we don't have width/height on the source, we fall back to width/height on the <img>. assert_equals: expected "auto 200 / 100" but got "auto"
 11FAIL If we only have one width/height attribute, we should get that attribute mapped but no aspect ratio, even if <img> has attributes. assert_equals: expected "100px" but got "200px"
 12FAIL Dynamically changing width/height should change computed style assert_equals: expected "auto 100 / 100" but got "auto"
 13FAIL Changing which <source> matches should change computed style assert_equals: expected "auto 100 / 100" but got "auto"
 14FAIL Percentages on source should be ignored for aspect-ratio but used for width/height. assert_equals: expected 100 but got 0
 15FAIL Trailing garbage should be ignored but not make the attribute invalid assert_equals: expected 100 but got 0
 16

LayoutTests/imported/w3c/web-platform-tests/html/rendering/replaced-elements/attributes-for-embedded-content-and-images/picture-aspect-ratio.html

 1<!doctype html>
 2<title>Image width and height attributes are used to infer aspect-ratio</title>
 3<script src="/resources/testharness.js"></script>
 4<script src="/resources/testharnessreport.js"></script>
 5<style>
 6 img:not([nowidth]) {
 7 width: 100%;
 8 max-width: 100px;
 9 height: auto;
 10 }
 11</style>
 12<picture>
 13 <source srcset="/images/green-100x50.png"></source>
 14 <img>
 15</picture>
 16
 17<picture>
 18 <source srcset="/images/green-100x50.png" width="100" height="100"></source>
 19 <img>
 20</picture>
 21
 22<picture>
 23 <source srcset="/images/green-100x50.png" width="100" height="100"></source>
 24 <img width="50" height="100">
 25</picture>
 26
 27<picture>
 28 <source srcset="/images/green-100x50.png" width="100" height="100" id="twosource-s1"></source>
 29 <source srcset="/images/green-100x50.png" width="300" height="150"></source>
 30 <img id="twosource-img">
 31</picture>
 32
 33<div style="width: 100px;">
 34 <picture>
 35 <source srcset="/images/green-100x50.png" width="100%" height="50%" id="percent-src"></source>
 36 <img style="contain:size;" id="percent-img" nowidth="true">
 37 </picture>
 38</div>
 39
 40<picture>
 41 <source srcset="/images/green-100x50.png" width="100abc" height="50abc" id="trailing-src"></source>
 42 <img style="contain:size;" id="trailing-img" nowidth="true">
 43</picture>
 44
 45<script>
 46let t = async_test("source width and height attributes are used to infer aspect-ratio in <picture>");
 47function assert_ratio(img, expected, description) {
 48 let epsilon = 0.001;
 49 assert_approx_equals(parseFloat(getComputedStyle(img).width, 10) / parseFloat(getComputedStyle(img).height, 10),
 50 expected, epsilon, description);
 51}
 52
 53function createPicture(width, height) {
 54 var picture = document.createElement("picture");
 55 var source = document.createElement("source");
 56 if (width !== undefined)
 57 source.setAttribute("width", width);
 58 if (height !== undefined)
 59 source.setAttribute("height", height);
 60 source.setAttribute("srcset", "/images/green.png");
 61 picture.appendChild(source);
 62 var img = document.createElement("img");
 63 picture.appendChild(img);
 64 document.body.appendChild(picture);
 65 return img;
 66}
 67
 68function assert_cs(img, val) {
 69 assert_equals(getComputedStyle(img).aspectRatio, val);
 70}
 71
 72// Create and append a new image and immediately check the ratio.
 73// This is not racy because the spec requires the user agent to queue a task:
 74// https://html.spec.whatwg.org/multipage/images.html#updating-the-image-data
 75test(function() {
 76 var img = createPicture(100, 100);
 77 assert_ratio(img, 1.0);
 78 assert_cs(img, "auto 100 / 100");
 79 img.style.display = "none";
 80 img.setAttribute("nowidth", "true");
 81 assert_equals(getComputedStyle(img).width, "100px");
 82 assert_equals(getComputedStyle(img).height, "100px");
 83 var source = img.previousSibling;
 84 assert_equals(getComputedStyle(source).width, "auto");
 85 assert_equals(getComputedStyle(source).height, "auto");
 86}, "Computed style for width/height/aspect-ratio");
 87
 88test(function() {
 89 img = createPicture(200, 100);
 90 img.setAttribute("width", 250);
 91 img.setAttribute("height", 50);
 92 assert_ratio(img, 2.0);
 93 assert_cs(img, "auto 200 / 100");
 94 img.style.display = "none";
 95 img.setAttribute("nowidth", "true");
 96 assert_equals(getComputedStyle(img).width, "200px");
 97 assert_equals(getComputedStyle(img).height, "100px");
 98 source = img.previousSibling;
 99 assert_equals(getComputedStyle(source).width, "auto");
 100 assert_equals(getComputedStyle(source).height, "auto");
 101}, "Source width/height should take precedence over img attributes.");
 102
 103test(function() {
 104 img.parentNode.removeChild(img.previousSibling);
 105 assert_cs(img, "auto 250 / 50");
 106 img.src = "/images/green.png";
 107 assert_ratio(img, 5.0);
 108 img.style.display = "none";
 109 img.setAttribute("nowidth", "true");
 110 assert_equals(getComputedStyle(img).width, "250px");
 111 assert_equals(getComputedStyle(img).height, "50px");
 112}, "Make sure style gets invalidated correctly when the source gets removed.");
 113
 114test(function() {
 115 img = createPicture(100, undefined);
 116 img.setAttribute("width", 200);
 117 img.setAttribute("height", 100);
 118 assert_cs(img, "auto");
 119 img.style.display = "none";
 120 img.setAttribute("nowidth", "true");
 121 assert_equals(getComputedStyle(img).width, "100px");
 122 assert_equals(getComputedStyle(img).height, "auto");
 123}, "If the <source> has only one of width/height, we don't get an aspect ratio, even if the <img> has both.");
 124
 125test(function() {
 126 img = createPicture(undefined, undefined);
 127 img.setAttribute("width", 200);
 128 img.setAttribute("height", 100);
 129 assert_cs(img, "auto 200 / 100");
 130}, "If we don't have width/height on the source, we fall back to width/height on the <img>.");
 131
 132test(function() {
 133 img = createPicture(100, undefined);
 134 img.parentNode.style.display = "none";
 135 img.setAttribute("width", "200");
 136 img.setAttribute("height", "300");
 137 img.setAttribute("nowidth", "true");
 138 assert_cs(img, "auto");
 139 assert_equals(getComputedStyle(img).width, "100px");
 140 assert_equals(getComputedStyle(img).height, "auto");
 141
 142 img = createPicture(undefined, 100);
 143 img.parentNode.style.display = "none";
 144 img.setAttribute("width", "200");
 145 img.setAttribute("height", "300");
 146 img.setAttribute("nowidth", "true");
 147 assert_cs(img, "auto");
 148 assert_equals(getComputedStyle(img).width, "auto");
 149 assert_equals(getComputedStyle(img).height, "100px");
 150}, "If we only have one width/height attribute, we should get that attribute mapped but no aspect ratio, even if <img> has attributes.");
 151
 152test(function() {
 153 img = createPicture(100, 100);
 154 assert_cs(img, "auto 100 / 100");
 155 img.previousSibling.setAttribute("height", "300");
 156 assert_cs(img, "auto 100 / 300");
 157 img.previousSibling.setAttribute("width", "10");
 158 assert_cs(img, "auto 10 / 300");
 159 img.style.display = "none";
 160 img.setAttribute("nowidth", "true");
 161 assert_equals(getComputedStyle(img).width, "10px");
 162 assert_equals(getComputedStyle(img).height, "300px");
 163}, "Dynamically changing width/height should change computed style");
 164
 165test(function() {
 166 img = document.getElementById("twosource-img");
 167 assert_cs(img, "auto 100 / 100");
 168 source = document.getElementById("twosource-s1");
 169 source.setAttribute("type", "x-foo/x-bar");
 170 // We should now match the second source
 171 assert_cs(img, "auto 300 / 150");
 172 img.style.display = "none";
 173 img.setAttribute("nowidth", "true");
 174 assert_equals(getComputedStyle(img).width, "300px");
 175 assert_equals(getComputedStyle(img).height, "150px");
 176}, "Changing which <source> matches should change computed style");
 177
 178test(function() {
 179 img = document.getElementById("percent-img");
 180 assert_equals(img.offsetWidth, 100);
 181 assert_equals(img.offsetHeight, 0);
 182 assert_cs(img, "auto");
 183 source = document.getElementById("percent-src");
 184 assert_equals(source.width, 100);
 185 assert_equals(source.height, 50);
 186 img.style.display = "none";
 187 img.setAttribute("nowidth", "true");
 188 assert_equals(getComputedStyle(img).width, "100%");
 189 assert_equals(getComputedStyle(img).height, "50%");
 190}, "Percentages on source should be ignored for aspect-ratio but used for width/height.");
 191
 192test(function() {
 193 img = document.getElementById("trailing-img");
 194 assert_equals(img.offsetWidth, 100);
 195 assert_equals(img.offsetHeight, 50);
 196 assert_cs(img, "auto 100 / 50");
 197 source = document.getElementById("trailing-src");
 198 assert_equals(source.width, 100);
 199 assert_equals(source.height, 50);
 200 img.style.display = "none";
 201 img.setAttribute("nowidth", "true");
 202 assert_equals(getComputedStyle(img).width, "100px");
 203 assert_equals(getComputedStyle(img).height, "50px");
 204}, "Trailing garbage should be ignored but not make the attribute invalid");
 205
 206onload = t.step_func_done(function() {
 207 let images = document.querySelectorAll("img");
 208 var img = images[0];
 209 assert_ratio(img, 2.0, "2.0 is the original aspect ratio of green-100x50.png");
 210 assert_cs(img, "auto");
 211 img.style.display = "none";
 212 img.setAttribute("nowidth", "true");
 213 assert_equals(getComputedStyle(img).width, "auto");
 214 assert_equals(getComputedStyle(img).height, "auto");
 215 img = images[1];
 216 assert_ratio(img, 2.0, "Loaded image's aspect ratio, at least by default, overrides width / height ratio.");
 217 assert_cs(img, "auto 100 / 100");
 218 img.style.display = "none";
 219 img.setAttribute("nowidth", "true");
 220 assert_equals(getComputedStyle(img).width, "100px");
 221 assert_equals(getComputedStyle(img).height, "100px");
 222 img = images[2];
 223 assert_ratio(img, 2.0, "Loaded image's aspect ratio, at least by default, overrides width / height ratio (2).");
 224 assert_cs(img, "auto 100 / 100");
 225 img.style.display = "none";
 226 img.setAttribute("nowidth", "true");
 227 assert_equals(getComputedStyle(img).width, "100px");
 228 assert_equals(getComputedStyle(img).height, "100px");
 229});
 230</script>

LayoutTests/imported/w3c/web-platform-tests/html/rendering/replaced-elements/attributes-for-embedded-content-and-images/resources/aspect-ratio.js

 1function test_computed_style_aspect_ratio(tag, attributes, expected) {
 2 test(function() {
 3 var elem = document.createElement(tag);
 4 for (name in attributes) {
 5 let val = attributes[name];
 6 if (val !== null)
 7 elem.setAttribute(name, val);
 8 }
 9 document.body.appendChild(elem);
 10 let aspectRatio = getComputedStyle(elem).aspectRatio;
 11 if (Array.isArray(expected)) {
 12 assert_in_array(aspectRatio, expected);
 13 } else {
 14 assert_equals(aspectRatio, expected);
 15 }
 16 elem.remove();
 17 }, `${tag} with ${JSON.stringify(attributes)}`);
 18}

LayoutTests/imported/w3c/web-platform-tests/html/rendering/replaced-elements/attributes-for-embedded-content-and-images/resources/w3c-import.log

 1The tests in this directory were imported from the W3C repository.
 2Do NOT modify these tests directly in WebKit.
 3Instead, create a pull request on the WPT github:
 4 https://github.com/web-platform-tests/wpt
 5
 6Then run the Tools/Scripts/import-w3c-tests in WebKit to reimport
 7
 8Do NOT modify or remove this file.
 9
 10------------------------------------------------------------------------
 11Properties requiring vendor prefixes:
 12None
 13Property values requiring vendor prefixes:
 14None
 15------------------------------------------------------------------------
 16List of files:
 17/LayoutTests/imported/w3c/web-platform-tests/html/rendering/replaced-elements/attributes-for-embedded-content-and-images/resources/aspect-ratio.js

LayoutTests/imported/w3c/web-platform-tests/html/rendering/replaced-elements/attributes-for-embedded-content-and-images/video-aspect-ratio-expected.txt

11
22
3 PASS Video width and height attributes are not used to infer aspect-ratio
 3FAIL Video width and height attributes are not used to infer aspect-ratio assert_approx_equals: expected 2.5 +/- 0.001 but got 2
 4FAIL video with {"width":"10","height":"20"} assert_equals: expected "auto 10 / 20" but got "auto"
 5FAIL video with {"width":"0.5","height":"1.5"} assert_equals: expected "auto 0.5 / 1.5" but got "auto"
 6PASS video with {"width":"0","height":"1"}
 7PASS video with {"width":"1","height":"0"}
 8PASS video with {"width":"0","height":"0"}
 9PASS video with {"width":null,"height":null}
 10PASS video with {"width":"10","height":null}
 11PASS video with {"width":null,"height":"20"}
 12PASS video with {"width":"xx","height":"20"}
 13PASS video with {"width":"10%","height":"20"}
414

LayoutTests/imported/w3c/web-platform-tests/html/rendering/replaced-elements/attributes-for-embedded-content-and-images/video-aspect-ratio.html

11<!doctype html><!-- webkit-test-runner [ AspectRatioOfImgFromWidthAndHeightEnabled=true ] -->
2 <title>Video width and height attributes are not used to infer aspect-ratio</title>
 2<title>Video width and height attributes are used to infer aspect-ratio</title>
33<script src="/resources/testharness.js"></script>
44<script src="/resources/testharnessreport.js"></script>
55<script src="/common/media.js"></script>
 6<script src="resources/aspect-ratio.js"></script>
67<style>
78 video {
89 width: 100%;

1112 }
1213</style>
1314<body>
 15<video width="250" height="100" id="contained" style="contain: size;"></video>
1416<script>
1517let t = async_test("Video width and height attributes are not used to infer aspect-ratio");
1618function assert_ratio(img, expected) {
1719 let epsilon = 0.001;
1820 assert_approx_equals(parseInt(getComputedStyle(img).width, 10) / parseInt(getComputedStyle(img).height, 10), expected, epsilon);
1921}
 22
 23function test_computed_style(width, height, expected) {
 24 test_computed_style_aspect_ratio("video", {width: width, height: height}, expected);
 25}
 26
 27t.step(function() {
 28 var video = document.getElementById("contained");
 29 video.src = getVideoURI('/media/2x2-green');
 30 assert_ratio(video, 2.5);
 31}, "contain:size aspect ratio");
 32
2033// Create and append a new video and immediately check the ratio.
2134// This is not racy because the spec requires the user agent to queue a task:
2235// https://html.spec.whatwg.org/multipage/media.html#concept-media-load-algorithm
2336t.step(function() {
24  var video = document.createElement("video");
 37 video = document.createElement("video");
2538 video.setAttribute("width", "250");
2639 video.setAttribute("height", "100");
2740 video.src = getVideoURI('/media/2x2-green');

@@t.step(function() {
3548 // When loaded this video is square.
3649 assert_ratio(video, 1);
3750 });
38 });
 51}, "aspect ratio for regular video");
 52
 53test_computed_style("10", "20", "auto 10 / 20");
 54test_computed_style("0.5", "1.5", "auto 0.5 / 1.5");
 55
 56// These are invalid per spec, but see
 57// https://github.com/whatwg/html/issues/4961
 58test_computed_style("0", "1", ["auto", "auto 0 / 1"]);
 59test_computed_style("1", "0", ["auto", "auto 1 / 0"]);
 60test_computed_style("0", "0", ["auto", "auto 0 / 0"]);
 61
 62test_computed_style(null, null, "auto");
 63test_computed_style("10", null, "auto");
 64test_computed_style(null, "20", "auto");
 65test_computed_style("xx", "20", "auto");
 66test_computed_style("10%", "20", "auto");
 67
3968</script>

LayoutTests/imported/w3c/web-platform-tests/html/rendering/replaced-elements/attributes-for-embedded-content-and-images/w3c-import.log

@@List of files:
3838/LayoutTests/imported/w3c/web-platform-tests/html/rendering/replaced-elements/attributes-for-embedded-content-and-images/input-image-inline-alt.html
3939/LayoutTests/imported/w3c/web-platform-tests/html/rendering/replaced-elements/attributes-for-embedded-content-and-images/input-type-change-from-image-1-expected.html
4040/LayoutTests/imported/w3c/web-platform-tests/html/rendering/replaced-elements/attributes-for-embedded-content-and-images/input-type-change-from-image-1.html
 41/LayoutTests/imported/w3c/web-platform-tests/html/rendering/replaced-elements/attributes-for-embedded-content-and-images/number-placeholder-right-aligned-expected.html
 42/LayoutTests/imported/w3c/web-platform-tests/html/rendering/replaced-elements/attributes-for-embedded-content-and-images/number-placeholder-right-aligned.html
4143/LayoutTests/imported/w3c/web-platform-tests/html/rendering/replaced-elements/attributes-for-embedded-content-and-images/object_border_perc-expected.xhtml
4244/LayoutTests/imported/w3c/web-platform-tests/html/rendering/replaced-elements/attributes-for-embedded-content-and-images/object_border_perc.xhtml
4345/LayoutTests/imported/w3c/web-platform-tests/html/rendering/replaced-elements/attributes-for-embedded-content-and-images/object_border_pixel-expected.xhtml
4446/LayoutTests/imported/w3c/web-platform-tests/html/rendering/replaced-elements/attributes-for-embedded-content-and-images/object_border_pixel.xhtml
 47/LayoutTests/imported/w3c/web-platform-tests/html/rendering/replaced-elements/attributes-for-embedded-content-and-images/picture-aspect-ratio.html
4548/LayoutTests/imported/w3c/web-platform-tests/html/rendering/replaced-elements/attributes-for-embedded-content-and-images/video-aspect-ratio.html