chromium/net/extras/sqlite/sqlite_persistent_shared_dictionary_store_unittest.cc

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

#include "net/extras/sqlite/sqlite_persistent_shared_dictionary_store.h"

#include <optional>
#include <tuple>

#include "base/files/file_util.h"
#include "base/files/scoped_temp_dir.h"
#include "base/logging.h"
#include "base/memory/scoped_refptr.h"
#include "base/numerics/safe_conversions.h"
#include "base/task/sequenced_task_runner.h"
#include "base/task/thread_pool.h"
#include "base/test/bind.h"
#include "base/test/test_file_util.h"
#include "base/time/time.h"
#include "build/build_config.h"
#include "net/base/schemeful_site.h"
#include "net/extras/shared_dictionary/shared_dictionary_info.h"
#include "net/shared_dictionary/shared_dictionary_isolation_key.h"
#include "net/test/test_with_task_environment.h"
#include "sql/database.h"
#include "sql/meta_table.h"
#include "sql/statement.h"
#include "sql/test/test_helpers.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"

ElementsAre;
ElementsAreArray;
Pair;
UnorderedElementsAreArray;

namespace net {

namespace {

const base::FilePath::CharType kSharedDictionaryStoreFilename[] =);

const int kCurrentVersionNumber =;

int GetDBCurrentVersionNumber(sql::Database* db) {}

bool CreateV1Schema(sql::Database* db) {}

bool CreateV2Schema(sql::Database* db) {}

SQLitePersistentSharedDictionaryStore::RegisterDictionaryResult
RegisterDictionaryImpl(SQLitePersistentSharedDictionaryStore* store,
                       const SharedDictionaryIsolationKey& isolation_key,
                       SharedDictionaryInfo dictionary_info,
                       uint64_t max_size_per_site = 1000000,
                       uint64_t max_count_per_site = 1000) {}

// Register following 4 dictionaries for ProcessEviction tests.
//   dict1: size=1000 last_used_time=now
//   dict2: size=3000 last_used_time=now+4
//   dict3: size=5000 last_used_time=now+2
//   dict4: size=7000 last_used_time=now+3
std::tuple<SharedDictionaryInfo,
           SharedDictionaryInfo,
           SharedDictionaryInfo,
           SharedDictionaryInfo>
RegisterSharedDictionariesForProcessEvictionTest(
    SQLitePersistentSharedDictionaryStore* store,
    const SharedDictionaryIsolationKey& isolation_key) {}

}  // namespace

SharedDictionaryIsolationKey CreateIsolationKey(
    const std::string& frame_origin_str,
    const std::optional<std::string>& top_frame_site_str = std::nullopt) {}

class SQLitePersistentSharedDictionaryStoreTest : public ::testing::Test,
                                                  public WithTaskEnvironment {};

TEST_F(SQLitePersistentSharedDictionaryStoreTest, SingleDictionary) {}

void SQLitePersistentSharedDictionaryStoreTest::RunMultipleDictionariesTest(
    const SharedDictionaryIsolationKey isolation_key1,
    const SharedDictionaryInfo dictionary_info1,
    const SharedDictionaryIsolationKey isolation_key2,
    const SharedDictionaryInfo dictionary_info2,
    bool expect_merged) {}

TEST_F(SQLitePersistentSharedDictionaryStoreTest,
       MultipleDictionariesDifferentOriginSameSite) {}

TEST_F(SQLitePersistentSharedDictionaryStoreTest,
       MultipleDictionariesDifferentSite) {}

TEST_F(SQLitePersistentSharedDictionaryStoreTest,
       MultipleDictionariesDifferentHostDifferentMatch) {}

TEST_F(SQLitePersistentSharedDictionaryStoreTest,
       SameIsolationKeySameHostDifferentMatchSameMatchDest) {}

TEST_F(SQLitePersistentSharedDictionaryStoreTest,
       SameIsolationKeySameHostSameMatchSameMatchDest) {}

TEST_F(SQLitePersistentSharedDictionaryStoreTest,
       SameIsolationKeySameHostSameMatchDifferentMatchDest) {}

void SQLitePersistentSharedDictionaryStoreTest::
    RunGetTotalDictionarySizeFailureTest(
        SQLitePersistentSharedDictionaryStore::Error expected_error) {}

TEST_F(SQLitePersistentSharedDictionaryStoreTest,
       GetTotalDictionarySizeErrorInitializationFailure) {}

TEST_F(SQLitePersistentSharedDictionaryStoreTest,
       GetTotalDictionarySizeErrorFailedToGetTotalDictSize) {}

void SQLitePersistentSharedDictionaryStoreTest::
    RunRegisterDictionaryFailureTest(
        SQLitePersistentSharedDictionaryStore::Error expected_error) {}

