dedicated-worker-import-data-url.any.js (1155B)
1 // META: script=/workers/modules/resources/import-test-cases.js 2 3 // Imports |testCase.scriptURL| on a dedicated worker loaded from a data 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_data_url_test(testCase) { 7 promise_test(async () => { 8 // The Access-Control-Allow-Origin header is necessary because a worker 9 // loaded from a data URL has a null origin and import() on the worker 10 // without the header is blocked. 11 const importURL = new URL(testCase.scriptURL, location.href) + 12 '?pipe=header(Access-Control-Allow-Origin, *)'; 13 const dataURL = `data:text/javascript,import "${importURL}";`; 14 15 const worker = new Worker(dataURL, { type: 'module'}); 16 worker.postMessage('Send message for tests from main script.'); 17 const msgEvent = await new Promise((resolve, reject) =>{ 18 worker.onmessage = resolve; 19 worker.onerror = reject; 20 }).catch(e => assert_true(false)); 21 assert_array_equals(msgEvent.data, testCase.expectation); 22 }, testCase.description); 23 } 24 25 testCases.forEach(import_data_url_test);