tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

automatic-beacon-use-ancestor-data.https.html (2283B)


      1 <!DOCTYPE html>
      2 <title>Test ancestor data for automatic beacons</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 <script src="/resources/testdriver.js"></script>
      9 <script src="/resources/testdriver-actions.js"></script>
     10 <script src="/resources/testdriver-vendor.js"></script>
     11 
     12 <body>
     13 <script>
     14 promise_test(async(t) => {
     15  const actions = new test_driver.Actions();
     16  const fencedframe = await attachFencedFrameContext({
     17    generator_api: 'fledge',
     18    register_beacon: true
     19  });
     20  const new_url = new URL("resources/close.html", location.href);
     21  const beacon_data = "this is the beacon data";
     22  const beacon_type = "reserved.top_navigation_start";
     23 
     24  await fencedframe.execute(async (new_url, beacon_data, beacon_type) => {
     25    let beacon_event = {
     26      eventType: beacon_type,
     27      eventData: beacon_data,
     28      destination: ["buyer"],
     29      crossOriginExposed: false,
     30    }
     31    window.fence.setReportEventDataForAutomaticBeacons(beacon_event);
     32 
     33    // Add a same-origin iframe that will perform the top-level navigation.
     34    const iframe = await attachIFrameContext();
     35    await iframe.execute(async (new_url) => {
     36      // Set beacon data for an unrelated event.
     37      let unrelated_event = {
     38        eventType: "reserved.top_navigation_commit",
     39        eventData: "unrelated data",
     40        destination: ["buyer"],
     41        crossOriginExposed: false,
     42      }
     43      window.fence.setReportEventDataForAutomaticBeacons(unrelated_event);
     44      addEventListener("click", (event) => {
     45        window.open(new_url, "_blank");
     46      });
     47    }, [new_url]);
     48  }, [new_url, beacon_data, beacon_type]);
     49 
     50  await actions.pointerMove(0, 0, {origin: fencedframe.element})
     51      .pointerDown()
     52      .pointerUp()
     53      .send();
     54 
     55  // The document should use the beacon data from its parent, since it doesn't
     56  // have any beacon data set for `reserved.top_navigation_start`, even though
     57  // it does have beacon data set.
     58  const received_beacon_data =
     59      await nextBeacon(beacon_type, beacon_data);
     60 }, 'Documents should use ancestor beacon data if not available');
     61 </script>
     62 </body>