64 lines
2.4 KiB
HTML
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>
|