fence-report-event-cross-origin.sub.https.html (2455B)
1 <!DOCTYPE html> 2 <title>Test window.fence.reportEvent from cross-origin subframes.</title> 3 <script src="/resources/testharness.js"></script> 4 <script src="/resources/testharnessreport.js"></script> 5 <script src="/common/utils.js"></script> 6 <script src="/common/dispatcher/dispatcher.js"></script> 7 <script src="/common/get-host-info.sub.js"></script> 8 <script src="resources/automatic-beacon-helper.js"></script> 9 <script src="resources/utils.js"></script> 10 11 <body> 12 <script> 13 promise_test(async(t) => { 14 const fencedframe = await attachFencedFrameContext({ 15 generator_api: 'fledge', 16 headers: [[ 17 'Allow-Cross-Origin-Event-Reporting', '?1' 18 ]], 19 register_beacon: true, 20 origin: 'https://{{hosts[alt][]}}:{{ports[https][0]}}', 21 }); 22 await fencedframe.execute(async () => { 23 const iframe = await attachIFrameContext({ 24 origin: 'https://{{hosts[alt][]}}:{{ports[https][1]}}' 25 }); 26 await iframe.execute(() => { 27 const destination_url = new URL(BEACON_URL + "?type=url", 28 get_host_info().HTTPS_ORIGIN); 29 window.fence.reportEvent({ 30 eventType: "click", 31 eventData: "enum", 32 destination: ["buyer"], 33 crossOriginExposed: true 34 }); 35 window.fence.reportEvent({ 36 destinationURL: destination_url, 37 crossOriginExposed: true 38 }); 39 }); 40 }); 41 // Check that both the destination enum and destination URL events were 42 // reported. 43 const [enum_origin, enum_referrer] = await nextBeacon("click", "enum") 44 .then(data => data.split(',')); 45 const [url_origin, url_referrer] = await nextBeacon("url", "<No data>") 46 .then(data => data.split(',')); 47 48 // Check the "Origin" headers are set to the origin that supplied the 49 // reporting URL. For destination enum events, that's the origin of the 50 // worklet. For destination URL events, that's the origin of the iframe. 51 assert_equals(enum_origin, get_host_info().HTTPS_ORIGIN, 52 'The enum origin should be correctly set.'); 53 assert_equals(url_origin, 'https://{{hosts[alt][]}}:{{ports[https][1]}}', 54 'The url origin should be correctly set.'); 55 56 assert_equals(enum_referrer, 57 'https://{{hosts[alt][]}}:{{ports[https][1]}}/', 58 'The enum referrer should be correctly set.'); 59 assert_equals(url_referrer, 'https://{{hosts[alt][]}}:{{ports[https][1]}}/', 60 'The url referrer should be correctly set.'); 61 }, 'window.fence.reportEvent from a cross-origin subframe'); 62 </script> 63 </body>