<!doctype html>
<meta charset=utf-8>
<meta name=timeout content=long>
<script src="/resources/testdriver.js"></script>
<script src="/resources/testdriver-vendor.js"></script>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/attribution-reporting/resources/helpers.js"></script>
<script>
attribution_reporting_promise_test(async t => {
const host = 'https://{{host}}';
const expectedSourceEventId = generateSourceEventId();
const expectedTriggerData = '1';
const deduplicationKey = '666';
registerAttributionSrcByImg(createRedirectChain([
{
source: {
destination: host,
source_event_id: expectedSourceEventId,
},
cookie: attributionDebugCookie,
},
{
trigger: {
event_trigger_data: [{
deduplication_key: deduplicationKey,
trigger_data: expectedTriggerData,
}],
},
},
]));
const payload = await pollEventLevelReports();
assert_equals(payload.reports.length, 1);
const report = JSON.parse(payload.reports[0].body);
assert_equals(report.trigger_data, expectedTriggerData);
assert_equals(report.attribution_destination, host);
const expectedTriggerDebugKey = '789';
registerAttributionSrcByImg(createRedirectChain([
{
trigger: {
debug_key: expectedTriggerDebugKey,
debug_reporting: true,
event_trigger_data: [{
deduplication_key: deduplicationKey,
}],
},
},
]));
const debugPayload = await pollVerboseDebugReports();
assert_equals(debugPayload.reports.length, 1);
const debugReport = JSON.parse(debugPayload.reports[0].body);
assert_equals(debugReport.length, 1);
assert_equals(debugReport[0].type, 'trigger-event-deduplicated');
assert_own_property(debugReport[0], 'body');
const debugReportBody = debugReport[0].body;
assert_equals(debugReportBody.attribution_destination, host);
assert_equals(debugReportBody.source_event_id, expectedSourceEventId);
assert_equals(debugReportBody.source_site, host);
assert_equals(debugReportBody.trigger_debug_key, expectedTriggerDebugKey);
assert_not_own_property(debugReportBody, 'source_debug_key');
}, 'Event-level report is deduplicated.');
</script>