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 f228d9afdbf960b33d70df5935a2d7700b4c5ec1..bb9c32a176fa7aae31e0b6df8413a5a14e0c1cce 100644 |
| --- a/net/http/http_stream_factory_impl_unittest.cc |
| +++ b/net/http/http_stream_factory_impl_unittest.cc |
| @@ -19,10 +19,13 @@ |
| #include "net/http/http_stream.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" |
|
tyoshino (SeeGerritForStatus)
2013/05/15 07:48:52
include net/socket/next_proto.h
yhirano
2013/05/15 08:21:28
Done.
|
| #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_spdy3.h" |
|
tyoshino (SeeGerritForStatus)
2013/05/15 07:48:52
what is thi for?
maybe spdy_test_util_common.h?
yhirano
2013/05/15 08:21:28
Done.
|
| +#include "net/ssl/ssl_config_service.h" |
| #include "net/ssl/ssl_config_service_defaults.h" |
| #include "testing/gtest/include/gtest/gtest.h" |
| @@ -30,9 +33,21 @@ namespace net { |
| namespace { |
| +class HttpStreamFactorySpdyForcer { |
| + public: |
| + HttpStreamFactorySpdyForcer() { |
| + HttpStreamFactory::set_force_spdy_over_ssl(true); |
| + HttpStreamFactory::set_force_spdy_always(true); |
| + } |
| + ~HttpStreamFactorySpdyForcer() { |
| + HttpStreamFactory::set_force_spdy_over_ssl(false); |
| + HttpStreamFactory::set_force_spdy_always(false); |
| + } |
|
tyoshino (SeeGerritForStatus)
2013/05/15 07:48:52
(optional) it would be more useful if the original
yhirano
2013/05/15 08:21:28
Done.
|
| +}; |
| + |
| class MockHttpStreamFactoryImpl : public HttpStreamFactoryImpl { |
| public: |
| - MockHttpStreamFactoryImpl(HttpNetworkSession* session) |
| + explicit MockHttpStreamFactoryImpl(HttpNetworkSession* session) |
| : HttpStreamFactoryImpl(session), |
| preconnect_done_(false), |
| waiting_for_preconnect_(false) {} |
| @@ -76,6 +91,26 @@ class StreamRequestWaiter : public HttpStreamRequest::Delegate { |
| stream_.reset(stream); |
| } |
| + virtual void OnSocketReady( |
| + const SSLConfig& used_ssl_config, |
| + const ProxyInfo& used_proxy_info, |
| + ClientSocketHandle* connection) OVERRIDE { |
| + stream_done_ = true; |
| + if (waiting_for_stream_) |
| + MessageLoop::current()->Quit(); |
| + connection_.reset(connection); |
| + } |
| + |
| + virtual void OnSpdySessionReady( |
| + const SSLConfig& used_ssl_config, |
| + const ProxyInfo& used_proxy_info, |
| + SpdySession* session) OVERRIDE { |
| + stream_done_ = true; |
| + if (waiting_for_stream_) |
| + MessageLoop::current()->Quit(); |
| + spdy_session_ = session; |
| + } |
| + |
| virtual void OnStreamFailed( |
| int status, |
| const SSLConfig& used_ssl_config) OVERRIDE {} |
| @@ -106,10 +141,18 @@ class StreamRequestWaiter : public HttpStreamRequest::Delegate { |
| } |
| } |
| + public: |
| + bool stream_done() const { return stream_done_; } |
| + HttpStreamBase* stream() { return stream_.get(); } |
| + 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<ClientSocketHandle> connection_; |
| + scoped_refptr<SpdySession> spdy_session_; |
| DISALLOW_COPY_AND_ASSIGN(StreamRequestWaiter); |
| }; |
| @@ -470,6 +513,153 @@ TEST(HttpStreamFactoryTest, JobNotifiesProxy) { |
| EXPECT_TRUE(iter != retry_info.end()); |
| } |
| +TEST(HttpStreamFactoryTest, RequestStream) { |
| + 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)); |
| + |
| + // Now request a stream. |
| + 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()); |
| +} |
| + |
| +TEST(HttpStreamFactoryTest, RequestSocket) { |
| + 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)); |
| + |
| + // 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; |
| + scoped_ptr<HttpStreamRequest> request( |
| + session->http_stream_factory()->RequestStreamForWebSocket( |
| + request_info, |
| + DEFAULT_PRIORITY, |
| + ssl_config, |
| + ssl_config, |
| + &waiter, |
| + BoundNetLog())); |
| + waiter.WaitForStream(); |
| + EXPECT_TRUE(waiter.stream_done()); |
| + EXPECT_TRUE(NULL == waiter.stream()); |
| + EXPECT_TRUE(NULL == waiter.spdy_session()); |
| + EXPECT_TRUE(NULL != waiter.connection()); |
| +} |
| + |
| +TEST(HttpStreamFactoryTest, RequestSpdyHttpStream) { |
| + HttpStreamFactorySpdyForcer use_spdy; |
| + SpdySessionDependencies session_deps(kProtoSPDY3, |
| + ProxyService::CreateDirect()); |
| + |
| + MockRead r(ASYNC, OK); |
|
tyoshino (SeeGerritForStatus)
2013/05/15 07:48:52
r -> mock_read
yhirano
2013/05/15 08:21:28
Done.
|
| + StaticSocketDataProvider socket_data(&r, 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)); |
| + |
| + // Now request a stream. |
| + 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_TRUE(waiter.stream()->IsSpdyHttpStream()); |
| +} |
| + |
| +TEST(HttpStreamFactoryTest, RequestSpdySession) { |
| + HttpStreamFactorySpdyForcer use_spdy; |
| + SpdySessionDependencies session_deps(kProtoSPDY3, |
| + ProxyService::CreateDirect()); |
| + |
| + MockRead r(ASYNC, OK); |
|
tyoshino (SeeGerritForStatus)
2013/05/15 07:48:52
ditto
yhirano
2013/05/15 08:21:28
Done.
|
| + StaticSocketDataProvider socket_data(&r, 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)); |
| + |
| + // 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; |
| + scoped_ptr<HttpStreamRequest> request( |
| + session->http_stream_factory()->RequestStreamForWebSocket( |
| + 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()); |
| +} |
| + |
| } // namespace |
| } // namespace net |