tor-browser

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

automatic-beacon-anchor-click-handler.https.html (2359B)


      1 <!DOCTYPE html>
      2 <title>Test window.fence.setReportEventDataForAutomaticBeacons</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 <script src="/common/get-host-info.sub.js"></script>
     12 <script src="resources/automatic-beacon-helper.js"></script>
     13 
     14 <body>
     15 <script>
     16 promise_test(async(t) => {
     17  const actions = new test_driver.Actions();
     18  const fencedframe = await attachFencedFrameContext(
     19    {generator_api: 'fledge', register_beacon: true,
     20     origin: get_host_info().HTTPS_REMOTE_ORIGIN});
     21  const new_url = new URL("resources/dummy.html", location.href);
     22  let beacon_event = {
     23    eventType: "reserved.top_navigation_commit",
     24    eventData: "This is the second test's beacon data!",
     25    destination: ["buyer"],
     26  }
     27 
     28  await fencedframe.execute((new_url, beacon_event) => {
     29    let a = document.createElement('a');
     30    a.textContent = "Click me!";
     31    a.href = new_url;
     32    a.target = "_blank";
     33    a.style.position = "absolute";
     34    a.style.left = "0px";
     35    a.style.top = "0px";
     36    a.style.width = "100%";
     37    a.style.height = "100%";
     38 
     39    // When the anchor link is clicked, the click handler will set the data
     40    // before the navigation happens. This test checks to make sure that the
     41    // data makes it to the correct place by the time the navigation commits.
     42    a.onclick = () => {
     43      window.fence.setReportEventDataForAutomaticBeacons(beacon_event);
     44    };
     45    document.body.appendChild(a);
     46 
     47  }, [new_url, beacon_event]);
     48 
     49  // This will trigger the beacon data storing + navigation.
     50  await actions.pointerMove(0, 0, {origin: fencedframe.element})
     51               .pointerDown()
     52               .pointerUp()
     53               .send();
     54 
     55  await verifyBeaconData(beacon_event.eventType, beacon_event.eventData,
     56      get_host_info().HTTPS_REMOTE_ORIGIN);
     57 
     58  // Leaving this fenced frame around for subsequent tests can lead to
     59  // flakiness.
     60  document.body.removeChild(fencedframe.element);
     61 }, 'Set and trigger an automatic beacon in an <a> click handler');
     62 
     63 </script>
     64 </body>