dedicated-worker-import-data-url-cross-origin.html (1997B)
1 <!DOCTYPE html> 2 <title>DedicatedWorker: ES modules for data URL workers</title> 3 <script src="/resources/testharness.js"></script> 4 <script src="/resources/testharnessreport.js"></script> 5 <script> 6 7 const import_from_data_url_worker_test = (importType, isDataURL, expectation) => { 8 promise_test(async () => { 9 const importURL = new URL(`resources/${importType}-import-` + 10 `${isDataURL ? 'data-url' : 'script'}-block-cross-origin.js`, 11 location.href) + '?pipe=header(Access-Control-Allow-Origin, *)'; 12 const dataURL = `data:text/javascript,import "${importURL}";`; 13 const worker = new Worker(dataURL, { type: 'module' }); 14 worker.postMessage('Send message for tests from main script.'); 15 const msgEvent = await new Promise((resolve, reject) =>{ 16 worker.onmessage = resolve; 17 worker.onerror = reject; 18 }).catch(e => assert_true(false)); 19 assert_array_equals(msgEvent.data, 20 expectation === 'blocked' ? ['ERROR'] 21 : ['export-block-cross-origin.js']); 22 }, `${importType} import ${isDataURL ? 'data url' : 'script'} from data: ` + 23 `URL should be ${expectation}.`); 24 } 25 26 // Static import should obey the outside settings. 27 // SecurityOrigin of the outside settings is decided by Window. 28 import_from_data_url_worker_test('static', true, 'allowed'); 29 import_from_data_url_worker_test('static', false, 'allowed'); 30 31 32 // Dynamic import should obey the inside settings. 33 // SecurityOrigin of the inside settings is a unique opaque origin. 34 // 35 // Data url script is cross-origin to the inside settings' SecurityOrigin, but 36 // dynamic importing it is allowed. 37 // https://fetch.spec.whatwg.org/#concept-main-fetch 38 // Step 5: request’s current URL’s scheme is "data" [spec text] 39 import_from_data_url_worker_test('dynamic', true, 'allowed'); 40 41 // Non-data url script is cross-origin to the inside settings' SecurityOrigin. 42 // It should be blocked. 43 import_from_data_url_worker_test('dynamic', false, 'blocked'); 44 45 </script>