chromium/third_party/blink/web_tests/wpt_internal/attribution-reporting/simple-event-level-report.sub.https.html

<!doctype html>
<meta charset=utf-8>
<meta name=timeout content=long>
<meta name=variant content="?default">
<meta name=variant content="?cross-origin">
<script src="/common/get-host-info.sub.js"></script>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/attribution-reporting/resources/helpers.js"></script>
<script>
const uuidPattern = /^[0-9a-f]{8}(-[0-9a-f]{4}){3}-[0-9a-f]{12}$/;

const reportingOrigin = getDefaultReportingOrigin();

attribution_reporting_promise_test(async t => {
  const host = 'https://{{host}}';
  const expectedSourceEventId = generateSourceEventId();

  registerAttributionSrcByImg(createRedirectChain([
    {
      cookie: 'foo=bar;Secure;HttpOnly;Path=/',
      reportingOrigin,
      source: {
        destination: host,
        source_event_id: expectedSourceEventId,
      },
    },
    {
      reportingOrigin,
      trigger: {event_trigger_data: [{trigger_data: '2'}]},
    },
  ]));

  const payload = await pollEventLevelReports(reportingOrigin);
  assert_equals(payload.reports.length, 1);

  const report = JSON.parse(payload.reports[0].body);

  // The trigger data is sanitized to "0" because event sources are limited to 1
  // bit.
  assert_equals(report.trigger_data, '0');
  assert_equals(report.source_event_id, expectedSourceEventId);
  assert_equals(report.source_type, 'event');
  assert_equals(report.attribution_destination, host);

  assert_between_inclusive(report.randomized_trigger_rate, 0.0, 1.0);

  assert_own_property(report, 'report_id');
  assert_equals(typeof report.report_id, 'string');
  assert_regexp_match(report.report_id, uuidPattern);

  assert_own_property(report, 'scheduled_report_time');
  assert_equals(typeof report.scheduled_report_time, 'string');
  assert_regexp_match(report.scheduled_report_time, /^[0-9]+$/);

  assert_not_own_property(report, 'source_debug_key');
  assert_not_own_property(report, 'trigger_debug_key');

  validateReportHeaders(payload.reports[0].headers);
}, 'Ensure attribution report is received.');
</script>