Chromium Code Reviews| Index: net/http/http_stream_factory_impl_unittest.cc |
| diff --git a/net/http/http_stream_factory_impl_unittest.cc b/net/http/http_stream_factory_impl_unittest.cc |
| index cac7f02d254583abdb332ce8ab758f8dcb5ea55a..e7be12b051d642caad66722474f39718d17aadfc 100644 |
| --- a/net/http/http_stream_factory_impl_unittest.cc |
| +++ b/net/http/http_stream_factory_impl_unittest.cc |
| @@ -5,6 +5,7 @@ |
| #include "net/http/http_stream_factory_impl.h" |
| #include <string> |
| +#include <vector> |
| #include "base/basictypes.h" |
| #include "net/base/net_log.h" |
| @@ -18,12 +19,17 @@ |
| #include "net/http/http_request_info.h" |
| #include "net/http/http_server_properties_impl.h" |
| #include "net/http/http_stream.h" |
| +#include "net/http/websocket_stream_base.h" |
| #include "net/proxy/proxy_info.h" |
| #include "net/proxy/proxy_service.h" |
| +#include "net/socket/client_socket_handle.h" |
| #include "net/socket/mock_client_socket_pool_manager.h" |
| +#include "net/socket/next_proto.h" |
| #include "net/socket/socket_test_util.h" |
| #include "net/spdy/spdy_session.h" |
| #include "net/spdy/spdy_session_pool.h" |
| +#include "net/spdy/spdy_test_util_common.h" |
| +#include "net/ssl/ssl_config_service.h" |
| #include "net/ssl/ssl_config_service_defaults.h" |
| #include "testing/gtest/include/gtest/gtest.h" |
| @@ -31,10 +37,113 @@ namespace net { |
| namespace { |
| +class ScopedForceSpdySsl { |
| + public: |
| + explicit ScopedForceSpdySsl(bool enabled): |
| + orig_force_spdy_over_ssl_(HttpStreamFactory::force_spdy_over_ssl()), |
| + orig_force_spdy_always_(HttpStreamFactory::force_spdy_always()), |
| + orig_spdy_enabled_(HttpStreamFactory::spdy_enabled()) { |
| + HttpStreamFactory::set_force_spdy_over_ssl(enabled); |
| + HttpStreamFactory::set_force_spdy_always(enabled); |
| + HttpStreamFactory::set_spdy_enabled(enabled); |
| + } |
| + ~ScopedForceSpdySsl() { |
| + HttpStreamFactory::set_spdy_enabled(orig_spdy_enabled_); |
| + HttpStreamFactory::set_force_spdy_over_ssl(orig_force_spdy_over_ssl_); |
| + HttpStreamFactory::set_force_spdy_always(orig_force_spdy_always_); |
| + } |
| + |
| + private: |
| + const bool orig_force_spdy_over_ssl_; |
| + const bool orig_force_spdy_always_; |
| + const bool orig_spdy_enabled_; |
| +}; |
| + |
| class MockHttpStreamFactoryImpl : public HttpStreamFactoryImpl { |
| public: |
| - MockHttpStreamFactoryImpl(HttpNetworkSession* session) |
| - : HttpStreamFactoryImpl(session), |
| + MockHttpStreamFactoryImpl(HttpNetworkSession* session, bool for_websockets) |
| + : HttpStreamFactoryImpl(session, for_websockets) {} |
| + |
| + struct InitSocketHandleParams { |
| + InitSocketHandleParams() |
| + : force_spdy_over_ssl(false), want_spdy_over_npn(false) {} |
| + |
| + InitSocketHandleParams( |
| + const GURL& request_url, |
| + const HttpRequestInfo& request_info, |
| + RequestPriority request_priority, |
| + const ProxyInfo& proxy_info, |
| + bool force_spdy_over_ssl, |
| + bool want_spdy_over_npn, |
| + const SSLConfig& ssl_config_for_origin, |
| + const SSLConfig& ssl_config_for_proxy, |
| + ClientSocketHandle* socket_handle) |
| + : request_url(request_url), request_info(request_info), |
| + request_priority(request_priority), proxy_info(proxy_info), |
| + force_spdy_over_ssl(force_spdy_over_ssl), |
| + want_spdy_over_npn(want_spdy_over_npn), |
| + ssl_config_for_origin(ssl_config_for_origin), |
| + ssl_config_for_proxy(ssl_config_for_proxy), |
| + socket_handle(socket_handle) {} |
| + |
| + GURL request_url; |
| + HttpRequestInfo request_info; |
| + RequestPriority request_priority; |
| + ProxyInfo proxy_info; |
| + bool force_spdy_over_ssl; |
| + bool want_spdy_over_npn; |
| + SSLConfig ssl_config_for_origin; |
| + SSLConfig ssl_config_for_proxy; |
| + // can be a dangling pointer. |
| + ClientSocketHandle* socket_handle; |
| + }; |
| + std::vector<InitSocketHandleParams> calls_init_socket_handle_for_http; |
| + |
| + private: |
| + virtual int InitSocketHandleForHttpRequest( |
| + const GURL& request_url, |
| + const HttpRequestInfo& request_info, |
| + RequestPriority request_priority, |
| + const ProxyInfo& proxy_info, |
| + bool force_spdy_over_ssl, |
| + bool want_spdy_over_npn, |
| + const SSLConfig& ssl_config_for_origin, |
| + const SSLConfig& ssl_config_for_proxy, |
| + const BoundNetLog& net_log, |
| + ClientSocketHandle* socket_handle, |
| + const OnHostResolutionCallback& resolution_callback, |
| + const CompletionCallback& callback) OVERRIDE { |
| + calls_init_socket_handle_for_http.push_back(InitSocketHandleParams( |
| + request_url, |
| + request_info, |
| + request_priority, |
| + proxy_info, |
| + force_spdy_over_ssl, |
| + want_spdy_over_npn, |
| + ssl_config_for_origin, |
| + ssl_config_for_proxy, |
| + socket_handle)); |
| + return HttpStreamFactoryImpl::InitSocketHandleForHttpRequest( |
| + request_url, |
| + request_info, |
| + request_priority, |
| + proxy_info, |
| + force_spdy_over_ssl, |
| + want_spdy_over_npn, |
| + ssl_config_for_origin, |
| + ssl_config_for_proxy, |
| + net_log, |
| + socket_handle, |
| + resolution_callback, |
| + callback); |
| + } |
| +}; |
| + |
| +class MockHttpStreamFactoryImplForPreconnect : public HttpStreamFactoryImpl { |
| + public: |
| + MockHttpStreamFactoryImplForPreconnect(HttpNetworkSession* session, |
| + bool for_websockets) |
| + : HttpStreamFactoryImpl(session, for_websockets), |
| preconnect_done_(false), |
| waiting_for_preconnect_(false) {} |
| @@ -78,6 +187,16 @@ class StreamRequestWaiter : public HttpStreamRequest::Delegate { |
| used_ssl_config_ = used_ssl_config; |
| } |
| + virtual void OnWebSocketStreamReady( |
| + const SSLConfig& used_ssl_config, |
| + const ProxyInfo& used_proxy_info, |
| + WebSocketStreamBase* stream) OVERRIDE { |
| + stream_done_ = true; |
| + if (waiting_for_stream_) |
| + MessageLoop::current()->Quit(); |
| + websocket_stream_.reset(stream); |
| + } |
| + |
| virtual void OnStreamFailed( |
| int status, |
| const SSLConfig& used_ssl_config) OVERRIDE {} |
| @@ -116,16 +235,59 @@ class StreamRequestWaiter : public HttpStreamRequest::Delegate { |
| return stream_.get(); |
| } |
| + WebSocketStreamBase* websocket_stream() { |
| + return websocket_stream_.get(); |
| + } |
| + |
| + bool stream_done() const { return stream_done_; } |
| + SpdySession* spdy_session() {return spdy_session_.get(); } |
| + ClientSocketHandle* connection() { return connection_.get(); } |
| private: |
| bool waiting_for_stream_; |
| bool stream_done_; |
| scoped_ptr<HttpStreamBase> stream_; |
| + scoped_ptr<WebSocketStreamBase> websocket_stream_; |
| SSLConfig used_ssl_config_; |
| + scoped_ptr<ClientSocketHandle> connection_; |
| + scoped_refptr<SpdySession> spdy_session_; |
|
mmenke
2013/05/28 21:22:37
These two are no longer in use.
yhirano
2013/05/30 04:44:32
Done.
|
| DISALLOW_COPY_AND_ASSIGN(StreamRequestWaiter); |
| }; |
| +class WebSocketSpdyStream : public WebSocketStreamBase { |
| + public: |
| + explicit WebSocketSpdyStream(SpdySession* spdy_session): |
| + WebSocketStreamBase(kStreamTypeSpdy), spdy_session_(spdy_session) {} |
| + SpdySession* spdy_session() {return spdy_session_.get();} |
| + |
| + private: |
| + scoped_refptr<SpdySession> spdy_session_; |
| +}; |
| + |
| +class WebSocketBasicStream : public WebSocketStreamBase { |
| + public: |
| + explicit WebSocketBasicStream(ClientSocketHandle* connection): |
| + WebSocketStreamBase(kStreamTypeBasic), connection_(connection) {} |
| + ClientSocketHandle* connection() {return connection_.get();} |
| + |
| + private: |
| + scoped_ptr<ClientSocketHandle> connection_; |
| +}; |
| + |
| +class WebSocketStreamFactory : public WebSocketStreamBase::Factory { |
| + public: |
| + virtual WebSocketStreamBase* CreateBasicStream(ClientSocketHandle* connection, |
| + bool using_proxy) OVERRIDE { |
| + return new WebSocketBasicStream(connection); |
| + } |
| + virtual WebSocketStreamBase* CreateSpdyStream( |
| + SpdySession* spdy_session, |
| + bool use_relative_url) OVERRIDE { |
| + return new WebSocketSpdyStream(spdy_session); |
| + } |
| +}; |
| + |
| struct SessionDependencies { |
| // Custom proxy service dependency. |
| explicit SessionDependencies(ProxyService* proxy_service) |
| @@ -158,6 +320,7 @@ HttpNetworkSession* CreateSession(SessionDependencies* session_deps) { |
| session_deps->http_auth_handler_factory.get(); |
| params.net_log = session_deps->net_log; |
| params.http_server_properties = &session_deps->http_server_properties; |
| + |
| return new HttpNetworkSession(params); |
| } |
| @@ -177,8 +340,8 @@ void PreconnectHelperForURL(int num_streams, |
| const GURL& url, |
| HttpNetworkSession* session) { |
| HttpNetworkSessionPeer peer(session); |
| - MockHttpStreamFactoryImpl* mock_factory = |
| - new MockHttpStreamFactoryImpl(session); |
| + MockHttpStreamFactoryImplForPreconnect* mock_factory = |
| + new MockHttpStreamFactoryImplForPreconnect(session, false); |
| peer.SetHttpStreamFactory(mock_factory); |
| SSLConfig ssl_config; |
| session->ssl_config_service()->GetSSLConfig(&ssl_config); |
| @@ -460,8 +623,7 @@ TEST(HttpStreamFactoryTest, JobNotifiesProxy) { |
| scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps)); |
| - // Now request a stream. It should succeed using the second proxy in the |
| - // list. |
| + // Now request a stream. |
| HttpRequestInfo request_info; |
| request_info.method = "GET"; |
| request_info.url = GURL("http://www.google.com"); |
| @@ -610,6 +772,385 @@ TEST(HttpStreamFactoryTest, GetLoadState) { |
| waiter.WaitForStream(); |
| } |
| +TEST(HttpStreamFactoryTest, RequestHttpStream) { |
| + SessionDependencies session_deps(ProxyService::CreateDirect()); |
| + |
| + StaticSocketDataProvider socket_data; |
| + socket_data.set_connect_data(MockConnect(ASYNC, OK)); |
| + session_deps.socket_factory.AddSocketDataProvider(&socket_data); |
| + |
| + scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps)); |
| + MockHttpStreamFactoryImpl* http_stream_factory = |
| + new MockHttpStreamFactoryImpl(session.get(), false); |
| + HttpNetworkSessionPeer(session).SetHttpStreamFactory(http_stream_factory); |
| + |
| + // Now request a stream. It should succeed using the second proxy in the |
| + // list. |
| + HttpRequestInfo request_info; |
| + request_info.method = "GET"; |
| + request_info.url = GURL("http://www.google.com"); |
| + request_info.load_flags = 0; |
| + |
| + SSLConfig ssl_config; |
| + StreamRequestWaiter waiter; |
| + scoped_ptr<HttpStreamRequest> request( |
| + session->http_stream_factory()->RequestStream( |
| + request_info, |
| + DEFAULT_PRIORITY, |
| + ssl_config, |
| + ssl_config, |
| + &waiter, |
| + BoundNetLog())); |
| + waiter.WaitForStream(); |
| + EXPECT_TRUE(waiter.stream_done()); |
| + EXPECT_TRUE(NULL == waiter.spdy_session()); |
| + EXPECT_TRUE(NULL == waiter.connection()); |
|
mmenke
2013/05/28 21:22:37
There's no code to initialize these. Should be ch
yhirano
2013/05/30 04:44:32
Done.
|
| + EXPECT_TRUE(NULL != waiter.stream()); |
| + EXPECT_EQ(1u, http_stream_factory->calls_init_socket_handle_for_http.size()); |
| + MockHttpStreamFactoryImpl::InitSocketHandleParams params = |
| + http_stream_factory->calls_init_socket_handle_for_http[0]; |
|
mmenke
2013/05/28 21:22:37
Is all this extra infrastructure necessary? The o
yhirano
2013/05/30 04:44:32
Thank you, you are right.
I deleted HttpStreamFact
|
| + EXPECT_EQ(request_info.url, params.request_url); |
| + EXPECT_TRUE(params.proxy_info.is_direct()); |
| + SSLInfo ssl_info; |
| + EXPECT_FALSE(params.socket_handle->socket()->GetSSLInfo(&ssl_info)); |
| +} |
| + |
| +TEST(HttpStreamFactoryTest, RequestHttpStreamOverSSL) { |
| + SessionDependencies session_deps(ProxyService::CreateDirect()); |
| + |
| + MockRead mock_read(ASYNC, ERR_IO_PENDING); |
| + StaticSocketDataProvider socket_data(&mock_read, 1, NULL, 0); |
| + socket_data.set_connect_data(MockConnect(ASYNC, OK)); |
| + session_deps.socket_factory.AddSocketDataProvider(&socket_data); |
| + |
| + SSLSocketDataProvider ssl_socket_data(ASYNC, OK); |
| + ssl_socket_data.protocol_negotiated = kProtoSPDY3; |
| + session_deps.socket_factory.AddSSLSocketDataProvider(&ssl_socket_data); |
| + |
| + SSLSocketDataProvider ssl_socket_data2(ASYNC, OK); |
| + ssl_socket_data2.protocol_negotiated = kProtoSPDY3; |
| + session_deps.socket_factory.AddSSLSocketDataProvider(&ssl_socket_data2); |
| + |
| + scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps)); |
| + |
| + MockHttpStreamFactoryImpl* http_stream_factory = |
| + new MockHttpStreamFactoryImpl(session.get(), false); |
| + HttpNetworkSessionPeer(session).SetHttpStreamFactory(http_stream_factory); |
| + |
| + // Now request a stream. It should succeed using the second proxy in the |
| + // list. |
| + HttpRequestInfo request_info; |
| + request_info.method = "GET"; |
| + request_info.url = GURL("https://www.google.com"); |
| + request_info.load_flags = 0; |
| + |
| + SSLConfig ssl_config; |
| + StreamRequestWaiter waiter; |
| + scoped_ptr<HttpStreamRequest> request( |
| + session->http_stream_factory()->RequestStream( |
| + request_info, |
| + DEFAULT_PRIORITY, |
| + ssl_config, |
| + ssl_config, |
| + &waiter, |
| + BoundNetLog())); |
| + waiter.WaitForStream(); |
| + EXPECT_TRUE(waiter.stream_done()); |
| + EXPECT_TRUE(NULL == waiter.spdy_session()); |
| + EXPECT_TRUE(NULL == waiter.connection()); |
| + EXPECT_TRUE(NULL != waiter.stream()); |
| + EXPECT_EQ(1u, http_stream_factory->calls_init_socket_handle_for_http.size()); |
| + MockHttpStreamFactoryImpl::InitSocketHandleParams params = |
| + http_stream_factory->calls_init_socket_handle_for_http[0]; |
| + EXPECT_EQ(request_info.url, params.request_url); |
| + EXPECT_TRUE(params.proxy_info.is_direct()); |
| + SSLInfo ssl_info; |
| + EXPECT_TRUE(params.socket_handle->socket()->GetSSLInfo(&ssl_info)); |
| +} |
| + |
| +TEST(HttpStreamFactoryTest, RequestHttpStreamOverProxy) { |
| + SessionDependencies session_deps(ProxyService::CreateFixed("myproxy:8888")); |
| + |
| + StaticSocketDataProvider socket_data; |
| + socket_data.set_connect_data(MockConnect(ASYNC, OK)); |
| + session_deps.socket_factory.AddSocketDataProvider(&socket_data); |
| + |
| + scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps)); |
| + MockHttpStreamFactoryImpl* http_stream_factory = |
| + new MockHttpStreamFactoryImpl(session.get(), false); |
| + HttpNetworkSessionPeer(session).SetHttpStreamFactory(http_stream_factory); |
| + |
| + // Now request a stream. It should succeed using the second proxy in the |
| + // list. |
| + HttpRequestInfo request_info; |
| + request_info.method = "GET"; |
| + request_info.url = GURL("http://www.google.com"); |
| + request_info.load_flags = 0; |
| + |
| + SSLConfig ssl_config; |
| + StreamRequestWaiter waiter; |
| + scoped_ptr<HttpStreamRequest> request( |
| + session->http_stream_factory()->RequestStream( |
| + request_info, |
| + DEFAULT_PRIORITY, |
| + ssl_config, |
| + ssl_config, |
| + &waiter, |
| + BoundNetLog())); |
| + waiter.WaitForStream(); |
| + EXPECT_TRUE(waiter.stream_done()); |
| + EXPECT_TRUE(NULL == waiter.spdy_session()); |
| + EXPECT_TRUE(NULL == waiter.connection()); |
| + EXPECT_TRUE(NULL != waiter.stream()); |
| + EXPECT_EQ(1u, http_stream_factory->calls_init_socket_handle_for_http.size()); |
| + MockHttpStreamFactoryImpl::InitSocketHandleParams params = |
| + http_stream_factory->calls_init_socket_handle_for_http[0]; |
| + EXPECT_EQ(request_info.url, params.request_url); |
| + EXPECT_FALSE(params.proxy_info.is_direct()); |
| + SSLInfo ssl_info; |
| + EXPECT_FALSE(params.socket_handle->socket()->GetSSLInfo(&ssl_info)); |
| +} |
| + |
| +TEST(HttpStreamFactoryTest, RequestWebSocketBasicStream) { |
| + SessionDependencies session_deps(ProxyService::CreateDirect()); |
| + |
| + StaticSocketDataProvider socket_data; |
| + socket_data.set_connect_data(MockConnect(ASYNC, OK)); |
| + session_deps.socket_factory.AddSocketDataProvider(&socket_data); |
| + |
| + scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps)); |
| + MockHttpStreamFactoryImpl* websocket_stream_factory = |
| + new MockHttpStreamFactoryImpl(session.get(), true); |
| + HttpNetworkSessionPeer(session).SetWebSocketStreamFactory( |
| + websocket_stream_factory); |
| + |
| + // Now request a stream. |
| + HttpRequestInfo request_info; |
| + request_info.method = "GET"; |
| + request_info.url = GURL("ws://www.google.com"); |
| + request_info.load_flags = 0; |
| + |
| + SSLConfig ssl_config; |
| + StreamRequestWaiter waiter; |
| + WebSocketStreamFactory factory; |
| + scoped_ptr<HttpStreamRequest> request( |
| + session->websocket_stream_factory()->RequestWebSocketStream( |
| + request_info, |
| + DEFAULT_PRIORITY, |
| + ssl_config, |
| + ssl_config, |
| + &waiter, |
| + &factory, |
| + BoundNetLog())); |
| + waiter.WaitForStream(); |
| + EXPECT_TRUE(waiter.stream_done()); |
| + EXPECT_TRUE(NULL == waiter.stream()); |
| + EXPECT_TRUE(NULL != waiter.websocket_stream()); |
| + EXPECT_EQ(WebSocketStreamBase::kStreamTypeBasic, |
| + waiter.websocket_stream()->type()); |
| + EXPECT_EQ(1u, |
| + websocket_stream_factory->calls_init_socket_handle_for_http.size()); |
| + MockHttpStreamFactoryImpl::InitSocketHandleParams params = |
| + websocket_stream_factory->calls_init_socket_handle_for_http[0]; |
| + EXPECT_EQ(request_info.url, params.request_url); |
| + EXPECT_TRUE(params.proxy_info.is_direct()); |
| + SSLInfo ssl_info; |
| + EXPECT_FALSE(params.socket_handle->socket()->GetSSLInfo(&ssl_info)); |
| +} |
| + |
| +TEST(HttpStreamFactoryTest, RequestWebSocketBasicStreamOverSSL) { |
| + ScopedForceSpdySsl use_spdy(false); |
| + SessionDependencies session_deps(ProxyService::CreateDirect()); |
| + |
| + MockRead mock_read(ASYNC, ERR_IO_PENDING); |
| + StaticSocketDataProvider socket_data(&mock_read, 1, NULL, 0); |
| + socket_data.set_connect_data(MockConnect(ASYNC, OK)); |
| + session_deps.socket_factory.AddSocketDataProvider(&socket_data); |
| + |
| + SSLSocketDataProvider ssl_socket_data(ASYNC, OK); |
| + ssl_socket_data.protocol_negotiated = kProtoSPDY3; |
| + session_deps.socket_factory.AddSSLSocketDataProvider(&ssl_socket_data); |
| + |
| + SSLSocketDataProvider ssl_socket_data2(ASYNC, OK); |
| + ssl_socket_data2.protocol_negotiated = kProtoSPDY3; |
| + session_deps.socket_factory.AddSSLSocketDataProvider(&ssl_socket_data2); |
| + |
| + scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps)); |
| + MockHttpStreamFactoryImpl* websocket_stream_factory = |
| + new MockHttpStreamFactoryImpl(session.get(), true); |
| + HttpNetworkSessionPeer(session).SetWebSocketStreamFactory( |
| + websocket_stream_factory); |
| + |
| + // Now request a stream. |
| + HttpRequestInfo request_info; |
| + request_info.method = "GET"; |
| + request_info.url = GURL("wss://www.google.com"); |
| + request_info.load_flags = 0; |
| + |
| + SSLConfig ssl_config; |
| + StreamRequestWaiter waiter; |
| + WebSocketStreamFactory factory; |
| + scoped_ptr<HttpStreamRequest> request( |
| + session->websocket_stream_factory()->RequestWebSocketStream( |
| + request_info, |
| + DEFAULT_PRIORITY, |
| + ssl_config, |
| + ssl_config, |
| + &waiter, |
| + &factory, |
| + BoundNetLog())); |
| + waiter.WaitForStream(); |
| + EXPECT_TRUE(waiter.stream_done()); |
| + EXPECT_TRUE(NULL == waiter.stream()); |
| + EXPECT_TRUE(NULL != waiter.websocket_stream()); |
| + EXPECT_EQ(WebSocketStreamBase::kStreamTypeBasic, |
| + waiter.websocket_stream()->type()); |
| + EXPECT_EQ(1u, |
| + websocket_stream_factory->calls_init_socket_handle_for_http.size()); |
| + MockHttpStreamFactoryImpl::InitSocketHandleParams params = |
| + websocket_stream_factory->calls_init_socket_handle_for_http[0]; |
| + EXPECT_EQ(request_info.url, params.request_url); |
| + EXPECT_TRUE(params.proxy_info.is_direct()); |
| + SSLInfo ssl_info; |
| + EXPECT_TRUE(params.socket_handle->socket()->GetSSLInfo(&ssl_info)); |
| +} |
| + |
| +TEST(HttpStreamFactoryTest, RequestSpdyHttpStream) { |
| + ScopedForceSpdySsl use_spdy(true); |
| + SpdySessionDependencies session_deps(kProtoSPDY3, |
| + ProxyService::CreateDirect()); |
| + |
| + MockRead mock_read(ASYNC, OK); |
| + StaticSocketDataProvider socket_data(&mock_read, 1, NULL, 0); |
| + socket_data.set_connect_data(MockConnect(ASYNC, OK)); |
| + session_deps.socket_factory->AddSocketDataProvider(&socket_data); |
| + |
| + SSLSocketDataProvider ssl_socket_data(ASYNC, OK); |
| + ssl_socket_data.protocol_negotiated = kProtoSPDY3; |
| + session_deps.socket_factory->AddSSLSocketDataProvider(&ssl_socket_data); |
| + |
| + HostPortPair host_port_pair("www.google.com", 80); |
| + scoped_refptr<HttpNetworkSession> |
| + session(SpdySessionDependencies::SpdyCreateSession(&session_deps)); |
| + MockHttpStreamFactoryImpl* http_stream_factory = |
| + new MockHttpStreamFactoryImpl(session.get(), false); |
| + HttpNetworkSessionPeer(session).SetHttpStreamFactory(http_stream_factory); |
| + |
| + // Now request a stream. |
| + HttpRequestInfo request_info; |
| + request_info.method = "GET"; |
| + request_info.url = GURL("https://www.google.com"); |
| + request_info.load_flags = 0; |
| + |
| + SSLConfig ssl_config; |
| + StreamRequestWaiter waiter; |
| + scoped_ptr<HttpStreamRequest> request( |
| + session->http_stream_factory()->RequestStream( |
| + request_info, |
| + DEFAULT_PRIORITY, |
| + ssl_config, |
| + ssl_config, |
| + &waiter, |
| + BoundNetLog())); |
| + waiter.WaitForStream(); |
| + EXPECT_TRUE(waiter.stream_done()); |
| + EXPECT_TRUE(NULL == waiter.websocket_stream()); |
| + EXPECT_TRUE(NULL != waiter.stream()); |
| + EXPECT_TRUE(waiter.stream()->IsSpdyHttpStream()); |
| + EXPECT_EQ(1u, http_stream_factory->calls_init_socket_handle_for_http.size()); |
| + MockHttpStreamFactoryImpl::InitSocketHandleParams params = |
| + http_stream_factory->calls_init_socket_handle_for_http[0]; |
| + EXPECT_EQ(request_info.url, params.request_url); |
| + EXPECT_TRUE(params.proxy_info.is_direct()); |
| + SSLInfo ssl_info; |
| + EXPECT_TRUE(params.socket_handle->socket()->GetSSLInfo(&ssl_info)); |
| +} |
| + |
| +TEST(HttpStreamFactoryTest, RequestWebSocketSpdyStream) { |
| + ScopedForceSpdySsl use_spdy(true); |
| + SpdySessionDependencies session_deps(kProtoSPDY3, |
| + ProxyService::CreateDirect()); |
| + |
| + MockRead mock_read(ASYNC, ERR_IO_PENDING); |
| + StaticSocketDataProvider socket_data(&mock_read, 1, NULL, 0); |
| + socket_data.set_connect_data(MockConnect(ASYNC, OK)); |
| + session_deps.socket_factory->AddSocketDataProvider(&socket_data); |
| + |
| + SSLSocketDataProvider ssl_socket_data(ASYNC, OK); |
| + ssl_socket_data.protocol_negotiated = kProtoSPDY3; |
| + session_deps.socket_factory->AddSSLSocketDataProvider(&ssl_socket_data); |
| + |
| + SSLSocketDataProvider ssl_socket_data2(ASYNC, OK); |
| + ssl_socket_data2.protocol_negotiated = kProtoSPDY3; |
| + session_deps.socket_factory->AddSSLSocketDataProvider(&ssl_socket_data2); |
| + |
| + HostPortPair host_port_pair("www.google.com", 80); |
| + scoped_refptr<HttpNetworkSession> |
| + session(SpdySessionDependencies::SpdyCreateSession(&session_deps)); |
| + MockHttpStreamFactoryImpl* websocket_stream_factory = |
| + new MockHttpStreamFactoryImpl(session.get(), true); |
| + HttpNetworkSessionPeer(session).SetWebSocketStreamFactory( |
| + websocket_stream_factory); |
| + |
| + // Now request a stream. |
| + HttpRequestInfo request_info; |
| + request_info.method = "GET"; |
| + request_info.url = GURL("wss://www.google.com"); |
| + request_info.load_flags = 0; |
| + |
| + SSLConfig ssl_config; |
| + StreamRequestWaiter waiter1; |
| + WebSocketStreamFactory factory; |
| + scoped_ptr<HttpStreamRequest> request1( |
| + session->websocket_stream_factory()->RequestWebSocketStream( |
| + request_info, |
| + DEFAULT_PRIORITY, |
| + ssl_config, |
| + ssl_config, |
| + &waiter1, |
| + &factory, |
| + BoundNetLog())); |
| + waiter1.WaitForStream(); |
| + EXPECT_TRUE(waiter1.stream_done()); |
| + EXPECT_TRUE(NULL != waiter1.websocket_stream()); |
| + EXPECT_EQ(WebSocketStreamBase::kStreamTypeSpdy, |
| + waiter1.websocket_stream()->type()); |
| + EXPECT_TRUE(NULL == waiter1.connection()); |
| + EXPECT_TRUE(NULL == waiter1.stream()); |
| + |
| + StreamRequestWaiter waiter2; |
| + scoped_ptr<HttpStreamRequest> request2( |
| + session->websocket_stream_factory()->RequestWebSocketStream( |
| + request_info, |
| + DEFAULT_PRIORITY, |
| + ssl_config, |
| + ssl_config, |
| + &waiter2, |
| + &factory, |
| + BoundNetLog())); |
| + waiter2.WaitForStream(); |
| + EXPECT_TRUE(waiter2.stream_done()); |
| + EXPECT_TRUE(NULL != waiter2.websocket_stream()); |
| + EXPECT_EQ(WebSocketStreamBase::kStreamTypeSpdy, |
| + waiter2.websocket_stream()->type()); |
| + EXPECT_TRUE(NULL == waiter2.connection()); |
| + EXPECT_TRUE(NULL == waiter2.stream()); |
| + EXPECT_NE(waiter2.websocket_stream(), waiter1.websocket_stream()); |
| + EXPECT_EQ(static_cast<WebSocketSpdyStream*>(waiter2.websocket_stream())-> |
| + spdy_session(), |
| + static_cast<WebSocketSpdyStream*>(waiter1.websocket_stream())-> |
| + spdy_session()); |
| + |
| + EXPECT_EQ(1u, |
| + websocket_stream_factory->calls_init_socket_handle_for_http.size()); |
| + MockHttpStreamFactoryImpl::InitSocketHandleParams params = |
| + websocket_stream_factory->calls_init_socket_handle_for_http[0]; |
| + EXPECT_EQ(request_info.url, params.request_url); |
| + EXPECT_TRUE(params.proxy_info.is_direct()); |
| + SSLInfo ssl_info; |
| + EXPECT_TRUE(params.socket_handle->socket()->GetSSLInfo(&ssl_info)); |
| +} |
| + |
| } // namespace |
| } // namespace net |