summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/fenced-frame/automatic-beacon-use-ancestor-data.https.html
blob: c5169d4a47ad6cd53fcdb3a96f35d8f30b19e4a3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<!DOCTYPE html>
<title>Test ancestor data for automatic beacons</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',
    register_beacon: true
  });
  const new_url = new URL("resources/close.html", location.href);
  const beacon_data = "this is the beacon data";
  const beacon_type = "reserved.top_navigation_start";

  await fencedframe.execute(async (new_url, beacon_data, beacon_type) => {
    let beacon_event = {
      eventType: beacon_type,
      eventData: beacon_data,
      destination: ["buyer"],
      crossOriginExposed: false,
    }
    window.fence.setReportEventDataForAutomaticBeacons(beacon_event);

    // Add a same-origin iframe that will perform the top-level navigation.
    const iframe = await attachIFrameContext();
    await iframe.execute(async (new_url) => {
      // Set beacon data for an unrelated event.
      let unrelated_event = {
        eventType: "reserved.top_navigation_commit",
        eventData: "unrelated data",
        destination: ["buyer"],
        crossOriginExposed: false,
      }
      window.fence.setReportEventDataForAutomaticBeacons(unrelated_event);
      addEventListener("click", (event) => {
        window.open(new_url, "_blank");
      });
    }, [new_url]);
  }, [new_url, beacon_data, beacon_type]);

  await actions.pointerMove(0, 0, {origin: fencedframe.element})
      .pointerDown()
      .pointerUp()
      .send();

  // The document should use the beacon data from its parent, since it doesn't
  // have any beacon data set for `reserved.top_navigation_start`, even though
  // it does have beacon data set.
  const received_beacon_data =
      await nextBeacon(beacon_type, beacon_data);
}, 'Documents should use ancestor beacon data if not available');
</script>
</body>