Debian Codegraph @

testing/web-platform/mozilla/tests/fetch/fetchpriority/support/image-tests/image-svg-dynamic-load.h2.html

raw
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <meta charset="UTF-8">
5 <title>internal priority of SVG's &lt;image&gt; element (dynamic insertion)</title>
6 </head>
7 <body>
8 <script>
9 onload = function() {
10 const kData = [
11 { src: "../resources/square_25px_x_25px.png?1", fetchPriority: "low" },
12 { src: "../resources/square_25px_x_25px.png?2", fetchPriority: "high" },
13 { src: "../resources/square_25px_x_25px.png?3", fetchPriority: "auto" },
14 { src: "../resources/square_25px_x_25px.png?4"},
15 ];
16 let numberOfLoads = 0;
17 for (const data of kData) {
18 const namespaceURI = "http://www.w3.org/2000/svg";
19 const imgElement = document.createElementNS(namespaceURI, "image");
20
21 if ("fetchPriority" in data) {
22 imgElement.fetchPriority = data.fetchPriority;
23 }
24
25 imgElement.addEventListener("load", () => {
26 ++numberOfLoads;
27 if (numberOfLoads == kData.length) {
28 opener.postMessage("ChildLoaded");
29 }
30 }, { once: "true"});
31
32 // Use setAttribute as corresponding SVGImageElement/SVGURIReference
33 // attributes are read-only.
34 imgElement.setAttribute("width", "25");
35 imgElement.setAttribute("height", "25");
36 imgElement.setAttribute("href", data.src);
37
38 // Per https://svgwg.org/svg2-draft/linking.html#processingURL
39 // the URL is only processed "at the time the element is connected to a
40 // document, or at the time when the attribute is set, whichever is
41 // later" so it's necessary to insert imgElement into the document in
42 // order to trigger ressource fetching.
43 let svg = document.createElementNS(namespaceURI, "svg");
44 svg.appendChild(imgElement);
45 document.body.appendChild(svg);
46 }
47 }
48 </script>
49 </body>
50 </html>