Skip to content

Commit

Permalink
Bug 1866970 [wpt PR 43385] - Add auto sizes wpt rendering tests, a=te…
Browse files Browse the repository at this point in the history
…stonly

Automatic update from web-platform-tests
Add auto sizes wpt rendering tests

Also update tests in size-auto to match spec update:
whatwg/html#9493

Spec:
https://html.spec.whatwg.org/#parsing-a-sizes-attribute
https://whatpr.org/html/9493/images.html#parsing-a-sizes-attribute

R=pdr
Bug: 1359051

Change-Id: I77ecbfef3a5a63101929f67025699550cc7f6413
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5064461
Commit-Queue: Traian Captan <tcaptanchromium.org>
Reviewed-by: Philip Rogers <pdrchromium.org>
Cr-Commit-Position: refs/heads/main{#1231380}

--

wpt-commits: 5904d197e1d4318c4fefb12bf406c921fbd123f3
wpt-pr: 43385

UltraBlame original commit: 5a6d84b529aebea9ea7277cc8a9aed89a7d2e349
  • Loading branch information
marco-c committed Dec 7, 2023
1 parent 519e706 commit 1f6a35d
Show file tree
Hide file tree
Showing 6 changed files with 137 additions and 9 deletions.
@@ -0,0 +1,8 @@
<!doctype html>
<title>Auto sizes rendering</title>
<link rel="help" href="https://html.spec.whatwg.org/multipage/images.html#sizes-attributes">
<img
src="/images/green.png"
width="33"
height="13"
>
@@ -0,0 +1,25 @@
<!doctype html>
<html class="reftest-wait">
<title>Auto sizes rendering</title>
<link rel="help" href="https://html.spec.whatwg.org/multipage/images.html#sizes-attributes">
<link rel="match" href="reference/sizes-auto-rendering-ref.html">
<script src="/common/rendering-utils.js"></script>
<script src="/common/reftest-wait.js"></script>
<img
id="testImg"
loading="lazy"
sizes="auto"
width="33"
height="13"
>
<script>
function imageLoaded() {
waitForAtLeastOneFrame().then(takeScreenshot);
}

testImg.addEventListener('load', imageLoaded);
testImg.setAttribute('srcset', `
/images/red.png 10w,
/images/green.png 100w
`);
</script>
@@ -0,0 +1,25 @@
<!doctype html>
<html class="reftest-wait">
<title>Auto sizes rendering</title>
<link rel="help" href="https://html.spec.whatwg.org/multipage/images.html#sizes-attributes">
<link rel="match" href="reference/sizes-auto-rendering-ref.html">
<script src="/common/rendering-utils.js"></script>
<script src="/common/reftest-wait.js"></script>
<img
id="testImg"
loading="lazy"
sizes="auto"
width="33"
height="13"
>
<script>
function imageLoaded() {
waitForAtLeastOneFrame().then(takeScreenshot);
}

testImg.addEventListener('load', imageLoaded);
testImg.setAttribute('srcset', `
/images/green.png 100w,
/images/red.png 1000w
`);
</script>
@@ -0,0 +1,38 @@
<!doctype html>
<html class="reftest-wait">
<title>Auto sizes dynamic rendering</title>
<link rel="help" href="https://html.spec.whatwg.org/multipage/images.html#sizes-attributes">
<link rel="match" href="reference/sizes-auto-rendering-ref.html">
<script src="/common/rendering-utils.js"></script>
<script src="/common/reftest-wait.js"></script>
<img
id="testImg"
loading="lazy"
sizes="auto"
width="1"
height="13"
>
<script>
function secondImageLoaded() {
waitForAtLeastOneFrame().then(takeScreenshot);
}

function firstImageLoaded() {
const expected = 'red.png';
if (!testImg.currentSrc.endsWith('red.png')) {
const fail_msg = `FAIL: currentSrc is ${testImg.currentSrc}, expected ${expected}.`;
document.body.textContent = fail_msg;
takeScreenshot();
}

testImg.addEventListener('load', secondImageLoaded);
testImg.style.width = '33px';
}

testImg.addEventListener('load', firstImageLoaded, {once: true});
testImg.setAttribute('srcset', `
/images/fail.gif 1000w,
/images/green.png 100w,
/images/red.png 10w
`);
</script>
@@ -0,0 +1,26 @@
<!doctype html>
<html class="reftest-wait">
<title>Auto sizes rendering</title>
<link rel="help" href="https://html.spec.whatwg.org/multipage/images.html#sizes-attributes">
<link rel="match" href="reference/sizes-auto-rendering-ref.html">
<script src="/common/rendering-utils.js"></script>
<script src="/common/reftest-wait.js"></script>
<img
id="testImg"
loading="lazy"
sizes="auto"
width="33"
height="13"
>
<script>
function imageLoaded() {
waitForAtLeastOneFrame().then(takeScreenshot);
}

testImg.addEventListener('load', imageLoaded);
testImg.setAttribute('srcset', `
/images/fail.gif 10w,
/images/green.png 100w,
/images/red.png 1000w
`);
</script>
@@ -1,5 +1,6 @@
<!doctype html>
<title>img parse a sizes attribute: sizes=auto</title>
<link rel="help" href="https://html.spec.whatwg.org/multipage/images.html#parse-a-sizes-attribute">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<style>
Expand Down Expand Up @@ -61,16 +62,16 @@
// Actual tests
{loading: 'lazy', sizes: 'auto', width: '10', 'data-ref': 'ref1'},
{loading: 'lazy', sizes: 'AUTO', width: '10', 'data-ref': 'ref1'},
{loading: 'lazy', width: '10', 'data-ref': 'ref1'},
{loading: 'lazy', style: 'width: 10px', 'data-ref': 'ref1'},
{loading: 'lazy', style: 'max-width: 10px', 'data-ref': 'ref2'}, // no specified width -> 0 -> 100vw
{loading: 'lazy', style: 'width: 100%; max-width: 10px', 'data-ref': 'ref1'},
{loading: 'lazy', width: '10', 'data-ref': 'ref2'}, // no `sizes: 'auto'` -> 100vw
{loading: 'lazy', style: 'width: 10px', 'data-ref': 'ref2'}, // no `sizes: 'auto'` -> 100vw
{loading: 'lazy', style: 'max-width: 10px', 'data-ref': 'ref2'}, // no `sizes: 'auto'` -> 100vw
{loading: 'lazy', style: 'width: 100%; max-width: 10px', 'data-ref': 'ref2'}, // no `sizes: 'auto'` -> 100vw
{loading: 'lazy', sizes: 'auto', width: '500', 'data-ref': 'ref2'},
{loading: 'lazy', sizes: 'auto', width: '10', style: 'visibility: hidden', 'data-ref': 'ref1'},
{loading: 'lazy', sizes: 'auto', width: '10', style: 'display: inline', hidden: '', 'data-ref': 'ref1'},
{loading: 'lazy', sizes: 'auto', width: '0', 'data-ref': 'ref2'}, // 0 -> 100vw
{loading: 'lazy', sizes: 'auto', style: 'width: 0px', 'data-ref': 'ref2'}, // 0 -> 100vw
{loading: 'lazy', sizes: 'auto', 'data-ref': 'ref2'}, // no specified width -> 0 -> 100vw
{loading: 'lazy', sizes: 'auto', width: '0', 'data-ref': 'ref1'},
{loading: 'lazy', sizes: 'auto', style: 'width: 0px', 'data-ref': 'ref1'},
{loading: 'lazy', sizes: 'auto', 'data-ref': 'ref2'}, // no width -> UA default of 300px
{loading: 'lazy', sizes: 'auto, 100vw', width: '10', 'data-ref': 'ref1'},
{loading: 'lazy', sizes: '100vw, auto', width: '10', 'data-ref': 'ref2'},
{loading: 'eager', sizes: 'auto', width: '10', 'data-ref': 'ref2'},
Expand All @@ -81,11 +82,11 @@
{loading: 'lazy', sizes: 'auto', style: 'min-height: 10px; aspect-ratio: 10 / 10', 'data-ref': 'ref1'},
{loading: 'lazy', sizes: 'auto', style: 'min-height: 10px; aspect-ratio: 500 / 10', 'data-ref': 'ref2'},
{loading: 'lazy', sizes: 'auto', style: 'inline-size: 10px', 'data-ref': 'ref1'},
{loading: 'lazy', sizes: 'auto', style: 'min-inline-size: 10px', 'data-ref': 'ref1'},
{loading: 'lazy', sizes: 'auto', style: 'min-inline-size: 10px', 'data-ref': 'ref2'}, // no width -> UA default of 300px
{loading: 'lazy', sizes: 'auto', style: 'block-size: 10px; aspect-ratio: 10 / 10', 'data-ref': 'ref1'},
{loading: 'lazy', sizes: 'auto', style: 'min-block-size: 10px; aspect-ratio: 10 / 10', 'data-ref': 'ref1'},
{loading: 'lazy', sizes: 'auto', style: 'block-size: 10px; writing-mode: vertical-rl', 'data-ref': 'ref1'},
{loading: 'lazy', sizes: 'auto', style: 'min-block-size: 10px; writing-mode: vertical-rl', 'data-ref': 'ref1'},
{loading: 'lazy', sizes: 'auto', style: 'min-block-size: 10px; writing-mode: vertical-rl', 'data-ref': 'ref2'}, // no width -> UA default of 300px
{loading: 'lazy', sizes: 'auto', style: 'inline-size: 10px; aspect-ratio: 10/10; writing-mode: vertical-rl', 'data-ref': 'ref1'},
{loading: 'lazy', sizes: 'auto', style: 'min-inline-size: 10px; aspect-ratio: 10/10; writing-mode: vertical-rl', 'data-ref': 'ref1'},
{loading: 'lazy', sizes: 'auto', style: '--my-width: 10px; width: var(--my-width)', 'data-ref': 'ref1'},
Expand Down Expand Up @@ -119,6 +120,11 @@
parent = document.getElementById(obj.parent);
break;
case 'sizes':
// Authors have to specify sizes="auto" on the img to use auto-sizes.
if(obj[attr].toLowerCase().startsWith("auto")) {
img.setAttribute(attr, obj[attr]);
break;
}
case 'type':
case 'media':
source.setAttribute(attr, obj[attr]);
Expand Down

0 comments on commit 1f6a35d

Please sign in to comment.