#include <atomic>
#include <optional>
#include <string>
#include <unordered_set>
#include <vector>
#include "base/command_line.h"
#include "base/files/file_path.h"
#include "base/files/file_util.h"
#include "base/files/scoped_temp_dir.h"
#include "base/functional/bind.h"
#include "base/location.h"
#include "base/memory/raw_ptr.h"
#include "base/path_service.h"
#include "base/strings/strcat.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "base/task/single_thread_task_runner.h"
#include "base/test/bind.h"
#include "base/threading/thread_restrictions.h"
#include "base/uuid.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/content_settings/cookie_settings_factory.h"
#include "chrome/browser/net/profile_network_context_service.h"
#include "chrome/browser/net/profile_network_context_service_factory.h"
#include "chrome/browser/net/system_network_context_manager.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/safe_browsing/safe_browsing_service.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/pref_names.h"
#include "chrome/common/webui_url_constants.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "components/content_settings/core/browser/cookie_settings.h"
#include "components/content_settings/core/common/content_settings.h"
#include "components/content_settings/core/common/pref_names.h"
#include "components/embedder_support/switches.h"
#include "components/embedder_support/user_agent_utils.h"
#include "components/language/core/browser/pref_names.h"
#include "components/network_session_configurator/common/network_switches.h"
#include "components/policy/core/browser/browser_policy_connector.h"
#include "components/policy/core/common/mock_configuration_policy_provider.h"
#include "components/policy/core/common/policy_map.h"
#include "components/policy/policy_constants.h"
#include "components/prefs/pref_service.h"
#include "components/proxy_config/proxy_config_dictionary.h"
#include "components/proxy_config/proxy_config_pref_names.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/network_service_instance.h"
#include "content/public/browser/network_service_util.h"
#include "content/public/browser/storage_partition.h"
#include "content/public/browser/storage_partition_config.h"
#include "content/public/common/content_switches.h"
#include "content/public/common/url_constants.h"
#include "content/public/test/browser_test.h"
#include "content/public/test/browser_test_utils.h"
#include "content/public/test/simple_url_loader_test_helper.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "mojo/public/cpp/system/data_pipe_utils.h"
#include "net/base/address_list.h"
#include "net/base/filename_util.h"
#include "net/base/host_port_pair.h"
#include "net/base/load_flags.h"
#include "net/base/net_errors.h"
#include "net/cookies/canonical_cookie.h"
#include "net/cookies/cookie_options.h"
#include "net/dns/mock_host_resolver.h"
#include "net/dns/public/resolve_error_info.h"
#include "net/http/http_response_headers.h"
#include "net/reporting/reporting_policy.h"
#include "net/ssl/ssl_config.h"
#include "net/ssl/ssl_server_config.h"
#include "net/test/embedded_test_server/controllable_http_response.h"
#include "net/test/embedded_test_server/default_handlers.h"
#include "net/test/embedded_test_server/embedded_test_server.h"
#include "net/test/embedded_test_server/embedded_test_server_connection_listener.h"
#include "net/test/embedded_test_server/http_request.h"
#include "net/test/embedded_test_server/http_response.h"
#include "net/test/gtest_util.h"
#include "net/test/spawned_test_server/spawned_test_server.h"
#include "net/traffic_annotation/network_traffic_annotation_test_helper.h"
#include "net/url_request/referrer_policy.h"
#include "services/network/public/cpp/features.h"
#include "services/network/public/cpp/network_connection_tracker.h"
#include "services/network/public/cpp/resource_request.h"
#include "services/network/public/cpp/simple_url_loader.h"
#include "services/network/public/mojom/cookie_manager.mojom.h"
#include "services/network/public/mojom/host_resolver.mojom.h"
#include "services/network/public/mojom/network_service.mojom.h"
#include "services/network/public/mojom/url_loader.mojom.h"
#include "services/network/public/mojom/url_loader_factory.mojom.h"
#include "services/network/test/test_dns_util.h"
#include "services/network/test/test_url_loader_client.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "url/gurl.h"
#if BUILDFLAG(IS_MAC)
#include "base/mac/mac_util.h"
#endif
#if BUILDFLAG(ENABLE_EXTENSIONS)
#include "chrome/browser/extensions/chrome_test_extension_loader.h"
#include "extensions/browser/browsertest_util.h"
#include "extensions/test/test_extension_dir.h"
#endif
namespace {
constexpr char kHostname[] = …;
constexpr char kAddress[] = …;
const char kCacheRandomPath[] = …;
const char kControllablePath[] = …;
enum class NetworkServiceState { … };
enum class NetworkContextType { … };
const NetworkContextType kNetworkContextTypes[] = …;
struct TestCase { … };
class ConnectionTypeWaiter
: public network::NetworkConnectionTracker::NetworkConnectionObserver { … };
class NetworkContextConfigurationBrowserTest
: public InProcessBrowserTest,
public testing::WithParamInterface<TestCase> { … };
IN_PROC_BROWSER_TEST_P(NetworkContextConfigurationBrowserTest,
SecureCookiesAllowedForChromeScheme) { … }
#if BUILDFLAG(ENABLE_EXTENSIONS)
std::unique_ptr<net::test_server::HttpResponse> EchoCookieHeader(
const net::test_server::HttpRequest& request) { … }
IN_PROC_BROWSER_TEST_P(NetworkContextConfigurationBrowserTest,
ThirdPartyCookiesAllowedForExtensions) { … }
#endif
IN_PROC_BROWSER_TEST_P(NetworkContextConfigurationBrowserTest, BasicRequest) { … }
IN_PROC_BROWSER_TEST_P(NetworkContextConfigurationBrowserTest, Cache) { … }
IN_PROC_BROWSER_TEST_P(NetworkContextConfigurationBrowserTest, CacheIsolation) { … }
IN_PROC_BROWSER_TEST_P(NetworkContextConfigurationBrowserTest, PRE_DiskCache) { … }
#if BUILDFLAG(IS_MAC)
#define MAYBE_DiskCache …
#else
#define MAYBE_DiskCache …
#endif
IN_PROC_BROWSER_TEST_P(NetworkContextConfigurationBrowserTest,
MAYBE_DiskCache) { … }
IN_PROC_BROWSER_TEST_P(NetworkContextConfigurationBrowserTest,
DnsCacheIsolation) { … }
IN_PROC_BROWSER_TEST_P(NetworkContextConfigurationBrowserTest, PRE_Hsts) { … }
IN_PROC_BROWSER_TEST_P(NetworkContextConfigurationBrowserTest, Hsts) { … }
IN_PROC_BROWSER_TEST_P(NetworkContextConfigurationBrowserTest, ProxyConfig) { … }
IN_PROC_BROWSER_TEST_P(NetworkContextConfigurationBrowserTest,
ShutdownWithLiveRequest) { … }
#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_MAC)
#define MAYBE_UserAgentAndLanguagePrefs …
#else
#define MAYBE_UserAgentAndLanguagePrefs …
#endif
IN_PROC_BROWSER_TEST_P(NetworkContextConfigurationBrowserTest,
MAYBE_UserAgentAndLanguagePrefs) { … }
IN_PROC_BROWSER_TEST_P(NetworkContextConfigurationBrowserTest,
PRE_EnableReferrers) { … }
IN_PROC_BROWSER_TEST_P(NetworkContextConfigurationBrowserTest,
EnableReferrers) { … }
IN_PROC_BROWSER_TEST_P(NetworkContextConfigurationBrowserTest,
PolicyViolatingReferrers) { … }
IN_PROC_BROWSER_TEST_P(NetworkContextConfigurationBrowserTest,
PRE_CookiesEnabled) { … }
IN_PROC_BROWSER_TEST_P(NetworkContextConfigurationBrowserTest,
DISABLED_CookiesEnabled) { … }
IN_PROC_BROWSER_TEST_P(NetworkContextConfigurationBrowserTest,
CookieIsolation) { … }
#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
#define MAYBE_PRE_ThirdPartyCookiesBlocked …
#define MAYBE_ThirdPartyCookiesBlocked …
#else
#define MAYBE_PRE_ThirdPartyCookiesBlocked …
#define MAYBE_ThirdPartyCookiesBlocked …
#endif
IN_PROC_BROWSER_TEST_P(NetworkContextConfigurationBrowserTest,
MAYBE_PRE_ThirdPartyCookiesBlocked) { … }
IN_PROC_BROWSER_TEST_P(NetworkContextConfigurationBrowserTest,
MAYBE_ThirdPartyCookiesBlocked) { … }
IN_PROC_BROWSER_TEST_P(NetworkContextConfigurationBrowserTest,
PRE_CookieSettings) { … }
IN_PROC_BROWSER_TEST_P(NetworkContextConfigurationBrowserTest, CookieSettings) { … }
IN_PROC_BROWSER_TEST_P(NetworkContextConfigurationBrowserTest, UploadFile) { … }
class NetworkContextConfigurationFixedPortBrowserTest
: public NetworkContextConfigurationBrowserTest { … };
IN_PROC_BROWSER_TEST_P(NetworkContextConfigurationFixedPortBrowserTest,
TestingFixedPort) { … }
class NetworkContextConfigurationProxyOnStartBrowserTest
: public NetworkContextConfigurationBrowserTest { … };
IN_PROC_BROWSER_TEST_P(NetworkContextConfigurationProxyOnStartBrowserTest,
TestInitialProxyConfig) { … }
class NetworkContextConfigurationHttpPacBrowserTest
: public NetworkContextConfigurationBrowserTest { … };
IN_PROC_BROWSER_TEST_P(NetworkContextConfigurationHttpPacBrowserTest, HttpPac) { … }
class NetworkContextConfigurationFilePacBrowserTest
: public NetworkContextConfigurationBrowserTest { … };
IN_PROC_BROWSER_TEST_P(NetworkContextConfigurationFilePacBrowserTest, FilePac) { … }
class NetworkContextConfigurationDataPacBrowserTest
: public NetworkContextConfigurationBrowserTest { … };
IN_PROC_BROWSER_TEST_P(NetworkContextConfigurationDataPacBrowserTest, DataPac) { … }
class NetworkContextConfigurationProxySettingsBrowserTest
: public NetworkContextConfigurationHttpPacBrowserTest { … };
#if BUILDFLAG(IS_MAC)
#define MAYBE_MaxConnectionsPerProxy …
#else
#define MAYBE_MaxConnectionsPerProxy …
#endif
IN_PROC_BROWSER_TEST_P(NetworkContextConfigurationProxySettingsBrowserTest,
MAYBE_MaxConnectionsPerProxy) { … }
class NetworkContextConfigurationManagedProxySettingsBrowserTest
: public NetworkContextConfigurationProxySettingsBrowserTest { … };
#if BUILDFLAG(IS_MAC)
#define MAYBE_MaxConnectionsPerProxy …
#else
#define MAYBE_MaxConnectionsPerProxy …
#endif
IN_PROC_BROWSER_TEST_P(
NetworkContextConfigurationManagedProxySettingsBrowserTest,
MAYBE_MaxConnectionsPerProxy) { … }
#if BUILDFLAG(ENABLE_REPORTING)
class NetworkContextConfigurationReportingAndNelBrowserTest
: public NetworkContextConfigurationBrowserTest { … };
namespace {
constexpr char kReportingEnabledURL[] = …;
constexpr char kCrossOriginReportingEnabledURL[] = …;
}
IN_PROC_BROWSER_TEST_P(NetworkContextConfigurationReportingAndNelBrowserTest,
PRE_PersistReportingAndNel) { … }
IN_PROC_BROWSER_TEST_P(NetworkContextConfigurationReportingAndNelBrowserTest,
PersistReportingAndNel) { … }
#endif
#define TEST_CASES(network_context_type) …
#if BUILDFLAG(ENABLE_EXTENSIONS)
#define INSTANTIATE_EXTENSION_TESTS(TestFixture) …
#else
#define INSTANTIATE_EXTENSION_TESTS …
#endif
#define INSTANTIATE_TEST_CASES_FOR_TEST_FIXTURE(TestFixture) …
INSTANTIATE_TEST_CASES_FOR_TEST_FIXTURE(…);
INSTANTIATE_TEST_CASES_FOR_TEST_FIXTURE(…);
INSTANTIATE_TEST_CASES_FOR_TEST_FIXTURE(…);
INSTANTIATE_TEST_CASES_FOR_TEST_FIXTURE(…);
INSTANTIATE_TEST_CASES_FOR_TEST_FIXTURE(…);
INSTANTIATE_TEST_CASES_FOR_TEST_FIXTURE(…);
INSTANTIATE_TEST_CASES_FOR_TEST_FIXTURE(…);
INSTANTIATE_TEST_CASES_FOR_TEST_FIXTURE(…);
#if BUILDFLAG(ENABLE_REPORTING)
INSTANTIATE_TEST_CASES_FOR_TEST_FIXTURE(…);
#endif
}