chromium/content/browser/attribution_reporting/attribution_storage_sql_unittest.cc

// Copyright 2020 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "content/browser/attribution_reporting/attribution_storage_sql.h"

#include <stdint.h>

#include <functional>
#include <limits>
#include <memory>
#include <optional>
#include <set>
#include <string>
#include <utility>
#include <vector>

#include "base/check.h"
#include "base/containers/span.h"
#include "base/files/file_util.h"
#include "base/files/scoped_temp_dir.h"
#include "base/functional/bind.h"
#include "base/functional/callback_helpers.h"
#include "base/functional/overloaded.h"
#include "base/memory/raw_ptr.h"
#include "base/rand_util.h"
#include "base/ranges/algorithm.h"
#include "base/run_loop.h"
#include "base/strings/string_util.h"
#include "base/strings/to_string.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/scoped_feature_list.h"
#include "base/test/task_environment.h"
#include "base/time/time.h"
#include "build/build_config.h"
#include "build/buildflag.h"
#include "components/attribution_reporting/constants.h"
#include "components/attribution_reporting/destination_set.h"
#include "components/attribution_reporting/event_level_epsilon.h"
#include "components/attribution_reporting/event_report_windows.h"
#include "components/attribution_reporting/filters.h"
#include "components/attribution_reporting/privacy_math.h"
#include "components/attribution_reporting/source_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 "content/browser/attribution_reporting/aggregatable_debug_report.h"
#include "content/browser/attribution_reporting/attribution_features.h"
#include "content/browser/attribution_reporting/attribution_report.h"
#include "content/browser/attribution_reporting/attribution_reporting.pb.h"
#include "content/browser/attribution_reporting/attribution_resolver_impl.h"
#include "content/browser/attribution_reporting/attribution_test_utils.h"
#include "content/browser/attribution_reporting/attribution_trigger.h"
#include "content/browser/attribution_reporting/process_aggregatable_debug_report_result.mojom.h"
#include "content/browser/attribution_reporting/sql_utils.h"
#include "content/browser/attribution_reporting/storable_source.h"
#include "content/browser/attribution_reporting/store_source_result.h"
#include "content/browser/attribution_reporting/stored_source.h"
#include "content/browser/attribution_reporting/test/configurable_storage_delegate.h"
#include "content/public/browser/attribution_data_model.h"
#include "net/base/schemeful_site.h"
#include "services/network/public/cpp/features.h"
#include "sql/database.h"
#include "sql/meta_table.h"
#include "sql/recovery.h"
#include "sql/sql_features.h"
#include "sql/statement.h"
#include "sql/test/scoped_error_expecter.h"
#include "sql/test/test_helpers.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/abseil-cpp/absl/types/variant.h"
#include "third_party/blink/public/common/storage_key/storage_key.h"
#include "url/gurl.h"
#include "url/origin.h"

