<!DOCTYPE html>
<title>DedicatedWorker: import</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
// Start a dedicated worker for |scriptURL| and wait until MessageEvents from
// imported modules up to |expectedNumberOfImportedModules|.
function RunImportTest(scriptURL, expectedNumberOfImportedModules) {
return new Promise(resolve => {
let numberOfImportedModules = 0;
const worker = new Worker(scriptURL, { type: 'module' });
worker.onmessage = e => {
if (e.data === 'LOADED')
++numberOfImportedModules;
if (numberOfImportedModules === expectedNumberOfImportedModules)
resolve();
};
});
}
promise_test(() => {
return RunImportTest('resources/static-import-worker.js', 2);
}, 'Test static import on DedicatedWorkerGlobalScope.');
promise_test(() => {
return RunImportTest('resources/nested-static-import-worker.js', 3);
}, 'Test nested static import on DedicatedWorkerGlobalScope.');
promise_test(() => {
return RunImportTest(
'resources/static-import-and-then-dynamic-import-worker.js', 3);
}, 'Test static import and then dynamic import on DedicatedWorkerGlobalScope.');
promise_test(() => {
return RunImportTest('resources/dynamic-import-worker.js', 2);
}, 'Test dynamic import on DedicatedWorkerGlobalScope.');
promise_test(() => {
return RunImportTest('resources/nested-dynamic-import-worker.js', 3);
}, 'Test nested dynamic import on DedicatedWorkerGlobalScope.');
promise_test(() => {
return RunImportTest(
'resources/dynamic-import-and-then-static-import-worker.js', 3);
}, 'Test dynamic import and then static import on DedicatedWorkerGlobalScope.');
</script>