Skip to content

Commit

Permalink
Bug 1843339 [wpt PR 41020] - Add option to send automatic beacons onl…
Browse files Browse the repository at this point in the history
…y once., a=testonly

Automatic update from web-platform-tests
Add option to send automatic beacons only once.

Automatic beacons currently have a design flaw that can cause extra
unwanted beacons to be sent out. For example, a top-level navigation
beacon is set in a click handler for an ad when the user clicks on the
ad. If the ad's visual display is programmed to change to have a button
that says "why this ad?" after the ad is clicked (the button will take
the user to an explainer page when clicked), then the automatic beacon
data will still be in place. If a user clicks back to the tab the ad is
on and clicks on "why this ad?" to perform a different top-level
navigation, the beacon will send out again as if the user clicked on the
ad normally. This creates an erroneous impression and results in
incorrect data being sent to reporting servers.

To fix the issue, this CL introduces a new parameter to the `FenceEvent`
dictionary: `once`. It defaults to false (to preserve the current
default behavior of automatic beacons). If set to true, when an
automatic beacon is sent out, the automatic beacon data will be cleared.

This CL also moves `AutomaticBeaconInfo` implementation functions from
"fenced_frame_reporter.cc" to "fenced_frame_config.cc" to reflect the
fact that its definition lives in "fenced_frame_config.h".

Change-Id: I1240557844a3c47c680a0f3d8a227e31794ab49f
Bug: 1464599
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4671534
Reviewed-by: Jonathan Ross <[email protected]>
Reviewed-by: Dominic Farolino <[email protected]>
Commit-Queue: Liam Brady <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1173132}

--

wpt-commits: f9206867fa91e0de3855b6b785631f3e906be82f
wpt-pr: 41020
  • Loading branch information
Liam Brady authored and moz-wptsync-bot committed Jul 22, 2023
1 parent d563f5d commit 8c3c801
Show file tree
Hide file tree
Showing 2 changed files with 112 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<!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'});
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",
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();
assert_equals(received_beacon_data_1, beacon_data);

// The second click should not have any associated automatic beacon data, so
// no beacon should be sent.
await actions.pointerMove(0, 0, {origin: fencedframe.element})
.pointerDown()
.pointerUp()
.send();

// Set up a timeout to ensure that there's enough time to send any potential
// automatic beacons.
const timeout = new Promise(resolve => t.step_timeout(resolve, 1000));
const result = await Promise.race([nextAutomaticBeacon(), timeout]);
assert_true(typeof result === "undefined");
}, 'Set expiring automatic beacon but trigger two events in a click handler');

</script>
</body>
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<!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'});
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) => {
// `once` defaults to false.
let beacon_event = {
eventType: "reserved.top_navigation",
eventData: beacon_data,
destination: ["buyer"],
}
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, but the beacon data
// should not be cleared out.
await actions.pointerMove(0, 0, {origin: fencedframe.element})
.pointerDown()
.pointerUp()
.send();
const received_beacon_data_1 = await nextAutomaticBeacon();
assert_equals(received_beacon_data_1, beacon_data);

// The second click should still have associated automatic beacon data, and a
// beacon should be sent.
await actions.pointerMove(0, 0, {origin: fencedframe.element})
.pointerDown()
.pointerUp()
.send();
const received_beacon_data_2 = await nextAutomaticBeacon();
assert_equals(received_beacon_data_2, beacon_data);
}, 'Set persisting automatic beacon but trigger two events in a click handler');

</script>
</body>

0 comments on commit 8c3c801

Please sign in to comment.