Update WPT tests for embedded content
[WebKit-https.git] / LayoutTests / imported / w3c / web-platform-tests / html / semantics / embedded-content / the-img-element / sizes / sizes-dynamic-002.html
1 <!doctype html>
2 <html class="reftest-wait">
3 <title>Image intrinsic size specified via sizes attribute reacts properly to media changes in Shadow DOM</title>
4 <link rel="author" title="Emilio Cobos Ãlvarez" href="mailto:emilio@crisal.io">
5 <link rel="match" href="sizes-dynamic-001-ref.html">
6 <link rel="help" href="https://html.spec.whatwg.org/#sizes-attributes">
7 <link rel="help" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1149357">
8 <script>
9 function frameLoaded(frame) {
10   let doc = frame.contentDocument;
11   let shadow = doc.getElementById("host").attachShadow({ mode: "open" });
12
13   let img = doc.createElement("img");
14   img.srcset = "/images/green-256x256.png 100w";
15   img.style.maxWidth = "100%";
16   img.setAttribute("sizes", "(min-width: 400px) 10px, 20px");
17
18   img.onload = function() {
19     img.offsetWidth; // Flush layout.
20
21     frame.width = "500";
22
23     // Trigger the viewport resize, which will trigger the image load task.
24     img.offsetWidth;
25
26     // Wait for the image load task to run.
27     setTimeout(() => document.documentElement.removeAttribute("class"), 0);
28   };
29
30   shadow.appendChild(img);
31 }
32 </script>
33 <iframe onload="frameLoaded(this)" width="200" height="500" srcdoc='<!doctype html><div id="host"></div>'></iframe>