|
1 | 1 | <!doctype html>
|
2 | 2 | <title>img parse a sizes attribute: sizes=auto</title>
|
| 3 | +<link rel="help" href="https://html.spec.whatwg.org/multipage/images.html#parse-a-sizes-attribute"> |
3 | 4 | <script src="/resources/testharness.js"></script>
|
4 | 5 | <script src="/resources/testharnessreport.js"></script>
|
5 | 6 | <style>
|
|
61 | 62 | // Actual tests
|
62 | 63 | {loading: 'lazy', sizes: 'auto', width: '10', 'data-ref': 'ref1'},
|
63 | 64 | {loading: 'lazy', sizes: 'AUTO', width: '10', 'data-ref': 'ref1'},
|
64 |
| - {loading: 'lazy', width: '10', 'data-ref': 'ref1'}, |
65 |
| - {loading: 'lazy', style: 'width: 10px', 'data-ref': 'ref1'}, |
66 |
| - {loading: 'lazy', style: 'max-width: 10px', 'data-ref': 'ref2'}, // no specified width -> 0 -> 100vw |
67 |
| - {loading: 'lazy', style: 'width: 100%; max-width: 10px', 'data-ref': 'ref1'}, |
| 65 | + {loading: 'lazy', width: '10', 'data-ref': 'ref2'}, // no `sizes: 'auto'` -> 100vw |
| 66 | + {loading: 'lazy', style: 'width: 10px', 'data-ref': 'ref2'}, // no `sizes: 'auto'` -> 100vw |
| 67 | + {loading: 'lazy', style: 'max-width: 10px', 'data-ref': 'ref2'}, // no `sizes: 'auto'` -> 100vw |
| 68 | + {loading: 'lazy', style: 'width: 100%; max-width: 10px', 'data-ref': 'ref2'}, // no `sizes: 'auto'` -> 100vw |
68 | 69 | {loading: 'lazy', sizes: 'auto', width: '500', 'data-ref': 'ref2'},
|
69 | 70 | {loading: 'lazy', sizes: 'auto', width: '10', style: 'visibility: hidden', 'data-ref': 'ref1'},
|
70 | 71 | {loading: 'lazy', sizes: 'auto', width: '10', style: 'display: inline', hidden: '', 'data-ref': 'ref1'},
|
71 |
| - {loading: 'lazy', sizes: 'auto', width: '0', 'data-ref': 'ref2'}, // 0 -> 100vw |
72 |
| - {loading: 'lazy', sizes: 'auto', style: 'width: 0px', 'data-ref': 'ref2'}, // 0 -> 100vw |
73 |
| - {loading: 'lazy', sizes: 'auto', 'data-ref': 'ref2'}, // no specified width -> 0 -> 100vw |
| 72 | + {loading: 'lazy', sizes: 'auto', width: '0', 'data-ref': 'ref1'}, |
| 73 | + {loading: 'lazy', sizes: 'auto', style: 'width: 0px', 'data-ref': 'ref1'}, |
| 74 | + {loading: 'lazy', sizes: 'auto', 'data-ref': 'ref2'}, // no width -> UA default of 300px |
74 | 75 | {loading: 'lazy', sizes: 'auto, 100vw', width: '10', 'data-ref': 'ref1'},
|
75 | 76 | {loading: 'lazy', sizes: '100vw, auto', width: '10', 'data-ref': 'ref2'},
|
76 | 77 | {loading: 'eager', sizes: 'auto', width: '10', 'data-ref': 'ref2'},
|
|
81 | 82 | {loading: 'lazy', sizes: 'auto', style: 'min-height: 10px; aspect-ratio: 10 / 10', 'data-ref': 'ref1'},
|
82 | 83 | {loading: 'lazy', sizes: 'auto', style: 'min-height: 10px; aspect-ratio: 500 / 10', 'data-ref': 'ref2'},
|
83 | 84 | {loading: 'lazy', sizes: 'auto', style: 'inline-size: 10px', 'data-ref': 'ref1'},
|
84 |
| - {loading: 'lazy', sizes: 'auto', style: 'min-inline-size: 10px', 'data-ref': 'ref1'}, |
| 85 | + {loading: 'lazy', sizes: 'auto', style: 'min-inline-size: 10px', 'data-ref': 'ref2'}, // no width -> UA default of 300px |
85 | 86 | {loading: 'lazy', sizes: 'auto', style: 'block-size: 10px; aspect-ratio: 10 / 10', 'data-ref': 'ref1'},
|
86 | 87 | {loading: 'lazy', sizes: 'auto', style: 'min-block-size: 10px; aspect-ratio: 10 / 10', 'data-ref': 'ref1'},
|
87 | 88 | {loading: 'lazy', sizes: 'auto', style: 'block-size: 10px; writing-mode: vertical-rl', 'data-ref': 'ref1'},
|
88 |
| - {loading: 'lazy', sizes: 'auto', style: 'min-block-size: 10px; writing-mode: vertical-rl', 'data-ref': 'ref1'}, |
| 89 | + {loading: 'lazy', sizes: 'auto', style: 'min-block-size: 10px; writing-mode: vertical-rl', 'data-ref': 'ref2'}, // no width -> UA default of 300px |
89 | 90 | {loading: 'lazy', sizes: 'auto', style: 'inline-size: 10px; aspect-ratio: 10/10; writing-mode: vertical-rl', 'data-ref': 'ref1'},
|
90 | 91 | {loading: 'lazy', sizes: 'auto', style: 'min-inline-size: 10px; aspect-ratio: 10/10; writing-mode: vertical-rl', 'data-ref': 'ref1'},
|
91 | 92 | {loading: 'lazy', sizes: 'auto', style: '--my-width: 10px; width: var(--my-width)', 'data-ref': 'ref1'},
|
|
119 | 120 | parent = document.getElementById(obj.parent);
|
120 | 121 | break;
|
121 | 122 | case 'sizes':
|
| 123 | + // Authors have to specify sizes="auto" on the img to use auto-sizes. |
| 124 | + if(obj[attr].toLowerCase().startsWith("auto")) { |
| 125 | + img.setAttribute(attr, obj[attr]); |
| 126 | + break; |
| 127 | + } |
122 | 128 | case 'type':
|
123 | 129 | case 'media':
|
124 | 130 | source.setAttribute(attr, obj[attr]);
|
|
0 commit comments