1
0
Fork 0
firefox/testing/web-platform/tests/wasm/webapi/esm-integration/source-phase-preload.tentative.html
Daniel Baumann 5e9a113729
Adding upstream version 140.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
2025-06-25 09:37:52 +02:00

64 lines
2.4 KiB
HTML

<!doctype html>
<title>Preload source phase modules</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<body>
<script>
function verifyNumberOfDownloads(url, number, allowTransferSizeOfZero = false) {
var numDownloads = 0;
let absoluteURL = new URL(url, location.href).href;
performance.getEntriesByName(absoluteURL).forEach(entry => {
if (entry.transferSize > 0 || allowTransferSizeOfZero) {
numDownloads++;
}
});
assert_equals(numDownloads, number, url);
}
function attachAndWaitForLoad(element) {
return new Promise((resolve, reject) => {
element.onload = resolve;
element.onerror = reject;
document.body.appendChild(element);
});
}
promise_test(function(t) {
var link = document.createElement('link');
link.rel = 'modulepreload';
link.href = 'resources/exported-names.wasm';
return attachAndWaitForLoad(link).then(() => {
verifyNumberOfDownloads('resources/exported-names.wasm', 1);
let promise = new Promise((resolve) => {window.resolveStatic = resolve});
// Verify that <script> doesn't fetch the module again.
var script = document.createElement('script');
script.type = 'module';
script.text = "import source exportedNamesSource from './resources/exported-names.wasm'; window.resolveStatic()";
document.body.appendChild(script);
return promise;
}).then(() => {
verifyNumberOfDownloads('resources/exported-names.wasm', 1);
})
}, 'Static source phase import.');
promise_test(function(t) {
var link = document.createElement('link');
link.rel = 'modulepreload';
link.href = 'resources/execute-start.wasm';
return attachAndWaitForLoad(link).then(() => {
verifyNumberOfDownloads('resources/execute-start.wasm', 1);
let promise = new Promise((resolve) => {window.resolveDynamic = resolve});
// Verify that <script> doesn't fetch the module again.
var script = document.createElement('script');
script.type = 'module';
script.text = "await import.source('./resources/execute-start.wasm'); window.resolveDynamic();";
document.body.appendChild(script);
return promise;
}).then(() => {
verifyNumberOfDownloads('resources/execute-start.wasm', 1);
})
}, 'Dynamic source phase import.');
</script>
</body>