namespace content {

namespace {

SuitableOrigin;
SourceType;

AllOf;
ElementsAre;
Field;
IsEmpty;
Key;
Pair;
Property;
SizeIs;
UnorderedElementsAre;

const char kDefaultReportOrigin[] =;

struct AttributionSourceRecord {};

struct AttributionReportRecord {};

struct AttributionEventLevelMetadataRecord {};

struct AttributionAggregatableMetadataRecord {};

struct AttributionNullAggregatableMetadataRecord {};

std::string CreateSerializedFilterData(
    const attribution_reporting::FilterValues& filter_values) {}

std::string SerializeReportMetadata(
    const AttributionEventLevelMetadataRecord& record) {}

std::string SerializeReportMetadata(
    const AttributionAggregatableMetadataRecord& record) {}

std::string SerializeReportMetadata(
    const AttributionNullAggregatableMetadataRecord& record) {}

class AttributionStorageSqlTest : public testing::Test {};

TEST_F(AttributionStorageSqlTest,
       DatabaseInitialized_TablesAndIndexesLazilyInitialized) {}

TEST_F(AttributionStorageSqlTest, DatabaseReopened_DataPersisted) {}

TEST_F(AttributionStorageSqlTest, CorruptDatabase_DeletedOnOpen) {}

TEST_F(AttributionStorageSqlTest, VersionTooNew_RazesDB) {}

TEST_F(AttributionStorageSqlTest,
       StorageUsedAfterFailedInitialization_NoCrash) {}

// Create a source with three triggers and craft a query that will target all.
TEST_F(AttributionStorageSqlTest, ClearDataRangeMultipleReports) {}

//  Create a source with two triggers resulting in two event-level reports (C1
//  and C2) and two aggregatable reports (A1 and A2). Craft a query that  will
//  target C2 and A2, which will in turn delete the source. We should ensure
//  that C1 and A1 are properly deleted (reports should not be stored
//  unattributed).
TEST_F(AttributionStorageSqlTest, ClearDataWithVestigialConversion) {}

// Same as the above test, but with a null filter.
TEST_F(AttributionStorageSqlTest, ClearAllDataWithVestigialConversion) {}

// The max time range with a null filter should delete everything.
TEST_F(AttributionStorageSqlTest, DeleteEverything) {}

TEST_F(AttributionStorageSqlTest, ClearData_KeepRateLimitData) {}

TEST_F(AttributionStorageSqlTest, DeleteAttributionDataByDataKey) {}

TEST_F(AttributionStorageSqlTest, MaxSourcesPerOrigin) {}

TEST_F(AttributionStorageSqlTest, MaxReportsPerDestination) {}

TEST_F(AttributionStorageSqlTest, CantOpenDb_NoCrash) {}

TEST_F(AttributionStorageSqlTest, DatabaseDirDoesExist_CreateDirAndOpenDB) {}

TEST_F(AttributionStorageSqlTest, DBinitializationSucceeds_HistogramsRecorded) {}

TEST_F(AttributionStorageSqlTest,
       DBinitializationSucceeds_SourcesPerSourceOriginHistogramsRecorded) {}

TEST_F(AttributionStorageSqlTest, MaxUint64StorageSucceeds) {}

TEST_F(AttributionStorageSqlTest, ImpressionNotExpired_NotDeleted) {}

TEST_F(AttributionStorageSqlTest, ImpressionExpired_Deleted) {}

TEST_F(AttributionStorageSqlTest, ImpressionExpired_TooFrequent_NotDeleted) {}

TEST_F(AttributionStorageSqlTest,
       ExpiredImpressionWithPendingConversion_NotDeleted) {}

TEST_F(AttributionStorageSqlTest, TwoImpressionsOneExpired_OneDeleted) {}

TEST_F(AttributionStorageSqlTest, ExpiredImpressionWithSentConversion_Deleted) {}

TEST_F(AttributionStorageSqlTest, DeleteAggregatableAttributionReport) {}

TEST_F(AttributionStorageSqlTest, NegativeTriggerMoment_HistogramRecorded) {}

TEST_F(AttributionStorageSqlTest,
       ExpiredSourceWithPendingAggregatableAttribution_NotDeleted) {}

TEST_F(AttributionStorageSqlTest,
       ExpiredSourceWithSentAggregatableAttribution_Deleted) {}

TEST_F(AttributionStorageSqlTest,
       InvalidSourceOriginOrSite_FailsDeserialization) {}

TEST_F(AttributionStorageSqlTest, CreateReport_DeletesUnattributedSources) {}

TEST_F(AttributionStorageSqlTest, CreateReport_DeactivatesAttributedSources) {}

// Tests that invalid filter keys present in the serialized data are removed.
TEST_F(AttributionStorageSqlTest, DeserializeFilterData_RemovesReservedKeys) {}

TEST_F(AttributionStorageSqlTest, ReportTablesStoreDestinationOrigin) {}

TEST_F(AttributionStorageSqlTest, FakeReportUsesSourceOriginAsContext) {}

TEST_F(AttributionStorageSqlTest,
       InvalidExpiryOrReportTime_FailsDeserialization) {}

TEST_F(AttributionStorageSqlTest,
       RandomizedResponseRateNotStored_RecalculatedWhenHandled) {}

TEST_F(AttributionStorageSqlTest, EpsilonNotStored_RecalculatedWhenHandled) {}

TEST_F(AttributionStorageSqlTest,
       TriggerDataNotStored_RecalculatedWhenHandled) {}

// Having the missing field default to the correct value allows us to avoid a
// DB migration to populate the field.
TEST_F(AttributionStorageSqlTest,
       MissingTriggerDataMatchingProtoField_DefaultsToModulus) {}

TEST_F(AttributionStorageSqlTest, InvalidReportingOrigin_FailsDeserialization) {}

TEST_F(AttributionStorageSqlTest,
       InvalidEventLevelMetadata_FailsDeserialization) {}

TEST_F(AttributionStorageSqlTest,
       InvalidAggregatableMetadata_FailsDeserialization) {}

TEST_F(AttributionStorageSqlTest,
       InvalidNullAggregatableMetadata_FailsDeserialization) {}

TEST_F(AttributionStorageSqlTest,
       NullAggregatableReport_ValidSourceMatched_FailsDeserialization) {}

TEST_F(AttributionStorageSqlTest,
       NullAggregatableReport_CorruptedSourceMatched_FailsDeserialization) {}

TEST_F(AttributionStorageSqlTest, InvalidStoredReportFields_MarkedAsCorrupted) {}

TEST_F(AttributionStorageSqlTest,
       InvalidReportCorrespondingSourceFields_MarkedAsCorrupted) {}

TEST_F(AttributionStorageSqlTest, SourceRemainingAggregatableBudget) {}

TEST_F(AttributionStorageSqlTest, SourceDebugKeyAndDebugCookieSetCombination) {}

TEST_F(AttributionStorageSqlTest, ClearData_AggregatableDebugDataDeleted) {}

TEST_F(AttributionStorageSqlTest, MaxImpressionsPerOrigin_LimitsStorage) {}

}  // namespace
}  // namespace content