summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/mozilla/tests/fetch/fetchpriority/support/image-tests/image-dynamic-load.h2.html
blob: 20de6ed0421ddc8857a4dcd870f4761e48a54040 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <title>fetchpriority</title>
</head>
<body>
<script>
  onload = function() {
    const kData = [
        { src: "../resources/square_25px_x_25px.png?1", fetchPriority: "low" },
        { src: "../resources/square_25px_x_25px.png?2", fetchPriority: "high" },
        { src: "../resources/square_25px_x_25px.png?3", fetchPriority: "auto" },
        { src: "../resources/square_25px_x_25px.png?4"},
    ];

    let numberOfLoads = 0;
    for (const data of kData) {
        const imgElement = document.createElement("img");

        if ("fetchPriority" in data) {
            imgElement.fetchPriority = data.fetchPriority;
        }

        imgElement.addEventListener("load", () => {
          ++numberOfLoads;
          if (numberOfLoads == kData.length) {
            opener.postMessage("ChildLoaded");
          }
        }, { once: "true"});

        imgElement.alt = "a";
        imgElement.src = data.src;

        // Don't append `imgElement` to the document to prevent re-
        // priotiziation.
    }
  }
</script>
</body>
</html>