Skip to content

Commit 9c629ec

Browse files
DOM: Ensure atomic moves trigger relevant mutations
See https://docs.google.com/document/d/1qfYyvdK4zhzloABKeh0K1lHPm-SpnEcsWEE9UdDuoMk/edit and the discussion around <picture>, <source>, and <img> relevant mutations during atomic moves. [email protected] Bug: 40150299 Change-Id: I7c7de31da763efd9a17cf5258e1c4be9e54c907b Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5906482 Reviewed-by: Noam Rosenthal <[email protected]> Commit-Queue: Dominic Farolino <[email protected]> Cr-Commit-Position: refs/heads/main@{#1364197}
1 parent 1a1d4ed commit 9c629ec

File tree

1 file changed

+65
-0
lines changed

1 file changed

+65
-0
lines changed
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<!DOCTYPE html>
2+
<title>Moving triggers relevant mutations</title>
3+
<script src="/resources/testharness.js"></script>
4+
<script src="/resources/testharnessreport.js"></script>
5+
<body>
6+
7+
<div></div>
8+
9+
<script>
10+
promise_test(async t => {
11+
const div = document.querySelector('div');
12+
div.innerHTML = `
13+
<picture>
14+
<source srcset="/images/green.png" media="(min-width: 10px)">
15+
<img src="/images/red.png">
16+
</picture>`;
17+
18+
const picture = document.querySelector('picture');
19+
const source = document.querySelector('source');
20+
const img = document.querySelector('img');
21+
22+
t.add_cleanup(() => {
23+
picture.remove();
24+
source.remove();
25+
img.remove();
26+
});
27+
28+
await new Promise(resolve => img.addEventListener('load', e => resolve(), {once: true}));
29+
30+
// Moving <source> out of <picture> triggers a relevant mutation on <img>.
31+
document.body.moveBefore(source, null);
32+
33+
await new Promise(resolve => img.addEventListener('load', e => resolve(), {once: true}));
34+
}, "Moving <source> out of <picture> triggers a relevant mutation on sibling <img>");
35+
36+
promise_test(async t => {
37+
const div = document.querySelector('div');
38+
div.innerHTML = `
39+
<picture>
40+
<source srcset="/images/green.png" media="(min-width: 10px)">
41+
</picture>`;
42+
43+
const picture = document.querySelector('picture');
44+
const source = document.querySelector('source');
45+
const img = document.createElement('img');
46+
img.src = '/images/red.png';
47+
48+
t.add_cleanup(() => {
49+
picture.remove();
50+
source.remove();
51+
img.remove();
52+
});
53+
54+
// The <img> will first load outside of the picture.
55+
await new Promise(resolve => img.addEventListener('load', e => resolve(), {once: true}));
56+
57+
// Moving the <img> element to the <picture> (as the last child), triggers a
58+
// relevant mutation and loads the <source> picture — which still fires a
59+
// load event at the <img>.
60+
picture.moveBefore(img, null);
61+
62+
await new Promise(resolve => img.addEventListener('load', e => resolve(), {once: true}));
63+
}, "Moving <img> into a <picture> triggers a relevant mutation on the <img>, " +
64+
"loading <source>");
65+
</script>

0 commit comments

Comments
 (0)