chromium/content/browser/interest_group/interest_group_storage_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/interest_group/interest_group_storage.h"

#include <stddef.h>

#include <functional>
#include <memory>
#include <optional>

#include "base/base64.h"
#include "base/files/file_util.h"
#include "base/files/scoped_temp_dir.h"
#include "base/functional/bind.h"
#include "base/path_service.h"
#include "base/run_loop.h"
#include "base/strings/escape.h"
#include "base/strings/strcat.h"
#include "base/strings/stringprintf.h"
#include "base/test/bind.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/scoped_feature_list.h"
#include "base/test/simple_test_clock.h"
#include "base/test/task_environment.h"
#include "base/time/time.h"
#include "content/browser/interest_group/bidding_and_auction_server_key_fetcher.h"
#include "content/browser/interest_group/for_debugging_only_report_util.h"
#include "content/browser/interest_group/interest_group_update.h"
#include "content/browser/interest_group/storage_interest_group.h"
#include "content/services/auction_worklet/public/mojom/bidder_worklet.mojom.h"
#include "crypto/sha2.h"
#include "sql/database.h"
#include "sql/meta_table.h"
#include "sql/test/scoped_error_expecter.h"
#include "sql/test/test_helpers.h"
#include "third_party/blink/public/common/features.h"
#include "third_party/blink/public/common/interest_group/interest_group.h"
#include "third_party/blink/public/common/interest_group/test/interest_group_test_utils.h"
#include "third_party/blink/public/common/interest_group/test_interest_group_builder.h"
#include "third_party/blink/public/common/storage_key/storage_key.h"
#include "url/origin.h"

