| <!DOCTYPE html> |
| <title>Test setReportEventDataForAutomaticBeacons called only once</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> |
| |
| <body> |
| <script> |
| promise_test(async(t) => { |
| const actions = new test_driver.Actions(); |
| const fencedframe = await attachFencedFrameContext( |
| {generator_api: 'fledge', automatic_beacon: true}); |
| const new_url = new URL("resources/dummy.html", location.href); |
| const beacon_data = "This is the beacon data!"; |
| |
| await fencedframe.execute((new_url, beacon_data) => { |
| let beacon_event = { |
| eventType: "reserved.top_navigation_commit", |
| eventData: beacon_data, |
| destination: ["buyer"], |
| once: true, |
| } |
| window.fence.setReportEventDataForAutomaticBeacons(beacon_event); |
| addEventListener("click", (event) => { |
| window.open(new_url, "_blank"); |
| }); |
| }, [new_url, beacon_data]); |
| |
| // The first click should trigger the automatic beacon and clear the beacon |
| // data. |
| await actions.pointerMove(0, 0, {origin: fencedframe.element}) |
| .pointerDown() |
| .pointerUp() |
| .send(); |
| const received_beacon_data_1 = await nextAutomaticBeacon(beacon_data); |
| assert_equals(received_beacon_data_1, beacon_data); |
| |
| // The second click should not have any associated automatic beacon info, so |
| // no beacon should be sent. |
| // Set up a timeout to ensure that there's enough time to send any potential |
| // automatic beacons. |
| await actions.pointerMove(0, 0, {origin: fencedframe.element}) |
| .pointerDown() |
| .pointerUp() |
| .send(); |
| const timeout = new Promise(resolve => t.step_timeout(resolve, 1000)); |
| const result = await Promise.race( |
| [nextAutomaticBeacon(beacon_data), timeout]); |
| assert_true(typeof result === "undefined"); |
| }, 'Set expiring automatic beacon but trigger two events in a click handler'); |
| |
| </script> |
| </body> |