#include "services/network/shared_dictionary/shared_dictionary_manager_on_disk.h"
#include "base/feature_list.h"
#include "base/files/file_path.h"
#include "base/files/file_util.h"
#include "base/files/scoped_temp_dir.h"
#include "base/functional/callback.h"
#include "base/memory/ref_counted.h"
#include "base/strings/strcat.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/stringprintf.h"
#include "base/test/bind.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/task_environment.h"
#include "base/test/test_file_util.h"
#include "base/time/time.h"
#include "build/build_config.h"
#include "crypto/secure_hash.h"
#include "net/base/hash_value.h"
#include "net/base/io_buffer.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/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_manager_on_disk.h"
#include "services/network/shared_dictionary/shared_dictionary_storage.h"
#include "services/network/shared_dictionary/shared_dictionary_storage_on_disk.h"
#include "services/network/shared_dictionary/shared_dictionary_writer.h"
#include "sql/database.h"
#include "sql/meta_table.h"
#include "sql/test/test_helpers.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "url/gurl.h"
#include "url/origin.h"
ElementsAre;
Pair;
namespace network {
namespace {
const GURL kUrl("https://origin.test/");
const net::SchemefulSite kSite(kUrl);
const std::string kTestData1 = …;
const std::string kTestData2 = …;
const std::string kDefaultCacheControlHeader = …;
const int kCurrentVersionNumber = …;
base::OnceCallback<bool()> DummyAccessAllowedCheckCallback() { … }
void WriteDictionary(SharedDictionaryStorage* storage,
const GURL& dictionary_url,
const std::string& match,
const std::string& data) { … }
void WriteDictionaryWithExpiry(SharedDictionaryStorage* storage,
const GURL& dictionary_url,
const std::string& match,
const base::TimeDelta& expires,
const std::string& data) { … }
bool DiskCacheEntryExists(SharedDictionaryManager* manager,
const std::string& disk_cache_key) { … }
bool DiskCacheEntryExists(SharedDictionaryManager* manager,
const base::UnguessableToken& disk_cache_key_token) { … }
void DoomDiskCacheEntry(SharedDictionaryManager* manager,
const base::UnguessableToken& disk_cache_key_token) { … }
void WriteDiskCacheEntry(SharedDictionaryManager* manager,
const std::string& disk_cache_key,
const std::string& data) { … }
}
class SharedDictionaryManagerOnDiskTest : public ::testing::Test { … };
TEST_F(SharedDictionaryManagerOnDiskTest, ReusingRefCountedSharedDictionary) { … }
TEST_F(SharedDictionaryManagerOnDiskTest,
MaybeCreateWriterAfterManagerDeleted) { … }
TEST_F(SharedDictionaryManagerOnDiskTest, GetDictionaryAfterManagerDeleted) { … }
TEST_F(SharedDictionaryManagerOnDiskTest,
DictionaryWrittenInDiskCacheAfterManagerDeleted) { … }
TEST_F(SharedDictionaryManagerOnDiskTest, OverridingDictionary) { … }
TEST_F(SharedDictionaryManagerOnDiskTest, MultipleDictionaries) { … }
TEST_F(SharedDictionaryManagerOnDiskTest, GetDictionary) { … }
#if !BUILDFLAG(IS_FUCHSIA)
TEST_F(SharedDictionaryManagerOnDiskTest, CorruptedDiskCacheAndWriteData) { … }
TEST_F(SharedDictionaryManagerOnDiskTest, CorruptedDiskCacheAndGetData) { … }
#endif
TEST_F(SharedDictionaryManagerOnDiskTest, CorruptedDatabase) { … }
TEST_F(SharedDictionaryManagerOnDiskTest, MetadataBrokenDatabase) { … }
TEST_F(SharedDictionaryManagerOnDiskTest, LastUsedTime) { … }
MATCHER_P(DictionaryUrlIs,
url,
std::string(negation ? "doesn't have" : "has") + " " + url +
" as the URL") { … }
TEST_F(SharedDictionaryManagerOnDiskTest, ClearData) { … }
TEST_F(SharedDictionaryManagerOnDiskTest, ClearDataSerializedOperation) { … }
TEST_F(SharedDictionaryManagerOnDiskTest, ClearDataForIsolationKey) { … }
TEST_F(SharedDictionaryManagerOnDiskTest, ExpiredDictionaryDeletionOnReload) { … }
TEST_F(SharedDictionaryManagerOnDiskTest,
ExpiredDictionaryDeletionOnNewDictionary) { … }
TEST_F(SharedDictionaryManagerOnDiskTest,
ExpiredDictionaryDeletionOnSetCacheMaxSize) { … }
TEST_F(SharedDictionaryManagerOnDiskTest,
ExpiredDictionaryDeletionOnClearData) { … }
TEST_F(SharedDictionaryManagerOnDiskTest,
ExpiredDictionaryDeletionOnClearDataForIsolationKey) { … }
TEST_F(SharedDictionaryManagerOnDiskTest, CacheEvictionOnReload) { … }
TEST_F(SharedDictionaryManagerOnDiskTest, CacheEvictionOnSetCacheMaxSize) { … }
TEST_F(SharedDictionaryManagerOnDiskTest, CacheEvictionOnNewDictionary) { … }
TEST_F(SharedDictionaryManagerOnDiskTest,
CacheEvictionPerSiteExceededSizeLimit) { … }
TEST_F(SharedDictionaryManagerOnDiskTest,
CacheEvictionPerSiteExceededCountLimit) { … }
TEST_F(SharedDictionaryManagerOnDiskTest,
CacheEvictionAfterUpdatingLastUsedTime) { … }
TEST_F(SharedDictionaryManagerOnDiskTest,
MismatchingEntryDeletionMetadataUnavailableDictionary) { … }
TEST_F(SharedDictionaryManagerOnDiskTest,
MismatchingEntryDeletionInvalidDiskCacheEntry) { … }
TEST_F(SharedDictionaryManagerOnDiskTest,
MismatchingEntryDeletionDiskCacheEntryUnavailableDictionary) { … }
TEST_F(SharedDictionaryManagerOnDiskTest,
MismatchingEntryDeletionCanBeTriggeredOnlyOnce) { … }
TEST_F(SharedDictionaryManagerOnDiskTest,
MismatchingEntryDeletionWritingEntryMustNotBeDeleted) { … }
TEST_F(SharedDictionaryManagerOnDiskTest,
MismatchingEntryDeletionWritingDiskCacheEntryMustNotBeDeleted) { … }
}