chromium/components/cronet/stale_host_resolver_unittest.cc

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

#ifdef UNSAFE_BUFFERS_BUILD
// TODO(crbug.com/40285824): Remove this and convert code to safer constructs.
#pragma allow_unsafe_buffers
#endif

#include "components/cronet/stale_host_resolver.h"

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

#include "base/check.h"
#include "base/functional/bind.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/ref_counted.h"
#include "base/run_loop.h"
#include "base/task/single_thread_task_runner.h"
#include "base/test/simple_test_tick_clock.h"
#include "base/test/task_environment.h"
#include "base/test/test_timeouts.h"
#include "base/time/time.h"
#include "base/values.h"
#include "build/build_config.h"
#include "components/cronet/url_request_context_config.h"
#include "net/base/address_family.h"
#include "net/base/host_port_pair.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_anonymization_key.h"
#include "net/base/network_change_notifier.h"
#include "net/cert/cert_verifier.h"
#include "net/dns/context_host_resolver.h"
#include "net/dns/dns_config.h"
#include "net/dns/dns_hosts.h"
#include "net/dns/dns_test_util.h"
#include "net/dns/host_cache.h"
#include "net/dns/host_resolver_manager.h"
#include "net/dns/host_resolver_proc.h"
#include "net/dns/host_resolver_system_task.h"
#include "net/dns/public/dns_protocol.h"
#include "net/dns/public/dns_query_type.h"
#include "net/dns/public/host_resolver_source.h"
#include "net/http/http_network_session.h"
#include "net/log/net_log_with_source.h"
#include "net/proxy_resolution/proxy_config.h"
#include "net/proxy_resolution/proxy_config_service_fixed.h"
#include "net/url_request/url_request_context.h"
#include "net/url_request/url_request_context_builder.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace cronet {

namespace {

const char kHostname[] =;
const char kCacheAddress[] =;
const char kNetworkAddress[] =;
const char kHostsAddress[] =;
const int kCacheEntryTTLSec =;

const int kNoStaleDelaySec =;
const int kLongStaleDelaySec =;
const uint16_t kPort =;

const int kAgeFreshSec =;
const int kAgeExpiredSec =;

// How long to wait for resolve calls to return. If the tests are working
// correctly, we won't end up waiting this long -- it's just a backup.
const int kWaitTimeoutSec =;

std::vector<net::IPEndPoint> MakeEndpoints(const char* ip_address_str) {}

net::AddressList MakeAddressList(const char* ip_address_str) {}

std::unique_ptr<net::DnsClient> CreateMockDnsClientForHosts() {}

// Create a net::DnsClient where address requests for |kHostname| will hang
// until unblocked via CompleteDelayedTransactions() and then fail.
std::unique_ptr<net::MockDnsClient> CreateHangingMockDnsClient() {}

class MockHostResolverProc : public net::HostResolverProc {};

class StaleHostResolverTest : public testing::Test {};

// Make sure that test harness can be created and destroyed without crashing.
TEST_F(StaleHostResolverTest, Null) {}

// Make sure that resolver can be created and destroyed without crashing.
TEST_F(StaleHostResolverTest, Create) {}

TEST_F(StaleHostResolverTest, Network) {}

TEST_F(StaleHostResolverTest, Hosts) {}

TEST_F(StaleHostResolverTest, FreshCache) {}

// Flaky on Linux ASan, crbug.com/838524.
#if defined(ADDRESS_SANITIZER)
#define MAYBE_StaleCache
#else
#define MAYBE_StaleCache
#endif
TEST_F(StaleHostResolverTest, MAYBE_StaleCache) {}

// If the resolver is destroyed before a stale cache entry is returned, the
// resolve should not complete.
TEST_F(StaleHostResolverTest, StaleCache_DestroyedResolver) {}

// Ensure that |use_stale_on_name_not_resolved| causes stale results to be
// returned when ERR_NAME_NOT_RESOLVED is returned from network resolution.
TEST_F(StaleHostResolverTest, StaleCacheNameNotResolvedEnabled) {}

// Ensure that without |use_stale_on_name_not_resolved| network resolution
// failing causes StaleHostResolver jobs to fail with the same error code.
TEST_F(StaleHostResolverTest, StaleCacheNameNotResolvedDisabled) {}

TEST_F(StaleHostResolverTest, NetworkWithStaleCache) {}

TEST_F(StaleHostResolverTest, CancelWithNoCache) {}

TEST_F(StaleHostResolverTest, CancelWithStaleCache) {}

TEST_F(StaleHostResolverTest, ReturnStaleCacheSync) {}

// CancelWithFreshCache makes no sense; the request would've returned
// synchronously.

// Disallow other networks cases fail under Fuchsia (crbug.com/816143).
// Flaky on Win buildbots. See crbug.com/836106
#if BUILDFLAG(IS_WIN)
#define MAYBE_StaleUsability
#else
#define MAYBE_StaleUsability
#endif
TEST_F(StaleHostResolverTest, MAYBE_StaleUsability) {}

TEST_F(StaleHostResolverTest, CreatedByContext) {}

}  // namespace

}  // namespace cronet