namespace content {
namespace {

IgExpectEqualsForTesting;
IgExpectNotEqualsForTesting;
InterestGroup;
Field;
Property;
UnorderedElementsAre;
UnorderedElementsAreArray;
SellerCapabilities;
SellerCapabilitiesType;

constexpr char kFullOriginStr[] =;
constexpr char kPartialOriginStr[] =;

constexpr int kOldestAllFieldsVersion =;

class InterestGroupStorageTest : public testing::Test {};

TEST_F(InterestGroupStorageTest, DatabaseInitialized_CreateDatabase) {}

TEST_F(InterestGroupStorageTest, DatabaseRazesOldVersion) {}

TEST_F(InterestGroupStorageTest, DatabaseRazesNewVersion) {}

TEST_F(InterestGroupStorageTest, DatabaseJoin) {}

TEST_F(InterestGroupStorageTest, GetGroupDoesNotReturnOutdatedKanonKeys) {}

TEST_F(InterestGroupStorageTest,
       JoinAndUpdateReturnCorrectKanonUpdateParameter) {}

// Test that joining an interest group twice increments the counter.
// Test that joining multiple interest groups with the same owner only creates a
// single distinct owner. Test that leaving one interest group does not affect
// membership of other interest groups by the same owner.
TEST_F(InterestGroupStorageTest, JoinJoinLeave) {}

// Test ClearOriginJoinedInterestGroups().
//
// Join the following interest groups:
// * With joining origin A, join 3 interest groups with owner B, 2 with an
//   `executionMode` of "group-by-origin".
// * With joining origin A, join 1 interest group with owner C.
// * With joining origin site C, join 1 interest group with owner B.
//
// Then call ClearOriginJoinedInterestGroups() from origin A with owner B
// a number of times, making sure that only the expected IGs are deleted
// each time.
TEST_F(InterestGroupStorageTest, ClearOriginJoinedInterestGroups) {}

// Make sure that ClearOriginJoinedInterestGroups() clears join, bid, and win
// history.
TEST_F(InterestGroupStorageTest, ClearOriginJoinedInterestGroupsClearsHistory) {}

// Join 5 interest groups in the same origin, and one interest group in another
// origin.
//
// Fetch interest groups for update with a limit of 2 interest groups. Only 2
// interest groups should be returned, and they should all belong to the first
// test origin.
//
// Then, fetch 100 groups for update. Only 5 should be returned.
TEST_F(InterestGroupStorageTest, GetInterestGroupsForUpdate) {}

TEST_F(InterestGroupStorageTest, BidCount) {}

TEST_F(InterestGroupStorageTest, RecordsWins) {}

TEST_F(InterestGroupStorageTest, RecordsDebugReportLockoutAndCooldown) {}

TEST_F(InterestGroupStorageTest, DeleteExpiredDebugReportCooldown) {}

//  TODO (b/356654297) Add tests for selectableBuyerAndSellerReportingIds,
//    when k-anon is implemented.
TEST_F(InterestGroupStorageTest, UpdatesAdKAnonymity) {}

TEST_F(InterestGroupStorageTest,
       UpdatesAdKAnonymityWithMultipleInterestGroups) {}

TEST_F(InterestGroupStorageTest, KAnonDataExpires) {}

TEST_F(InterestGroupStorageTest, StoresAllFields) {}

#if !BUILDFLAG(IS_IOS)
// std::system is not available on iOS.
TEST_F(InterestGroupStorageTest, DumpAllIgFields) {}
#endif

TEST_F(InterestGroupStorageTest, DeleteOriginDeleteAll) {}

TEST_F(InterestGroupStorageTest, DeleteOwnerJoinerPair) {}

// Maintenance should prune the number of interest groups and interest group
// owners based on the set limit.
TEST_F(InterestGroupStorageTest, JoinTooManyRegularGroupNames) {}

// Maintenance should prune the number of interest groups and interest group
// owners based on the set limit.
TEST_F(InterestGroupStorageTest, JoinTooManyNegativeGroupNames) {}

// Maintenance should prune groups when the interest group owner exceeds the
// storage size limit.
TEST_F(InterestGroupStorageTest, JoinTooMuchStorage) {}

// Excess group owners should have their groups pruned by maintenance.
// In this test we trigger maintenance by having too many operations in a short
// period to test max_ops_before_maintenance_.
TEST_F(InterestGroupStorageTest, JoinTooManyGroupOwners) {}

TEST_F(InterestGroupStorageTest, ExpiredGroupsNotReturned) {}

TEST_F(InterestGroupStorageTest, DBMaintenanceExpiresOldInterestGroups) {}

// Test that when an interest group expires, data about the expired group from
// the additional tables (`prev_wins`, `join_count`, `num_bids`) is not
// preserved if the interest group is joined again. This tests both the case
// where the expired group is destroyed by normal database maintenance, and the
// case where it's overwritten by a new group with the same name and owner
// before maintenance can be performed.
TEST_F(InterestGroupStorageTest, ExpirationDeletesMetadata) {}

// Upgrades a v6 database dump to an expected current database.
// The v6 database dump was extracted from the InterestGroups database in
// a browser profile by using `sqlite3 dump <path-to-database>` and then
// cleaning up and formatting the output.
TEST_F(InterestGroupStorageTest, UpgradeFromV6) {}

// Upgrades a v6 database dump to an expected current database, then attempts to
// insert new rows into the migrated database.
//
// The v6 database dump was extracted from the InterestGroups database in
// a browser profile by using `sqlite3 dump <path-to-database>` and then
// cleaning up and formatting the output.
TEST_F(InterestGroupStorageTest, UpgradeFromV6ThenAcceptNewData) {}

// Upgrades a v16 database dump to an expected current database.
// The v16 database dump was extracted from an updated version of
// the v6 data dump, then altered to have new k-anon keys --
// the format of k-anon keys has changed between the two versions
// (without migration of one key type to the next)
// so this new dump is necessary to test changes to the k-anon
// table.
TEST_F(InterestGroupStorageTest, UpgradeFromV16) {}

TEST_F(InterestGroupStorageTest, MultiVersionUpgradeTest) {}

TEST_F(InterestGroupStorageTest,
       ClusteredGroupsClearedWhenClusterChangesOnJoin) {}

TEST_F(InterestGroupStorageTest,
       ClusteredGroupsClearedWhenClusterChangesOnLeave) {}

TEST_F(InterestGroupStorageTest, SetGetLastKAnonReported) {}

TEST_F(InterestGroupStorageTest, UpdatePrioritySignalsOverrides) {}

TEST_F(InterestGroupStorageTest, OnlyDeletesExpiredKAnon) {}

TEST_F(InterestGroupStorageTest, SetGetBiddingAndAuctionKeys) {}

TEST_F(InterestGroupStorageTest, SetGetBiddingAndAuctionKeysNonUtf8) {}

}  // namespace
}  // namespace content