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..a5ffabe5f44c94988e271954604e05bc6c645873 100644 |
--- a/net/http/http_stream_factory_impl_unittest.cc |
+++ b/net/http/http_stream_factory_impl_unittest.cc |
@@ -19,10 +19,14 @@ |
#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/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" |
@@ -30,9 +34,26 @@ namespace net { |
namespace { |
+class HttpStreamFactorySpdyForcer { |
mmenke
2013/05/15 15:38:20
Suggest ScopedForceSpdyOverSsl.
yhirano
2013/05/16 05:02:35
Done.
|
+ public: |
+ HttpStreamFactorySpdyForcer(): |
+ over_ssl_(HttpStreamFactory::force_spdy_over_ssl()), |
+ always_(HttpStreamFactory::force_spdy_always()) { |
+ HttpStreamFactory::set_force_spdy_over_ssl(true); |
+ HttpStreamFactory::set_force_spdy_always(true); |
+ } |
+ ~HttpStreamFactorySpdyForcer() { |
+ HttpStreamFactory::set_force_spdy_over_ssl(over_ssl_); |
+ HttpStreamFactory::set_force_spdy_always(always_); |
+ } |
+ private: |
mmenke
2013/05/15 15:38:20
nit: Line break before private
yhirano
2013/05/16 05:02:35
Done.
|
+ const bool over_ssl_; |
+ const bool always_; |
mmenke
2013/05/15 15:38:20
I suggest orig_force_spdy_over_ssl_ / orig_force_s
yhirano
2013/05/16 05:02:35
Done.
|
+}; |
+ |
class MockHttpStreamFactoryImpl : public HttpStreamFactoryImpl { |
public: |
- MockHttpStreamFactoryImpl(HttpNetworkSession* session) |
+ explicit MockHttpStreamFactoryImpl(HttpNetworkSession* session) |
: HttpStreamFactoryImpl(session), |
preconnect_done_(false), |
waiting_for_preconnect_(false) {} |
@@ -76,6 +97,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 +147,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 +519,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 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)); |
+ |
+ // 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) { |
mmenke
2013/05/15 15:38:20
Maybe a test where there's a pre-existing SPDY ses
yhirano
2013/05/16 05:02:35
Done.
|
+ HttpStreamFactorySpdyForcer use_spdy; |
+ 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)); |
+ |
+ // 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 |