chromium/services/network/shared_dictionary/shared_dictionary_manager_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 "services/network/shared_dictionary/shared_dictionary_manager.h"

#include <optional>
#include <string>
#include <vector>

#include "base/feature_list.h"
#include "base/files/file_path.h"
#include "base/files/scoped_temp_dir.h"
#include "base/format_macros.h"
#include "base/functional/callback.h"
#include "base/memory/ref_counted.h"
#include "base/strings/strcat.h"
#include "base/strings/stringprintf.h"
#include "base/test/bind.h"
#include "base/test/scoped_feature_list.h"
#include "base/test/task_environment.h"
#include "base/test/test_future.h"
#include "base/time/time.h"
#include "crypto/secure_hash.h"
#include "net/base/hash_value.h"
#include "net/base/io_buffer.h"
#include "net/base/load_flags.h"
#include "net/base/net_errors.h"
#include "net/base/network_isolation_key.h"
#include "net/base/schemeful_site.h"
#include "net/disk_cache/disk_cache.h"
#include "net/disk_cache/disk_cache_test_util.h"
#include "net/extras/shared_dictionary/shared_dictionary_info.h"
#include "net/extras/shared_dictionary/shared_dictionary_usage_info.h"
#include "net/http/http_response_headers.h"
#include "net/shared_dictionary/shared_dictionary.h"
#include "services/network/public/cpp/features.h"
#include "services/network/public/mojom/shared_dictionary_error.mojom.h"
#include "services/network/shared_dictionary/shared_dictionary_constants.h"
#include "services/network/shared_dictionary/shared_dictionary_disk_cache.h"
#include "services/network/shared_dictionary/shared_dictionary_in_memory.h"
#include "services/network/shared_dictionary/shared_dictionary_manager_on_disk.h"
#include "services/network/shared_dictionary/shared_dictionary_storage.h"
#include "services/network/shared_dictionary/shared_dictionary_storage_in_memory.h"
#include "services/network/shared_dictionary/shared_dictionary_storage_on_disk.h"
#include "services/network/shared_dictionary/shared_dictionary_writer.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "url/gurl.h"
#include "url/origin.h"

UnorderedElementsAreArray;