TEST_F(SQLitePersistentSharedDictionaryStoreTest,
       RegisterDictionaryErrorDatabaseInitializationFailure) {}

TEST_F(SQLitePersistentSharedDictionaryStoreTest,
       RegisterDictionaryErrorInvalidSql) {}

#if !BUILDFLAG(IS_FUCHSIA) && !BUILDFLAG(IS_WIN)
// MakeFileUnwritable() doesn't cause the failure on Fuchsia and Windows. So
// disabling the test on Fuchsia and Windows.
TEST_F(SQLitePersistentSharedDictionaryStoreTest,
       RegisterDictionaryErrorSqlExecutionFailure) {}
#endif  // !BUILDFLAG(IS_FUCHSIA)

TEST_F(SQLitePersistentSharedDictionaryStoreTest,
       RegisterDictionaryErrorFailedToGetTotalDictSize) {}

TEST_F(SQLitePersistentSharedDictionaryStoreTest,
       RegisterDictionaryErrorInvalidTotalDictSize) {}

TEST_F(SQLitePersistentSharedDictionaryStoreTest,
       RegisterDictionaryErrorTooBigDictionary) {}

TEST_F(SQLitePersistentSharedDictionaryStoreTest,
       RegisterDictionaryPerSiteEvictionWhenExceededSizeLimit) {}

TEST_F(SQLitePersistentSharedDictionaryStoreTest,
       RegisterDictionaryPerSiteEvictionWhenExceededCountLimit) {}

TEST_F(
    SQLitePersistentSharedDictionaryStoreTest,
    RegisterDictionaryPerSiteEvictionWhenExceededCountLimitWithoutSizeLimit) {}

TEST_F(SQLitePersistentSharedDictionaryStoreTest,
       RegisterDictionaryPerSiteEvictionWhenExceededBothSizeAndCountLimit) {}

void SQLitePersistentSharedDictionaryStoreTest::RunGetDictionariesFailureTest(
    SQLitePersistentSharedDictionaryStore::Error expected_error) {}

TEST_F(SQLitePersistentSharedDictionaryStoreTest,
       GetDictionariesErrorDatabaseInitializationFailure) {}

TEST_F(SQLitePersistentSharedDictionaryStoreTest,
       GetDictionariesErrorInvalidSql) {}

void SQLitePersistentSharedDictionaryStoreTest::
    RunGetAllDictionariesFailureTest(
        SQLitePersistentSharedDictionaryStore::Error expected_error) {}

TEST_F(SQLitePersistentSharedDictionaryStoreTest,
       GetAllDictionariesErrorDatabaseInitializationFailure) {}

TEST_F(SQLitePersistentSharedDictionaryStoreTest,
       GetAllDictionariesErrorInvalidSql) {}

void SQLitePersistentSharedDictionaryStoreTest::RunGetUsageInfoFailureTest(
    SQLitePersistentSharedDictionaryStore::Error expected_error) {}

TEST_F(SQLitePersistentSharedDictionaryStoreTest,
       RunGetUsageInfoErrorDatabaseInitializationFailure) {}

TEST_F(SQLitePersistentSharedDictionaryStoreTest,
       RunGetUsageInfoErrorInvalidSql) {}

void SQLitePersistentSharedDictionaryStoreTest::RunGetOriginsBetweenFailureTest(
    SQLitePersistentSharedDictionaryStore::Error expected_error) {}

TEST_F(SQLitePersistentSharedDictionaryStoreTest,
       RunGetOriginsBetweenErrorDatabaseInitializationFailure) {}

TEST_F(SQLitePersistentSharedDictionaryStoreTest,
       RunGetOriginsBetweenErrorInvalidSql) {}

void SQLitePersistentSharedDictionaryStoreTest::
    RunClearAllDictionariesFailureTest(
        SQLitePersistentSharedDictionaryStore::Error expected_error) {}

TEST_F(SQLitePersistentSharedDictionaryStoreTest,
       ClearAllDictionariesErrorDatabaseInitializationFailure) {}

#if !BUILDFLAG(IS_FUCHSIA) && !BUILDFLAG(IS_WIN)
// MakeFileUnwritable() doesn't cause the failure on Fuchsia and Windows. So
// disabling the test on Fuchsia and Windows.
TEST_F(SQLitePersistentSharedDictionaryStoreTest,
       ClearAllDictionariesErrorSqlExecutionFailure) {}
#endif  // !BUILDFLAG(IS_FUCHSIA)

void SQLitePersistentSharedDictionaryStoreTest::RunClearDictionariesFailureTest(
    base::RepeatingCallback<bool(const GURL&)> url_matcher,
    SQLitePersistentSharedDictionaryStore::Error expected_error) {}

