summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/loading/early-hints/resources/csp-document-disallow.html
blob: 53b6ee232dc38e7e5e9aae372d4377cf8624ed51 (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
<!DOCTYPE html>
<meta charset=utf-8>
<meta http-equiv="Content-Security-Policy" content="script-src 'self' 'unsafe-inline'">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="early-hints-helpers.sub.js"></script>
<body>
<script>
const SEARCH_PARAMS = new URLSearchParams(window.location.search);
const POLICY = SEARCH_PARAMS.get("early-hints-policy");

promise_test(async (t) => {
    const resource_url = SEARCH_PARAMS.get("resource-url");

    // Resume the delayed preload.
    const resume_url = SEARCH_PARAMS.get("resume-url");
    await fetch(resume_url);

    // Wait for the preload to finish.
    await new Promise(resolve => t.step_timeout(resolve, 300));

    // The preload should be denied by CSP.
    await promise_rejects_js(t, Error, fetchScript(resource_url));
}, `Early hints preload CSP = ${POLICY}, document disallowed the preload later.`);
</script>
</body>