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/http/transport_security_state.h" | 23 #include "net/http/transport_security_state.h" |
| 22 #include "net/proxy/proxy_info.h" | 24 #include "net/proxy/proxy_info.h" |
| 23 #include "net/proxy/proxy_service.h" | 25 #include "net/proxy/proxy_service.h" |
| 26 #include "net/socket/client_socket_handle.h" | |
| 24 #include "net/socket/mock_client_socket_pool_manager.h" | 27 #include "net/socket/mock_client_socket_pool_manager.h" |
| 28 #include "net/socket/next_proto.h" | |
| 25 #include "net/socket/socket_test_util.h" | 29 #include "net/socket/socket_test_util.h" |
| 26 #include "net/spdy/spdy_session.h" | 30 #include "net/spdy/spdy_session.h" |
| 27 #include "net/spdy/spdy_session_pool.h" | 31 #include "net/spdy/spdy_session_pool.h" |
| 32 #include "net/spdy/spdy_test_util_common.h" | |
| 33 #include "net/ssl/ssl_config_service.h" | |
| 28 #include "net/ssl/ssl_config_service_defaults.h" | 34 #include "net/ssl/ssl_config_service_defaults.h" |
| 35 // This file can be included from net/http even though | |
| 36 // it is in net/websockets because it doesn't | |
| 37 // introduce any link dependency to net/websockets. | |
| 38 #include "net/websockets/websocket_stream_base.h" | |
| 29 #include "testing/gtest/include/gtest/gtest.h" | 39 #include "testing/gtest/include/gtest/gtest.h" |
| 30 | 40 |
| 31 namespace net { | 41 namespace net { |
| 32 | 42 |
| 33 namespace { | 43 namespace { |
| 34 | 44 |
| 35 class MockHttpStreamFactoryImpl : public HttpStreamFactoryImpl { | 45 class UseAlternateProtocolsScopedSetter { |
| 36 public: | 46 public: |
| 37 MockHttpStreamFactoryImpl(HttpNetworkSession* session) | 47 UseAlternateProtocolsScopedSetter(bool use_alternate_protocols) |
| 38 : HttpStreamFactoryImpl(session), | 48 : use_alternate_protocols_(HttpStreamFactory::use_alternate_protocols()) { |
| 49 HttpStreamFactory::set_use_alternate_protocols(use_alternate_protocols); | |
| 50 } | |
| 51 ~UseAlternateProtocolsScopedSetter() { | |
| 52 HttpStreamFactory::set_use_alternate_protocols(use_alternate_protocols_); | |
| 53 } | |
| 54 | |
| 55 private: | |
| 56 bool use_alternate_protocols_; | |
| 57 }; | |
| 58 | |
| 59 class MockWebSocketStream : public WebSocketStreamBase { | |
| 60 public: | |
| 61 enum StreamType { | |
| 62 kStreamTypeBasic, | |
| 63 kStreamTypeSpdy, | |
| 64 }; | |
| 65 | |
| 66 explicit MockWebSocketStream(StreamType type) : type_(type) {} | |
| 67 | |
| 68 virtual ~MockWebSocketStream() {} | |
| 69 | |
| 70 virtual WebSocketStream* AsWebSocketStream() OVERRIDE { return NULL; } | |
| 71 | |
| 72 StreamType type() const { | |
| 73 return type_; | |
| 74 } | |
| 75 | |
| 76 private: | |
| 77 const StreamType type_; | |
| 78 }; | |
| 79 | |
| 80 // HttpStreamFactoryImpl subclass that can wait until a preconnect is complete. | |
| 81 class MockHttpStreamFactoryImplForPreconnect : public HttpStreamFactoryImpl { | |
| 82 public: | |
| 83 MockHttpStreamFactoryImplForPreconnect(HttpNetworkSession* session, | |
| 84 bool for_websockets) | |
| 85 : HttpStreamFactoryImpl(session, for_websockets), | |
| 39 preconnect_done_(false), | 86 preconnect_done_(false), |
| 40 waiting_for_preconnect_(false) {} | 87 waiting_for_preconnect_(false) {} |
| 41 | 88 |
| 42 | 89 |
| 43 void WaitForPreconnects() { | 90 void WaitForPreconnects() { |
| 44 while (!preconnect_done_) { | 91 while (!preconnect_done_) { |
| 45 waiting_for_preconnect_ = true; | 92 waiting_for_preconnect_ = true; |
| 46 base::MessageLoop::current()->Run(); | 93 base::MessageLoop::current()->Run(); |
| 47 waiting_for_preconnect_ = false; | 94 waiting_for_preconnect_ = false; |
| 48 } | 95 } |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 70 | 117 |
| 71 virtual void OnStreamReady( | 118 virtual void OnStreamReady( |
| 72 const SSLConfig& used_ssl_config, | 119 const SSLConfig& used_ssl_config, |
| 73 const ProxyInfo& used_proxy_info, | 120 const ProxyInfo& used_proxy_info, |
| 74 HttpStreamBase* stream) OVERRIDE { | 121 HttpStreamBase* stream) OVERRIDE { |
| 75 stream_done_ = true; | 122 stream_done_ = true; |
| 76 if (waiting_for_stream_) | 123 if (waiting_for_stream_) |
| 77 base::MessageLoop::current()->Quit(); | 124 base::MessageLoop::current()->Quit(); |
| 78 stream_.reset(stream); | 125 stream_.reset(stream); |
| 79 used_ssl_config_ = used_ssl_config; | 126 used_ssl_config_ = used_ssl_config; |
| 127 used_proxy_info_ = used_proxy_info; | |
| 128 } | |
| 129 | |
| 130 virtual void OnWebSocketStreamReady( | |
| 131 const SSLConfig& used_ssl_config, | |
| 132 const ProxyInfo& used_proxy_info, | |
| 133 WebSocketStreamBase* stream) OVERRIDE { | |
| 134 stream_done_ = true; | |
| 135 if (waiting_for_stream_) | |
| 136 base::MessageLoop::current()->Quit(); | |
| 137 websocket_stream_.reset(stream); | |
| 138 used_ssl_config_ = used_ssl_config; | |
| 139 used_proxy_info_ = used_proxy_info; | |
| 80 } | 140 } |
| 81 | 141 |
| 82 virtual void OnStreamFailed( | 142 virtual void OnStreamFailed( |
| 83 int status, | 143 int status, |
| 84 const SSLConfig& used_ssl_config) OVERRIDE {} | 144 const SSLConfig& used_ssl_config) OVERRIDE {} |
| 85 | 145 |
| 86 virtual void OnCertificateError( | 146 virtual void OnCertificateError( |
| 87 int status, | 147 int status, |
| 88 const SSLConfig& used_ssl_config, | 148 const SSLConfig& used_ssl_config, |
| 89 const SSLInfo& ssl_info) OVERRIDE {} | 149 const SSLInfo& ssl_info) OVERRIDE {} |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 106 waiting_for_stream_ = true; | 166 waiting_for_stream_ = true; |
| 107 base::MessageLoop::current()->Run(); | 167 base::MessageLoop::current()->Run(); |
| 108 waiting_for_stream_ = false; | 168 waiting_for_stream_ = false; |
| 109 } | 169 } |
| 110 } | 170 } |
| 111 | 171 |
| 112 const SSLConfig& used_ssl_config() const { | 172 const SSLConfig& used_ssl_config() const { |
| 113 return used_ssl_config_; | 173 return used_ssl_config_; |
| 114 } | 174 } |
| 115 | 175 |
| 176 const ProxyInfo& used_proxy_info() const { | |
| 177 return used_proxy_info_; | |
| 178 } | |
| 179 | |
| 116 HttpStreamBase* stream() { | 180 HttpStreamBase* stream() { |
| 117 return stream_.get(); | 181 return stream_.get(); |
| 118 } | 182 } |
| 119 | 183 |
| 184 MockWebSocketStream* websocket_stream() { | |
| 185 return static_cast<MockWebSocketStream*>(websocket_stream_.get()); | |
| 186 } | |
| 187 | |
| 188 bool stream_done() const { return stream_done_; } | |
| 120 | 189 |
| 121 private: | 190 private: |
| 122 bool waiting_for_stream_; | 191 bool waiting_for_stream_; |
| 123 bool stream_done_; | 192 bool stream_done_; |
| 124 scoped_ptr<HttpStreamBase> stream_; | 193 scoped_ptr<HttpStreamBase> stream_; |
| 194 scoped_ptr<WebSocketStreamBase> websocket_stream_; | |
| 125 SSLConfig used_ssl_config_; | 195 SSLConfig used_ssl_config_; |
| 196 ProxyInfo used_proxy_info_; | |
| 126 | 197 |
| 127 DISALLOW_COPY_AND_ASSIGN(StreamRequestWaiter); | 198 DISALLOW_COPY_AND_ASSIGN(StreamRequestWaiter); |
| 128 }; | 199 }; |
| 129 | 200 |
| 201 class WebSocketSpdyStream : public MockWebSocketStream { | |
| 202 public: | |
| 203 explicit WebSocketSpdyStream(SpdySession* spdy_session) | |
| 204 : MockWebSocketStream(kStreamTypeSpdy), spdy_session_(spdy_session) {} | |
| 205 | |
| 206 virtual ~WebSocketSpdyStream() {} | |
| 207 | |
| 208 SpdySession* spdy_session() { return spdy_session_.get(); } | |
| 209 | |
| 210 private: | |
| 211 scoped_refptr<SpdySession> spdy_session_; | |
| 212 }; | |
| 213 | |
| 214 class WebSocketBasicStream : public MockWebSocketStream { | |
| 215 public: | |
| 216 explicit WebSocketBasicStream(ClientSocketHandle* connection) | |
| 217 : MockWebSocketStream(kStreamTypeBasic), connection_(connection) {} | |
| 218 | |
| 219 virtual ~WebSocketBasicStream() { | |
| 220 connection_->socket()->Disconnect(); | |
| 221 } | |
| 222 | |
| 223 ClientSocketHandle* connection() { return connection_.get(); } | |
| 224 | |
| 225 private: | |
| 226 scoped_ptr<ClientSocketHandle> connection_; | |
| 227 }; | |
| 228 | |
| 229 class WebSocketStreamFactory : public WebSocketStreamBase::Factory { | |
| 230 public: | |
| 231 virtual ~WebSocketStreamFactory() {} | |
| 232 | |
| 233 virtual WebSocketStreamBase* CreateBasicStream(ClientSocketHandle* connection, | |
| 234 bool using_proxy) OVERRIDE { | |
| 235 return new WebSocketBasicStream(connection); | |
| 236 } | |
| 237 | |
| 238 virtual WebSocketStreamBase* CreateSpdyStream( | |
| 239 SpdySession* spdy_session, | |
| 240 bool use_relative_url) OVERRIDE { | |
| 241 return new WebSocketSpdyStream(spdy_session); | |
| 242 } | |
| 243 }; | |
| 244 | |
| 130 struct SessionDependencies { | 245 struct SessionDependencies { |
| 131 // Custom proxy service dependency. | 246 // Custom proxy service dependency. |
| 132 explicit SessionDependencies(ProxyService* proxy_service) | 247 explicit SessionDependencies(ProxyService* proxy_service) |
| 133 : host_resolver(new MockHostResolver), | 248 : host_resolver(new MockHostResolver), |
| 134 cert_verifier(new MockCertVerifier), | 249 cert_verifier(new MockCertVerifier), |
| 135 transport_security_state(new TransportSecurityState), | 250 transport_security_state(new TransportSecurityState), |
| 136 proxy_service(proxy_service), | 251 proxy_service(proxy_service), |
| 137 ssl_config_service(new SSLConfigServiceDefaults), | 252 ssl_config_service(new SSLConfigServiceDefaults), |
| 138 http_auth_handler_factory( | 253 http_auth_handler_factory( |
| 139 HttpAuthHandlerFactory::CreateDefault(host_resolver.get())), | 254 HttpAuthHandlerFactory::CreateDefault(host_resolver.get())), |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 156 params.cert_verifier = session_deps->cert_verifier.get(); | 271 params.cert_verifier = session_deps->cert_verifier.get(); |
| 157 params.transport_security_state = | 272 params.transport_security_state = |
| 158 session_deps->transport_security_state.get(); | 273 session_deps->transport_security_state.get(); |
| 159 params.proxy_service = session_deps->proxy_service.get(); | 274 params.proxy_service = session_deps->proxy_service.get(); |
| 160 params.ssl_config_service = session_deps->ssl_config_service.get(); | 275 params.ssl_config_service = session_deps->ssl_config_service.get(); |
| 161 params.client_socket_factory = &session_deps->socket_factory; | 276 params.client_socket_factory = &session_deps->socket_factory; |
| 162 params.http_auth_handler_factory = | 277 params.http_auth_handler_factory = |
| 163 session_deps->http_auth_handler_factory.get(); | 278 session_deps->http_auth_handler_factory.get(); |
| 164 params.net_log = session_deps->net_log; | 279 params.net_log = session_deps->net_log; |
| 165 params.http_server_properties = &session_deps->http_server_properties; | 280 params.http_server_properties = &session_deps->http_server_properties; |
| 281 | |
| 166 return new HttpNetworkSession(params); | 282 return new HttpNetworkSession(params); |
| 167 } | 283 } |
| 168 | 284 |
| 169 struct TestCase { | 285 struct TestCase { |
| 170 int num_streams; | 286 int num_streams; |
| 171 bool ssl; | 287 bool ssl; |
| 172 }; | 288 }; |
| 173 | 289 |
| 174 TestCase kTests[] = { | 290 TestCase kTests[] = { |
| 175 { 1, false }, | 291 { 1, false }, |
| 176 { 2, false }, | 292 { 2, false }, |
| 177 { 1, true}, | 293 { 1, true}, |
| 178 { 2, true}, | 294 { 2, true}, |
| 179 }; | 295 }; |
| 180 | 296 |
| 181 void PreconnectHelperForURL(int num_streams, | 297 void PreconnectHelperForURL(int num_streams, |
| 182 const GURL& url, | 298 const GURL& url, |
| 183 HttpNetworkSession* session) { | 299 HttpNetworkSession* session) { |
| 184 HttpNetworkSessionPeer peer(session); | 300 HttpNetworkSessionPeer peer(session); |
| 185 MockHttpStreamFactoryImpl* mock_factory = | 301 MockHttpStreamFactoryImplForPreconnect* mock_factory = |
| 186 new MockHttpStreamFactoryImpl(session); | 302 new MockHttpStreamFactoryImplForPreconnect(session, false); |
| 187 peer.SetHttpStreamFactory(mock_factory); | 303 peer.SetHttpStreamFactory(mock_factory); |
| 188 SSLConfig ssl_config; | 304 SSLConfig ssl_config; |
| 189 session->ssl_config_service()->GetSSLConfig(&ssl_config); | 305 session->ssl_config_service()->GetSSLConfig(&ssl_config); |
| 190 | 306 |
| 191 HttpRequestInfo request; | 307 HttpRequestInfo request; |
| 192 request.method = "GET"; | 308 request.method = "GET"; |
| 193 request.url = url; | 309 request.url = url; |
| 194 request.load_flags = 0; | 310 request.load_flags = 0; |
| 195 | 311 |
| 196 session->http_stream_factory()->PreconnectStreams( | 312 session->http_stream_factory()->PreconnectStreams( |
| (...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 458 socket_data1.set_connect_data(MockConnect(ASYNC, ERR_ADDRESS_UNREACHABLE)); | 574 socket_data1.set_connect_data(MockConnect(ASYNC, ERR_ADDRESS_UNREACHABLE)); |
| 459 session_deps.socket_factory.AddSocketDataProvider(&socket_data1); | 575 session_deps.socket_factory.AddSocketDataProvider(&socket_data1); |
| 460 | 576 |
| 461 // Second connection attempt succeeds | 577 // Second connection attempt succeeds |
| 462 StaticSocketDataProvider socket_data2; | 578 StaticSocketDataProvider socket_data2; |
| 463 socket_data2.set_connect_data(MockConnect(ASYNC, OK)); | 579 socket_data2.set_connect_data(MockConnect(ASYNC, OK)); |
| 464 session_deps.socket_factory.AddSocketDataProvider(&socket_data2); | 580 session_deps.socket_factory.AddSocketDataProvider(&socket_data2); |
| 465 | 581 |
| 466 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps)); | 582 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps)); |
| 467 | 583 |
| 468 // Now request a stream. It should succeed using the second proxy in the | 584 // Now request a stream. It should succeed using the second proxy in the |
| 469 // list. | 585 // list. |
| 470 HttpRequestInfo request_info; | 586 HttpRequestInfo request_info; |
| 471 request_info.method = "GET"; | 587 request_info.method = "GET"; |
| 472 request_info.url = GURL("http://www.google.com"); | 588 request_info.url = GURL("http://www.google.com"); |
| 473 | 589 |
| 474 SSLConfig ssl_config; | 590 SSLConfig ssl_config; |
| 475 StreamRequestWaiter waiter; | 591 StreamRequestWaiter waiter; |
| 476 scoped_ptr<HttpStreamRequest> request( | 592 scoped_ptr<HttpStreamRequest> request( |
| 477 session->http_stream_factory()->RequestStream( | 593 session->http_stream_factory()->RequestStream( |
| 478 request_info, DEFAULT_PRIORITY, ssl_config, ssl_config, | 594 request_info, DEFAULT_PRIORITY, ssl_config, ssl_config, |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 530 int GetSocketPoolGroupCount(ClientSocketPool* pool) { | 646 int GetSocketPoolGroupCount(ClientSocketPool* pool) { |
| 531 int count = 0; | 647 int count = 0; |
| 532 scoped_ptr<base::DictionaryValue> dict(pool->GetInfoAsValue("", "", false)); | 648 scoped_ptr<base::DictionaryValue> dict(pool->GetInfoAsValue("", "", false)); |
| 533 EXPECT_TRUE(dict != NULL); | 649 EXPECT_TRUE(dict != NULL); |
| 534 base::DictionaryValue* groups = NULL; | 650 base::DictionaryValue* groups = NULL; |
| 535 if (dict->GetDictionary("groups", &groups) && (groups != NULL)) { | 651 if (dict->GetDictionary("groups", &groups) && (groups != NULL)) { |
| 536 count = static_cast<int>(groups->size()); | 652 count = static_cast<int>(groups->size()); |
| 537 } | 653 } |
| 538 return count; | 654 return count; |
| 539 } | 655 } |
| 540 }; | 656 } // namespace |
| 541 | 657 |
| 542 TEST(HttpStreamFactoryTest, PrivacyModeUsesDifferentSocketPoolGroup) { | 658 TEST(HttpStreamFactoryTest, PrivacyModeUsesDifferentSocketPoolGroup) { |
| 543 SessionDependencies session_deps(ProxyService::CreateDirect()); | 659 SessionDependencies session_deps(ProxyService::CreateDirect()); |
| 544 | 660 |
| 545 StaticSocketDataProvider socket_data; | 661 StaticSocketDataProvider socket_data; |
| 546 socket_data.set_connect_data(MockConnect(ASYNC, OK)); | 662 socket_data.set_connect_data(MockConnect(ASYNC, OK)); |
| 547 session_deps.socket_factory.AddSocketDataProvider(&socket_data); | 663 session_deps.socket_factory.AddSocketDataProvider(&socket_data); |
| 548 | 664 |
| 549 SSLSocketDataProvider ssl(ASYNC, OK); | 665 SSLSocketDataProvider ssl(ASYNC, OK); |
| 550 session_deps.socket_factory.AddSSLSocketDataProvider(&ssl); | 666 session_deps.socket_factory.AddSSLSocketDataProvider(&ssl); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 608 scoped_ptr<HttpStreamRequest> request( | 724 scoped_ptr<HttpStreamRequest> request( |
| 609 session->http_stream_factory()->RequestStream( | 725 session->http_stream_factory()->RequestStream( |
| 610 request_info, DEFAULT_PRIORITY, ssl_config, ssl_config, | 726 request_info, DEFAULT_PRIORITY, ssl_config, ssl_config, |
| 611 &waiter, BoundNetLog())); | 727 &waiter, BoundNetLog())); |
| 612 | 728 |
| 613 EXPECT_EQ(LOAD_STATE_RESOLVING_HOST, request->GetLoadState()); | 729 EXPECT_EQ(LOAD_STATE_RESOLVING_HOST, request->GetLoadState()); |
| 614 | 730 |
| 615 waiter.WaitForStream(); | 731 waiter.WaitForStream(); |
| 616 } | 732 } |
| 617 | 733 |
| 734 TEST(HttpStreamFactoryTest, RequestHttpStream) { | |
| 735 SessionDependencies session_deps(ProxyService::CreateDirect()); | |
| 736 | |
| 737 StaticSocketDataProvider socket_data; | |
| 738 socket_data.set_connect_data(MockConnect(ASYNC, OK)); | |
| 739 session_deps.socket_factory.AddSocketDataProvider(&socket_data); | |
| 740 | |
| 741 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps)); | |
| 742 | |
| 743 // Now request a stream. It should succeed using the second proxy in the | |
| 744 // list. | |
| 745 HttpRequestInfo request_info; | |
| 746 request_info.method = "GET"; | |
| 747 request_info.url = GURL("http://www.google.com"); | |
| 748 request_info.load_flags = 0; | |
| 749 | |
| 750 SSLConfig ssl_config; | |
| 751 StreamRequestWaiter waiter; | |
| 752 scoped_ptr<HttpStreamRequest> request( | |
| 753 session->http_stream_factory()->RequestStream( | |
| 754 request_info, | |
| 755 DEFAULT_PRIORITY, | |
| 756 ssl_config, | |
| 757 ssl_config, | |
| 758 &waiter, | |
| 759 BoundNetLog())); | |
| 760 waiter.WaitForStream(); | |
| 761 EXPECT_TRUE(waiter.stream_done()); | |
| 762 ASSERT_TRUE(NULL != waiter.stream()); | |
| 763 EXPECT_TRUE(NULL == waiter.websocket_stream()); | |
| 764 EXPECT_FALSE(waiter.stream()->IsSpdyHttpStream()); | |
| 765 | |
| 766 EXPECT_EQ(1, GetSocketPoolGroupCount( | |
| 767 session->GetTransportSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL))); | |
| 768 EXPECT_EQ(0, GetSocketPoolGroupCount(session->GetSSLSocketPool( | |
| 769 HttpNetworkSession::NORMAL_SOCKET_POOL))); | |
| 770 EXPECT_TRUE(waiter.used_proxy_info().is_direct()); | |
| 771 } | |
| 772 | |
| 773 TEST(HttpStreamFactoryTest, RequestHttpStreamOverSSL) { | |
| 774 SessionDependencies session_deps(ProxyService::CreateDirect()); | |
| 775 | |
| 776 MockRead mock_read(ASYNC, OK); | |
| 777 StaticSocketDataProvider socket_data(&mock_read, 1, NULL, 0); | |
| 778 socket_data.set_connect_data(MockConnect(ASYNC, OK)); | |
| 779 session_deps.socket_factory.AddSocketDataProvider(&socket_data); | |
| 780 | |
| 781 SSLSocketDataProvider ssl_socket_data(ASYNC, OK); | |
| 782 session_deps.socket_factory.AddSSLSocketDataProvider(&ssl_socket_data); | |
| 783 | |
| 784 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps)); | |
| 785 | |
| 786 // Now request a stream. | |
| 787 HttpRequestInfo request_info; | |
| 788 request_info.method = "GET"; | |
| 789 request_info.url = GURL("https://www.google.com"); | |
| 790 request_info.load_flags = 0; | |
| 791 | |
| 792 SSLConfig ssl_config; | |
| 793 StreamRequestWaiter waiter; | |
| 794 scoped_ptr<HttpStreamRequest> request( | |
| 795 session->http_stream_factory()->RequestStream( | |
| 796 request_info, | |
| 797 DEFAULT_PRIORITY, | |
| 798 ssl_config, | |
| 799 ssl_config, | |
| 800 &waiter, | |
| 801 BoundNetLog())); | |
| 802 waiter.WaitForStream(); | |
| 803 EXPECT_TRUE(waiter.stream_done()); | |
| 804 ASSERT_TRUE(NULL != waiter.stream()); | |
| 805 EXPECT_TRUE(NULL == waiter.websocket_stream()); | |
| 806 EXPECT_FALSE(waiter.stream()->IsSpdyHttpStream()); | |
| 807 EXPECT_EQ(1, GetSocketPoolGroupCount( | |
| 808 session->GetTransportSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL))); | |
| 809 EXPECT_EQ(1, GetSocketPoolGroupCount( | |
| 810 session->GetSSLSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL))); | |
| 811 EXPECT_TRUE(waiter.used_proxy_info().is_direct()); | |
| 812 } | |
| 813 | |
| 814 TEST(HttpStreamFactoryTest, RequestHttpStreamOverProxy) { | |
|
mmenke
2013/06/17 19:55:01
There's no WebSocket version of this one?
yhirano
2013/06/18 08:34:14
Done.
| |
| 815 SessionDependencies session_deps(ProxyService::CreateFixed("myproxy:8888")); | |
| 816 | |
| 817 StaticSocketDataProvider socket_data; | |
| 818 socket_data.set_connect_data(MockConnect(ASYNC, OK)); | |
| 819 session_deps.socket_factory.AddSocketDataProvider(&socket_data); | |
| 820 | |
| 821 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps)); | |
| 822 | |
| 823 // Now request a stream. It should succeed using the second proxy in the | |
| 824 // list. | |
| 825 HttpRequestInfo request_info; | |
| 826 request_info.method = "GET"; | |
| 827 request_info.url = GURL("http://www.google.com"); | |
| 828 request_info.load_flags = 0; | |
| 829 | |
| 830 SSLConfig ssl_config; | |
| 831 StreamRequestWaiter waiter; | |
| 832 scoped_ptr<HttpStreamRequest> request( | |
| 833 session->http_stream_factory()->RequestStream( | |
| 834 request_info, | |
| 835 DEFAULT_PRIORITY, | |
| 836 ssl_config, | |
| 837 ssl_config, | |
| 838 &waiter, | |
| 839 BoundNetLog())); | |
| 840 waiter.WaitForStream(); | |
| 841 EXPECT_TRUE(waiter.stream_done()); | |
| 842 ASSERT_TRUE(NULL != waiter.stream()); | |
| 843 EXPECT_TRUE(NULL == waiter.websocket_stream()); | |
| 844 EXPECT_FALSE(waiter.stream()->IsSpdyHttpStream()); | |
| 845 EXPECT_EQ(0, GetSocketPoolGroupCount( | |
| 846 session->GetTransportSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL))); | |
| 847 EXPECT_EQ(0, GetSocketPoolGroupCount( | |
| 848 session->GetSSLSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL))); | |
| 849 EXPECT_EQ(1, GetSocketPoolGroupCount(session->GetSocketPoolForHTTPProxy( | |
| 850 HttpNetworkSession::NORMAL_SOCKET_POOL, | |
| 851 HostPortPair("myproxy", 8888)))); | |
| 852 EXPECT_EQ(0, GetSocketPoolGroupCount(session->GetSocketPoolForSSLWithProxy( | |
| 853 HttpNetworkSession::NORMAL_SOCKET_POOL, | |
| 854 HostPortPair("myproxy", 8888)))); | |
| 855 EXPECT_FALSE(waiter.used_proxy_info().is_direct()); | |
| 856 } | |
| 857 | |
| 858 TEST(HttpStreamFactoryTest, RequestWebSocketBasicStream) { | |
| 859 SessionDependencies session_deps(ProxyService::CreateDirect()); | |
| 860 | |
| 861 StaticSocketDataProvider socket_data; | |
| 862 socket_data.set_connect_data(MockConnect(ASYNC, OK)); | |
| 863 session_deps.socket_factory.AddSocketDataProvider(&socket_data); | |
| 864 | |
| 865 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps)); | |
| 866 | |
| 867 // Now request a stream. | |
| 868 HttpRequestInfo request_info; | |
| 869 request_info.method = "GET"; | |
| 870 request_info.url = GURL("ws://www.google.com"); | |
| 871 request_info.load_flags = 0; | |
| 872 | |
| 873 SSLConfig ssl_config; | |
| 874 StreamRequestWaiter waiter; | |
| 875 WebSocketStreamFactory factory; | |
| 876 scoped_ptr<HttpStreamRequest> request( | |
| 877 session->websocket_stream_factory()->RequestWebSocketStream( | |
| 878 request_info, | |
| 879 DEFAULT_PRIORITY, | |
| 880 ssl_config, | |
| 881 ssl_config, | |
| 882 &waiter, | |
| 883 &factory, | |
| 884 BoundNetLog())); | |
| 885 waiter.WaitForStream(); | |
| 886 EXPECT_TRUE(waiter.stream_done()); | |
| 887 EXPECT_TRUE(NULL == waiter.stream()); | |
| 888 ASSERT_TRUE(NULL != waiter.websocket_stream()); | |
| 889 EXPECT_EQ(MockWebSocketStream::kStreamTypeBasic, | |
| 890 waiter.websocket_stream()->type()); | |
| 891 EXPECT_EQ(1, GetSocketPoolGroupCount( | |
| 892 session->GetTransportSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL))); | |
| 893 EXPECT_EQ(0, GetSocketPoolGroupCount( | |
| 894 session->GetSSLSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL))); | |
| 895 EXPECT_TRUE(waiter.used_proxy_info().is_direct()); | |
| 896 } | |
| 897 | |
| 898 TEST(HttpStreamFactoryTest, RequestWebSocketBasicStreamOverSSL) { | |
| 899 SessionDependencies session_deps(ProxyService::CreateDirect()); | |
| 900 | |
| 901 MockRead mock_read(ASYNC, OK); | |
| 902 StaticSocketDataProvider socket_data(&mock_read, 1, NULL, 0); | |
| 903 socket_data.set_connect_data(MockConnect(ASYNC, OK)); | |
| 904 session_deps.socket_factory.AddSocketDataProvider(&socket_data); | |
| 905 | |
| 906 SSLSocketDataProvider ssl_socket_data(ASYNC, OK); | |
| 907 session_deps.socket_factory.AddSSLSocketDataProvider(&ssl_socket_data); | |
| 908 | |
| 909 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps)); | |
| 910 | |
| 911 // Now request a stream. | |
| 912 HttpRequestInfo request_info; | |
| 913 request_info.method = "GET"; | |
| 914 request_info.url = GURL("wss://www.google.com"); | |
| 915 request_info.load_flags = 0; | |
| 916 | |
| 917 SSLConfig ssl_config; | |
| 918 StreamRequestWaiter waiter; | |
| 919 WebSocketStreamFactory factory; | |
| 920 scoped_ptr<HttpStreamRequest> request( | |
| 921 session->websocket_stream_factory()->RequestWebSocketStream( | |
| 922 request_info, | |
| 923 DEFAULT_PRIORITY, | |
| 924 ssl_config, | |
| 925 ssl_config, | |
| 926 &waiter, | |
| 927 &factory, | |
| 928 BoundNetLog())); | |
| 929 waiter.WaitForStream(); | |
| 930 EXPECT_TRUE(waiter.stream_done()); | |
| 931 EXPECT_TRUE(NULL == waiter.stream()); | |
| 932 ASSERT_TRUE(NULL != waiter.websocket_stream()); | |
| 933 EXPECT_EQ(MockWebSocketStream::kStreamTypeBasic, | |
| 934 waiter.websocket_stream()->type()); | |
| 935 EXPECT_EQ(1, GetSocketPoolGroupCount( | |
| 936 session->GetTransportSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL))); | |
| 937 EXPECT_EQ(1, GetSocketPoolGroupCount( | |
| 938 session->GetSSLSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL))); | |
| 939 EXPECT_TRUE(waiter.used_proxy_info().is_direct()); | |
| 940 } | |
| 941 | |
| 942 TEST(HttpStreamFactoryTest, RequestSpdyHttpStream) { | |
| 943 SpdySessionDependencies session_deps(kProtoSPDY3, | |
| 944 ProxyService::CreateDirect()); | |
| 945 | |
| 946 MockRead mock_read(ASYNC, OK); | |
| 947 StaticSocketDataProvider socket_data(&mock_read, 1, NULL, 0); | |
| 948 socket_data.set_connect_data(MockConnect(ASYNC, OK)); | |
| 949 session_deps.socket_factory->AddSocketDataProvider(&socket_data); | |
| 950 | |
| 951 SSLSocketDataProvider ssl_socket_data(ASYNC, OK); | |
| 952 ssl_socket_data.SetNextProto(kProtoSPDY3); | |
| 953 session_deps.socket_factory->AddSSLSocketDataProvider(&ssl_socket_data); | |
| 954 | |
| 955 HostPortPair host_port_pair("www.google.com", 443); | |
| 956 scoped_refptr<HttpNetworkSession> | |
| 957 session(SpdySessionDependencies::SpdyCreateSession(&session_deps)); | |
| 958 | |
| 959 // Now request a stream. | |
| 960 HttpRequestInfo request_info; | |
| 961 request_info.method = "GET"; | |
| 962 request_info.url = GURL("https://www.google.com"); | |
| 963 request_info.load_flags = 0; | |
| 964 | |
| 965 SSLConfig ssl_config; | |
| 966 StreamRequestWaiter waiter; | |
| 967 scoped_ptr<HttpStreamRequest> request( | |
| 968 session->http_stream_factory()->RequestStream( | |
| 969 request_info, | |
| 970 DEFAULT_PRIORITY, | |
| 971 ssl_config, | |
| 972 ssl_config, | |
| 973 &waiter, | |
| 974 BoundNetLog())); | |
| 975 waiter.WaitForStream(); | |
| 976 EXPECT_TRUE(waiter.stream_done()); | |
| 977 EXPECT_TRUE(NULL == waiter.websocket_stream()); | |
| 978 ASSERT_TRUE(NULL != waiter.stream()); | |
| 979 EXPECT_TRUE(waiter.stream()->IsSpdyHttpStream()); | |
| 980 EXPECT_EQ(1, GetSocketPoolGroupCount( | |
| 981 session->GetTransportSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL))); | |
| 982 EXPECT_EQ(1, GetSocketPoolGroupCount( | |
| 983 session->GetSSLSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL))); | |
| 984 EXPECT_TRUE(waiter.used_proxy_info().is_direct()); | |
| 985 } | |
| 986 | |
| 987 TEST(HttpStreamFactoryTest, RequestWebSocketSpdyStream) { | |
| 988 SpdySessionDependencies session_deps(kProtoSPDY3, | |
| 989 ProxyService::CreateDirect()); | |
| 990 | |
| 991 MockRead mock_read(SYNCHRONOUS, ERR_IO_PENDING); | |
| 992 StaticSocketDataProvider socket_data(&mock_read, 1, NULL, 0); | |
| 993 socket_data.set_connect_data(MockConnect(ASYNC, OK)); | |
| 994 session_deps.socket_factory->AddSocketDataProvider(&socket_data); | |
| 995 | |
| 996 SSLSocketDataProvider ssl_socket_data(ASYNC, OK); | |
| 997 ssl_socket_data.SetNextProto(kProtoSPDY3); | |
| 998 session_deps.socket_factory->AddSSLSocketDataProvider(&ssl_socket_data); | |
| 999 | |
| 1000 HostPortPair host_port_pair("www.google.com", 80); | |
| 1001 scoped_refptr<HttpNetworkSession> | |
| 1002 session(SpdySessionDependencies::SpdyCreateSession(&session_deps)); | |
| 1003 | |
| 1004 // Now request a stream. | |
| 1005 HttpRequestInfo request_info; | |
| 1006 request_info.method = "GET"; | |
| 1007 request_info.url = GURL("wss://www.google.com"); | |
| 1008 request_info.load_flags = 0; | |
| 1009 | |
| 1010 SSLConfig ssl_config; | |
| 1011 StreamRequestWaiter waiter1; | |
| 1012 WebSocketStreamFactory factory; | |
| 1013 scoped_ptr<HttpStreamRequest> request1( | |
| 1014 session->websocket_stream_factory()->RequestWebSocketStream( | |
| 1015 request_info, | |
| 1016 DEFAULT_PRIORITY, | |
| 1017 ssl_config, | |
| 1018 ssl_config, | |
| 1019 &waiter1, | |
| 1020 &factory, | |
| 1021 BoundNetLog())); | |
| 1022 waiter1.WaitForStream(); | |
| 1023 EXPECT_TRUE(waiter1.stream_done()); | |
| 1024 ASSERT_TRUE(NULL != waiter1.websocket_stream()); | |
| 1025 EXPECT_EQ(MockWebSocketStream::kStreamTypeSpdy, | |
| 1026 waiter1.websocket_stream()->type()); | |
| 1027 EXPECT_TRUE(NULL == waiter1.stream()); | |
| 1028 | |
| 1029 StreamRequestWaiter waiter2; | |
| 1030 scoped_ptr<HttpStreamRequest> request2( | |
| 1031 session->websocket_stream_factory()->RequestWebSocketStream( | |
| 1032 request_info, | |
| 1033 DEFAULT_PRIORITY, | |
| 1034 ssl_config, | |
| 1035 ssl_config, | |
| 1036 &waiter2, | |
| 1037 &factory, | |
| 1038 BoundNetLog())); | |
| 1039 waiter2.WaitForStream(); | |
| 1040 EXPECT_TRUE(waiter2.stream_done()); | |
| 1041 ASSERT_TRUE(NULL != waiter2.websocket_stream()); | |
| 1042 EXPECT_EQ(MockWebSocketStream::kStreamTypeSpdy, | |
| 1043 waiter2.websocket_stream()->type()); | |
| 1044 EXPECT_TRUE(NULL == waiter2.stream()); | |
| 1045 EXPECT_NE(waiter2.websocket_stream(), waiter1.websocket_stream()); | |
| 1046 EXPECT_EQ(static_cast<WebSocketSpdyStream*>(waiter2.websocket_stream())-> | |
| 1047 spdy_session(), | |
| 1048 static_cast<WebSocketSpdyStream*>(waiter1.websocket_stream())-> | |
| 1049 spdy_session()); | |
| 1050 | |
| 1051 EXPECT_EQ(1, GetSocketPoolGroupCount( | |
| 1052 session->GetTransportSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL))); | |
| 1053 EXPECT_EQ(1, GetSocketPoolGroupCount( | |
| 1054 session->GetSSLSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL))); | |
| 1055 EXPECT_TRUE(waiter1.used_proxy_info().is_direct()); | |
| 1056 } | |
| 1057 | |
| 1058 TEST(HttpStreamFactoryTest, OrphanedWebSocketStream) { | |
| 1059 UseAlternateProtocolsScopedSetter use_alternate_protocols(true); | |
| 1060 SpdySessionDependencies session_deps(kProtoSPDY3, | |
| 1061 ProxyService::CreateDirect()); | |
| 1062 | |
| 1063 MockRead mock_read(ASYNC, OK); | |
| 1064 StaticSocketDataProvider socket_data(&mock_read, 1, NULL, 0); | |
| 1065 socket_data.set_connect_data(MockConnect(ASYNC, OK)); | |
| 1066 session_deps.socket_factory->AddSocketDataProvider(&socket_data); | |
| 1067 | |
| 1068 MockRead mock_read2(ASYNC, OK); | |
| 1069 StaticSocketDataProvider socket_data2(&mock_read2, 1, NULL, 0); | |
| 1070 socket_data2.set_connect_data(MockConnect(ASYNC, ERR_IO_PENDING)); | |
| 1071 session_deps.socket_factory->AddSocketDataProvider(&socket_data2); | |
| 1072 | |
| 1073 SSLSocketDataProvider ssl_socket_data(ASYNC, OK); | |
| 1074 ssl_socket_data.SetNextProto(kProtoSPDY3); | |
| 1075 session_deps.socket_factory->AddSSLSocketDataProvider(&ssl_socket_data); | |
| 1076 | |
| 1077 scoped_refptr<HttpNetworkSession> | |
| 1078 session(SpdySessionDependencies::SpdyCreateSession(&session_deps)); | |
| 1079 | |
| 1080 // Now request a stream. | |
| 1081 HttpRequestInfo request_info; | |
| 1082 request_info.method = "GET"; | |
| 1083 request_info.url = GURL("ws://www.google.com:8888"); | |
| 1084 request_info.load_flags = 0; | |
| 1085 | |
| 1086 session->http_server_properties()->SetAlternateProtocol( | |
| 1087 HostPortPair("www.google.com", 8888), | |
| 1088 9999, | |
| 1089 NPN_SPDY_3); | |
| 1090 | |
| 1091 SSLConfig ssl_config; | |
| 1092 StreamRequestWaiter waiter; | |
| 1093 WebSocketStreamFactory factory; | |
| 1094 scoped_ptr<HttpStreamRequest> request( | |
| 1095 session->websocket_stream_factory()->RequestWebSocketStream( | |
| 1096 request_info, | |
| 1097 DEFAULT_PRIORITY, | |
| 1098 ssl_config, | |
| 1099 ssl_config, | |
| 1100 &waiter, | |
| 1101 &factory, | |
| 1102 BoundNetLog())); | |
| 1103 waiter.WaitForStream(); | |
| 1104 EXPECT_TRUE(waiter.stream_done()); | |
| 1105 EXPECT_TRUE(NULL == waiter.stream()); | |
| 1106 ASSERT_TRUE(NULL != waiter.websocket_stream()); | |
| 1107 EXPECT_EQ(MockWebSocketStream::kStreamTypeSpdy, | |
| 1108 waiter.websocket_stream()->type()); | |
| 1109 | |
| 1110 // Make sure that there was an alternative connection | |
| 1111 // which consumes extra connections. | |
| 1112 EXPECT_EQ(2, GetSocketPoolGroupCount( | |
| 1113 session->GetTransportSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL))); | |
|
mmenke
2013/06/17 19:55:01
Shouldn't the socket have been deleted by this poi
yhirano
2013/06/18 08:34:14
I think deleted (pooled) socket is counted.
I thin
mmenke
2013/06/18 20:21:45
I'm not sure, which is the problem.
yhirano
2013/06/19 11:18:38
OK, I added the Disconnect code in http_stream_fac
| |
| 1114 EXPECT_EQ(1, GetSocketPoolGroupCount( | |
| 1115 session->GetSSLSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL))); | |
| 1116 EXPECT_TRUE(waiter.used_proxy_info().is_direct()); | |
| 1117 | |
| 1118 // Make sure there is no orphaned job. it is already canceled. | |
| 1119 ASSERT_EQ(0u, static_cast<HttpStreamFactoryImpl*>( | |
| 1120 session->websocket_stream_factory())->num_orphaned_jobs()); | |
| 1121 } | |
| 1122 | |
| 618 } // namespace | 1123 } // namespace |
| 619 | 1124 |
| 620 } // namespace net | 1125 } // namespace net |
| OLD | NEW |