TEST_F(SQLitePersistentSharedDictionaryStoreTest,
       ClearDictionariesErrorDatabaseInitializationFailure) {}

TEST_F(SQLitePersistentSharedDictionaryStoreTest,
       ClearDictionariesErrorInvalidSql) {}

TEST_F(SQLitePersistentSharedDictionaryStoreTest,
       ClearDictionariesWithUrlMatcherErrorInvalidSql) {}

#if !BUILDFLAG(IS_FUCHSIA) && !BUILDFLAG(IS_WIN)
// MakeFileUnwritable() doesn't cause the failure on Fuchsia and Windows. So
// disabling the test on Fuchsia and Windows.
TEST_F(SQLitePersistentSharedDictionaryStoreTest,
       ClearDictionariesErrorSqlExecutionFailure) {}

TEST_F(SQLitePersistentSharedDictionaryStoreTest,
       ClearDictionariesWithUrlMatcherErrorSqlExecutionFailure) {}
#endif  // !BUILDFLAG(IS_FUCHSIA)

TEST_F(SQLitePersistentSharedDictionaryStoreTest,
       ClearDictionariesErrorFailedToGetTotalDictSize) {}

void SQLitePersistentSharedDictionaryStoreTest::
    RunClearDictionariesForIsolationKeyFailureTest(
        SQLitePersistentSharedDictionaryStore::Error expected_error) {}

TEST_F(SQLitePersistentSharedDictionaryStoreTest,
       ClearDictionariesForIsolationKeyErrorDatabaseInitializationFailure) {}

TEST_F(SQLitePersistentSharedDictionaryStoreTest,
       ClearDictionariesForIsolationKeyErrorInvalidSql) {}

TEST_F(SQLitePersistentSharedDictionaryStoreTest,
       ClearDictionariesForIsolationKeyErrorFailedToGetTotalDictSize) {}

void SQLitePersistentSharedDictionaryStoreTest::
    RunDeleteExpiredDictionariesFailureTest(
        SQLitePersistentSharedDictionaryStore::Error expected_error) {}

TEST_F(SQLitePersistentSharedDictionaryStoreTest,
       DeleteExpiredDictionariesErrorDatabaseInitializationFailure) {}

TEST_F(SQLitePersistentSharedDictionaryStoreTest,
       DeleteExpiredDictionariesErrorInvalidSql) {}

TEST_F(SQLitePersistentSharedDictionaryStoreTest,
       DeleteExpiredDictionariesErrorFailedToGetTotalDictSize) {}

void SQLitePersistentSharedDictionaryStoreTest::RunProcessEvictionFailureTest(
    SQLitePersistentSharedDictionaryStore::Error expected_error) {}

TEST_F(SQLitePersistentSharedDictionaryStoreTest,
       ProcessEvictionErrorDatabaseInitializationFailure) {}

TEST_F(SQLitePersistentSharedDictionaryStoreTest,
       ProcessEvictionErrorInvalidSql) {}

#if !BUILDFLAG(IS_FUCHSIA) && !BUILDFLAG(IS_WIN)
// MakeFileUnwritable() doesn't cause the failure on Fuchsia and Windows. So
// disabling the test on Fuchsia and Windows.
TEST_F(SQLitePersistentSharedDictionaryStoreTest,
       ProcessEvictionErrorSqlExecutionFailure) {}
#endif  // !BUILDFLAG(IS_FUCHSIA)

TEST_F(SQLitePersistentSharedDictionaryStoreTest,
       ProcessEvictionErrorFailedToGetTotalDictSize) {}

void SQLitePersistentSharedDictionaryStoreTest::
    RunGetAllDiskCacheKeyTokensFailureTest(
        SQLitePersistentSharedDictionaryStore::Error expected_error) {}

TEST_F(SQLitePersistentSharedDictionaryStoreTest,
       GetAllDiskCacheKeyTokensErrorDatabaseInitializationFailure) {}

TEST_F(SQLitePersistentSharedDictionaryStoreTest,
       GetAllDiskCacheKeyTokensErrorInvalidSql) {}

TEST_F(
    SQLitePersistentSharedDictionaryStoreTest,
    DeleteDictionariesByDiskCacheKeyTokensErrorDatabaseInitializationFailure) {}

TEST_F(SQLitePersistentSharedDictionaryStoreTest,
       DeleteDictionariesByDiskCacheKeyTokensErrorInvalidSql) {}

TEST_F(SQLitePersistentSharedDictionaryStoreTest,
       DeleteDictionariesByDiskCacheKeyTokensErrorFailedToGetTotalDictSize) {}

