reporting-to-frame-owner.https.html (3312B)
1 <!doctype html> 2 <html> 3 <head> 4 <title>Check COEP reports are sent to iframe 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 iframe_path = "worker-owner-frame.html?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 iframe document's response. 34 // - `worker_coep` the COEP header of the DedicatedWorker's script response. 35 // 36 // Test expectations: 37 // - `length` the length of reports. 38 // - `disposition` the disposition in a report's body. Empty string if the 39 // length of reports is expected to be 0. 40 function check( 41 // Test parameters: 42 owner_coep, 43 worker_coep, 44 // Test expectations: 45 length, 46 disposition) { 47 promise_test(async (t) => { 48 const worker_url = worker_path + coep_header[worker_coep]; 49 const iframe_url = iframe_path + coep_header[owner_coep]; 50 const iframe = await with_iframe("./resources/" + iframe_url); 51 t.add_cleanup(() => iframe.remove()); 52 53 const iframe_response = new Promise(resolve => window.onmessage = resolve); 54 iframe.contentWindow.startWorkerAndObserveReports(worker_url, length > 0); 55 56 const {data} = await iframe_response; 57 assert_equals(data.length, length); 58 if (data.length > 0) { 59 const blocked_url = `${ORIGIN}${RESOURCES_PATH}/${worker_url}`; 60 const url = `${ORIGIN}${RESOURCES_PATH}/${iframe_url}`; 61 checkReport( 62 data[0], 63 url, 64 blocked_url, 65 disposition 66 ); 67 } 68 }, `Reporting to ${owner_coep} frame with ${worker_coep} worker`); 69 } 70 71 // ----------------------------------------------------------------------------- 72 // owner_coep , worker_coep , length , disposition 73 // ----------------------------------------------------------------------------- 74 check("coep-none" , "coep-none" , 0 , ""); 75 check("coep-none" , "coep-report-only" , 0 , ""); 76 check("coep-none" , "coep-require-corp" , 0 , ""); 77 check("coep-report-only" , "coep-none" , 1 , "reporting"); 78 check("coep-report-only" , "coep-report-only" , 1 , "reporting"); 79 check("coep-report-only" , "coep-require-corp" , 0 , ""); 80 check("coep-require-corp" , "coep-none" , 1 , "enforce"); 81 check("coep-require-corp" , "coep-report-only" , 1 , "enforce"); 82 check("coep-require-corp" , "coep-require-corp" , 0 , ""); 83 84 </script> 85 </body> 86 </html>