chromium/net/dns/context_host_resolver_unittest.cc

// Copyright 2019 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/context_host_resolver.h"

#include <memory>
#include <optional>
#include <utility>

#include "base/containers/fixed_flat_map.h"
#include "base/functional/bind.h"
#include "base/memory/raw_ptr.h"
#include "base/run_loop.h"
#include "base/test/scoped_feature_list.h"
#include "base/test/simple_test_tick_clock.h"
#include "base/test/task_environment.h"
#include "base/time/time.h"
#include "net/base/features.h"
#include "net/base/host_port_pair.h"
#include "net/base/ip_address.h"
#include "net/base/ip_endpoint.h"
#include "net/base/mock_network_change_notifier.h"
#include "net/base/net_errors.h"
#include "net/base/network_isolation_key.h"
#include "net/base/schemeful_site.h"
#include "net/base/test_completion_callback.h"
#include "net/dns/dns_config.h"
#include "net/dns/dns_test_util.h"
#include "net/dns/dns_util.h"
#include "net/dns/host_cache.h"
#include "net/dns/host_resolver.h"
#include "net/dns/host_resolver_manager.h"
#include "net/dns/host_resolver_results_test_util.h"
#include "net/dns/host_resolver_system_task.h"
#include "net/dns/mock_host_resolver.h"
#include "net/dns/public/dns_over_https_config.h"
#include "net/dns/public/dns_protocol.h"
#include "net/dns/public/host_resolver_source.h"
#include "net/dns/public/resolve_error_info.h"
#include "net/dns/resolve_context.h"
#include "net/log/net_log_with_source.h"
#include "net/test/gtest_util.h"
#include "net/test/test_with_task_environment.h"
#include "net/url_request/url_request_context.h"
#include "net/url_request/url_request_context_builder.h"
#include "net/url_request/url_request_test_util.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"

#if BUILDFLAG(IS_ANDROID)
#include "base/android/build_info.h"
#include "net/android/network_change_notifier_factory_android.h"
#endif  // BUILDFLAG(IS_ANDROID)

namespace net {

namespace {
const IPEndPoint kEndpoint(IPAddress(1, 2, 3, 4), 100);
}

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

TEST_F(ContextHostResolverTest, Resolve) {}

TEST_F(ContextHostResolverTest, ResolveWithScheme) {}

TEST_F(ContextHostResolverTest, ResolveWithSchemeAndIpLiteral) {}

// Test that destroying a request silently cancels that request.
TEST_F(ContextHostResolverTest, DestroyRequest) {}

TEST_F(ContextHostResolverTest, DohProbeRequest) {}

TEST_F(ContextHostResolverTest, DohProbesFromSeparateContexts) {}

// Test that cancelling a resolver cancels its (and only its) requests.
TEST_F(ContextHostResolverTest, DestroyResolver) {}

TEST_F(ContextHostResolverTest, DestroyResolver_CompletedRequests) {}

// Test a request created before resolver destruction but not yet started.
TEST_F(ContextHostResolverTest, DestroyResolver_DelayedStartRequest) {}

TEST_F(ContextHostResolverTest, DestroyResolver_DelayedStartDohProbeRequest) {}

TEST_F(ContextHostResolverTest, OnShutdown_PendingRequest) {}

TEST_F(ContextHostResolverTest, OnShutdown_CompletedRequests) {}

TEST_F(ContextHostResolverTest, OnShutdown_SubsequentRequests) {}

TEST_F(ContextHostResolverTest, OnShutdown_SubsequentDohProbeRequest) {}

// Test a request created before shutdown but not yet started.
TEST_F(ContextHostResolverTest, OnShutdown_DelayedStartRequest) {}

TEST_F(ContextHostResolverTest, OnShutdown_DelayedStartDohProbeRequest) {}

TEST_F(ContextHostResolverTest, ResolveFromCache) {}

TEST_F(ContextHostResolverTest, ResultsAddedToCache) {}

// Do a lookup with a NetworkIsolationKey, and then make sure the entry added to
// the cache is in fact using that NetworkIsolationKey.
TEST_F(ContextHostResolverTest, ResultsAddedToCacheWithNetworkIsolationKey) {}

// Test that the underlying HostCache can receive invalidations from the manager
// and that it safely does not receive invalidations after the resolver (and the
// HostCache) is destroyed.
TEST_F(ContextHostResolverTest, HostCacheInvalidation) {}

class FakeServiceEndpontRequestDelegate
    : public HostResolver::ServiceEndpointRequest::Delegate {};

class ContextHostResolverServiceEndpointTest : public ContextHostResolverTest {};

TEST_F(ContextHostResolverServiceEndpointTest, Resolve) {}

TEST_F(ContextHostResolverServiceEndpointTest, DestroyResolver) {}

class NetworkBoundResolveContext : public ResolveContext {};

// A mock HostResolverProc which returns different IP addresses based on the
// `network` parameter received.
class NetworkAwareHostResolverProc : public HostResolverProc {};

TEST_F(ContextHostResolverTest, ExistingNetworkBoundLookup) {}

TEST_F(ContextHostResolverTest, NotExistingNetworkBoundLookup) {}

// Test that the underlying HostCache does not receive invalidations when its
// ResolveContext/HostResolverManager is bound to a network.
TEST_F(ContextHostResolverTest, NetworkBoundResolverCacheInvalidation) {}

}  // namespace net