summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/preload/link-header-preload-imagesrcset.html
blob: 65c8c061ada5ba94b1b6fc6a9b130a5629d72076 (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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<!DOCTYPE html>
<title>Makes sure that Link headers preload images with imagesrcset/imagesizes attributes.</title>
<link rel="help" href="https://github.com/w3c/preload/issues/120">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/preload/resources/preload_helper.js"></script>
<body>
<script>
    setup({single_test: true});

    var iterations = 0;
    var expectation = new Array(10).fill(0);
    if (window.devicePixelRatio < 1.5) {
        expectation[0] = expectation[5] = expectation[8] = 1;
    } else if (window.devicePixelRatio >= 1.5) {
        expectation[1] = expectation[6] = expectation[9] = 1;
    }

    function check_finished() {
        if (numberOfResourceTimingEntries('resources/square.png?from-header&1x') == expectation[0] &&
            numberOfResourceTimingEntries('resources/square.png?from-header&2x') == expectation[1] &&
            numberOfResourceTimingEntries('resources/square.png?from-header&3x') == expectation[2] &&
            numberOfResourceTimingEntries('resources/square.png?from-header&base') == expectation[3] &&
            numberOfResourceTimingEntries('resources/square.png?from-header&200') == expectation[4] &&
            numberOfResourceTimingEntries('resources/square.png?from-header&400') == expectation[5] &&
            numberOfResourceTimingEntries('resources/square.png?from-header&800') == expectation[6] &&
            numberOfResourceTimingEntries('resources/square.png?from-header&150') == expectation[7] &&
            numberOfResourceTimingEntries('resources/square.png?from-header&300') == expectation[8] &&
            numberOfResourceTimingEntries('resources/square.png?from-header&600') == expectation[9]) {
            done();
        }
        iterations++;
        if (iterations == 10) {
            // At least one is expected to fail, but this should give details to the exact failure(s).
            verifyNumberOfResourceTimingEntries('resources/square.png?from-header&1x', expectation[0]);
            verifyNumberOfResourceTimingEntries('resources/square.png?from-header&2x', expectation[1]);
            verifyNumberOfResourceTimingEntries('resources/square.png?from-header&3x', expectation[2]);
            verifyNumberOfResourceTimingEntries('resources/square.png?from-header&base', expectation[3]);
            verifyNumberOfResourceTimingEntries('resources/square.png?from-header&200', expectation[4]);
            verifyNumberOfResourceTimingEntries('resources/square.png?from-header&400', expectation[5]);
            verifyNumberOfResourceTimingEntries('resources/square.png?from-header&800', expectation[6]);
            verifyNumberOfResourceTimingEntries('resources/square.png?from-header&150', expectation[7]);
            verifyNumberOfResourceTimingEntries('resources/square.png?from-header&300', expectation[8]);
            verifyNumberOfResourceTimingEntries('resources/square.png?from-header&600', expectation[9]);
            done();
        } else {
            step_timeout(check_finished, 500);
        }
    }

    window.addEventListener("load", function() {
        verifyPreloadAndRTSupport();
        step_timeout(check_finished, 500);
    });
</script>
</body>