#include "content/browser/aggregation_service/aggregatable_report.h"
#include <stddef.h>
#include <stdint.h>
#include <array>
#include <limits>
#include <optional>
#include <string>
#include <string_view>
#include <utility>
#include <vector>
#include "base/check_op.h"
#include "base/containers/flat_map.h"
#include "base/containers/span.h"
#include "base/json/json_writer.h"
#include "base/numerics/byte_conversions.h"
#include "base/numerics/ostream_operators.h"
#include "base/strings/abseil_string_number_conversions.h"
#include "base/strings/string_number_conversions.h"
#include "base/test/gtest_util.h"
#include "base/test/scoped_feature_list.h"
#include "base/time/time.h"
#include "base/uuid.h"
#include "base/values.h"
#include "components/aggregation_service/aggregation_coordinator_utils.h"
#include "components/cbor/reader.h"
#include "components/cbor/values.h"
#include "content/browser/aggregation_service/aggregatable_report.h"
#include "content/browser/aggregation_service/aggregation_service_features.h"
#include "content/browser/aggregation_service/aggregation_service_test_utils.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/abseil-cpp/absl/numeric/int128.h"
#include "third_party/blink/public/mojom/aggregation_service/aggregatable_report.mojom.h"
#include "third_party/distributed_point_functions/shim/buildflags.h"
#include "url/gurl.h"
#include "url/origin.h"
namespace content {
namespace {
testing::AssertionResult CborMapContainsKeyAndType(
const cbor::Value::MapValue& map,
std::string_view key,
cbor::Value::Type value_type) { … }
std::vector<blink::mojom::AggregatableReportHistogramContribution>
PadContributions(
std::vector<blink::mojom::AggregatableReportHistogramContribution>
contributions,
size_t max_contributions_allowed) { … }
void VerifyReport(
const std::optional<AggregatableReport>& report,
const AggregationServicePayloadContents& expected_payload_contents,
const AggregatableReportSharedInfo& expected_shared_info,
size_t expected_num_processing_urls,
const std::optional<uint64_t>& expected_debug_key,
const base::flat_map<std::string, std::string>& expected_additional_fields,
const std::vector<aggregation_service::TestHpkeKey>& encryption_keys) { … }
class AggregatableReportTest : public ::testing::Test { … };
TEST_F(AggregatableReportTest,
ValidExperimentalPoplarRequest_ValidReportReturned) { … }
TEST_F(AggregatableReportTest, ValidTeeBasedRequest_ValidReportReturned) { … }
TEST_F(AggregatableReportTest,
ValidMultipleContributionsRequest_ValidReportReturned) { … }
TEST_F(AggregatableReportTest,
ValidNoContributionsRequest_ValidReportReturned) { … }
TEST_F(AggregatableReportTest,
ValidDebugModeEnabledRequest_ValidReportReturned) { … }
TEST_F(AggregatableReportTest,
ValidDebugKeyPresentRequest_ValidReportReturned) { … }
TEST_F(AggregatableReportTest, AdditionalFieldsPresent_ValidReportReturned) { … }
class AggregatableReportFilteringIdTest : public AggregatableReportTest { … };
TEST_F(AggregatableReportFilteringIdTest,
FilteringIdMaxBytesSpecified_ValidReportReturned) { … }
TEST_F(AggregatableReportFilteringIdTest,
FilteringIdsSpecified_ValidReportReturned) { … }
TEST_F(AggregatableReportTest,
RequestCreatedWithNonPositiveValue_FailsIfNegative) { … }
TEST_F(AggregatableReportTest, RequestCreatedWithInvalidReportId_Failed) { … }
TEST_F(AggregatableReportTest, TeeBasedRequestCreatedWithZeroContributions) { … }
TEST_F(AggregatableReportTest,
ExperimentalPoplarRequestNotCreatedWithZeroContributions) { … }
TEST_F(AggregatableReportTest, RequestCreatedWithTooManyContributions) { … }
TEST_F(AggregatableReportTest,
RequestCreatedWithDebugKeyButDebugModeDisabled_Failed) { … }
TEST_F(AggregatableReportTest, GetAsJsonOnePayload_ValidJsonReturned) { … }
TEST_F(AggregatableReportTest, GetAsJsonTwoPayloads_ValidJsonReturned) { … }
TEST_F(AggregatableReportTest,
GetAsJsonDebugCleartextPayload_ValidJsonReturned) { … }
TEST_F(AggregatableReportTest, GetAsJsonDebugKey_ValidJsonReturned) { … }
TEST_F(AggregatableReportTest, GetAsJsonAdditionalFields_ValidJsonReturned) { … }
TEST_F(AggregatableReportTest,
SharedInfoDebugModeDisabled_SerializeAsJsonReturnsExpectedString) { … }
TEST_F(AggregatableReportTest,
SharedInfoDebugModeEnabled_SerializeAsJsonReturnsExpectedString) { … }
TEST_F(AggregatableReportTest, SharedInfoAdditionalFields) { … }
TEST_F(AggregatableReportTest, ReportingPathSet_SetInRequest) { … }
TEST_F(AggregatableReportTest, RequestCreatedWithInvalidFailedAttempt_Failed) { … }
TEST_F(AggregatableReportTest,
RequestCreatedWithMaxContributionsAllowed_FailsIfInvalid) { … }
TEST_F(AggregatableReportTest, FailedSendAttempts) { … }
TEST_F(AggregatableReportTest, DelayTypeSerializeNulloptCrashes) { … }
TEST_F(AggregatableReportTest, DelayTypeSerializeUnscheduledCrashes) { … }
TEST_F(AggregatableReportTest, DelayTypeSerializesAndDeserializesCorrectly) { … }
TEST_F(AggregatableReportTest, MaxContributionsAllowed) { … }
TEST_F(AggregatableReportTest, AggregationCoordinatorOrigin) { … }
TEST_F(AggregatableReportTest, AggregationCoordinatorOriginAllowlistChanged) { … }
TEST_F(AggregatableReportTest, ReportingPathEmpty_NotSetInRequest) { … }
TEST_F(AggregatableReportTest, EmptyPayloads) { … }
TEST_F(AggregatableReportFilteringIdTest, FilteringIdMaxBytesNullopt) { … }
TEST_F(AggregatableReportFilteringIdTest, FilteringIdMaxBytesMax) { … }
TEST_F(AggregatableReportFilteringIdTest, FilteringIdMaxBytesNotMax) { … }
TEST_F(AggregatableReportTest, FilteringIdsIgnoredIfFeatureDisabled) { … }
TEST_F(AggregatableReportFilteringIdTest, FilteringIdMaxBytesTooSmall) { … }
TEST_F(AggregatableReportFilteringIdTest, FilteringIdMaxBytesTooLarge) { … }
TEST(AggregatableReportProtoMigrationTest,
NoDebugKeyOrFailedSendAttempts_ParsesCorrectly) { … }
TEST(AggregatableReportProtoMigrationTest, NegativeDebugKey_ParsesCorrectly) { … }
TEST(
AggregatableReportProtoMigrationTest,
NoAdditionalFieldsOrAggregationCoordinatorOriginOrFilteringIdOrDelayType_ParsesCorrectly) { … }
TEST_F(AggregatableReportTest, ProcessingUrlSet) { … }
TEST_F(AggregatableReportTest, AggregationCoordinator_ProcessingUrlSet) { … }
TEST_F(AggregatableReportTest, AggregationCoordinator_SetInReport) { … }
TEST(AggregatableReportPayloadLengthTest, With20Contributions) { … }
TEST(AggregatableReportPayloadLengthTest, With100Contributions) { … }
TEST(AggregatableReportPayloadLengthTest, OutOfRange) { … }
TEST(AggregatableReportPayloadLengthTest, PredictionMatchesReality) { … }
}
}