TEST_F(SQLitePersistentSharedDictionaryStoreTest,
       UpdateDictionaryLastFetchTimeErrorDatabaseInitializationFailure) {}

TEST_F(SQLitePersistentSharedDictionaryStoreTest,
       UpdateDictionaryLastFetchTimeErrorInvalidSql) {}

#if !BUILDFLAG(IS_FUCHSIA) && !BUILDFLAG(IS_WIN)
// MakeFileUnwritable() doesn't cause the failure on Fuchsia and Windows. So
// disabling the test on Fuchsia and Windows.
TEST_F(SQLitePersistentSharedDictionaryStoreTest,
       UpdateDictionaryLastFetchTimeErrorSqlExecutionFailure) {}
#endif  // !BUILDFLAG(IS_FUCHSIA)

TEST_F(SQLitePersistentSharedDictionaryStoreTest, InvalidHash) {}

TEST_F(SQLitePersistentSharedDictionaryStoreTest, InvalidToken) {}

TEST_F(SQLitePersistentSharedDictionaryStoreTest,
       GetTotalDictionarySizeCallbackNotCalledAfterStoreDeleted) {}

TEST_F(SQLitePersistentSharedDictionaryStoreTest,
       RegisterDictionaryCallbackNotCalledAfterStoreDeleted) {}

TEST_F(SQLitePersistentSharedDictionaryStoreTest,
       GetDictionariesCallbackNotCalledAfterStoreDeleted) {}

TEST_F(SQLitePersistentSharedDictionaryStoreTest,
       GetAllDictionariesCallbackNotCalledAfterStoreDeleted) {}

TEST_F(SQLitePersistentSharedDictionaryStoreTest,
       ClearAllDictionariesCallbackNotCalledAfterStoreDeleted) {}

TEST_F(SQLitePersistentSharedDictionaryStoreTest,
       ClearDictionariesCallbackNotCalledAfterStoreDeleted) {}

TEST_F(SQLitePersistentSharedDictionaryStoreTest,
       DeleteExpiredDictionariesCallbackNotCalledAfterStoreDeleted) {}

TEST_F(SQLitePersistentSharedDictionaryStoreTest, ClearDictionaries) {}

TEST_F(SQLitePersistentSharedDictionaryStoreTest,
       ClearDictionariesWithUrlMatcher) {}

TEST_F(SQLitePersistentSharedDictionaryStoreTest,
       ClearDictionariesForIsolationKeyEmptyStore) {}

TEST_F(SQLitePersistentSharedDictionaryStoreTest,
       ClearDictionariesForIsolation) {}

TEST_F(SQLitePersistentSharedDictionaryStoreTest,
       ClearDictionariesForIsolationMultipleDictionaries) {}

TEST_F(SQLitePersistentSharedDictionaryStoreTest, DeleteExpiredDictionaries) {}

TEST_F(SQLitePersistentSharedDictionaryStoreTest, ProcessEvictionNotExceeded) {}

TEST_F(SQLitePersistentSharedDictionaryStoreTest, ProcessEvictionSizeExceeded) {}

TEST_F(SQLitePersistentSharedDictionaryStoreTest,
       ProcessEvictionSizeExceededEvictiedUntilCountLowWatermark) {}

TEST_F(SQLitePersistentSharedDictionaryStoreTest,
       ProcessEvictionCountExceeded) {}

TEST_F(SQLitePersistentSharedDictionaryStoreTest,
       ProcessEvictionCountExceededEvictedUntilSizeLowWaterMark) {}

TEST_F(SQLitePersistentSharedDictionaryStoreTest, ProcessEvictionZeroMaxSize) {}

TEST_F(SQLitePersistentSharedDictionaryStoreTest, ProcessEvictionDeletesAll) {}

TEST_F(SQLitePersistentSharedDictionaryStoreTest, GetAllDiskCacheKeyTokens) {}

TEST_F(SQLitePersistentSharedDictionaryStoreTest,
       DeleteDictionariesByDiskCacheKeyTokens) {}

TEST_F(SQLitePersistentSharedDictionaryStoreTest,
       UpdateDictionaryLastFetchTime) {}

TEST_F(SQLitePersistentSharedDictionaryStoreTest,
       UpdateDictionaryLastUsedTime) {}

TEST_F(SQLitePersistentSharedDictionaryStoreTest,
       MassiveUpdateDictionaryLastUsedTime) {}

TEST_F(SQLitePersistentSharedDictionaryStoreTest, MigrateFromV1ToV3) {}

TEST_F(SQLitePersistentSharedDictionaryStoreTest, MigrateFromV2ToV3) {}

}  // namespace net