#include "content/browser/attribution_reporting/attribution_test_utils.h"
#include <stdint.h>
#include <algorithm>
#include <optional>
#include <tuple>
#include <utility>
#include <vector>
#include "base/check.h"
#include "base/functional/overloaded.h"
#include "base/strings/string_number_conversions.h"
#include "base/time/time.h"
#include "components/attribution_reporting/aggregatable_debug_reporting_config.h"
#include "components/attribution_reporting/aggregatable_dedup_key.h"
#include "components/attribution_reporting/aggregatable_filtering_id_max_bytes.h"
#include "components/attribution_reporting/aggregatable_trigger_config.h"
#include "components/attribution_reporting/aggregatable_trigger_data.h"
#include "components/attribution_reporting/aggregatable_values.h"
#include "components/attribution_reporting/attribution_scopes_data.h"
#include "components/attribution_reporting/constants.h"
#include "components/attribution_reporting/destination_set.h"
#include "components/attribution_reporting/event_report_windows.h"
#include "components/attribution_reporting/event_trigger_data.h"
#include "components/attribution_reporting/filters.h"
#include "components/attribution_reporting/max_event_level_reports.h"
#include "components/attribution_reporting/os_registration.h"
#include "components/attribution_reporting/source_type.mojom.h"
#include "components/attribution_reporting/suitable_origin.h"
#include "components/attribution_reporting/test_utils.h"
#include "components/attribution_reporting/trigger_config.h"
#include "components/attribution_reporting/trigger_data_matching.mojom-forward.h"
#include "components/attribution_reporting/trigger_registration.h"
#include "content/browser/attribution_reporting/attribution_observer.h"
#include "content/browser/attribution_reporting/attribution_reporting.mojom.h"
#include "content/browser/attribution_reporting/attribution_trigger.h"
#include "content/browser/attribution_reporting/attribution_utils.h"
#include "content/browser/attribution_reporting/os_registration.h"
#include "content/browser/attribution_reporting/rate_limit_result.h"
#include "content/browser/attribution_reporting/stored_source.h"
#include "content/public/browser/attribution_data_model.h"
#include "net/base/net_errors.h"
#include "net/base/schemeful_site.h"
#include "net/http/structured_headers.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/abseil-cpp/absl/numeric/int128.h"
#include "third_party/abseil-cpp/absl/types/variant.h"
#include "url/gurl.h"
#include "url/origin.h"
namespace content {
namespace {
FilterPair;
OsRegistrationItem;
SuitableOrigin;
SourceType;
const char kDefaultSourceOrigin[] = …;
const char kDefaultDestinationOrigin[] = …;
const char kDefaultReportOrigin[] = …;
}
base::Uuid DefaultExternalReportID() { … }
SourceBuilder::SourceBuilder(base::Time time)
: … { … }
SourceBuilder::~SourceBuilder() = default;
SourceBuilder::SourceBuilder(const SourceBuilder&) = default;
SourceBuilder::SourceBuilder(SourceBuilder&&) = default;
SourceBuilder& SourceBuilder::operator=(const SourceBuilder&) = default;
SourceBuilder& SourceBuilder::operator=(SourceBuilder&&) = default;
SourceBuilder& SourceBuilder::SetExpiry(base::TimeDelta delta) { … }
SourceBuilder& SourceBuilder::SetAggregatableReportWindow(
base::TimeDelta delta) { … }
SourceBuilder& SourceBuilder::SetSourceEventId(uint64_t source_event_id) { … }
SourceBuilder& SourceBuilder::SetSourceOrigin(SuitableOrigin origin) { … }
SourceBuilder& SourceBuilder::SetDestinationSites(
base::flat_set<net::SchemefulSite> sites) { … }
SourceBuilder& SourceBuilder::SetReportingOrigin(SuitableOrigin origin) { … }
SourceBuilder& SourceBuilder::SetSourceType(SourceType source_type) { … }
SourceBuilder& SourceBuilder::SetPriority(int64_t priority) { … }
SourceBuilder& SourceBuilder::SetFilterData(
attribution_reporting::FilterData filter_data) { … }
SourceBuilder& SourceBuilder::SetDebugKey(std::optional<uint64_t> debug_key) { … }
SourceBuilder& SourceBuilder::SetAttributionLogic(
StoredSource::AttributionLogic attribution_logic) { … }
SourceBuilder& SourceBuilder::SetActiveState(
StoredSource::ActiveState active_state) { … }
SourceBuilder& SourceBuilder::SetSourceId(StoredSource::Id source_id) { … }
SourceBuilder& SourceBuilder::SetDedupKeys(std::vector<uint64_t> dedup_keys) { … }
SourceBuilder& SourceBuilder::SetAggregationKeys(
attribution_reporting::AggregationKeys aggregation_keys) { … }
SourceBuilder& SourceBuilder::SetRemainingAggregatableAttributionBudget(
int remaining_aggregatable_attribution_budget) { … }
SourceBuilder& SourceBuilder::SetRemainingAggregatableDebugBudget(
int remaining_aggregatable_debug_budget) { … }
SourceBuilder& SourceBuilder::SetRandomizedResponseRate(
double randomized_response_rate) { … }
SourceBuilder& SourceBuilder::SetAggregatableDedupKeys(
std::vector<uint64_t> dedup_keys) { … }
SourceBuilder& SourceBuilder::SetIsWithinFencedFrame(
bool is_within_fenced_frame) { … }
SourceBuilder& SourceBuilder::SetDebugReporting(bool debug_reporting) { … }
SourceBuilder& SourceBuilder::SetTriggerSpecs(
attribution_reporting::TriggerSpecs trigger_specs) { … }
SourceBuilder& SourceBuilder::SetMaxEventLevelReports(
int max_event_level_reports) { … }
SourceBuilder& SourceBuilder::SetTriggerDataMatching(
attribution_reporting::mojom::TriggerDataMatching trigger_data_matching) { … }
SourceBuilder& SourceBuilder::SetDebugCookieSet(bool debug_cookie_set) { … }
SourceBuilder& SourceBuilder::SetAggregatableDebugReportingConfig(
attribution_reporting::SourceAggregatableDebugReportingConfig
aggregatable_debug_reporting_config) { … }
SourceBuilder& SourceBuilder::SetDestinationLimitPriority(int64_t priority) { … }
SourceBuilder& SourceBuilder::SetAttributionScopesData(
attribution_reporting::AttributionScopesData attribution_scopes) { … }
StorableSource SourceBuilder::Build() const { … }
StoredSource SourceBuilder::BuildStored() const { … }
AttributionTrigger DefaultTrigger() { … }
TriggerBuilder::TriggerBuilder()
: … { … }
TriggerBuilder::~TriggerBuilder() = default;
TriggerBuilder::TriggerBuilder(const TriggerBuilder&) = default;
TriggerBuilder::TriggerBuilder(TriggerBuilder&&) = default;
TriggerBuilder& TriggerBuilder::operator=(const TriggerBuilder&) = default;
TriggerBuilder& TriggerBuilder::operator=(TriggerBuilder&&) = default;
TriggerBuilder& TriggerBuilder::SetTriggerData(uint64_t trigger_data) { … }
TriggerBuilder& TriggerBuilder::SetDestinationOrigin(SuitableOrigin origin) { … }
TriggerBuilder& TriggerBuilder::SetReportingOrigin(SuitableOrigin origin) { … }
TriggerBuilder& TriggerBuilder::SetPriority(int64_t priority) { … }
TriggerBuilder& TriggerBuilder::SetDedupKey(std::optional<uint64_t> dedup_key) { … }
TriggerBuilder& TriggerBuilder::SetDebugKey(std::optional<uint64_t> debug_key) { … }
TriggerBuilder& TriggerBuilder::SetAggregatableTriggerData(
std::vector<attribution_reporting::AggregatableTriggerData>
aggregatable_trigger_data) { … }
TriggerBuilder& TriggerBuilder::SetAggregatableValues(
std::vector<attribution_reporting::AggregatableValues>
aggregatable_values) { … }
TriggerBuilder& TriggerBuilder::SetAggregatableDedupKey(
std::optional<uint64_t> aggregatable_dedup_key) { … }
TriggerBuilder& TriggerBuilder::SetIsWithinFencedFrame(
bool is_within_fenced_frame) { … }
TriggerBuilder& TriggerBuilder::SetDebugReporting(bool debug_reporting) { … }
TriggerBuilder& TriggerBuilder::SetAggregationCoordinatorOrigin(
SuitableOrigin aggregation_coordinator_origin) { … }
TriggerBuilder& TriggerBuilder::SetSourceRegistrationTimeConfig(
attribution_reporting::mojom::SourceRegistrationTimeConfig
source_registration_time_config) { … }
TriggerBuilder& TriggerBuilder::SetFilterPair(
attribution_reporting::FilterPair filter_pair) { … }
TriggerBuilder& TriggerBuilder::SetAggregatableDedupKeyFilterPair(
attribution_reporting::FilterPair filter_pair) { … }
TriggerBuilder& TriggerBuilder::SetTriggerContextId(
std::string trigger_context_id) { … }
TriggerBuilder& TriggerBuilder::SetAggregatableDebugReportingConfig(
attribution_reporting::AggregatableDebugReportingConfig
aggregatable_trigger_config) { … }
TriggerBuilder& TriggerBuilder::SetAggregatableFilteringIdMaxBytes(
attribution_reporting::AggregatableFilteringIdsMaxBytes max_bytes) { … }
TriggerBuilder& TriggerBuilder::SetAttributionScopes(
attribution_reporting::AttributionScopesSet attribution_scopes) { … }
AttributionTrigger TriggerBuilder::Build(
bool generate_event_trigger_data) const { … }
AttributionInfoBuilder::AttributionInfoBuilder(SuitableOrigin context_origin)
: … { … }
AttributionInfoBuilder::~AttributionInfoBuilder() = default;
AttributionInfoBuilder& AttributionInfoBuilder::SetTime(base::Time time) { … }
AttributionInfoBuilder& AttributionInfoBuilder::SetDebugKey(
std::optional<uint64_t> debug_key) { … }
AttributionInfo AttributionInfoBuilder::Build() const { … }
ReportBuilder::ReportBuilder(AttributionInfo attribution_info,
StoredSource source)
: … { … }
ReportBuilder::~ReportBuilder() = default;
ReportBuilder& ReportBuilder::SetTriggerData(uint64_t trigger_data) { … }
ReportBuilder& ReportBuilder::SetReportTime(base::Time time) { … }
ReportBuilder& ReportBuilder::SetPriority(int64_t priority) { … }
ReportBuilder& ReportBuilder::SetExternalReportId(
base::Uuid external_report_id) { … }
ReportBuilder& ReportBuilder::SetReportId(AttributionReport::Id id) { … }
ReportBuilder& ReportBuilder::SetAggregatableHistogramContributions(
std::vector<blink::mojom::AggregatableReportHistogramContribution>
contributions) { … }
ReportBuilder& ReportBuilder::SetAggregationCoordinatorOrigin(
SuitableOrigin aggregation_coordinator_origin) { … }
ReportBuilder& ReportBuilder::SetSourceRegistrationTimeConfig(
attribution_reporting::mojom::SourceRegistrationTimeConfig
source_registration_time_config) { … }
ReportBuilder& ReportBuilder::SetAggregatableFilteringIdsMaxBytes(
attribution_reporting::AggregatableFilteringIdsMaxBytes max_bytes) { … }
ReportBuilder& ReportBuilder::SetTriggerContextId(
std::string trigger_context_id) { … }
AttributionReport ReportBuilder::Build() const { … }
AttributionReport ReportBuilder::BuildAggregatableAttribution() const { … }
AttributionReport ReportBuilder::BuildNullAggregatable() const { … }
bool operator==(const StoredSource& a, const StoredSource& b) { … }
bool operator==(const AttributionReport::CommonAggregatableData& a,
const AttributionReport::CommonAggregatableData& b) { … }
bool operator==(const AttributionReport::AggregatableAttributionData& a,
const AttributionReport::AggregatableAttributionData& b) { … }
bool operator==(const AttributionReport::NullAggregatableData& a,
const AttributionReport::NullAggregatableData& b) { … }
bool operator==(const AttributionReport& a, const AttributionReport& b) { … }
std::ostream& operator<<(std::ostream& out, RateLimitResult result) { … }
std::ostream& operator<<(std::ostream& out,
StoredSource::AttributionLogic attribution_logic) { … }
std::ostream& operator<<(std::ostream& out,
StoredSource::ActiveState active_state) { … }
std::ostream& operator<<(std::ostream& out,
const AttributionTrigger& conversion) { … }
std::ostream& operator<<(std::ostream& out, const CommonSourceInfo& source) { … }
std::ostream& operator<<(std::ostream& out,
const AttributionInfo& attribution_info) { … }
std::ostream& operator<<(std::ostream& out, const StorableSource& source) { … }
std::ostream& operator<<(std::ostream& out, const StoredSource& source) { … }
std::ostream& operator<<(
std::ostream& out,
const blink::mojom::AggregatableReportHistogramContribution& contribution) { … }
std::ostream& operator<<(std::ostream& out,
const AttributionReport::EventLevelData& data) { … }
std::ostream& operator<<(
std::ostream& out,
const AttributionReport::CommonAggregatableData& data) { … }
std::ostream& operator<<(
std::ostream& out,
const AttributionReport::AggregatableAttributionData& data) { … }
std::ostream& operator<<(std::ostream& out,
const AttributionReport::NullAggregatableData& data) { … }
namespace {
std::ostream& operator<<(std::ostream& out,
const AttributionReport::Data& data) { … }
}
std::ostream& operator<<(std::ostream& out, const AttributionReport& report) { … }
std::ostream& operator<<(std::ostream& out, SendResult::Status status) { … }
std::ostream& operator<<(std::ostream& out, const SendResult& info) { … }
std::ostream& operator<<(std::ostream& out,
const AttributionDataModel::DataKey& key) { … }
TestAggregatableSourceProvider::TestAggregatableSourceProvider(size_t size) { … }
TestAggregatableSourceProvider::~TestAggregatableSourceProvider() = default;
SourceBuilder TestAggregatableSourceProvider::GetBuilder(
base::Time source_time) const { … }
TriggerBuilder DefaultAggregatableTriggerBuilder(
const std::vector<uint32_t>& histogram_values) { … }
std::vector<blink::mojom::AggregatableReportHistogramContribution>
DefaultAggregatableHistogramContributions(
const std::vector<int32_t>& histogram_values) { … }
bool operator==(const OsRegistration& a, const OsRegistration& b) { … }
std::ostream& operator<<(std::ostream& out, const OsRegistration& r) { … }
namespace {
void CheckAttributionReportingHeader(
const std::string& header,
const std::vector<std::string>& required_keys,
const std::vector<std::string>& prohibited_keys) { … }
}
void ExpectValidAttributionReportingEligibleHeaderForEventBeacon(
const std::string& header) { … }
void ExpectValidAttributionReportingEligibleHeaderForImg(
const std::string& header) { … }
void ExpectValidAttributionReportingEligibleHeaderForNavigation(
const std::string& header) { … }
void ExpectEmptyAttributionReportingEligibleHeader(const std::string& header) { … }
void ExpectValidAttributionReportingSupportHeader(const std::string& header,
bool web_expected,
bool os_expected) { … }
}