| <!DOCTYPE html> |
| <title>Test window.fence.setReportEventDataForAutomaticBeacons</title> |
| <script src="/resources/testharness.js"></script> |
| <script src="/resources/testharnessreport.js"></script> |
| <script src="/common/utils.js"></script> |
| <script src="/common/dispatcher/dispatcher.js"></script> |
| <script src="resources/utils.js"></script> |
| <script src="/resources/testdriver.js"></script> |
| <script src="/resources/testdriver-actions.js"></script> |
| <script src="/resources/testdriver-vendor.js"></script> |
| <script src="/common/get-host-info.sub.js"></script> |
| |
| <body> |
| <script> |
| promise_test(async(t) => { |
| const actions = new test_driver.Actions(); |
| const fencedframe = await attachFencedFrameContext( |
| {generator_api: 'fledge', automatic_beacon: true, |
| origin: get_host_info().HTTPS_REMOTE_ORIGIN}); |
| const new_url = new URL("resources/dummy.html", location.href); |
| const start_beacon_data = "This is the start beacon data!"; |
| const commit_beacon_data = "This is the commit beacon data!"; |
| |
| await fencedframe.execute( |
| (new_url, start_beacon_data, commit_beacon_data) => { |
| addEventListener("click", (event) => { |
| let start_beacon_event = { |
| eventType: "reserved.top_navigation_start", |
| eventData: start_beacon_data, |
| destination: ["buyer"], |
| } |
| window.fence.setReportEventDataForAutomaticBeacons(start_beacon_event); |
| let commit_beacon_event = { |
| eventType: "reserved.top_navigation_commit", |
| eventData: commit_beacon_data, |
| destination: ["buyer"], |
| } |
| window.fence.setReportEventDataForAutomaticBeacons(commit_beacon_event); |
| window.open(new_url, "_blank"); |
| }); |
| }, [new_url, start_beacon_data, commit_beacon_data]); |
| |
| await actions.pointerMove(0, 0, {origin: fencedframe.element}) |
| .pointerDown() |
| .pointerUp() |
| .send(); |
| |
| const beacon_1_initiator_origin = await nextAutomaticBeacon(start_beacon_data); |
| assert_equals(beacon_1_initiator_origin, get_host_info().HTTPS_ORIGIN); |
| const beacon_2_initiator_origin = await nextAutomaticBeacon(commit_beacon_data); |
| assert_equals(beacon_2_initiator_origin, get_host_info().HTTPS_ORIGIN); |
| |
| // Leaving this fenced frame around for subsequent tests can lead to |
| // flakiness. |
| document.body.removeChild(fencedframe.element); |
| }, 'Set and trigger an automatic beacon in a click handler'); |
| |
| </script> |
| </body> |