cache-storage-reporting-service-worker.https.html (2664B)
1 <!doctype html> 2 <html> 3 <head> 4 <title> 5 Check COEP report are send for CacheStorage requests in ServiceWorker. 6 </title> 7 <script src="/resources/testharness.js"></script> 8 <script src="/resources/testharnessreport.js"></script> 9 <script src="/common/get-host-info.sub.js"></script> 10 <script src="/common/utils.js"></script> 11 <script src="/service-workers/service-worker/resources/test-helpers.sub.js"> 12 </script> 13 <script src="./resources/cache-storage-reporting.js"></script> 14 </head> 15 <script> 16 17 promise_test(async (t) => { 18 const worker_url = local(encode(worker_path + header_coep)); 19 // As we don't want the service worker to control any page, generate a 20 // one-time scope. 21 const SCOPE = new URL(`resources/${token()}.html`, location).pathname; 22 const reg = 23 await service_worker_unregister_and_register(t, worker_url, SCOPE); 24 add_completion_callback(() => reg.unregister()); 25 const worker = reg.installing || reg.waiting || reg.active; 26 const mc = new MessageChannel(); 27 worker.postMessage({script: eval_script, port: mc.port2}, [mc.port2]); 28 const reports = (await new Promise(r => mc.port1.onmessage = r)).data; 29 assert_not_equals(reports, 'TIMEOUT'); 30 assert_equals(reports.length, 1); 31 const report = reports[0]; 32 assert_equals(report.body.blockedURL, image_url); 33 assert_equals(report.body.type, "corp"); 34 assert_equals(report.body.disposition, "enforce"); 35 assert_equals(report.body.destination, ""); 36 assert_equals(report.type, "coep"); 37 assert_equals(report.url, worker_url); 38 }, "COEP support on ServiceWorker."); 39 40 promise_test(async (t) => { 41 const worker_url = local(encode(worker_path + header_coep_report_only)); 42 // As we don't want the service worker to control any page, generate a 43 // one-time scope. 44 const SCOPE = new URL(`resources/${token()}.html`, location).pathname; 45 const reg = 46 await service_worker_unregister_and_register(t, worker_url, SCOPE); 47 add_completion_callback(() => reg.unregister()); 48 const worker = reg.installing || reg.waiting || reg.active; 49 const mc = new MessageChannel(); 50 worker.postMessage({script: eval_script, port: mc.port2}, [mc.port2]); 51 const reports = (await new Promise(r => mc.port1.onmessage = r)).data; 52 assert_not_equals(reports, 'TIMEOUT'); 53 assert_equals(reports.length, 1); 54 const report = reports[0]; 55 assert_equals(report.body.blockedURL, image_url); 56 assert_equals(report.body.type, "corp"); 57 assert_equals(report.body.disposition, "reporting"); 58 assert_equals(report.body.destination, ""); 59 assert_equals(report.type, "coep"); 60 assert_equals(report.url, worker_url); 61 }, "COEP-Report-Only support on ServiceWorker."); 62 63 </script> 64 </html>