shared-worker-import-blob-url.window.js (1120B)
1 // META: script=/workers/modules/resources/import-test-cases.js 2 3 // Imports |testCase.scriptURL| on a shared worker loaded from a blob URL, 4 // and waits until the list of imported modules is sent from the worker. Passes 5 // if the list is equal to |testCase.expectation|. 6 function import_blob_url_test(testCase) { 7 promise_test(async () => { 8 const importURL = new URL(testCase.scriptURL, location.href); 9 const blob = 10 new Blob([`import "${importURL}";`], {type: 'text/javascript'}); 11 const blobURL = URL.createObjectURL(blob); 12 const worker = new SharedWorker(blobURL, {type: 'module'}); 13 worker.port.postMessage('Send message for tests from main script.'); 14 const msgEvent = await new Promise((resolve, reject) => { 15 worker.port.onmessage = resolve; 16 worker.onerror = error => { 17 const msg = error instanceof ErrorEvent ? error.message 18 : 'unknown error'; 19 reject(msg); 20 }; 21 }); 22 assert_array_equals(msgEvent.data, testCase.expectation); 23 }, testCase.description); 24 } 25 26 testCases.forEach(import_blob_url_test);