Files
sousa-gecko/testing/web-platform/tests/preload/modulepreload-sri-importmap.html
Yoshi Cheng-Hao Huang 219073d4f5 Bug 2055211 - Part 4: Update /preload/modulepreload-sri-(importmap).html. r=jonco
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
2026-07-30 01:46:29 +00:00

45 lines
1.8 KiB
HTML

<!doctype html>
<meta charset=utf-8>
<title>modulepreload with an invalid integrity does not poison a later import (with an import map)</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script type="importmap">
{
"imports": {
"test": "https://example.com/test.js"
}
}
</script>
<body>
<script>
// As modulepreload-sri.html, but with an import map registered. The import map
// does not affect resolution of module1.js, so it must not change the result:
// a modulepreload whose integrity check fails is a fetch error, which is not
// cached in the module map, so a later no-integrity <script type=module> for
// the same URL fetches it again and loads 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, with an import map registered");
</script>