#include "services/network/network_service.h"
#include <cstdint>
#include <memory>
#include <optional>
#include <string_view>
#include <utility>
#include "base/base64.h"
#include "base/command_line.h"
#include "base/containers/span.h"
#include "base/files/file_util.h"
#include "base/files/scoped_temp_dir.h"
#include "base/functional/bind.h"
#include "base/path_service.h"
#include "base/ranges/algorithm.h"
#include "base/run_loop.h"
#include "base/strings/escape.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "base/test/bind.h"
#include "base/test/scoped_feature_list.h"
#include "base/test/task_environment.h"
#include "base/test/test_future.h"
#include "base/test/values_test_util.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "components/os_crypt/async/browser/test_utils.h"
#include "components/os_crypt/sync/os_crypt_mocker.h"
#include "components/privacy_sandbox/masked_domain_list/masked_domain_list.pb.h"
#include "mojo/public/cpp/base/proto_wrapper.h"
#include "net/base/ip_address.h"
#include "net/base/ip_endpoint.h"
#include "net/base/mock_network_change_notifier.h"
#include "net/base/url_util.h"
#include "net/cookies/canonical_cookie.h"
#include "net/cookies/cookie_options.h"
#include "net/cookies/cookie_util.h"
#include "net/dns/dns_client.h"
#include "net/dns/dns_config.h"
#include "net/dns/dns_config_service.h"
#include "net/dns/dns_test_util.h"
#include "net/dns/host_resolver.h"
#include "net/dns/host_resolver_manager.h"
#include "net/dns/public/dns_over_https_config.h"
#include "net/dns/public/dns_protocol.h"
#include "net/dns/public/doh_provider_entry.h"
#include "net/http/http_auth_handler_factory.h"
#include "net/http/http_auth_scheme.h"
#include "net/http/http_network_session.h"
#include "net/http/http_transaction_factory.h"
#include "net/http/transport_security_state.h"
#include "net/log/file_net_log_observer.h"
#include "net/net_buildflags.h"
#include "net/socket/client_socket_pool_manager.h"
#include "net/test/embedded_test_server/embedded_test_server.h"
#include "net/test/embedded_test_server/http_request.h"
#include "net/test/embedded_test_server/http_response.h"
#include "net/test/spawned_test_server/spawned_test_server.h"
#include "net/test/test_data_directory.h"
#include "net/traffic_annotation/network_traffic_annotation_test_helper.h"
#include "net/url_request/url_request_context.h"
#include "services/network/network_context.h"
#include "services/network/public/cpp/features.h"
#include "services/network/public/cpp/network_switches.h"
#include "services/network/public/mojom/cookie_encryption_provider.mojom.h"
#include "services/network/public/mojom/cookie_manager.mojom.h"
#include "services/network/public/mojom/host_resolver.mojom.h"
#include "services/network/public/mojom/net_log.mojom.h"
#include "services/network/public/mojom/network_annotation_monitor.mojom.h"
#include "services/network/public/mojom/network_change_manager.mojom.h"
#include "services/network/public/mojom/network_context.mojom.h"
#include "services/network/public/mojom/network_service.mojom.h"
#include "services/network/public/mojom/system_dns_resolution.mojom.h"
#include "services/network/test/fake_test_cert_verifier_params_factory.h"
#include "services/network/test/test_network_context_client.h"
#include "services/network/test/test_url_loader_client.h"
#include "services/network/test/test_url_loader_network_observer.h"
#include "services/network/test/test_utils.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "url/gurl.h"
#if BUILDFLAG(USE_KERBEROS)
#include "net/http/http_auth_handler_negotiate.h"
#endif
#if BUILDFLAG(IS_CHROMEOS_ASH)
#include "services/network/mock_mojo_dhcp_wpad_url_client.h"
#endif
#if BUILDFLAG(ENABLE_WEBSOCKETS)
#include "services/network/test_mojo_proxy_resolver_factory.h"
#endif
namespace network {
namespace {
const base::FilePath::CharType kServicesTestData[] = …);
GURL AddQuery(const GURL& url,
const std::string& key,
const std::string& value) { … }
mojom::NetworkContextParamsPtr CreateContextParams() { … }
class NetworkServiceTest : public testing::Test { … };
TEST_F(NetworkServiceTest, CreateAndDestroyContext) { … }
TEST_F(NetworkServiceTest, DestroyingServiceDestroysContext) { … }
TEST_F(NetworkServiceTest, CreateContextWithoutChannelID) { … }
TEST_F(NetworkServiceTest, CreateContextWithMaskedDomainListProxyConfig) { … }
TEST_F(NetworkServiceTest,
CreateContextWithCustomProxyConfig_MdlConfigIsNotUsed) { … }
TEST_F(NetworkServiceTest, CreateContextWithoutMaskedDomainListData) { … }
TEST_F(NetworkServiceTest, AuthDefaultParams) { … }
TEST_F(NetworkServiceTest, AuthSchemesDynamicallyChanging) { … }
TEST_F(NetworkServiceTest, AuthSchemesNone) { … }
#if BUILDFLAG(USE_EXTERNAL_GSSAPI)
TEST_F(NetworkServiceTest, AuthGssapiLibraryName) { … }
#endif
TEST_F(NetworkServiceTest, AuthServerAllowlist) { … }
TEST_F(NetworkServiceTest, AuthDelegateAllowlist) { … }
TEST_F(NetworkServiceTest, DelegateByKdcPolicy) { … }
TEST_F(NetworkServiceTest, AuthNegotiateCnameLookup) { … }
TEST_F(NetworkServiceTest, AuthEnableNegotiatePort) { … }
#if !BUILDFLAG(IS_IOS)
TEST_F(NetworkServiceTest, DnsClientEnableDisable) { … }
TEST_F(NetworkServiceTest, HandlesAdditionalDnsQueryTypesEnableDisable) { … }
TEST_F(NetworkServiceTest, DnsOverHttpsEnableDisable) { … }
TEST_F(NetworkServiceTest, DisableDohUpgradeProviders) { … }
TEST_F(NetworkServiceTest, DohProbe) { … }
TEST_F(NetworkServiceTest, DohProbe_MultipleContexts) { … }
TEST_F(NetworkServiceTest, DohProbe_ContextAddedBeforeTimeout) { … }
TEST_F(NetworkServiceTest, DohProbe_ContextAddedAfterTimeout) { … }
TEST_F(NetworkServiceTest, DohProbe_ContextRemovedBeforeTimeout) { … }
TEST_F(NetworkServiceTest, DohProbe_ContextRemovedAfterTimeout) { … }
#endif
#if BUILDFLAG(IS_POSIX)
TEST_F(NetworkServiceTest, AuthNtlmV2Enabled) { … }
#endif
#if BUILDFLAG(IS_ANDROID)
TEST_F(NetworkServiceTest, AuthAndroidNegotiateAccountType) {
const char kInitialAccountType[] = "Scorpio";
const char kFinalAccountType[] = "Pisces";
mojom::HttpAuthDynamicParamsPtr auth_params =
mojom::HttpAuthDynamicParams::New();
auth_params->android_negotiate_account_type = kInitialAccountType;
service()->ConfigureHttpAuthPrefs(std::move(auth_params));
mojo::Remote<mojom::NetworkContext> network_context_remote;
NetworkContext network_context(
service(), network_context_remote.BindNewPipeAndPassReceiver(),
CreateContextParams());
net::HttpAuthHandlerFactory* auth_handler_factory =
network_context.url_request_context()->http_auth_handler_factory();
ASSERT_TRUE(auth_handler_factory);
ASSERT_TRUE(auth_handler_factory->http_auth_preferences());
EXPECT_EQ(kInitialAccountType, auth_handler_factory->http_auth_preferences()
->AuthAndroidNegotiateAccountType());
auth_params = mojom::HttpAuthDynamicParams::New();
auth_params->android_negotiate_account_type = kFinalAccountType;
service()->ConfigureHttpAuthPrefs(std::move(auth_params));
EXPECT_EQ(kFinalAccountType, auth_handler_factory->http_auth_preferences()
->AuthAndroidNegotiateAccountType());
}
#endif
static int GetGlobalMaxConnectionsPerProxyChain() { … }
TEST_F(NetworkServiceTest, SetMaxConnectionsPerProxyChain) { … }
#if BUILDFLAG(IS_CT_SUPPORTED)
TEST_F(NetworkServiceTest, DisableCTEnforcement) { … }
#endif
TEST_F(NetworkServiceTest, SetMaskedDomainList) { … }
class TestCookieEncryptionProvider : public mojom::CookieEncryptionProvider { … };
class NetworkServiceCookieTest
: public NetworkServiceTest,
public testing::WithParamInterface<
std::tuple< bool, bool>> { … };
TEST_P(NetworkServiceCookieTest, CookieEncryptionProvider) { … }
INSTANTIATE_TEST_SUITE_P(…);
class NetworkServiceTestWithService : public testing::Test { … };
TEST_F(NetworkServiceTestWithService, Basic) { … }
TEST_F(NetworkServiceTestWithService, StartsNetLog) { … }
TEST_F(NetworkServiceTestWithService, StartsNetLogBounded) { … }
TEST_F(NetworkServiceTestWithService, RawRequestHeadersAbsent) { … }
class NetworkServiceTestWithResolverMap : public NetworkServiceTestWithService { … };
TEST_F(NetworkServiceTestWithService, SetNetworkConditions) { … }
TEST_F(NetworkServiceTestWithService, SetsTrustTokenKeyCommitments) { … }
TEST_F(NetworkServiceTestWithService, GetDnsConfigChangeManager) { … }
TEST_F(NetworkServiceTestWithService, GetNetworkList) { … }
class TestNetworkChangeManagerClient
: public mojom::NetworkChangeManagerClient { … };
class NetworkChangeTest : public testing::Test { … };
TEST_F(NetworkChangeTest, NetworkChangeManagerRequest) { … }
class NetworkServiceNetworkChangeTest : public testing::Test { … };
TEST_F(NetworkServiceNetworkChangeTest, NetworkChangeManagerRequest) { … }
class NetworkServiceNetworkDelegateTest : public NetworkServiceTest { … };
class ClearSiteDataAuthCertObserver : public TestURLLoaderNetworkObserver { … };
TEST_F(NetworkServiceNetworkDelegateTest, ClearSiteDataObserver) { … }
TEST_F(NetworkServiceNetworkDelegateTest, HandleClearSiteDataHeaders) { … }
class TestNetworkAnnotationMonitor : public mojom::NetworkAnnotationMonitor { … };
TEST_F(NetworkServiceNetworkDelegateTest, NetworkAnnotationMonitor) { … }
#if BUILDFLAG(ENABLE_WEBSOCKETS)
TEST_F(NetworkServiceNetworkDelegateTest,
NetworkAnnotationMonitorWithoutLoader) { … }
#endif
class NetworkServiceTestWithSystemDnsResolver
: public NetworkServiceTestWithService { … };
class StubHostResolverClient : public mojom::ResolveHostClient { … };
TEST_F(NetworkServiceTestWithSystemDnsResolver,
HandlesDeadSystemDnsResolverService) { … }
TEST_F(NetworkServiceTest, NetworkAnnotationMonitor) { … }
}
}