summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/preload/prefetch-types.https.html
blob: 276439e5440b2157eb2bfaf6a2fbe8b4ec05b3ff (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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<!DOCTYPE html>
<title>Ensures that prefetch is not specific to resource types</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/common/utils.js"></script>
<script src="/common/get-host-info.sub.js"></script>
<script src="resources/prefetch-helper.js"></script>
<body>
<script>
    const host_info = get_host_info();
const loaders = {
    "": {
        file: "../../common/dummy.xml",
        type: "text/xml",
        load: fetch
    },
    image: {
        file: '../../images/green.png',
        type: 'image/png',
        load: href => {
            const image = document.createElement('img');
            image.src = href;
            document.body.appendChild(image);
            return new Promise(resolve => image.addEventListener('load', resolve));
        }
    },
    script: {
        file: 'dummy.js',
        type: 'application/javascript',
        load: href => {
            const script = document.createElement('script');
            script.src = href;
            document.body.appendChild(script);
            return new Promise(resolve => script.addEventListener('load', resolve));
        }
    },
    style: {
        file: 'dummy.css',
        type: 'text/css',
        load: href => {
            const link = document.createElement('link');
            link.href = href;
            link.rel = "stylesheet";
            document.body.appendChild(link);
            return new Promise(resolve => link.addEventListener('load', resolve));
        }
    },
    document: {
        file: 'empty.html',
        type: 'text/html',
        load: href => {
            const iframe = document.createElement("iframe");
            iframe.src = href;
            document.body.appendChild(iframe);
            return new Promise(resolve => iframe.addEventListener("load", resolve));
        }
    }
};

for (const as in loaders) {
    for (const consumer in loaders) {
        const {file, type, load} = loaders[as]
        promise_test(async t => {
            const {href} = await prefetch({file, type, as, origin: host_info[origin]});
            const requests = await get_prefetch_info(href);
            assert_equals(requests.length, 1);
            assert_equals(requests[0].headers["sec-fetch-dest"], "empty");
        }, `Prefetch as=${as} should work when consumed as ${consumer} (${origin})`);
    }
}

</script>
</body>