Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "net/http/http_stream_factory_impl.h" | 5 #include "net/http/http_stream_factory_impl.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <vector> | |
| 8 | 9 |
| 9 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 10 #include "net/base/net_log.h" | 11 #include "net/base/net_log.h" |
| 11 #include "net/base/test_completion_callback.h" | 12 #include "net/base/test_completion_callback.h" |
| 12 #include "net/cert/mock_cert_verifier.h" | 13 #include "net/cert/mock_cert_verifier.h" |
| 13 #include "net/dns/mock_host_resolver.h" | 14 #include "net/dns/mock_host_resolver.h" |
| 14 #include "net/http/http_auth_handler_factory.h" | 15 #include "net/http/http_auth_handler_factory.h" |
| 15 #include "net/http/http_network_session.h" | 16 #include "net/http/http_network_session.h" |
| 16 #include "net/http/http_network_session_peer.h" | 17 #include "net/http/http_network_session_peer.h" |
| 17 #include "net/http/http_network_transaction.h" | 18 #include "net/http/http_network_transaction.h" |
| 18 #include "net/http/http_request_info.h" | 19 #include "net/http/http_request_info.h" |
| 20 #include "net/http/http_server_properties.h" | |
| 19 #include "net/http/http_server_properties_impl.h" | 21 #include "net/http/http_server_properties_impl.h" |
| 20 #include "net/http/http_stream.h" | 22 #include "net/http/http_stream.h" |
| 21 #include "net/proxy/proxy_info.h" | 23 #include "net/proxy/proxy_info.h" |
| 22 #include "net/proxy/proxy_service.h" | 24 #include "net/proxy/proxy_service.h" |
| 25 #include "net/socket/client_socket_handle.h" | |
| 23 #include "net/socket/mock_client_socket_pool_manager.h" | 26 #include "net/socket/mock_client_socket_pool_manager.h" |
| 27 #include "net/socket/next_proto.h" | |
| 24 #include "net/socket/socket_test_util.h" | 28 #include "net/socket/socket_test_util.h" |
| 25 #include "net/spdy/spdy_session.h" | 29 #include "net/spdy/spdy_session.h" |
| 26 #include "net/spdy/spdy_session_pool.h" | 30 #include "net/spdy/spdy_session_pool.h" |
| 31 #include "net/spdy/spdy_test_util_common.h" | |
| 32 #include "net/ssl/ssl_config_service.h" | |
| 27 #include "net/ssl/ssl_config_service_defaults.h" | 33 #include "net/ssl/ssl_config_service_defaults.h" |
| 34 // This file can be included from net/http even though | |
| 35 // it is in net/websockets because it doesn't | |
| 36 // introduce any link dependency to net/websockets. | |
| 37 #include "net/websockets/websocket_stream_base.h" | |
| 28 #include "testing/gtest/include/gtest/gtest.h" | 38 #include "testing/gtest/include/gtest/gtest.h" |
| 29 | 39 |
| 30 namespace net { | 40 namespace net { |
| 31 | 41 |
| 42 class MockWebSocketStream : public WebSocketStreamBase { | |
| 43 public: | |
| 44 enum StreamType { | |
| 45 kStreamTypeBasic, | |
| 46 kStreamTypeSpdy, | |
| 47 }; | |
| 48 | |
| 49 explicit MockWebSocketStream(StreamType type) : type_(type) {} | |
| 50 | |
| 51 virtual ~MockWebSocketStream() {} | |
| 52 | |
| 53 virtual WebSocketStream* AsWebSocketStream() OVERRIDE { return NULL; } | |
| 54 | |
| 55 StreamType type() const { | |
| 56 return type_; | |
| 57 } | |
| 58 | |
| 59 private: | |
| 60 const StreamType type_; | |
| 61 }; | |
| 62 | |
| 32 namespace { | 63 namespace { |
| 33 | 64 |
| 34 class MockHttpStreamFactoryImpl : public HttpStreamFactoryImpl { | 65 // HttpStreamFactoryImpl subclass that can wait until a preconnect is complete. |
| 66 class MockHttpStreamFactoryImplForPreconnect : public HttpStreamFactoryImpl { | |
| 35 public: | 67 public: |
| 36 MockHttpStreamFactoryImpl(HttpNetworkSession* session) | 68 MockHttpStreamFactoryImplForPreconnect(HttpNetworkSession* session, |
| 37 : HttpStreamFactoryImpl(session), | 69 bool for_websockets) |
| 70 : HttpStreamFactoryImpl(session, for_websockets), | |
| 38 preconnect_done_(false), | 71 preconnect_done_(false), |
| 39 waiting_for_preconnect_(false) {} | 72 waiting_for_preconnect_(false) {} |
| 40 | 73 |
| 41 | 74 |
| 42 void WaitForPreconnects() { | 75 void WaitForPreconnects() { |
| 43 while (!preconnect_done_) { | 76 while (!preconnect_done_) { |
| 44 waiting_for_preconnect_ = true; | 77 waiting_for_preconnect_ = true; |
| 45 base::MessageLoop::current()->Run(); | 78 base::MessageLoop::current()->Run(); |
| 46 waiting_for_preconnect_ = false; | 79 waiting_for_preconnect_ = false; |
| 47 } | 80 } |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 69 | 102 |
| 70 virtual void OnStreamReady( | 103 virtual void OnStreamReady( |
| 71 const SSLConfig& used_ssl_config, | 104 const SSLConfig& used_ssl_config, |
| 72 const ProxyInfo& used_proxy_info, | 105 const ProxyInfo& used_proxy_info, |
| 73 HttpStreamBase* stream) OVERRIDE { | 106 HttpStreamBase* stream) OVERRIDE { |
| 74 stream_done_ = true; | 107 stream_done_ = true; |
| 75 if (waiting_for_stream_) | 108 if (waiting_for_stream_) |
| 76 base::MessageLoop::current()->Quit(); | 109 base::MessageLoop::current()->Quit(); |
| 77 stream_.reset(stream); | 110 stream_.reset(stream); |
| 78 used_ssl_config_ = used_ssl_config; | 111 used_ssl_config_ = used_ssl_config; |
| 112 used_proxy_info_ = used_proxy_info; | |
| 113 } | |
| 114 | |
| 115 virtual void OnWebSocketStreamReady( | |
| 116 const SSLConfig& used_ssl_config, | |
| 117 const ProxyInfo& used_proxy_info, | |
| 118 WebSocketStreamBase* stream) OVERRIDE { | |
| 119 stream_done_ = true; | |
| 120 if (waiting_for_stream_) | |
| 121 base::MessageLoop::current()->Quit(); | |
| 122 websocket_stream_.reset(stream); | |
| 123 used_ssl_config_ = used_ssl_config; | |
| 124 used_proxy_info_ = used_proxy_info; | |
| 79 } | 125 } |
| 80 | 126 |
| 81 virtual void OnStreamFailed( | 127 virtual void OnStreamFailed( |
| 82 int status, | 128 int status, |
| 83 const SSLConfig& used_ssl_config) OVERRIDE {} | 129 const SSLConfig& used_ssl_config) OVERRIDE {} |
| 84 | 130 |
| 85 virtual void OnCertificateError( | 131 virtual void OnCertificateError( |
| 86 int status, | 132 int status, |
| 87 const SSLConfig& used_ssl_config, | 133 const SSLConfig& used_ssl_config, |
| 88 const SSLInfo& ssl_info) OVERRIDE {} | 134 const SSLInfo& ssl_info) OVERRIDE {} |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 105 waiting_for_stream_ = true; | 151 waiting_for_stream_ = true; |
| 106 base::MessageLoop::current()->Run(); | 152 base::MessageLoop::current()->Run(); |
| 107 waiting_for_stream_ = false; | 153 waiting_for_stream_ = false; |
| 108 } | 154 } |
| 109 } | 155 } |
| 110 | 156 |
| 111 const SSLConfig& used_ssl_config() const { | 157 const SSLConfig& used_ssl_config() const { |
| 112 return used_ssl_config_; | 158 return used_ssl_config_; |
| 113 } | 159 } |
| 114 | 160 |
| 161 const ProxyInfo& used_proxy_info() const { | |
| 162 return used_proxy_info_; | |
| 163 } | |
| 164 | |
| 115 HttpStreamBase* stream() { | 165 HttpStreamBase* stream() { |
| 116 return stream_.get(); | 166 return stream_.get(); |
| 117 } | 167 } |
| 118 | 168 |
| 169 WebSocketStreamBase* websocket_stream() { | |
| 170 return websocket_stream_.get(); | |
| 171 } | |
| 172 | |
| 173 bool stream_done() const { return stream_done_; } | |
| 119 | 174 |
| 120 private: | 175 private: |
| 121 bool waiting_for_stream_; | 176 bool waiting_for_stream_; |
| 122 bool stream_done_; | 177 bool stream_done_; |
| 123 scoped_ptr<HttpStreamBase> stream_; | 178 scoped_ptr<HttpStreamBase> stream_; |
| 179 scoped_ptr<WebSocketStreamBase> websocket_stream_; | |
| 124 SSLConfig used_ssl_config_; | 180 SSLConfig used_ssl_config_; |
| 181 ProxyInfo used_proxy_info_; | |
| 125 | 182 |
| 126 DISALLOW_COPY_AND_ASSIGN(StreamRequestWaiter); | 183 DISALLOW_COPY_AND_ASSIGN(StreamRequestWaiter); |
| 127 }; | 184 }; |
| 128 | 185 |
| 186 class WebSocketSpdyStream : public MockWebSocketStream { | |
| 187 public: | |
| 188 explicit WebSocketSpdyStream(SpdySession* spdy_session) | |
| 189 : MockWebSocketStream(kStreamTypeSpdy), spdy_session_(spdy_session) {} | |
| 190 | |
| 191 virtual ~WebSocketSpdyStream() {} | |
| 192 | |
| 193 SpdySession* spdy_session() { return spdy_session_.get(); } | |
| 194 | |
| 195 private: | |
| 196 scoped_refptr<SpdySession> spdy_session_; | |
| 197 }; | |
| 198 | |
| 199 class WebSocketBasicStream : public MockWebSocketStream { | |
| 200 public: | |
| 201 explicit WebSocketBasicStream(ClientSocketHandle* connection) | |
| 202 : MockWebSocketStream(kStreamTypeBasic), connection_(connection) {} | |
| 203 | |
| 204 virtual ~WebSocketBasicStream() {} | |
|
mmenke
2013/06/10 20:26:03
Suggest you call connection_.socket()->Disconnect(
yhirano
2013/06/11 11:13:16
Done, but I don't understand why this is necessary
mmenke
2013/06/12 02:27:05
When a ClientSocketHandle is deleted, by default,
yhirano
2013/06/12 06:44:56
Thank you, I understand.
| |
| 205 | |
| 206 ClientSocketHandle* connection() { return connection_.get(); } | |
| 207 | |
| 208 private: | |
| 209 scoped_ptr<ClientSocketHandle> connection_; | |
| 210 }; | |
| 211 | |
| 212 class WebSocketStreamFactory : public WebSocketStreamBase::Factory { | |
| 213 public: | |
|
mmenke
2013/06/10 20:26:03
Should have a virtual destructor, per Google style
yhirano
2013/06/11 11:13:16
Done.
| |
| 214 virtual WebSocketStreamBase* CreateBasicStream(ClientSocketHandle* connection, | |
| 215 bool using_proxy) OVERRIDE { | |
| 216 return new WebSocketBasicStream(connection); | |
| 217 } | |
| 218 virtual WebSocketStreamBase* CreateSpdyStream( | |
| 219 SpdySession* spdy_session, | |
| 220 bool use_relative_url) OVERRIDE { | |
| 221 return new WebSocketSpdyStream(spdy_session); | |
| 222 } | |
| 223 }; | |
| 224 | |
| 129 struct SessionDependencies { | 225 struct SessionDependencies { |
| 130 // Custom proxy service dependency. | 226 // Custom proxy service dependency. |
| 131 explicit SessionDependencies(ProxyService* proxy_service) | 227 explicit SessionDependencies(ProxyService* proxy_service) |
| 132 : host_resolver(new MockHostResolver), | 228 : host_resolver(new MockHostResolver), |
| 133 cert_verifier(new MockCertVerifier), | 229 cert_verifier(new MockCertVerifier), |
| 134 proxy_service(proxy_service), | 230 proxy_service(proxy_service), |
| 135 ssl_config_service(new SSLConfigServiceDefaults), | 231 ssl_config_service(new SSLConfigServiceDefaults), |
| 136 http_auth_handler_factory( | 232 http_auth_handler_factory( |
| 137 HttpAuthHandlerFactory::CreateDefault(host_resolver.get())), | 233 HttpAuthHandlerFactory::CreateDefault(host_resolver.get())), |
| 138 net_log(NULL) {} | 234 net_log(NULL) {} |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 151 HttpNetworkSession::Params params; | 247 HttpNetworkSession::Params params; |
| 152 params.host_resolver = session_deps->host_resolver.get(); | 248 params.host_resolver = session_deps->host_resolver.get(); |
| 153 params.cert_verifier = session_deps->cert_verifier.get(); | 249 params.cert_verifier = session_deps->cert_verifier.get(); |
| 154 params.proxy_service = session_deps->proxy_service.get(); | 250 params.proxy_service = session_deps->proxy_service.get(); |
| 155 params.ssl_config_service = session_deps->ssl_config_service.get(); | 251 params.ssl_config_service = session_deps->ssl_config_service.get(); |
| 156 params.client_socket_factory = &session_deps->socket_factory; | 252 params.client_socket_factory = &session_deps->socket_factory; |
| 157 params.http_auth_handler_factory = | 253 params.http_auth_handler_factory = |
| 158 session_deps->http_auth_handler_factory.get(); | 254 session_deps->http_auth_handler_factory.get(); |
| 159 params.net_log = session_deps->net_log; | 255 params.net_log = session_deps->net_log; |
| 160 params.http_server_properties = &session_deps->http_server_properties; | 256 params.http_server_properties = &session_deps->http_server_properties; |
| 257 | |
| 161 return new HttpNetworkSession(params); | 258 return new HttpNetworkSession(params); |
| 162 } | 259 } |
| 163 | 260 |
| 164 struct TestCase { | 261 struct TestCase { |
| 165 int num_streams; | 262 int num_streams; |
| 166 bool ssl; | 263 bool ssl; |
| 167 }; | 264 }; |
| 168 | 265 |
| 169 TestCase kTests[] = { | 266 TestCase kTests[] = { |
| 170 { 1, false }, | 267 { 1, false }, |
| 171 { 2, false }, | 268 { 2, false }, |
| 172 { 1, true}, | 269 { 1, true}, |
| 173 { 2, true}, | 270 { 2, true}, |
| 174 }; | 271 }; |
| 175 | 272 |
| 176 void PreconnectHelperForURL(int num_streams, | 273 void PreconnectHelperForURL(int num_streams, |
| 177 const GURL& url, | 274 const GURL& url, |
| 178 HttpNetworkSession* session) { | 275 HttpNetworkSession* session) { |
| 179 HttpNetworkSessionPeer peer(session); | 276 HttpNetworkSessionPeer peer(session); |
| 180 MockHttpStreamFactoryImpl* mock_factory = | 277 MockHttpStreamFactoryImplForPreconnect* mock_factory = |
| 181 new MockHttpStreamFactoryImpl(session); | 278 new MockHttpStreamFactoryImplForPreconnect(session, false); |
| 182 peer.SetHttpStreamFactory(mock_factory); | 279 peer.SetHttpStreamFactory(mock_factory); |
| 183 SSLConfig ssl_config; | 280 SSLConfig ssl_config; |
| 184 session->ssl_config_service()->GetSSLConfig(&ssl_config); | 281 session->ssl_config_service()->GetSSLConfig(&ssl_config); |
| 185 | 282 |
| 186 HttpRequestInfo request; | 283 HttpRequestInfo request; |
| 187 request.method = "GET"; | 284 request.method = "GET"; |
| 188 request.url = url; | 285 request.url = url; |
| 189 request.load_flags = 0; | 286 request.load_flags = 0; |
| 190 | 287 |
| 191 session->http_stream_factory()->PreconnectStreams( | 288 session->http_stream_factory()->PreconnectStreams( |
| (...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 453 socket_data1.set_connect_data(MockConnect(ASYNC, ERR_ADDRESS_UNREACHABLE)); | 550 socket_data1.set_connect_data(MockConnect(ASYNC, ERR_ADDRESS_UNREACHABLE)); |
| 454 session_deps.socket_factory.AddSocketDataProvider(&socket_data1); | 551 session_deps.socket_factory.AddSocketDataProvider(&socket_data1); |
| 455 | 552 |
| 456 // Second connection attempt succeeds | 553 // Second connection attempt succeeds |
| 457 StaticSocketDataProvider socket_data2; | 554 StaticSocketDataProvider socket_data2; |
| 458 socket_data2.set_connect_data(MockConnect(ASYNC, OK)); | 555 socket_data2.set_connect_data(MockConnect(ASYNC, OK)); |
| 459 session_deps.socket_factory.AddSocketDataProvider(&socket_data2); | 556 session_deps.socket_factory.AddSocketDataProvider(&socket_data2); |
| 460 | 557 |
| 461 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps)); | 558 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps)); |
| 462 | 559 |
| 463 // Now request a stream. It should succeed using the second proxy in the | 560 // Now request a stream. It should succeed using the second proxy in the |
| 464 // list. | 561 // list. |
| 465 HttpRequestInfo request_info; | 562 HttpRequestInfo request_info; |
| 466 request_info.method = "GET"; | 563 request_info.method = "GET"; |
| 467 request_info.url = GURL("http://www.google.com"); | 564 request_info.url = GURL("http://www.google.com"); |
| 468 | 565 |
| 469 SSLConfig ssl_config; | 566 SSLConfig ssl_config; |
| 470 StreamRequestWaiter waiter; | 567 StreamRequestWaiter waiter; |
| 471 scoped_ptr<HttpStreamRequest> request( | 568 scoped_ptr<HttpStreamRequest> request( |
| 472 session->http_stream_factory()->RequestStream( | 569 session->http_stream_factory()->RequestStream( |
| 473 request_info, DEFAULT_PRIORITY, ssl_config, ssl_config, | 570 request_info, DEFAULT_PRIORITY, ssl_config, ssl_config, |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 603 scoped_ptr<HttpStreamRequest> request( | 700 scoped_ptr<HttpStreamRequest> request( |
| 604 session->http_stream_factory()->RequestStream( | 701 session->http_stream_factory()->RequestStream( |
| 605 request_info, DEFAULT_PRIORITY, ssl_config, ssl_config, | 702 request_info, DEFAULT_PRIORITY, ssl_config, ssl_config, |
| 606 &waiter, BoundNetLog())); | 703 &waiter, BoundNetLog())); |
| 607 | 704 |
| 608 EXPECT_EQ(LOAD_STATE_RESOLVING_HOST, request->GetLoadState()); | 705 EXPECT_EQ(LOAD_STATE_RESOLVING_HOST, request->GetLoadState()); |
| 609 | 706 |
| 610 waiter.WaitForStream(); | 707 waiter.WaitForStream(); |
| 611 } | 708 } |
| 612 | 709 |
| 710 TEST(HttpStreamFactoryTest, RequestHttpStream) { | |
| 711 SessionDependencies session_deps(ProxyService::CreateDirect()); | |
| 712 | |
| 713 StaticSocketDataProvider socket_data; | |
| 714 socket_data.set_connect_data(MockConnect(ASYNC, OK)); | |
| 715 session_deps.socket_factory.AddSocketDataProvider(&socket_data); | |
| 716 | |
| 717 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps)); | |
| 718 | |
| 719 // Now request a stream. It should succeed using the second proxy in the | |
| 720 // list. | |
| 721 HttpRequestInfo request_info; | |
| 722 request_info.method = "GET"; | |
| 723 request_info.url = GURL("http://www.google.com"); | |
| 724 request_info.load_flags = 0; | |
| 725 | |
| 726 SSLConfig ssl_config; | |
| 727 StreamRequestWaiter waiter; | |
| 728 scoped_ptr<HttpStreamRequest> request( | |
| 729 session->http_stream_factory()->RequestStream( | |
| 730 request_info, | |
| 731 DEFAULT_PRIORITY, | |
| 732 ssl_config, | |
| 733 ssl_config, | |
| 734 &waiter, | |
| 735 BoundNetLog())); | |
| 736 waiter.WaitForStream(); | |
| 737 EXPECT_TRUE(waiter.stream_done()); | |
| 738 EXPECT_TRUE(NULL != waiter.stream()); | |
|
mmenke
2013/06/10 20:26:03
ASSERT_TRUE (Same for all the other NULL checks l
yhirano
2013/06/11 11:13:16
Done.
| |
| 739 EXPECT_TRUE(NULL == waiter.websocket_stream()); | |
| 740 EXPECT_FALSE(waiter.stream()->IsSpdyHttpStream()); | |
| 741 | |
| 742 EXPECT_EQ(1, GetSocketPoolGroupCount( | |
| 743 session->GetTransportSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL))); | |
| 744 EXPECT_EQ(0, GetSocketPoolGroupCount(session->GetSSLSocketPool( | |
| 745 HttpNetworkSession::NORMAL_SOCKET_POOL))); | |
| 746 EXPECT_TRUE(waiter.used_proxy_info().is_direct()); | |
| 747 } | |
| 748 | |
| 749 TEST(HttpStreamFactoryTest, RequestHttpStreamOverSSL) { | |
| 750 SessionDependencies session_deps(ProxyService::CreateDirect()); | |
| 751 | |
| 752 MockRead mock_read(ASYNC, ERR_IO_PENDING); | |
| 753 StaticSocketDataProvider socket_data(&mock_read, 1, NULL, 0); | |
| 754 socket_data.set_connect_data(MockConnect(ASYNC, OK)); | |
| 755 session_deps.socket_factory.AddSocketDataProvider(&socket_data); | |
| 756 | |
| 757 SSLSocketDataProvider ssl_socket_data(ASYNC, OK); | |
| 758 session_deps.socket_factory.AddSSLSocketDataProvider(&ssl_socket_data); | |
| 759 | |
| 760 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps)); | |
| 761 | |
| 762 // Now request a stream. | |
| 763 HttpRequestInfo request_info; | |
| 764 request_info.method = "GET"; | |
| 765 request_info.url = GURL("https://www.google.com"); | |
| 766 request_info.load_flags = 0; | |
| 767 | |
| 768 SSLConfig ssl_config; | |
| 769 StreamRequestWaiter waiter; | |
| 770 scoped_ptr<HttpStreamRequest> request( | |
| 771 session->http_stream_factory()->RequestStream( | |
| 772 request_info, | |
| 773 DEFAULT_PRIORITY, | |
| 774 ssl_config, | |
| 775 ssl_config, | |
| 776 &waiter, | |
| 777 BoundNetLog())); | |
| 778 waiter.WaitForStream(); | |
| 779 EXPECT_TRUE(waiter.stream_done()); | |
| 780 EXPECT_TRUE(NULL == waiter.websocket_stream()); | |
| 781 EXPECT_TRUE(NULL != waiter.stream()); | |
|
mmenke
2013/06/10 20:26:03
nit: Should use consistent order for these two te
yhirano
2013/06/11 11:13:16
Done.
| |
| 782 EXPECT_FALSE(waiter.stream()->IsSpdyHttpStream()); | |
| 783 EXPECT_EQ(1, GetSocketPoolGroupCount( | |
| 784 session->GetTransportSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL))); | |
| 785 EXPECT_EQ(1, GetSocketPoolGroupCount( | |
| 786 session->GetSSLSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL))); | |
| 787 EXPECT_TRUE(waiter.used_proxy_info().is_direct()); | |
| 788 } | |
| 789 | |
| 790 TEST(HttpStreamFactoryTest, RequestHttpStreamOverProxy) { | |
| 791 SessionDependencies session_deps(ProxyService::CreateFixed("myproxy:8888")); | |
| 792 | |
| 793 StaticSocketDataProvider socket_data; | |
| 794 socket_data.set_connect_data(MockConnect(ASYNC, OK)); | |
| 795 session_deps.socket_factory.AddSocketDataProvider(&socket_data); | |
| 796 | |
| 797 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps)); | |
| 798 | |
| 799 // Now request a stream. It should succeed using the second proxy in the | |
| 800 // list. | |
| 801 HttpRequestInfo request_info; | |
| 802 request_info.method = "GET"; | |
| 803 request_info.url = GURL("http://www.google.com"); | |
| 804 request_info.load_flags = 0; | |
| 805 | |
| 806 SSLConfig ssl_config; | |
| 807 StreamRequestWaiter waiter; | |
| 808 scoped_ptr<HttpStreamRequest> request( | |
| 809 session->http_stream_factory()->RequestStream( | |
| 810 request_info, | |
| 811 DEFAULT_PRIORITY, | |
| 812 ssl_config, | |
| 813 ssl_config, | |
| 814 &waiter, | |
| 815 BoundNetLog())); | |
| 816 waiter.WaitForStream(); | |
| 817 EXPECT_TRUE(waiter.stream_done()); | |
| 818 EXPECT_TRUE(NULL == waiter.websocket_stream()); | |
| 819 EXPECT_TRUE(NULL != waiter.stream()); | |
| 820 EXPECT_FALSE(waiter.stream()->IsSpdyHttpStream()); | |
| 821 EXPECT_EQ(0, GetSocketPoolGroupCount( | |
| 822 session->GetTransportSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL))); | |
| 823 EXPECT_EQ(0, GetSocketPoolGroupCount( | |
| 824 session->GetSSLSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL))); | |
| 825 EXPECT_EQ(1, GetSocketPoolGroupCount(session->GetSocketPoolForHTTPProxy( | |
| 826 HttpNetworkSession::NORMAL_SOCKET_POOL, | |
| 827 HostPortPair("myproxy", 8888)))); | |
| 828 EXPECT_EQ(0, GetSocketPoolGroupCount(session->GetSocketPoolForSSLWithProxy( | |
| 829 HttpNetworkSession::NORMAL_SOCKET_POOL, | |
| 830 HostPortPair("myproxy", 8888)))); | |
| 831 EXPECT_FALSE(waiter.used_proxy_info().is_direct()); | |
| 832 } | |
| 833 | |
| 834 TEST(HttpStreamFactoryTest, RequestWebSocketBasicStream) { | |
| 835 SessionDependencies session_deps(ProxyService::CreateDirect()); | |
| 836 | |
| 837 StaticSocketDataProvider socket_data; | |
| 838 socket_data.set_connect_data(MockConnect(ASYNC, OK)); | |
| 839 session_deps.socket_factory.AddSocketDataProvider(&socket_data); | |
| 840 | |
| 841 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps)); | |
| 842 | |
| 843 // Now request a stream. | |
| 844 HttpRequestInfo request_info; | |
| 845 request_info.method = "GET"; | |
| 846 request_info.url = GURL("ws://www.google.com"); | |
| 847 request_info.load_flags = 0; | |
| 848 | |
| 849 SSLConfig ssl_config; | |
| 850 StreamRequestWaiter waiter; | |
| 851 WebSocketStreamFactory factory; | |
| 852 scoped_ptr<HttpStreamRequest> request( | |
| 853 session->websocket_stream_factory()->RequestWebSocketStream( | |
| 854 request_info, | |
| 855 DEFAULT_PRIORITY, | |
| 856 ssl_config, | |
| 857 ssl_config, | |
| 858 &waiter, | |
| 859 &factory, | |
| 860 BoundNetLog())); | |
| 861 waiter.WaitForStream(); | |
| 862 EXPECT_TRUE(waiter.stream_done()); | |
| 863 EXPECT_TRUE(NULL == waiter.stream()); | |
| 864 EXPECT_TRUE(NULL != waiter.websocket_stream()); | |
| 865 EXPECT_EQ(MockWebSocketStream::kStreamTypeBasic, | |
| 866 static_cast<MockWebSocketStream*>(waiter.websocket_stream()) | |
|
mmenke
2013/06/10 20:26:03
Suggest having the waiter do the cast to MockWebSo
yhirano
2013/06/11 11:13:16
Done.
| |
| 867 ->type()); | |
| 868 EXPECT_EQ(1, GetSocketPoolGroupCount( | |
| 869 session->GetTransportSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL))); | |
| 870 EXPECT_EQ(0, GetSocketPoolGroupCount( | |
| 871 session->GetSSLSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL))); | |
| 872 EXPECT_TRUE(waiter.used_proxy_info().is_direct()); | |
| 873 } | |
| 874 | |
| 875 TEST(HttpStreamFactoryTest, RequestWebSocketBasicStreamOverSSL) { | |
| 876 SessionDependencies session_deps(ProxyService::CreateDirect()); | |
| 877 | |
| 878 MockRead mock_read(ASYNC, ERR_IO_PENDING); | |
| 879 StaticSocketDataProvider socket_data(&mock_read, 1, NULL, 0); | |
| 880 socket_data.set_connect_data(MockConnect(ASYNC, OK)); | |
| 881 session_deps.socket_factory.AddSocketDataProvider(&socket_data); | |
| 882 | |
| 883 SSLSocketDataProvider ssl_socket_data(ASYNC, OK); | |
| 884 session_deps.socket_factory.AddSSLSocketDataProvider(&ssl_socket_data); | |
| 885 | |
| 886 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps)); | |
| 887 | |
| 888 // Now request a stream. | |
| 889 HttpRequestInfo request_info; | |
| 890 request_info.method = "GET"; | |
| 891 request_info.url = GURL("wss://www.google.com"); | |
| 892 request_info.load_flags = 0; | |
| 893 | |
| 894 SSLConfig ssl_config; | |
| 895 StreamRequestWaiter waiter; | |
| 896 WebSocketStreamFactory factory; | |
| 897 scoped_ptr<HttpStreamRequest> request( | |
| 898 session->websocket_stream_factory()->RequestWebSocketStream( | |
| 899 request_info, | |
| 900 DEFAULT_PRIORITY, | |
| 901 ssl_config, | |
| 902 ssl_config, | |
| 903 &waiter, | |
| 904 &factory, | |
| 905 BoundNetLog())); | |
| 906 waiter.WaitForStream(); | |
| 907 EXPECT_TRUE(waiter.stream_done()); | |
| 908 EXPECT_TRUE(NULL == waiter.stream()); | |
| 909 EXPECT_TRUE(NULL != waiter.websocket_stream()); | |
| 910 EXPECT_EQ(MockWebSocketStream::kStreamTypeBasic, | |
| 911 static_cast<MockWebSocketStream*>(waiter.websocket_stream()) | |
| 912 ->type()); | |
| 913 EXPECT_EQ(1, GetSocketPoolGroupCount( | |
| 914 session->GetTransportSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL))); | |
| 915 EXPECT_EQ(1, GetSocketPoolGroupCount( | |
| 916 session->GetSSLSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL))); | |
| 917 EXPECT_TRUE(waiter.used_proxy_info().is_direct()); | |
| 918 } | |
| 919 | |
| 920 TEST(HttpStreamFactoryTest, RequestSpdyHttpStream) { | |
| 921 SpdySessionDependencies session_deps(kProtoSPDY3, | |
| 922 ProxyService::CreateDirect()); | |
| 923 | |
| 924 MockRead mock_read(ASYNC, OK); | |
| 925 StaticSocketDataProvider socket_data(&mock_read, 1, NULL, 0); | |
| 926 socket_data.set_connect_data(MockConnect(ASYNC, OK)); | |
| 927 session_deps.socket_factory->AddSocketDataProvider(&socket_data); | |
| 928 | |
| 929 SSLSocketDataProvider ssl_socket_data(ASYNC, OK); | |
| 930 ssl_socket_data.SetNextProto(kProtoSPDY3); | |
| 931 session_deps.socket_factory->AddSSLSocketDataProvider(&ssl_socket_data); | |
| 932 | |
| 933 HostPortPair host_port_pair("www.google.com", 443); | |
| 934 scoped_refptr<HttpNetworkSession> | |
| 935 session(SpdySessionDependencies::SpdyCreateSession(&session_deps)); | |
| 936 | |
| 937 // Now request a stream. | |
| 938 HttpRequestInfo request_info; | |
| 939 request_info.method = "GET"; | |
| 940 request_info.url = GURL("https://www.google.com"); | |
| 941 request_info.load_flags = 0; | |
| 942 | |
| 943 SSLConfig ssl_config; | |
| 944 StreamRequestWaiter waiter; | |
| 945 scoped_ptr<HttpStreamRequest> request( | |
| 946 session->http_stream_factory()->RequestStream( | |
| 947 request_info, | |
| 948 DEFAULT_PRIORITY, | |
| 949 ssl_config, | |
| 950 ssl_config, | |
| 951 &waiter, | |
| 952 BoundNetLog())); | |
| 953 waiter.WaitForStream(); | |
| 954 EXPECT_TRUE(waiter.stream_done()); | |
| 955 EXPECT_TRUE(NULL == waiter.websocket_stream()); | |
| 956 EXPECT_TRUE(NULL != waiter.stream()); | |
| 957 EXPECT_TRUE(waiter.stream()->IsSpdyHttpStream()); | |
| 958 EXPECT_EQ(1, GetSocketPoolGroupCount( | |
| 959 session->GetTransportSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL))); | |
| 960 EXPECT_EQ(1, GetSocketPoolGroupCount( | |
| 961 session->GetSSLSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL))); | |
| 962 EXPECT_TRUE(waiter.used_proxy_info().is_direct()); | |
| 963 } | |
| 964 | |
| 965 TEST(HttpStreamFactoryTest, RequestWebSocketSpdyStream) { | |
| 966 SpdySessionDependencies session_deps(kProtoSPDY3, | |
| 967 ProxyService::CreateDirect()); | |
| 968 | |
| 969 MockRead mock_read(ASYNC, ERR_IO_PENDING); | |
| 970 StaticSocketDataProvider socket_data(&mock_read, 1, NULL, 0); | |
| 971 socket_data.set_connect_data(MockConnect(ASYNC, OK)); | |
| 972 session_deps.socket_factory->AddSocketDataProvider(&socket_data); | |
| 973 | |
| 974 SSLSocketDataProvider ssl_socket_data(ASYNC, OK); | |
| 975 ssl_socket_data.SetNextProto(kProtoSPDY3); | |
| 976 session_deps.socket_factory->AddSSLSocketDataProvider(&ssl_socket_data); | |
| 977 | |
| 978 HostPortPair host_port_pair("www.google.com", 80); | |
| 979 scoped_refptr<HttpNetworkSession> | |
| 980 session(SpdySessionDependencies::SpdyCreateSession(&session_deps)); | |
| 981 | |
| 982 // Now request a stream. | |
| 983 HttpRequestInfo request_info; | |
| 984 request_info.method = "GET"; | |
| 985 request_info.url = GURL("wss://www.google.com"); | |
| 986 request_info.load_flags = 0; | |
| 987 | |
| 988 SSLConfig ssl_config; | |
| 989 StreamRequestWaiter waiter1; | |
| 990 WebSocketStreamFactory factory; | |
| 991 scoped_ptr<HttpStreamRequest> request1( | |
| 992 session->websocket_stream_factory()->RequestWebSocketStream( | |
| 993 request_info, | |
| 994 DEFAULT_PRIORITY, | |
| 995 ssl_config, | |
| 996 ssl_config, | |
| 997 &waiter1, | |
| 998 &factory, | |
| 999 BoundNetLog())); | |
| 1000 waiter1.WaitForStream(); | |
| 1001 EXPECT_TRUE(waiter1.stream_done()); | |
| 1002 EXPECT_TRUE(NULL != waiter1.websocket_stream()); | |
| 1003 EXPECT_EQ(MockWebSocketStream::kStreamTypeSpdy, | |
| 1004 static_cast<MockWebSocketStream*>(waiter1.websocket_stream()) | |
| 1005 ->type()); | |
| 1006 EXPECT_TRUE(NULL == waiter1.stream()); | |
| 1007 | |
| 1008 StreamRequestWaiter waiter2; | |
| 1009 scoped_ptr<HttpStreamRequest> request2( | |
| 1010 session->websocket_stream_factory()->RequestWebSocketStream( | |
| 1011 request_info, | |
| 1012 DEFAULT_PRIORITY, | |
| 1013 ssl_config, | |
| 1014 ssl_config, | |
| 1015 &waiter2, | |
| 1016 &factory, | |
| 1017 BoundNetLog())); | |
| 1018 waiter2.WaitForStream(); | |
| 1019 EXPECT_TRUE(waiter2.stream_done()); | |
| 1020 EXPECT_TRUE(NULL != waiter2.websocket_stream()); | |
| 1021 EXPECT_EQ(MockWebSocketStream::kStreamTypeSpdy, | |
| 1022 static_cast<MockWebSocketStream*>(waiter2.websocket_stream()) | |
| 1023 ->type()); | |
| 1024 EXPECT_TRUE(NULL == waiter2.stream()); | |
| 1025 EXPECT_NE(waiter2.websocket_stream(), waiter1.websocket_stream()); | |
| 1026 EXPECT_EQ(static_cast<WebSocketSpdyStream*>(waiter2.websocket_stream())-> | |
| 1027 spdy_session(), | |
| 1028 static_cast<WebSocketSpdyStream*>(waiter1.websocket_stream())-> | |
| 1029 spdy_session()); | |
| 1030 | |
| 1031 EXPECT_EQ(1, GetSocketPoolGroupCount( | |
| 1032 session->GetTransportSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL))); | |
| 1033 EXPECT_EQ(1, GetSocketPoolGroupCount( | |
| 1034 session->GetSSLSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL))); | |
| 1035 EXPECT_TRUE(waiter1.used_proxy_info().is_direct()); | |
| 1036 } | |
| 1037 | |
| 613 } // namespace | 1038 } // namespace |
| 614 | 1039 |
| 615 } // namespace net | 1040 } // namespace net |
| OLD | NEW |