namespace network {

namespace {

enum class TestManagerType {};

const GURL kUrl1("https://origin1.test/");
const GURL kUrl2("https://origin2.test/");
const GURL kUrl3("https://origin3.test/");
const net::SchemefulSite kSite1(kUrl1);
const net::SchemefulSite kSite2(kUrl2);
const net::SchemefulSite kSite3(kUrl3);

const std::string kTestData1 =;
const std::string kTestData2 =;

// The SHA256 hash of kTestData1
const net::SHA256HashValue kTestData1Hash =;
// The SHA256 hash of kTestData2
const net::SHA256HashValue kTestData2Hash =;

const size_t kCacheMaxCount =;

// Default cache control header for dictionary entries which expires in 30 days.
const std::string kDefaultCacheControlHeader =;

std::string ToString(TestManagerType type) {}

void CheckDiskCacheEntryDataEquals(
    SharedDictionaryDiskCache& disk_cache,
    const base::UnguessableToken& disk_cache_key_token,
    const std::string& expected_data) {}

void WriteDictionary(
    SharedDictionaryStorage* storage,
    const GURL& dictionary_url,
    const std::string& match,
    const std::vector<std::string>& data_list,
    const std::string& additional_options = std::string(),
    const std::string& additional_header = kDefaultCacheControlHeader) {}

base::TimeDelta GetDefaultExpiration() {}

}  // namespace

class SharedDictionaryManagerTest
    : public ::testing::Test,
      public ::testing::WithParamInterface<TestManagerType> {};

INSTANTIATE_TEST_SUITE_P();

TEST_P(SharedDictionaryManagerTest, SameStorageForSameIsolationKey) {}

TEST_P(SharedDictionaryManagerTest, DifferentStorageForDifferentIsolationKey) {}

TEST_P(SharedDictionaryManagerTest, CachedStorage) {}

TEST_P(SharedDictionaryManagerTest, CachedStorageEvicted) {}

TEST_P(SharedDictionaryManagerTest,
       StorageNotCachedWithModerateMemoryPressure) {}

TEST_P(SharedDictionaryManagerTest,
       StorageNotCachedWithCriticalMemoryPressure) {}

TEST_P(SharedDictionaryManagerTest,
       CachedStorageClearedOnModerateMemoryPressure) {}

TEST_P(SharedDictionaryManagerTest,
       CachedStorageClearedOnCriticalMemoryPressure) {}

TEST_P(SharedDictionaryManagerTest, WriterForUseAsDictionaryHeader) {}

TEST_P(SharedDictionaryManagerTest, DictionaryLifetimeFromCacheControlHeader) {}

TEST_P(SharedDictionaryManagerTest, WriterForUseAsDictionaryIdOption) {}

TEST_P(SharedDictionaryManagerTest, WriterForUseAsDictionaryMatchDestOption) {}

TEST_P(SharedDictionaryManagerTest, InvalidMatch) {}

TEST_P(SharedDictionaryManagerTest, AccessAllowedCheckReturnTrue) {}

TEST_P(SharedDictionaryManagerTest, AccessAllowedCheckReturnFalse) {}

TEST_P(SharedDictionaryManagerTest, SameDictionaryFromDiskCache) {}

TEST_P(SharedDictionaryManagerTest, DifferentDictionaryFromDiskCache) {}

TEST_P(SharedDictionaryManagerTest, WriteAndGetDictionary) {}

TEST_P(SharedDictionaryManagerTest, WriteAndReadDictionary) {}

TEST_P(SharedDictionaryManagerTest, LongestMatchDictionaryWin) {}

TEST_P(SharedDictionaryManagerTest, LastFetchedDictionaryWin) {}

TEST_P(SharedDictionaryManagerTest, OverrideDictionary) {}

TEST_P(SharedDictionaryManagerTest, ZeroSizeDictionaryShouldNotBeStored) {}

TEST_P(SharedDictionaryManagerTest,
       CacheEvictionSizeExceededOnSetCacheMaxSize) {}

TEST_P(SharedDictionaryManagerTest, CacheEvictionZeroMaxSizeCountExceeded) {}

TEST_P(SharedDictionaryManagerTest,
       CacheEvictionOnNewDictionaryMultiIsolation) {}

TEST_P(SharedDictionaryManagerTest, CacheEvictionAfterUpdatingLastUsedTime) {}

TEST_P(SharedDictionaryManagerTest, CacheEvictionPerSiteSizeExceeded) {}

TEST_P(SharedDictionaryManagerTest,
       CacheEvictionPerSiteZeroMaxSizeCountExceeded) {}

TEST_P(SharedDictionaryManagerTest,
       CacheEvictionPerSiteNonZeroMaxSizeCountExceeded) {}

TEST_P(SharedDictionaryManagerTest,
       CacheEvictionPerSiteBothSizeAndCountExceeded) {}

TEST_P(SharedDictionaryManagerTest, ClearDataMatchFrameOrigin) {}

TEST_P(SharedDictionaryManagerTest, ClearDataMatchTopFrameSite) {}

TEST_P(SharedDictionaryManagerTest, ClearDataMatchDictionaryUrl) {}

TEST_P(SharedDictionaryManagerTest, ClearDataNullUrlMatcher) {}

TEST_P(SharedDictionaryManagerTest, ClearDataDoNotInvalidateActiveDictionary) {}

TEST_P(SharedDictionaryManagerTest, ClearDataForIsolationKey) {}

TEST_P(SharedDictionaryManagerTest, GetUsageInfo) {}

TEST_P(SharedDictionaryManagerTest, GetUsageInfoEmptyResult) {}

TEST_P(SharedDictionaryManagerTest, GetSharedDictionaryInfo) {}

TEST_P(SharedDictionaryManagerTest, GetSharedDictionaryInfoEmptyResult) {}

TEST_P(SharedDictionaryManagerTest, GetTotalSizeAndOrigins) {}

TEST_P(SharedDictionaryManagerTest, DeleteExpiredDictionariesOnGetDictionary) {}

TEST_P(SharedDictionaryManagerTest, DictionaryEquality) {}

TEST_P(SharedDictionaryManagerTest, PreloadSharedDictionaryInfo) {}

TEST_P(SharedDictionaryManagerTest,
       PreloadSharedDictionaryInfoOpaqueOriginDoNotCrash) {}

TEST_P(SharedDictionaryManagerTest, MaybeCreateSharedDictionaryGetterFlags) {}

TEST_P(SharedDictionaryManagerTest, MaybeCreateSharedDictionaryGetter) {}

TEST_P(SharedDictionaryManagerTest, PreloadedDictionaryConditionalUseEnabled) {}

TEST_P(SharedDictionaryManagerTest, PreloadedDictionaryConditionalUseDisabled) {}

}  // namespace network