chromium/net/dns/resolve_context_unittest.cc

// Copyright 2020 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/resolve_context.h"

#include <stdint.h>
#include <memory>
#include <string>
#include <utility>

#include "base/functional/bind.h"
#include "base/memory/ref_counted.h"
#include "base/run_loop.h"
#include "base/strings/stringprintf.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/time/time.h"
#include "net/base/address_list.h"
#include "net/base/features.h"
#include "net/base/ip_address.h"
#include "net/base/ip_endpoint.h"
#include "net/base/mock_network_change_notifier.h"
#include "net/base/network_change_notifier.h"
#include "net/base/network_isolation_key.h"
#include "net/dns/dns_config.h"
#include "net/dns/dns_server_iterator.h"
#include "net/dns/dns_session.h"
#include "net/dns/dns_util.h"
#include "net/dns/host_cache.h"
#include "net/dns/public/dns_over_https_config.h"
#include "net/dns/public/dns_over_https_server_config.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/dns/public/secure_dns_mode.h"
#include "net/socket/socket_test_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"

namespace net {

namespace {

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

DnsConfig CreateDnsConfig(int num_servers, int num_doh_servers) {}

DnsConfig CreateDnsConfigWithKnownDohProviderConfig() {}

// Simulate a new session with the same pointer as an old deleted session by
// invalidating WeakPtrs.
TEST_F(ResolveContextTest, ReusedSessionPointer) {}

TEST_F(ResolveContextTest, DohServerAvailability_InitialAvailability) {}

TEST_F(ResolveContextTest, DohServerAvailability_RecordedSuccess) {}

TEST_F(ResolveContextTest, DohServerAvailability_NoCurrentSession) {}

TEST_F(ResolveContextTest, DohServerAvailability_DifferentSession) {}

TEST_F(ResolveContextTest, DohServerIndexToUse) {}

TEST_F(ResolveContextTest, DohServerIndexToUse_NoneEligible) {}

TEST_F(ResolveContextTest, DohServerIndexToUse_SecureMode) {}

TEST_F(ResolveContextTest, StartDohAutoupgradeSuccessTimer) {}

class TestDnsObserver : public NetworkChangeNotifier::DNSObserver {};

TEST_F(ResolveContextTest, DohServerAvailabilityNotification) {}

TEST_F(ResolveContextTest, HostCacheInvalidation) {}

TEST_F(ResolveContextTest, HostCacheInvalidation_SameSession) {}

TEST_F(ResolveContextTest, Failures_Consecutive) {}

TEST_F(ResolveContextTest, Failures_NonConsecutive) {}

TEST_F(ResolveContextTest, Failures_NoSession) {}

TEST_F(ResolveContextTest, Failures_DifferentSession) {}

// Test 2 of 3 servers failing.
TEST_F(ResolveContextTest, TwoFailures) {}

class TestDohStatusObserver : public ResolveContext::DohStatusObserver {};

TEST_F(ResolveContextTest, DohFailures_Consecutive) {}

TEST_F(ResolveContextTest, DohFailures_NonConsecutive) {}

TEST_F(ResolveContextTest, DohFailures_SuccessAfterFailures) {}

TEST_F(ResolveContextTest, DohFailures_NoSession) {}

TEST_F(ResolveContextTest, DohFailures_DifferentSession) {}

TEST_F(ResolveContextTest, DohFailures_NeverSuccessful) {}

// Test that metrics are recorded properly when auto-upgrade is never successful
// for a provider that is in the list of providers where we can auto-upgrade
// insecure DNS queries to secure DNS queries.
TEST_F(ResolveContextTest, DohFailures_NeverSuccessfulKnownProviderConfig) {}

// Test 2 of 3 DoH servers failing.
TEST_F(ResolveContextTest, TwoDohFailures) {}

// Expect default calculated fallback period to be within 10ms of
// |DnsConfig::fallback_period|.
TEST_F(ResolveContextTest, FallbackPeriod_Default) {}

// Expect short calculated fallback period to be within 10ms of
// |DnsConfig::fallback_period|.
TEST_F(ResolveContextTest, FallbackPeriod_ShortConfigured) {}

// Expect long calculated fallback period to be equal to
// |DnsConfig::fallback_period|. (Default max fallback period is 5 seconds, so
// NextClassicFallbackPeriod() should return exactly the config fallback
// period.)
TEST_F(ResolveContextTest, FallbackPeriod_LongConfigured) {}

// Expect fallback periods to increase on recording long round-trip times.
TEST_F(ResolveContextTest, FallbackPeriod_LongRtt) {}

// Expect recording round-trip times to have no affect on fallback period
// without a current session.
TEST_F(ResolveContextTest, FallbackPeriod_NoSession) {}

// Expect recording round-trip times to have no affect on fallback periods
// without a current session.
TEST_F(ResolveContextTest, FallbackPeriod_DifferentSession) {}

// Expect minimum timeout will be used when fallback period is small.
TEST_F(ResolveContextTest, SecureTransactionTimeout_SmallFallbackPeriod) {}

// Expect multiplier on fallback period to be used when larger than minimum
// timeout.
TEST_F(ResolveContextTest, SecureTransactionTimeout_LongFallbackPeriod) {}

TEST_F(ResolveContextTest, SecureTransactionTimeout_LongRtt) {}

TEST_F(ResolveContextTest, SecureTransactionTimeout_DifferentSession) {}

// Expect minimum timeout will be used when fallback period is small.
TEST_F(ResolveContextTest, ClassicTransactionTimeout_SmallFallbackPeriod) {}

// Expect multiplier on fallback period to be used when larger than minimum
// timeout.
TEST_F(ResolveContextTest, ClassicTransactionTimeout_LongFallbackPeriod) {}

TEST_F(ResolveContextTest, ClassicTransactionTimeout_LongRtt) {}

TEST_F(ResolveContextTest, ClassicTransactionTimeout_DifferentSession) {}

// Ensures that reported negative RTT values don't cause a crash. Regression
// test for https://crbug.com/753568.
TEST_F(ResolveContextTest, NegativeRtt) {}

TEST_F(ResolveContextTest, SessionChange) {}

TEST_F(ResolveContextTest, SessionChange_NoSession) {}

TEST_F(ResolveContextTest, SessionChange_NoDohServers) {}

}  // namespace
}  // namespace net