chromium/content/browser/aggregation_service/aggregation_service_storage_sql_unittest.cc

// Copyright 2021 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/aggregation_service/aggregation_service_storage_sql.h"

#include <memory>
#include <optional>
#include <string>
#include <string_view>
#include <utility>
#include <vector>

#include "base/containers/flat_set.h"
#include "base/files/file_path.h"
#include "base/files/file_util.h"
#include "base/files/scoped_temp_dir.h"
#include "base/functional/callback_helpers.h"
#include "base/metrics/histogram_base.h"
#include "base/path_service.h"
#include "base/strings/strcat.h"
#include "base/strings/string_number_conversions.h"
#include "base/test/bind.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/simple_test_clock.h"
#include "base/time/time.h"
#include "components/aggregation_service/aggregation_coordinator_utils.h"
#include "content/browser/aggregation_service/aggregatable_report.h"
#include "content/browser/aggregation_service/aggregation_service.h"
#include "content/browser/aggregation_service/aggregation_service_storage.h"
#include "content/browser/aggregation_service/aggregation_service_test_utils.h"
#include "content/browser/aggregation_service/public_key.h"
#include "content/public/common/content_paths.h"
#include "sql/database.h"
#include "sql/meta_table.h"
#include "sql/sqlite_result_code_values.h"
#include "sql/statement.h"
#include "sql/test/scoped_error_expecter.h"
#include "sql/test/test_helpers.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/public/common/storage_key/storage_key.h"
#include "third_party/blink/public/mojom/aggregation_service/aggregatable_report.mojom-shared.h"
#include "url/gurl.h"
#include "url/origin.h"

namespace content {

namespace {

RequestIdIs;
ElementsAre;

RequestId;
RequestAndId;

const char kExampleUrl[] =;

const std::vector<PublicKey> kExampleKeys{};

std::string RemoveQuotes(std::string_view input) {}

AggregatableReportRequest CreateExampleRequestWithDelayType() {}

}  // namespace

class AggregationServiceStorageSqlTest : public testing::Test {};

class AggregationServiceStorageSqlInMemoryTest : public testing::Test {};

TEST_F(AggregationServiceStorageSqlTest,
       DBInitializationSucceeds_HistogramRecorded) {}

TEST_F(AggregationServiceStorageSqlTest, CantOpenDb_HistogramRecorded) {}

TEST_F(AggregationServiceStorageSqlTest,
       DatabaseInitialized_TablesAndIndexesLazilyInitialized) {}

TEST_F(AggregationServiceStorageSqlTest, DatabaseReopened_KeysPersisted) {}

TEST_F(AggregationServiceStorageSqlTest, SetPublicKeys_ExpectedResult) {}

TEST_F(AggregationServiceStorageSqlTest, GetPublicKeysExpired_EmptyResult) {}

TEST_F(AggregationServiceStorageSqlTest, ClearPublicKeys) {}

TEST_F(AggregationServiceStorageSqlTest, ReplacePublicKeys) {}

TEST_F(AggregationServiceStorageSqlTest,
       ClearDataBetween_PublicKeyRangeDeleted) {}

TEST_F(AggregationServiceStorageSqlTest,
       ClearAllDataWithFilter_PublicKeysAllDeleted) {}

TEST_F(AggregationServiceStorageSqlTest,
       ClearAllDataWithoutFilter_AllPublicKeysDeleted) {}

TEST_F(AggregationServiceStorageSqlTest,
       ClearPublicKeysExpiredBy_RangeDeleted) {}

TEST_F(AggregationServiceStorageSqlTest, VersionTooNew_RazesDB) {}

TEST_F(AggregationServiceStorageSqlInMemoryTest,
       DatabaseInMemoryReopened_PublicKeyDataNotPersisted) {}

TEST_F(AggregationServiceStorageSqlTest, StoreRequest_ExpectedResult) {}

TEST_F(AggregationServiceStorageSqlTest, DeleteRequest_ExpectedResult) {}

TEST_F(AggregationServiceStorageSqlTest,
       UpdateReportForSendFailure_ExpectedResult) {}

TEST_F(AggregationServiceStorageSqlTest,
       RepeatGetPendingRequests_RequestReturnedAgain) {}

TEST_F(AggregationServiceStorageSqlTest, DatabaseReopened_RequestsPersisted) {}

TEST_F(AggregationServiceStorageSqlTest,
       GetRequestsReportingOnOrBefore_ReturnValuesAlignWithReportTime) {}

TEST_F(AggregationServiceStorageSqlTest,
       GetRequestsReportingOnOrBefore_ReturnValuesAlignWithLimit) {}

TEST_F(AggregationServiceStorageSqlTest, GetRequests_ReturnValuesAlignWithIds) {}

TEST_F(AggregationServiceStorageSqlTest,
       NextReportTimeAfter_ReturnValuesAlignWithReportTime) {}

TEST_F(AggregationServiceStorageSqlTest,
       MultipleRequests_ReturnValuesAlignsWithReportTime) {}

TEST_F(AggregationServiceStorageSqlTest,
       ClearAllDataWithoutFilter_AllRequestsDeleted) {}

TEST_F(AggregationServiceStorageSqlTest,
       ClearDataBetween_RequestsTimeRangeDeleted) {}

TEST_F(AggregationServiceStorageSqlTest,
       ClearDataAllTimesWithFilter_OnlyRequestsSpecifiedAreDeleted) {}

TEST_F(AggregationServiceStorageSqlTest, GetReportRequestReportingOrigins) {}

TEST_F(AggregationServiceStorageSqlTest,
       AdjustOfflineReportTimes_AffectsPastReportsOnly) {}

TEST_F(AggregationServiceStorageSqlTest,
       AdjustOfflineReportTimes_SupportsZeroMinAndConstantDelay) {}

TEST_F(AggregationServiceStorageSqlTest,
       AdjustOfflineReportTimes_MultipleReports) {}

// This test verifies that `AggregationServiceStorageSql::Open()` deletes the
// database file when it encounters catastrophic errors.
TEST_F(AggregationServiceStorageSqlTest,
       AdjustOfflineReportTimes_DiskCorruption) {}

TEST_F(AggregationServiceStorageSqlTest, StoreRequest_RespectsLimit) {}

TEST_F(AggregationServiceStorageSqlTest, StoreRequest_LimitIsScopedCorrectly) {}

TEST_F(AggregationServiceStorageSqlTest,
       StoreRequestWithDebugKey_DeserializedWithDebugKey) {}

TEST_F(AggregationServiceStorageSqlTest,
       StoreRequestWithAdditionalFields_DeserializedWithFields) {}

TEST_F(AggregationServiceStorageSqlTest,
       StoreRequestWithCoordinatorOrigin_DeserializedWithOrigin) {}

TEST_F(AggregationServiceStorageSqlInMemoryTest,
       DatabaseInMemoryReopened_RequestsNotPersisted) {}

TEST_F(AggregationServiceStorageSqlTest,
       AggregationCoordinatorAllowlistChanges_ReportDeleted) {}

class AggregationServiceStorageSqlMigrationsTest
    : public AggregationServiceStorageSqlTest {};

TEST_F(AggregationServiceStorageSqlMigrationsTest, MigrateEmptyToCurrent) {}

// Note: We should add a MigrateLatestDeprecatedVersion test when we first
// deprecate a version.

TEST_F(AggregationServiceStorageSqlMigrationsTest, MigrateVersion1ToCurrent) {}

TEST_F(AggregationServiceStorageSqlMigrationsTest, MigrateVersion2ToCurrent) {}

}  // namespace content