| 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..76fc1174545b0cf23eb8ca956e4311e8fcdd9c14 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,27 @@ namespace net {
|
|
|
| namespace {
|
|
|
| +class ScopedForceSpdySsl {
|
| + public:
|
| + ScopedForceSpdySsl():
|
| + orig_force_spdy_over_ssl_(HttpStreamFactory::force_spdy_over_ssl()),
|
| + orig_force_spdy_always_(HttpStreamFactory::force_spdy_always()) {
|
| + HttpStreamFactory::set_force_spdy_over_ssl(true);
|
| + HttpStreamFactory::set_force_spdy_always(true);
|
| + }
|
| + ~ScopedForceSpdySsl() {
|
| + 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_;
|
| +};
|
| +
|
| class MockHttpStreamFactoryImpl : public HttpStreamFactoryImpl {
|
| public:
|
| - MockHttpStreamFactoryImpl(HttpNetworkSession* session)
|
| + explicit MockHttpStreamFactoryImpl(HttpNetworkSession* session)
|
| : HttpStreamFactoryImpl(session),
|
| preconnect_done_(false),
|
| waiting_for_preconnect_(false) {}
|
| @@ -76,6 +98,26 @@ class StreamRequestWaiter : public HttpStreamRequest::Delegate {
|
| stream_.reset(stream);
|
| }
|
|
|
| + virtual void OnSocketReadyForWebSocket(
|
| + 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 OnSpdySessionReadyForWebSocket(
|
| + 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 +148,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 +520,173 @@ 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) {
|
| + ScopedForceSpdySsl 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) {
|
| + ScopedForceSpdySsl use_spdy;
|
| + 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));
|
| +
|
| + // 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;
|
| + scoped_ptr<HttpStreamRequest> request1(
|
| + session->http_stream_factory()->RequestStreamForWebSocket(
|
| + request_info,
|
| + DEFAULT_PRIORITY,
|
| + ssl_config,
|
| + ssl_config,
|
| + &waiter1,
|
| + BoundNetLog()));
|
| + waiter1.WaitForStream();
|
| + EXPECT_TRUE(waiter1.stream_done());
|
| + EXPECT_TRUE(NULL != waiter1.spdy_session());
|
| + EXPECT_TRUE(NULL == waiter1.connection());
|
| + EXPECT_TRUE(NULL == waiter1.stream());
|
| +
|
| + StreamRequestWaiter waiter2;
|
| + scoped_ptr<HttpStreamRequest> request2(
|
| + session->http_stream_factory()->RequestStreamForWebSocket(
|
| + request_info,
|
| + DEFAULT_PRIORITY,
|
| + ssl_config,
|
| + ssl_config,
|
| + &waiter2,
|
| + BoundNetLog()));
|
| + waiter2.WaitForStream();
|
| + EXPECT_TRUE(waiter2.stream_done());
|
| + EXPECT_TRUE(NULL != waiter2.spdy_session());
|
| + EXPECT_TRUE(NULL == waiter2.connection());
|
| + EXPECT_TRUE(NULL == waiter2.stream());
|
| + EXPECT_EQ(waiter2.spdy_session(), waiter1.spdy_session());
|
| +}
|
| +
|
| } // namespace
|
|
|
| } // namespace net
|
|
|