reporting-to-worker-owner.https.html (3368B)
1 <!doctype html> 2 <html> 3 <head> 4 <title>Check COEP reports are sent to parent worker for 'new Worker()' failure</title> 5 </head> 6 <body> 7 <script src="/common/get-host-info.sub.js"></script> 8 <script src="/resources/testharness.js"></script> 9 <script src="/resources/testharnessreport.js"></script> 10 <script src="/service-workers/service-worker/resources/test-helpers.sub.js"></script> 11 <script> 12 const {ORIGIN} = get_host_info(); 13 const RESOURCES_PATH= new URL("resources", location).pathname; 14 const parent_worker_path = "worker-owner.js?pipe="; 15 const worker_path = "universal-worker.js?pipe="; 16 17 const coep_header= { 18 "coep-none" : "", 19 "coep-report-only" : 20 "header(Cross-Origin-Embedder-Policy-Report-Only,require-corp)", 21 "coep-require-corp" : "|header(Cross-Origin-Embedder-Policy,require-corp)", 22 }; 23 24 function checkReport(report, url, blocked_url, disposition) { 25 assert_equals(report.type, "coep"); 26 assert_equals(report.url, url); 27 assert_equals(report.body.type, "worker initialization"); 28 assert_equals(report.body.blockedURL, blocked_url); 29 assert_equals(report.body.disposition, disposition); 30 } 31 32 // Test parameters: 33 // - `owner_coep` the COEP header of the parent DedicatedWorker's script 34 // response. 35 // - `worker_coep` the COEP header of the DedicatedWorker's script response. 36 // 37 // Test expectations: 38 // - `length` the length of reports. 39 // - `disposition` the disposition in a report's body. Empty string if the 40 // length of reports is expected to be 0. 41 function check( 42 // Test parameters: 43 owner_coep, 44 worker_coep, 45 // Test expectations: 46 length, 47 disposition) { 48 promise_test(async (t) => { 49 const worker_url = worker_path + coep_header[worker_coep]; 50 const parent_worker_url = parent_worker_path + coep_header[owner_coep]; 51 const parent_worker = new Worker('./resources/' + parent_worker_url); 52 53 const worker_response = 54 new Promise(resolve => parent_worker.onmessage = resolve); 55 parent_worker.postMessage( 56 {worker_url: worker_url, wait_for_report: length > 0}); 57 58 const {data} = await worker_response; 59 assert_equals(data.length, length); 60 if (data.length > 0) { 61 const blocked_url = `${ORIGIN}${RESOURCES_PATH}/${worker_url}`; 62 const url = `${ORIGIN}${RESOURCES_PATH}/${parent_worker_url}`; 63 checkReport( 64 data[0], 65 url, 66 blocked_url, 67 disposition 68 ); 69 } 70 }, `Reporting to ${owner_coep} worker with ${worker_coep} worker`); 71 } 72 73 // ----------------------------------------------------------------------------- 74 // owner_coep , worker_coep , length , disposition 75 // ----------------------------------------------------------------------------- 76 check("coep-none" , "coep-none" , 0 , ""); 77 check("coep-none" , "coep-report-only" , 0 , ""); 78 check("coep-none" , "coep-require-corp" , 0 , ""); 79 check("coep-report-only" , "coep-none" , 1 , "reporting"); 80 check("coep-report-only" , "coep-report-only" , 1 , "reporting"); 81 check("coep-report-only" , "coep-require-corp" , 0 , ""); 82 check("coep-require-corp" , "coep-none" , 1 , "enforce"); 83 check("coep-require-corp" , "coep-report-only" , 1 , "enforce"); 84 check("coep-require-corp" , "coep-require-corp" , 0 , ""); 85 86 </script> 87 </body> 88 </html>