Make sure the <script> is inserted after <link rel="modulepreload"> is done, so the result would be consistent. Otherwise the <script> might also be preloaded by the speculative parser and will join a single in-flight fetch with the <link>. Differential Revision: https://phabricator.services.mozilla.com/D313496
37 lines
1.5 KiB
HTML
37 lines
1.5 KiB
HTML
<!doctype html>
|
|
<meta charset=utf-8>
|
|
<title>modulepreload with an invalid integrity does not poison a later import</title>
|
|
<script src="/resources/testharness.js"></script>
|
|
<script src="/resources/testharnessreport.js"></script>
|
|
<body>
|
|
<script>
|
|
// A modulepreload whose integrity check fails is a fetch error, which per the
|
|
// HTML spec is not cached in the module map. A later <script type=module> for
|
|
// the same URL that has no integrity requirement must therefore be able to
|
|
// fetch it again and load successfully.
|
|
// https://html.spec.whatwg.org/#fetch-a-single-module-script
|
|
//
|
|
// The <script> is only inserted after the modulepreload has finished, so the
|
|
// two never join a single in-flight fetch.
|
|
promise_test(async () => {
|
|
const link = document.createElement('link');
|
|
link.rel = 'modulepreload';
|
|
link.href = 'resources/module1.js';
|
|
link.integrity = 'sha384-invalid';
|
|
await new Promise((resolve, reject) => {
|
|
link.onload = () => reject(new Error('modulepreload should have failed its integrity check'));
|
|
link.onerror = resolve;
|
|
document.head.appendChild(link);
|
|
});
|
|
|
|
const script = document.createElement('script');
|
|
script.type = 'module';
|
|
script.src = 'resources/module1.js';
|
|
await new Promise((resolve, reject) => {
|
|
script.onload = resolve;
|
|
script.onerror = () => reject(new Error('script should have loaded'));
|
|
document.body.appendChild(script);
|
|
});
|
|
}, "A module script should load even if an earlier modulepreload for the same URL failed its integrity check");
|
|
</script>
|