Skip to content

Commit 515b639

Browse files
emiliomoz-wptsync-bot
authored andcommitted
Don't consider an image incomplete due to a non-alwaysLoad task.
This would've also fixed the issue, and I think it's the right thing to do. It's more annoying to test tho. Differential Revision: https://phabricator.services.mozilla.com/D314435 bugzilla-url: https://bugzilla.mozilla.org/show_bug.cgi?id=2058110 gecko-commit: 4a669da0a1f9d7891ed912919d20834521630fda gecko-commit-git: 26ee5665f273e5f362a5f77ffaaf72534792ddd6 gecko-reviewers: edgar, dom-core-reviewers
1 parent e3cdf1b commit 515b639

1 file changed

Lines changed: 61 additions & 0 deletions

File tree

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<!doctype html>
2+
<meta charset=utf-8>
3+
<title>img.complete shouldn't change on viewport changes that don't change the selected source</title>
4+
<link rel=help href="https://html.spec.whatwg.org/multipage/embedded-content.html#dom-img-complete">
5+
<link rel=help href="https://html.spec.whatwg.org/multipage/images.html#reacting-to-environment-changes">
6+
<script src="/resources/testharness.js"></script>
7+
<script src="/resources/testharnessreport.js"></script>
8+
<body>
9+
<script>
10+
// The <source> and the <img> point at the same URL, so no matter which one is
11+
// selected reacting to environment changes never starts a new load.
12+
const IFRAME_SRCDOC = `
13+
<style>html, body { margin: 0 }</style>
14+
<picture>
15+
<source media='(max-width: 150px)' srcset='/images/green-2x2.png'>
16+
<img src='/images/green-2x2.png'>
17+
</picture>
18+
`;
19+
20+
promise_test(async t => {
21+
const iframe = document.createElement("iframe");
22+
iframe.style.width = "300px";
23+
iframe.style.height = "100px";
24+
iframe.srcdoc = IFRAME_SRCDOC;
25+
document.body.appendChild(iframe);
26+
t.add_cleanup(() => iframe.remove());
27+
await new Promise(resolve => {iframe.onload = resolve;});
28+
29+
const win = iframe.contentWindow;
30+
const img = win.document.querySelector("img");
31+
const mql = win.matchMedia("(max-width: 150px)");
32+
assert_true(img.complete, "Image should be complete once loaded");
33+
assert_false(mql.matches, "Media query shouldn't match initially");
34+
const currentSrc = img.currentSrc;
35+
36+
img.addEventListener("load", t.unreached_func("Unexpected load event"));
37+
img.addEventListener("error", t.unreached_func("Unexpected error event"));
38+
39+
for (const width of ["100px", "300px"]) {
40+
const shouldMatch = width == "100px";
41+
const completeOnChange = new Promise(resolve => {
42+
mql.addEventListener("change", () => resolve(img.complete), {once: true});
43+
});
44+
45+
iframe.style.width = width;
46+
if (mql.matches == shouldMatch) {
47+
assert_true(img.complete,
48+
`complete right after the media feature values changed (${width})`);
49+
}
50+
assert_true(await completeOnChange,
51+
`complete during the media query change event (${width})`);
52+
assert_true(img.complete, `complete after the environment change (${width})`);
53+
assert_equals(mql.matches, shouldMatch, `Media query state (${width})`);
54+
assert_equals(img.currentSrc, currentSrc, `currentSrc unchanged (${width})`);
55+
await new Promise(r => {
56+
// Give a chance for any unexpected load / error event to fire.
57+
win.requestAnimationFrame(() => win.requestAnimationFrame(r))
58+
});
59+
}
60+
}, "Resizing the viewport with a <picture> element shouldn't change img.complete");
61+
</script>

0 commit comments

Comments
 (0)