document-reporting-named-endpoints.https.sub.html (2198B)
1 <!DOCTYPE HTML> 2 <html> 3 4 <head> 5 <title>Test that reports are sent to multiple named endpoints</title> 6 <script src='/resources/testharness.js'></script> 7 <script src='/resources/testharnessreport.js'></script> 8 <script src='resources/report-helper.js'></script> 9 </head> 10 11 <body> 12 <script> 13 const t = async_test("Test that image does not load"); 14 async_test(function (t) { 15 const observer = new ReportingObserver((reports, observer) => { 16 t.step(() => { 17 assert_equals(reports[0].type, 'csp-violation'); 18 }); 19 t.done(); 20 }, { types: ['csp-violation'] }); 21 observer.observe(); 22 }, "csp violation report observed"); 23 24 promise_test(async t => { 25 return new Promise(resolve => { 26 new ReportingObserver((reports, observer) => resolve(reports), 27 { types: ['document-policy-violation'] }).observe(); 28 }).then((reports) => { 29 assert_equals(reports[0].type, 'document-policy-violation'); 30 }) 31 }, "document policy violation observed"); 32 </script> 33 <img src='/reporting/resources/fail.png' onload='t.unreached_func("The image should not have loaded");' 34 onerror='t.done();'> 35 <script> 36 // Attempt a synchronous XHR - this should succeed but cause a report to be sent. 37 const xhr = new XMLHttpRequest(); 38 xhr.open("GET", document.location.href, false); 39 xhr.send(); 40 </script> 41 <script> 42 const base_url = `${location.protocol}//${location.host}`; 43 const endpoint = `${base_url}/reporting/resources/report.py`; 44 const group1_id = '0d334af1-1c5c-4e59-9079-065131ff2a45'; 45 const group2_id = '09c1a265-5fc7-4c49-b35c-32078c2d0c19'; 46 promise_test(async t => { 47 await wait(3000); 48 // Verify CSP reports are sent to configured endpoint. 49 const csp_reports = await pollReports(endpoint, group1_id); 50 checkReportExists(csp_reports, 'csp-violation', location.href); 51 // Verify Document Policy reports are sent to configured endpoint. 52 const dp_reports = await pollReports(endpoint, group2_id); 53 checkReportExists(dp_reports, 'document-policy-violation', location.href); 54 }, "Reporting endpoints received reports."); 55 </script> 56 57 </body> 58 59 </html>