Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(96)

Unified Diff: net/http/http_stream_factory_impl_unittest.cc

Issue 14813024: Introduce RequestWebSocketStream into HttpStreamFactory (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix a comment. Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..bcff43029c312f72767db37fd5538e004345bc5a 100644
--- a/net/http/http_stream_factory_impl_unittest.cc
+++ b/net/http/http_stream_factory_impl_unittest.cc
@@ -19,20 +19,68 @@
#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 {
+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) {}
@@ -76,6 +124,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 +174,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 +196,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();
Adam Rice 2013/05/13 13:03:03 This looks like the MockSSLConfigService is never
yhirano 2013/05/14 05:43:53 Thanks, done.
+ }
scoped_ptr<MockHostResolverBase> host_resolver;
scoped_ptr<CertVerifier> cert_verifier;
@@ -470,6 +554,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
Adam Rice 2013/05/13 13:03:03 Doesn't ProxyService::CreateDirect() above imply t
yhirano 2013/05/14 05:43:53 Thanks, I copied from the comment from the above t
+ // 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
« net/http/http_stream_factory_impl_job.cc ('K') | « net/http/http_stream_factory_impl_request.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698