#include <stdint.h>
#include <memory>
#include <optional>
#include <string>
#include <string_view>
#include <utility>
#include <vector>
#include "base/check.h"
#include "base/containers/span.h"
#include "base/files/file_path.h"
#include "base/functional/bind.h"
#include "base/functional/callback.h"
#include "base/location.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/scoped_refptr.h"
#include "base/run_loop.h"
#include "base/strings/strcat.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/stringprintf.h"
#include "base/task/single_thread_task_runner.h"
#include "base/test/scoped_feature_list.h"
#include "build/build_config.h"
#include "net/base/auth.h"
#include "net/base/connection_endpoint_metadata.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/isolation_info.h"
#include "net/base/net_errors.h"
#include "net/base/proxy_chain.h"
#include "net/base/proxy_delegate.h"
#include "net/base/request_priority.h"
#include "net/base/url_util.h"
#include "net/cookies/site_for_cookies.h"
#include "net/dns/host_resolver.h"
#include "net/dns/mock_host_resolver.h"
#include "net/dns/public/host_resolver_results.h"
#include "net/http/http_request_headers.h"
#include "net/log/net_log.h"
#include "net/proxy_resolution/configured_proxy_resolution_service.h"
#include "net/proxy_resolution/proxy_bypass_rules.h"
#include "net/proxy_resolution/proxy_config.h"
#include "net/proxy_resolution/proxy_config_service.h"
#include "net/proxy_resolution/proxy_config_service_fixed.h"
#include "net/proxy_resolution/proxy_config_with_annotation.h"
#include "net/proxy_resolution/proxy_info.h"
#include "net/proxy_resolution/proxy_resolution_service.h"
#include "net/proxy_resolution/proxy_retry_info.h"
#include "net/ssl/ssl_server_config.h"
#include "net/storage_access_api/status.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/ssl_test_util.h"
#include "net/test/test_data_directory.h"
#include "net/test/test_with_task_environment.h"
#include "net/traffic_annotation/network_traffic_annotation_test_helper.h"
#include "net/url_request/url_request.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 "net/websockets/websocket_channel.h"
#include "net/websockets/websocket_event_interface.h"
#include "net/websockets/websocket_handshake_response_info.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/abseil-cpp/absl/types/variant.h"
#include "url/gurl.h"
#include "url/origin.h"
#include "url/url_constants.h"
namespace net {
class HttpResponseHeaders;
class ProxyServer;
class SSLInfo;
struct WebSocketHandshakeRequestInfo;
namespace {
BasicHttpResponse;
HttpRequest;
HttpResponse;
static constexpr char kEchoServer[] = …;
GURL ReplaceUrlScheme(const GURL& in_url, std::string_view scheme) { … }
class ConnectTestingEventInterface : public WebSocketEventInterface { … };
ConnectTestingEventInterface::ConnectTestingEventInterface() = default;
void ConnectTestingEventInterface::WaitForResponse() { … }
std::string ConnectTestingEventInterface::failure_message() const { … }
std::string ConnectTestingEventInterface::selected_subprotocol() const { … }
std::string ConnectTestingEventInterface::extensions() const { … }
void ConnectTestingEventInterface::OnAddChannelResponse(
std::unique_ptr<WebSocketHandshakeResponseInfo> response,
const std::string& selected_subprotocol,
const std::string& extensions) { … }
void ConnectTestingEventInterface::OnDataFrame(bool fin,
WebSocketMessageType type,
base::span<const char> payload) { … }
void ConnectTestingEventInterface::OnSendDataFrameDone() { … }
void ConnectTestingEventInterface::OnClosingHandshake() { … }
void ConnectTestingEventInterface::OnDropChannel(bool was_clean,
uint16_t code,
const std::string& reason) { … }
void ConnectTestingEventInterface::OnFailChannel(
const std::string& message,
int net_error,
std::optional<int> response_code) { … }
void ConnectTestingEventInterface::OnStartOpeningHandshake(
std::unique_ptr<WebSocketHandshakeRequestInfo> request) { … }
void ConnectTestingEventInterface::OnSSLCertificateError(
std::unique_ptr<SSLErrorCallbacks> ssl_error_callbacks,
const GURL& url,
int net_error,
const SSLInfo& ssl_info,
bool fatal) { … }
int ConnectTestingEventInterface::OnAuthRequired(
const AuthChallengeInfo& auth_info,
scoped_refptr<HttpResponseHeaders> response_headers,
const IPEndPoint& remote_endpoint,
base::OnceCallback<void(const AuthCredentials*)> callback,
std::optional<AuthCredentials>* credentials) { … }
void ConnectTestingEventInterface::QuitNestedEventLoop() { … }
class TestProxyDelegateWithProxyInfo : public ProxyDelegate { … };
class WebSocketEndToEndTest : public TestWithTaskEnvironment { … };
TEST_F(WebSocketEndToEndTest, BasicSmokeTest) { … }
#if BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_FUCHSIA)
#define MAYBE_HttpsProxyUnauthedFails …
#define MAYBE_HttpsWssProxyUnauthedFails …
#define MAYBE_HttpsProxyUsed …
#else
#define MAYBE_HttpsProxyUnauthedFails …
#define MAYBE_HttpsWssProxyUnauthedFails …
#define MAYBE_HttpsProxyUsed …
#endif
TEST_F(WebSocketEndToEndTest, MAYBE_HttpsProxyUnauthedFails) { … }
TEST_F(WebSocketEndToEndTest, MAYBE_HttpsWssProxyUnauthedFails) { … }
TEST_F(WebSocketEndToEndTest, MAYBE_HttpsProxyUsed) { … }
std::unique_ptr<HttpResponse> ProxyPacHandler(const HttpRequest& request) { … }
#if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_APPLE)
#define MAYBE_ProxyPacUsed …
#else
#define MAYBE_ProxyPacUsed …
#endif
TEST_F(WebSocketEndToEndTest, MAYBE_ProxyPacUsed) { … }
TEST_F(WebSocketEndToEndTest, TruncatedResponse) { … }
TEST_F(WebSocketEndToEndTest, HstsHttpsToWebSocket) { … }
TEST_F(WebSocketEndToEndTest, HstsWebSocketToHttps) { … }
TEST_F(WebSocketEndToEndTest, HstsWebSocketToWebSocket) { … }
TEST_F(WebSocketEndToEndTest, TrailingWhitespace) { … }
TEST_F(WebSocketEndToEndTest, HeaderContinuations) { … }
TEST_F(WebSocketEndToEndTest, DnsSchemeUpgradeSupported) { … }
TEST_F(WebSocketEndToEndTest, HostResolverEndpointResult) { … }
TEST_F(WebSocketEndToEndTest, EncryptedClientHello) { … }
}
}