Source code

Revision control

Copy as Markdown

Other Tools

<!doctype html>
<title>The width and height attributes do not give an aspect ratio to an image that renders alt text</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<style>
#grid {
display: grid;
width: 420px;
height: 200px;
}
#grid > img {
width: 100%;
height: 100%;
}
#stretched {
width: 100%;
height: auto;
}
#natural {
width: auto;
height: auto;
}
</style>
<div id="grid"><img id="grid-item" src="error.png" width="1600" height="900" alt="alt text"></div>
<div style="width: 420px"><img id="stretched" src="error.png" width="1600" height="900" alt="alt text"></div>
<img id="natural" src="error.png" width="1600" height="900" alt="alt text">
<script>
setup({ explicit_done: true });
onload = () => {
test(() => {
let rect = document.getElementById("grid-item").getBoundingClientRect();
assert_equals(rect.width, 420, "inline size fills the grid area");
assert_equals(rect.height, 200, "block size fills the grid area and does not overflow it");
}, "An error image with alt text and height:100% fills its definite grid area");
test(() => {
let stretched = document.getElementById("stretched").getBoundingClientRect();
let natural = document.getElementById("natural").getBoundingClientRect();
assert_not_equals(stretched.height, stretched.width, "the box is not square");
assert_equals(stretched.height, natural.height, "the block size comes from the alt text box");
}, "An error image with alt text does not transfer its inline size through an aspect ratio");
done();
};
</script>