chromium/net/dns/host_cache_unittest.cc

// Copyright 2012 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/dns/host_cache.h"

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

#include "base/format_macros.h"
#include "base/functional/bind.h"
#include "base/functional/callback.h"
#include "base/functional/callback_helpers.h"
#include "base/json/json_reader.h"
#include "base/json/json_writer.h"
#include "base/ranges/algorithm.h"
#include "base/strings/strcat.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "base/time/time.h"
#include "base/values.h"
#include "net/base/connection_endpoint_metadata.h"
#include "net/base/host_port_pair.h"
#include "net/base/ip_address.h"
#include "net/base/ip_endpoint.h"
#include "net/base/network_anonymization_key.h"
#include "net/base/schemeful_site.h"
#include "net/dns/host_resolver_internal_result.h"
#include "net/dns/host_resolver_results_test_util.h"
#include "net/dns/https_record_rdata.h"
#include "net/dns/public/host_resolver_results.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "url/gurl.h"
#include "url/scheme_host_port.h"
#include "url/url_constants.h"

_;
ElementsAre;
ElementsAreArray;
IsEmpty;
Optional;
Pair;
Pointee;
Property;
UnorderedElementsAre;

namespace net {

namespace {

const int kMaxCacheEntries =;

// Builds a key for |hostname|, defaulting the query type to unspecified.
HostCache::Key Key(const std::string& hostname) {}

bool FoobarIndexIsOdd(const std::string& foobarx_com) {}

class MockPersistenceDelegate : public HostCache::PersistenceDelegate {};

MATCHER_P(EntryContentsEqual,
          entry,
          base::StrCat({}

IPAddress MakeIP(std::string_view literal) {}

std::vector<IPEndPoint> MakeEndpoints(std::vector<std::string> my_addresses) {}

}  // namespace

TEST(HostCacheTest, Basic) {}

TEST(HostCacheTest, GetEndpoints) {}

TEST(HostCacheTest, GetEmptyEndpoints) {}

TEST(HostCacheTest, GetEmptyEndpointsWithMetadata) {}

TEST(HostCacheTest, GetMissingEndpoints) {}

TEST(HostCacheTest, GetMissingEndpointsWithMetadata) {}

// Test that Keys without scheme are allowed and treated as completely different
// from similar Keys with scheme.
TEST(HostCacheTest, HandlesKeysWithoutScheme) {}

// Make sure NetworkAnonymizationKey is respected.
TEST(HostCacheTest, NetworkAnonymizationKey) {}

// Try caching entries for a failed resolve attempt -- since we set the TTL of
// such entries to 0 it won't store, but it will kick out the previous result.
TEST(HostCacheTest, NoCacheZeroTTL) {}

// Try caching entries for a failed resolves for 10 seconds.
TEST(HostCacheTest, CacheNegativeEntry) {}

// Tests that the same hostname can be duplicated in the cache, so long as
// the query type differs.
TEST(HostCacheTest, DnsQueryTypeIsPartOfKey) {}

// Tests that the same hostname can be duplicated in the cache, so long as
// the HostResolverFlags differ.
TEST(HostCacheTest, HostResolverFlagsArePartOfKey) {}

// Tests that the same hostname can be duplicated in the cache, so long as
// the HostResolverSource differs.
TEST(HostCacheTest, HostResolverSourceIsPartOfKey) {}

// Tests that the same hostname can be duplicated in the cache, so long as
// the secure field in the key differs.
TEST(HostCacheTest, SecureIsPartOfKey) {}

TEST(HostCacheTest, PreferLessStaleMoreSecure) {}

TEST(HostCacheTest, NoCache) {}

TEST(HostCacheTest, Clear) {}

TEST(HostCacheTest, ClearForHosts) {}

// Try to add too many entries to cache; it should evict the one with the oldest
// expiration time.
TEST(HostCacheTest, Evict) {}

// Try to retrieve stale entries from the cache. They should be returned by
// |LookupStale()| but not |Lookup()|, with correct |EntryStaleness| data.
TEST(HostCacheTest, Stale) {}

TEST(HostCacheTest, EvictStale) {}

// Pinned entries should not be evicted, even if the cache is full and the Entry
// has expired.
TEST(HostCacheTest, NoEvictPinned) {}

// Obsolete pinned entries should be evicted normally.
TEST(HostCacheTest, EvictObsoletePinned) {}

// An active pin is preserved if the record is
// replaced due to a Set() call without the pin.
TEST(HostCacheTest, PreserveActivePin) {}

// An obsolete cache pin is not preserved if the record is replaced.
TEST(HostCacheTest, DontPreserveObsoletePin) {}

// An active pin is removed if the record is replaced by a Set() call
// with the pin flag set to false.
TEST(HostCacheTest, Unpin) {}

// Tests the less than and equal operators for HostCache::Key work.
TEST(HostCacheTest, KeyComparators) {}

TEST(HostCacheTest, SerializeAndDeserializeWithExpirations) {}

// Test that any changes between serialization and restore are preferred over
// old restored entries.
TEST(HostCacheTest, SerializeAndDeserializeWithChanges) {}

TEST(HostCacheTest, SerializeAndDeserializeAddresses) {}

TEST(HostCacheTest, SerializeAndDeserializeEntryWithoutScheme) {}

TEST(HostCacheTest, SerializeAndDeserializeWithNetworkAnonymizationKey) {}

TEST(HostCacheTest, SerializeForDebugging) {}

TEST(HostCacheTest, SerializeAndDeserialize_Text) {}

TEST(HostCacheTest, SerializeAndDeserialize_Hostname) {}

TEST(HostCacheTest, SerializeAndDeserializeEndpointResult) {}

TEST(HostCacheTest, DeserializeNoEndpointNoAliase) {}

TEST(HostCacheTest, DeserializeLegacyAddresses) {}

TEST(HostCacheTest, DeserializeInvalidQueryTypeIntegrity) {}

TEST(HostCacheTest, DeserializeInvalidQueryTypeHttpsExperimental) {}

TEST(HostCacheTest, PersistenceDelegate) {}

TEST(HostCacheTest, MergeEndpointsWithAliases) {}

TEST(HostCacheTest, MergeEndpointsKeepEndpointsOrder) {}

TEST(HostCacheTest, MergeMetadatas) {}

TEST(HostCacheTest, MergeMetadatasWithIpEndpointsDifferentCanonicalName) {}

TEST(HostCacheTest, MergeMetadatasWithIpEndpointsMatchingCanonicalName) {}

TEST(HostCacheTest, MergeMultipleMetadatasWithIpEndpoints) {}

TEST(HostCacheTest, MergeAliases) {}

TEST(HostCacheTest, MergeEntries_frontEmpty) {}

TEST(HostCacheTest, MergeEntries_backEmpty) {}

TEST(HostCacheTest, MergeEntries_bothEmpty) {}

TEST(HostCacheTest, MergeEntries_frontWithAliasesNoAddressesBackWithBoth) {}

TEST(HostCacheTest, MergeEntries_backWithAliasesNoAddressesFrontWithBoth) {}

TEST(HostCacheTest, MergeEntries_frontWithAddressesNoAliasesBackWithBoth) {}

TEST(HostCacheTest, MergeEntries_backWithAddressesNoAliasesFrontWithBoth) {}

TEST(HostCacheTest, MergeEntries_differentTtl) {}

TEST(HostCacheTest, MergeEntries_FrontCannonnamePreserved) {}

// Test that the back canonname can be used if there is no front cannonname.
TEST(HostCacheTest, MergeEntries_BackCannonnameUsable) {}

TEST(HostCacheTest, ConvertFromInternalAddressResult) {}

TEST(HostCacheTest, ConvertFromInternalMetadataResult) {}

// Test the case of compatible HTTPS records but no metadata of use to Chrome.
// Represented in internal result type as an empty metadata result. Represented
// in HostCache::Entry as empty metadata with at least one true in
// `https_record_compatibility_`.
TEST(HostCacheTest, ConvertFromCompatibleOnlyInternalMetadataResult) {}

TEST(HostCacheTest, ConvertFromInternalErrorResult) {}

TEST(HostCacheTest, ConvertFromNonCachableInternalErrorResult) {}

TEST(HostCacheTest, ConvertFromInternalAliasOnlyResult) {}

TEST(HostCacheTest, ConvertFromEmptyInternalResult) {}

}  // namespace net