report-event.https.html (2014B)
1 <!DOCTYPE html> 2 <title>Test that window.fence.reportEvent() succeeds in a fenced frame.</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="resources/utils.js"></script> 8 9 <body> 10 <script> 11 promise_test(async(t) => { 12 const fencedframe = await attachFencedFrameContext({generator_api: 'fledge', 13 register_beacon: true}); 14 15 // This page will call reportEvent twice: Once for an enum event, and once 16 // for a custom URL event. Both beacons are expected to send successfully. 17 await fencedframe.execute(() => { 18 const destination_enum_event = { 19 eventType: 'click', 20 eventData: 'enum', 21 destination: ['buyer'] 22 } 23 window.fence.reportEvent(destination_enum_event); 24 25 const destination_url = new URL(BEACON_URL + "?type=url", 26 get_host_info().HTTPS_ORIGIN); 27 28 const destination_url_event = { 29 destinationURL: destination_url 30 } 31 window.fence.reportEvent(destination_url_event); 32 }); 33 34 const [enum_origin, enum_referrer] = await nextBeacon("click", "enum") 35 .then(data => data.split(',')); 36 const [url_origin, url_referrer] = await nextBeacon("url", "<No data>") 37 .then(data => data.split(',')); 38 39 assert_equals(enum_origin, location.origin, 40 'The enum origin should be correctly set.'); 41 // GET requests do not set an 'Origin' header if same-origin to the request's 42 // destination. 43 assert_equals(url_origin, '<No data>', 44 'The url origin should be correctly set.'); 45 46 assert_equals(enum_referrer, location.origin + "/", 47 'The enum referrer should be correctly set.'); 48 assert_equals(url_referrer, location.origin + "/", 49 'The url referrer should be correctly set.'); 50 }, 'Test that window.fence.reportEvent() succeeds in a fenced frame.'); 51 </script> 52 </body>