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..2529e8d79bdd8b8ddfd807c384e943a789c5c6e2 100644 |
| --- a/net/http/http_stream_factory_impl_unittest.cc |
| +++ b/net/http/http_stream_factory_impl_unittest.cc |
| @@ -19,20 +19,67 @@ |
| #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" |
| #include "net/socket/socket_test_util.h" |
| #include "net/spdy/spdy_session.h" |
| #include "net/spdy/spdy_session_pool.h" |
| +#include "net/spdy/spdy_stream.h" |
| +#include "net/spdy/spdy_test_util_spdy3.h" |
| +#include "net/ssl/ssl_config_service.h" |
| #include "net/ssl/ssl_config_service_defaults.h" |
| +#include "testing/gmock/include/gmock/gmock.h" |
| #include "testing/gtest/include/gtest/gtest.h" |
| namespace net { |
| namespace { |
|
tyoshino (SeeGerritForStatus)
2013/05/13 11:04:44
blank line
yhirano
2013/05/13 11:45:50
Done.
|
| +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); |
| + } |
| +}; |
| + |
| +class MockSSLConfigService : public SSLConfigService { |
| + public: |
| + explicit MockSSLConfigService(const SSLConfig& config) : config_(config) {} |
| + |
| + // SSLConfigService implementation |
| + virtual void GetSSLConfig(SSLConfig* config) OVERRIDE { |
| + *config = config_; |
| + } |
| + |
| + // Sets the SSLConfig to be returned by GetSSLConfig and processes any |
| + // updates. |
| + void SetSSLConfig(const SSLConfig& config) { |
| + SSLConfig old_config = config_; |
| + config_ = config; |
| + ProcessConfigUpdate(old_config, config_); |
| + } |
| + |
| + private: |
| + virtual ~MockSSLConfigService() {} |
| + |
| + SSLConfig config_; |
| +}; |
| + |
| +class MockSSLConfigServiceObserver : public SSLConfigService::Observer { |
| + public: |
| + MockSSLConfigServiceObserver() {} |
| + virtual ~MockSSLConfigServiceObserver() {} |
| + |
| + MOCK_METHOD0(OnSSLConfigChanged, void()); |
| +}; |
| class MockHttpStreamFactoryImpl : public HttpStreamFactoryImpl { |
| public: |
| - MockHttpStreamFactoryImpl(HttpNetworkSession* session) |
| + explicit MockHttpStreamFactoryImpl(HttpNetworkSession* session) |
| : HttpStreamFactoryImpl(session), |
| preconnect_done_(false), |
| waiting_for_preconnect_(false) {} |
| @@ -55,7 +102,7 @@ class MockHttpStreamFactoryImpl : public HttpStreamFactoryImpl { |
| } |
| bool preconnect_done_; |
| - bool waiting_for_preconnect_; |
| + ; bool waiting_for_preconnect_; |
|
tyoshino (SeeGerritForStatus)
2013/05/13 11:04:44
typo?
yhirano
2013/05/13 11:45:50
Thanks, done.
|
| }; |
| class StreamRequestWaiter : public HttpStreamRequest::Delegate { |
| @@ -76,6 +123,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 +173,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); |
| }; |
| @@ -120,10 +195,18 @@ struct SessionDependencies { |
| : host_resolver(new MockHostResolver), |
| cert_verifier(new MockCertVerifier), |
| proxy_service(proxy_service), |
| - ssl_config_service(new SSLConfigServiceDefaults), |
| http_auth_handler_factory( |
| HttpAuthHandlerFactory::CreateDefault(host_resolver.get())), |
| - net_log(NULL) {} |
| + net_log(NULL) { |
| + SSLConfig initial_config; |
| + initial_config.rev_checking_enabled = false; |
| + initial_config.false_start_enabled = false; |
| + initial_config.unrestricted_ssl3_fallback_enabled = false; |
| + initial_config.version_min = SSL_PROTOCOL_VERSION_SSL3; |
| + initial_config.version_max = SSL_PROTOCOL_VERSION_TLS1_1; |
| + ssl_config_service = new MockSSLConfigService(initial_config); |
| + ssl_config_service = new SSLConfigServiceDefaults(); |
| + } |
| scoped_ptr<MockHostResolverBase> host_resolver; |
| scoped_ptr<CertVerifier> cert_verifier; |
| @@ -470,6 +553,157 @@ 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. 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()); |
| +} |
| + |
| +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. It should succeed using the second proxy in the |
| + // list. |
| + 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); |
| + 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. 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_TRUE(waiter.stream()->IsSpdyHttpStream()); |
| +} |
| + |
| +TEST(HttpStreamFactoryTest, RequestSpdySession) { |
| + HttpStreamFactorySpdyForcer use_spdy; |
| + SpdySessionDependencies session_deps(kProtoSPDY3, |
| + ProxyService::CreateDirect()); |
| + |
| + MockRead r(ASYNC, OK); |
| + 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. It should succeed using the second proxy in the |
| + // list. |
| + 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 |