Chromium Code Reviews| Index: net/http/http_network_transaction_unittest.cc |
| diff --git a/net/http/http_network_transaction_unittest.cc b/net/http/http_network_transaction_unittest.cc |
| index 7846028187a746511d5ad2cb339f436955757dcc..78df5347b2b10256042ce5de92d6f68a164b5e98 100644 |
| --- a/net/http/http_network_transaction_unittest.cc |
| +++ b/net/http/http_network_transaction_unittest.cc |
| @@ -64,6 +64,7 @@ |
| #include "net/ssl/ssl_config_service_defaults.h" |
| #include "net/ssl/ssl_info.h" |
| #include "net/test/cert_test_util.h" |
| +#include "net/websockets/websocket_handshake_stream_base.h" |
| #include "testing/gtest/include/gtest/gtest.h" |
| #include "testing/platform_test.h" |
| #include "url/gurl.h" |
| @@ -11957,12 +11958,24 @@ class FakeStreamRequest : public HttpStreamRequest, |
| FakeStreamRequest(RequestPriority priority, |
| HttpStreamRequest::Delegate* delegate) |
| : priority_(priority), |
| - delegate_(delegate) {} |
| + delegate_(delegate), |
| + websocket_stream_factory_(NULL) {} |
| + FakeStreamRequest(RequestPriority priority, |
|
szym
2013/11/08 20:45:51
nit: Add blank line after multi-line implementatio
Adam Rice
2013/11/11 02:06:22
Done.
|
| + HttpStreamRequest::Delegate* delegate, |
| + WebSocketHandshakeStreamBase::Factory* factory) |
| + : priority_(priority), |
| + delegate_(delegate), |
| + websocket_stream_factory_(factory) {} |
| virtual ~FakeStreamRequest() {} |
| RequestPriority priority() const { return priority_; } |
| + const WebSocketHandshakeStreamBase::Factory* websocket_stream_factory() |
| + const { |
| + return websocket_stream_factory_; |
| + } |
| + |
| // Create a new FakeStream and pass it to the request's |
| // delegate. Returns a weak pointer to the FakeStream. |
| base::WeakPtr<FakeStream> FinishStreamRequest() { |
| @@ -12004,6 +12017,7 @@ class FakeStreamRequest : public HttpStreamRequest, |
| private: |
| RequestPriority priority_; |
| HttpStreamRequest::Delegate* const delegate_; |
| + WebSocketHandshakeStreamBase::Factory* websocket_stream_factory_; |
| DISALLOW_COPY_AND_ASSIGN(FakeStreamRequest); |
| }; |
| @@ -12040,8 +12054,10 @@ class FakeStreamFactory : public HttpStreamFactory { |
| HttpStreamRequest::Delegate* delegate, |
| WebSocketHandshakeStreamBase::Factory* factory, |
| const BoundNetLog& net_log) OVERRIDE { |
| - ADD_FAILURE(); |
| - return NULL; |
| + FakeStreamRequest* fake_request = |
| + new FakeStreamRequest(priority, delegate, factory); |
| + last_stream_request_ = fake_request->AsWeakPtr(); |
| + return fake_request; |
| } |
| virtual void PreconnectStreams(int num_streams, |
| @@ -12068,6 +12084,33 @@ class FakeStreamFactory : public HttpStreamFactory { |
| DISALLOW_COPY_AND_ASSIGN(FakeStreamFactory); |
| }; |
| +// TODO(yhirano): Split this class out into a net/websockets file, if it is |
| +// worth doing. |
| +class FakeWebSocketStreamFactory : |
| + public WebSocketHandshakeStreamBase::Factory { |
| + public: |
| + virtual WebSocketHandshakeStreamBase* CreateBasicStream( |
| + ClientSocketHandle* connection, |
| + bool using_proxy) OVERRIDE { |
| + NOTREACHED(); |
| + return NULL; |
| + } |
| + |
| + virtual WebSocketHandshakeStreamBase* CreateSpdyStream( |
| + const base::WeakPtr<SpdySession>& session, |
| + bool use_relative_url) OVERRIDE { |
| + NOTREACHED(); |
| + return NULL; |
| + }; |
| + |
| + virtual ~FakeWebSocketStreamFactory() {} |
| + |
| + virtual scoped_ptr<WebSocketStream> Upgrade() { |
| + NOTREACHED(); |
| + return scoped_ptr<WebSocketStream>(); |
| + } |
| +}; |
| + |
| } // namespace |
| // Make sure that HttpNetworkTransaction passes on its priority to its |
| @@ -12144,6 +12187,56 @@ TEST_P(HttpNetworkTransactionTest, SetStreamPriority) { |
| EXPECT_EQ(LOWEST, fake_stream->priority()); |
| } |
| +TEST_P(HttpNetworkTransactionTest, CreateWebSocketHandshakeStream) { |
| + scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| + HttpNetworkSessionPeer peer(session); |
| + FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
| + FakeWebSocketStreamFactory websocket_stream_factory; |
| + peer.SetWebSocketHandshakeStreamFactory(fake_factory); |
| + |
| + HttpNetworkTransaction trans(LOW, session); |
| + trans.SetWebSocketHandshakeStreamFactory(&websocket_stream_factory); |
| + |
| + HttpRequestInfo request; |
| + TestCompletionCallback callback; |
| + request.method = "GET"; |
| + request.url = GURL("ws://www.google.com/"); |
| + |
| + EXPECT_EQ(ERR_IO_PENDING, |
| + trans.Start(&request, callback.callback(), BoundNetLog())); |
| + |
| + base::WeakPtr<FakeStreamRequest> fake_request = |
| + fake_factory->last_stream_request(); |
| + ASSERT_TRUE(fake_request != NULL); |
| + EXPECT_EQ(&websocket_stream_factory, |
| + fake_request->websocket_stream_factory()); |
| +} |
| + |
| +TEST_P(HttpNetworkTransactionTest, CreateWebSocketSecureHandshakeStream) { |
|
szym
2013/11/08 20:45:51
These two tests are identical except the url. Sugg
Adam Rice
2013/11/11 02:06:22
Done.
|
| + scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| + HttpNetworkSessionPeer peer(session); |
| + FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
| + FakeWebSocketStreamFactory websocket_stream_factory; |
| + peer.SetWebSocketHandshakeStreamFactory(fake_factory); |
| + |
| + HttpNetworkTransaction trans(LOW, session); |
| + trans.SetWebSocketHandshakeStreamFactory(&websocket_stream_factory); |
| + |
| + HttpRequestInfo request; |
| + TestCompletionCallback callback; |
| + request.method = "GET"; |
| + request.url = GURL("wss://www.google.com/"); |
| + |
| + EXPECT_EQ(ERR_IO_PENDING, |
| + trans.Start(&request, callback.callback(), BoundNetLog())); |
| + |
| + base::WeakPtr<FakeStreamRequest> fake_request = |
| + fake_factory->last_stream_request(); |
| + ASSERT_TRUE(fake_request != NULL); |
| + EXPECT_EQ(&websocket_stream_factory, |
| + fake_request->websocket_stream_factory()); |
| +} |
| + |
| // Tests that when a used socket is returned to the SSL socket pool, it's closed |
| // if the transport socket pool is stalled on the global socket limit. |
| TEST_P(HttpNetworkTransactionTest, CloseSSLSocketOnIdleForHttpRequest) { |