#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "net/websockets/websocket_stream.h"
#include <algorithm>
#include <iterator>
#include <string>
#include <string_view>
#include <tuple>
#include <utility>
#include <vector>
#include "base/check_op.h"
#include "base/containers/span.h"
#include "base/memory/weak_ptr.h"
#include "base/metrics/histogram_samples.h"
#include "base/run_loop.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/scoped_feature_list.h"
#include "base/timer/mock_timer.h"
#include "base/timer/timer.h"
#include "net/base/auth.h"
#include "net/base/features.h"
#include "net/base/isolation_info.h"
#include "net/base/net_errors.h"
#include "net/base/request_priority.h"
#include "net/base/test_completion_callback.h"
#include "net/base/url_util.h"
#include "net/cookies/cookie_setting_override.h"
#include "net/cookies/site_for_cookies.h"
#include "net/http/http_network_session.h"
#include "net/http/http_request_headers.h"
#include "net/http/http_response_headers.h"
#include "net/log/net_log_with_source.h"
#include "net/socket/next_proto.h"
#include "net/socket/socket_test_util.h"
#include "net/spdy/spdy_test_util_common.h"
#include "net/ssl/ssl_info.h"
#include "net/storage_access_api/status.h"
#include "net/test/cert_test_util.h"
#include "net/test/gtest_util.h"
#include "net/test/test_data_directory.h"
#include "net/third_party/quiche/src/quiche/common/http/http_header_block.h"
#include "net/third_party/quiche/src/quiche/http2/test_tools/spdy_test_utils.h"
#include "net/third_party/quiche/src/quiche/spdy/core/spdy_protocol.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_test_util.h"
#include "net/websockets/websocket_frame.h"
#include "net/websockets/websocket_handshake_request_info.h"
#include "net/websockets/websocket_handshake_response_info.h"
#include "net/websockets/websocket_handshake_stream_base.h"
#include "net/websockets/websocket_stream_create_test_base.h"
#include "net/websockets/websocket_test_util.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "url/gurl.h"
#include "url/origin.h"
IsError;
IsOk;
TestWithParam;
Values;
namespace net {
namespace {
enum HandshakeStreamType { … };
std::unique_ptr<SequencedSocketData> BuildSocketData(
base::span<MockRead> reads,
base::span<MockWrite> writes) { … }
std::unique_ptr<SequencedSocketData> BuildNullSocketData() { … }
class MockWeakTimer : public base::MockOneShotTimer { … };
constexpr char kOrigin[] = …;
static url::Origin Origin() { … }
static net::SiteForCookies SiteForCookies() { … }
static IsolationInfo CreateIsolationInfo() { … }
class WebSocketStreamCreateTest
: public TestWithParam<std::tuple<HandshakeStreamType, bool>>,
public WebSocketStreamCreateTestBase { … };
INSTANTIATE_TEST_SUITE_P(…);
WebSocketMultiProtocolStreamCreateTest;
INSTANTIATE_TEST_SUITE_P(…);
class WebSocketStreamCreateExtensionTest
: public WebSocketMultiProtocolStreamCreateTest { … };
INSTANTIATE_TEST_SUITE_P(…);
class CommonAuthTestHelper { … };
class WebSocketStreamCreateBasicAuthTest : public WebSocketStreamCreateTest { … };
INSTANTIATE_TEST_SUITE_P(…);
class WebSocketStreamCreateDigestAuthTest : public WebSocketStreamCreateTest { … };
INSTANTIATE_TEST_SUITE_P(…);
const char WebSocketStreamCreateBasicAuthTest::kUnauthorizedResponse[] = …;
const char WebSocketStreamCreateDigestAuthTest::kUnauthorizedResponse[] = …;
const char WebSocketStreamCreateDigestAuthTest::kAuthorizedRequest[] = …;
TEST_P(WebSocketMultiProtocolStreamCreateTest, SimpleSuccess) { … }
TEST_P(WebSocketStreamCreateTest, HandshakeInfo) { … }
TEST_P(WebSocketStreamCreateTest, HandshakeOverrideHeaders) { … }
TEST_P(WebSocketStreamCreateTest, OmitsHasStorageAccess) { … }
TEST_P(WebSocketStreamCreateTest, PlumbsHasStorageAccess) { … }
TEST_P(WebSocketStreamCreateTest, NeedsToRunLoop) { … }
TEST_P(WebSocketMultiProtocolStreamCreateTest, PathIsUsed) { … }
TEST_P(WebSocketMultiProtocolStreamCreateTest, SubProtocolIsUsed) { … }
TEST_P(WebSocketMultiProtocolStreamCreateTest, UnsolicitedSubProtocol) { … }
TEST_P(WebSocketMultiProtocolStreamCreateTest, UnacceptedSubProtocol) { … }
TEST_P(WebSocketMultiProtocolStreamCreateTest, MultipleSubProtocolsInResponse) { … }
TEST_P(WebSocketMultiProtocolStreamCreateTest, UnmatchedSubProtocolInResponse) { … }
TEST_P(WebSocketStreamCreateExtensionTest, PerMessageDeflateSuccess) { … }
TEST_P(WebSocketStreamCreateExtensionTest, PerMessageDeflateParamsSuccess) { … }
TEST_P(WebSocketStreamCreateExtensionTest, PerMessageDeflateInflates) { … }
TEST_P(WebSocketStreamCreateExtensionTest, UnknownExtension) { … }
TEST_P(WebSocketStreamCreateExtensionTest, MalformedExtension) { … }
TEST_P(WebSocketStreamCreateExtensionTest, OnlyOnePerMessageDeflateAllowed) { … }
TEST_P(WebSocketStreamCreateExtensionTest, NoMaxWindowBitsArgument) { … }
TEST_P(WebSocketStreamCreateTest, DoubleAccept) { … }
TEST_P(WebSocketMultiProtocolStreamCreateTest, InvalidStatusCode) { … }
TEST_P(WebSocketMultiProtocolStreamCreateTest, RedirectsRejected) { … }
TEST_P(WebSocketStreamCreateTest, MalformedResponse) { … }
TEST_P(WebSocketStreamCreateTest, MissingUpgradeHeader) { … }
TEST_P(WebSocketStreamCreateTest, DoubleUpgradeHeader) { … }
TEST_P(WebSocketStreamCreateTest, IncorrectUpgradeHeader) { … }
TEST_P(WebSocketStreamCreateTest, MissingConnectionHeader) { … }
TEST_P(WebSocketStreamCreateTest, IncorrectConnectionHeader) { … }
TEST_P(WebSocketStreamCreateTest, AdditionalTokenInConnectionHeader) { … }
TEST_P(WebSocketStreamCreateTest, MissingSecWebSocketAccept) { … }
TEST_P(WebSocketStreamCreateTest, WrongSecWebSocketAccept) { … }
TEST_P(WebSocketStreamCreateTest, Cancellation) { … }
TEST_P(WebSocketStreamCreateTest, ConnectionFailure) { … }
TEST_P(WebSocketStreamCreateTest, ConnectionTimeout) { … }
TEST_P(WebSocketStreamCreateTest, HandshakeTimeout) { … }
TEST_P(WebSocketStreamCreateTest, HandshakeTimerOnSuccess) { … }
TEST_P(WebSocketStreamCreateTest, HandshakeTimerOnFailure) { … }
TEST_P(WebSocketStreamCreateTest, CancellationDuringConnect) { … }
TEST_P(WebSocketStreamCreateTest, CancellationDuringWrite) { … }
TEST_P(WebSocketStreamCreateTest, CancellationDuringRead) { … }
TEST_P(WebSocketStreamCreateTest, VeryLargeResponseHeaders) { … }
TEST_P(WebSocketStreamCreateTest, NoResponse) { … }
TEST_P(WebSocketStreamCreateTest, SelfSignedCertificateFailure) { … }
TEST_P(WebSocketStreamCreateTest, SelfSignedCertificateSuccess) { … }
TEST_P(WebSocketStreamCreateBasicAuthTest, FailureNoCredentials) { … }
TEST_P(WebSocketStreamCreateBasicAuthTest, SuccessPasswordInUrl) { … }
TEST_P(WebSocketStreamCreateBasicAuthTest, FailureIncorrectPasswordInUrl) { … }
TEST_P(WebSocketStreamCreateBasicAuthTest, SuccessfulConnectionReuse) { … }
TEST_P(WebSocketStreamCreateBasicAuthTest, OnAuthRequiredCancelAuth) { … }
TEST_P(WebSocketStreamCreateBasicAuthTest, OnAuthRequiredSetAuth) { … }
TEST_P(WebSocketStreamCreateDigestAuthTest, DigestPasswordInUrl) { … }
TEST_P(WebSocketMultiProtocolStreamCreateTest, Incomplete) { … }
TEST_P(WebSocketMultiProtocolStreamCreateTest, Http2StreamReset) { … }
TEST_P(WebSocketStreamCreateTest, HandleErrConnectionClosed) { … }
TEST_P(WebSocketStreamCreateTest, HandleErrTunnelConnectionFailed) { … }
TEST_P(WebSocketStreamCreateTest, CancelSSLRequestAfterDelete) { … }
TEST_P(WebSocketStreamCreateTest, ContinueSSLRequestAfterDelete) { … }
TEST_P(WebSocketStreamCreateTest, HandleConnectionCloseInFirstSegment) { … }
}
}