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" |
| 19 #include "net/http/http_server_properties_impl.h" | 20 #include "net/http/http_server_properties_impl.h" |
| 20 #include "net/http/http_stream.h" | 21 #include "net/http/http_stream.h" |
| 22 #include "net/http/websocket_stream_base.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" |
| 28 #include "testing/gtest/include/gtest/gtest.h" | 34 #include "testing/gtest/include/gtest/gtest.h" |
| 29 | 35 |
| 30 namespace net { | 36 namespace net { |
| 31 | 37 |
| 32 namespace { | 38 namespace { |
| 33 | 39 |
| 34 class MockHttpStreamFactoryImpl : public HttpStreamFactoryImpl { | 40 class ScopedForceSpdySsl { |
|
mmenke
2013/05/30 19:46:14
I don't believe this class is needed. Looks like
yhirano
2013/05/31 08:36:45
Done.
In order to control was_spdy_negotiated in M
| |
| 35 public: | 41 public: |
| 36 MockHttpStreamFactoryImpl(HttpNetworkSession* session) | 42 explicit ScopedForceSpdySsl(bool enabled): |
| 37 : HttpStreamFactoryImpl(session), | 43 orig_force_spdy_over_ssl_(HttpStreamFactory::force_spdy_over_ssl()), |
| 44 orig_force_spdy_always_(HttpStreamFactory::force_spdy_always()), | |
| 45 orig_spdy_enabled_(HttpStreamFactory::spdy_enabled()) { | |
| 46 HttpStreamFactory::set_force_spdy_over_ssl(enabled); | |
| 47 HttpStreamFactory::set_force_spdy_always(enabled); | |
| 48 HttpStreamFactory::set_spdy_enabled(enabled); | |
| 49 } | |
| 50 ~ScopedForceSpdySsl() { | |
| 51 HttpStreamFactory::set_spdy_enabled(orig_spdy_enabled_); | |
| 52 HttpStreamFactory::set_force_spdy_over_ssl(orig_force_spdy_over_ssl_); | |
| 53 HttpStreamFactory::set_force_spdy_always(orig_force_spdy_always_); | |
| 54 } | |
| 55 | |
| 56 private: | |
| 57 const bool orig_force_spdy_over_ssl_; | |
| 58 const bool orig_force_spdy_always_; | |
| 59 const bool orig_spdy_enabled_; | |
| 60 }; | |
| 61 | |
| 62 class MockHttpStreamFactoryImplForPreconnect : public HttpStreamFactoryImpl { | |
| 63 public: | |
| 64 MockHttpStreamFactoryImplForPreconnect(HttpNetworkSession* session, | |
| 65 bool for_websockets) | |
| 66 : HttpStreamFactoryImpl(session, for_websockets), | |
| 38 preconnect_done_(false), | 67 preconnect_done_(false), |
| 39 waiting_for_preconnect_(false) {} | 68 waiting_for_preconnect_(false) {} |
| 40 | 69 |
| 41 | 70 |
| 42 void WaitForPreconnects() { | 71 void WaitForPreconnects() { |
| 43 while (!preconnect_done_) { | 72 while (!preconnect_done_) { |
| 44 waiting_for_preconnect_ = true; | 73 waiting_for_preconnect_ = true; |
| 45 base::MessageLoop::current()->Run(); | 74 base::MessageLoop::current()->Run(); |
| 46 waiting_for_preconnect_ = false; | 75 waiting_for_preconnect_ = false; |
| 47 } | 76 } |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 69 | 98 |
| 70 virtual void OnStreamReady( | 99 virtual void OnStreamReady( |
| 71 const SSLConfig& used_ssl_config, | 100 const SSLConfig& used_ssl_config, |
| 72 const ProxyInfo& used_proxy_info, | 101 const ProxyInfo& used_proxy_info, |
| 73 HttpStreamBase* stream) OVERRIDE { | 102 HttpStreamBase* stream) OVERRIDE { |
| 74 stream_done_ = true; | 103 stream_done_ = true; |
| 75 if (waiting_for_stream_) | 104 if (waiting_for_stream_) |
| 76 base::MessageLoop::current()->Quit(); | 105 base::MessageLoop::current()->Quit(); |
| 77 stream_.reset(stream); | 106 stream_.reset(stream); |
| 78 used_ssl_config_ = used_ssl_config; | 107 used_ssl_config_ = used_ssl_config; |
| 108 used_proxy_info_ = used_proxy_info; | |
| 109 } | |
| 110 | |
| 111 virtual void OnWebSocketStreamReady( | |
| 112 const SSLConfig& used_ssl_config, | |
| 113 const ProxyInfo& used_proxy_info, | |
| 114 WebSocketStreamBase* stream) OVERRIDE { | |
| 115 stream_done_ = true; | |
| 116 if (waiting_for_stream_) | |
| 117 MessageLoop::current()->Quit(); | |
| 118 websocket_stream_.reset(stream); | |
| 119 used_ssl_config_ = used_ssl_config; | |
| 120 used_proxy_info_ = used_proxy_info; | |
| 79 } | 121 } |
| 80 | 122 |
| 81 virtual void OnStreamFailed( | 123 virtual void OnStreamFailed( |
| 82 int status, | 124 int status, |
| 83 const SSLConfig& used_ssl_config) OVERRIDE {} | 125 const SSLConfig& used_ssl_config) OVERRIDE {} |
| 84 | 126 |
| 85 virtual void OnCertificateError( | 127 virtual void OnCertificateError( |
| 86 int status, | 128 int status, |
| 87 const SSLConfig& used_ssl_config, | 129 const SSLConfig& used_ssl_config, |
| 88 const SSLInfo& ssl_info) OVERRIDE {} | 130 const SSLInfo& ssl_info) OVERRIDE {} |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 105 waiting_for_stream_ = true; | 147 waiting_for_stream_ = true; |
| 106 base::MessageLoop::current()->Run(); | 148 base::MessageLoop::current()->Run(); |
| 107 waiting_for_stream_ = false; | 149 waiting_for_stream_ = false; |
| 108 } | 150 } |
| 109 } | 151 } |
| 110 | 152 |
| 111 const SSLConfig& used_ssl_config() const { | 153 const SSLConfig& used_ssl_config() const { |
| 112 return used_ssl_config_; | 154 return used_ssl_config_; |
| 113 } | 155 } |
| 114 | 156 |
| 157 const ProxyInfo& used_proxy_info() const { | |
| 158 return used_proxy_info_; | |
| 159 } | |
| 160 | |
| 115 HttpStreamBase* stream() { | 161 HttpStreamBase* stream() { |
| 116 return stream_.get(); | 162 return stream_.get(); |
| 117 } | 163 } |
| 118 | 164 |
| 165 WebSocketStreamBase* websocket_stream() { | |
| 166 return websocket_stream_.get(); | |
| 167 } | |
| 168 | |
| 169 bool stream_done() const { return stream_done_; } | |
| 119 | 170 |
| 120 private: | 171 private: |
| 121 bool waiting_for_stream_; | 172 bool waiting_for_stream_; |
| 122 bool stream_done_; | 173 bool stream_done_; |
| 123 scoped_ptr<HttpStreamBase> stream_; | 174 scoped_ptr<HttpStreamBase> stream_; |
| 175 scoped_ptr<WebSocketStreamBase> websocket_stream_; | |
| 124 SSLConfig used_ssl_config_; | 176 SSLConfig used_ssl_config_; |
| 177 ProxyInfo used_proxy_info_; | |
| 125 | 178 |
| 126 DISALLOW_COPY_AND_ASSIGN(StreamRequestWaiter); | 179 DISALLOW_COPY_AND_ASSIGN(StreamRequestWaiter); |
| 127 }; | 180 }; |
| 128 | 181 |
| 182 class WebSocketSpdyStream : public WebSocketStreamBase { | |
| 183 public: | |
| 184 explicit WebSocketSpdyStream(SpdySession* spdy_session): | |
| 185 WebSocketStreamBase(kStreamTypeSpdy), spdy_session_(spdy_session) {} | |
| 186 SpdySession* spdy_session() {return spdy_session_.get();} | |
| 187 | |
| 188 private: | |
| 189 scoped_refptr<SpdySession> spdy_session_; | |
| 190 }; | |
| 191 | |
| 192 class WebSocketBasicStream : public WebSocketStreamBase { | |
| 193 public: | |
| 194 explicit WebSocketBasicStream(ClientSocketHandle* connection): | |
| 195 WebSocketStreamBase(kStreamTypeBasic), connection_(connection) {} | |
| 196 ClientSocketHandle* connection() {return connection_.get();} | |
| 197 | |
| 198 private: | |
| 199 scoped_ptr<ClientSocketHandle> connection_; | |
| 200 }; | |
| 201 | |
| 202 class WebSocketStreamFactory : public WebSocketStreamBase::Factory { | |
| 203 public: | |
| 204 virtual WebSocketStreamBase* CreateBasicStream(ClientSocketHandle* connection, | |
| 205 bool using_proxy) OVERRIDE { | |
| 206 return new WebSocketBasicStream(connection); | |
| 207 } | |
| 208 virtual WebSocketStreamBase* CreateSpdyStream( | |
| 209 SpdySession* spdy_session, | |
| 210 bool use_relative_url) OVERRIDE { | |
| 211 return new WebSocketSpdyStream(spdy_session); | |
| 212 } | |
| 213 }; | |
| 214 | |
| 129 struct SessionDependencies { | 215 struct SessionDependencies { |
| 130 // Custom proxy service dependency. | 216 // Custom proxy service dependency. |
| 131 explicit SessionDependencies(ProxyService* proxy_service) | 217 explicit SessionDependencies(ProxyService* proxy_service) |
| 132 : host_resolver(new MockHostResolver), | 218 : host_resolver(new MockHostResolver), |
| 133 cert_verifier(new MockCertVerifier), | 219 cert_verifier(new MockCertVerifier), |
| 134 proxy_service(proxy_service), | 220 proxy_service(proxy_service), |
| 135 ssl_config_service(new SSLConfigServiceDefaults), | 221 ssl_config_service(new SSLConfigServiceDefaults), |
| 136 http_auth_handler_factory( | 222 http_auth_handler_factory( |
| 137 HttpAuthHandlerFactory::CreateDefault(host_resolver.get())), | 223 HttpAuthHandlerFactory::CreateDefault(host_resolver.get())), |
| 138 net_log(NULL) {} | 224 net_log(NULL) {} |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 151 HttpNetworkSession::Params params; | 237 HttpNetworkSession::Params params; |
| 152 params.host_resolver = session_deps->host_resolver.get(); | 238 params.host_resolver = session_deps->host_resolver.get(); |
| 153 params.cert_verifier = session_deps->cert_verifier.get(); | 239 params.cert_verifier = session_deps->cert_verifier.get(); |
| 154 params.proxy_service = session_deps->proxy_service.get(); | 240 params.proxy_service = session_deps->proxy_service.get(); |
| 155 params.ssl_config_service = session_deps->ssl_config_service; | 241 params.ssl_config_service = session_deps->ssl_config_service; |
| 156 params.client_socket_factory = &session_deps->socket_factory; | 242 params.client_socket_factory = &session_deps->socket_factory; |
| 157 params.http_auth_handler_factory = | 243 params.http_auth_handler_factory = |
| 158 session_deps->http_auth_handler_factory.get(); | 244 session_deps->http_auth_handler_factory.get(); |
| 159 params.net_log = session_deps->net_log; | 245 params.net_log = session_deps->net_log; |
| 160 params.http_server_properties = &session_deps->http_server_properties; | 246 params.http_server_properties = &session_deps->http_server_properties; |
| 247 | |
| 161 return new HttpNetworkSession(params); | 248 return new HttpNetworkSession(params); |
| 162 } | 249 } |
| 163 | 250 |
| 164 struct TestCase { | 251 struct TestCase { |
| 165 int num_streams; | 252 int num_streams; |
| 166 bool ssl; | 253 bool ssl; |
| 167 }; | 254 }; |
| 168 | 255 |
| 169 TestCase kTests[] = { | 256 TestCase kTests[] = { |
| 170 { 1, false }, | 257 { 1, false }, |
| 171 { 2, false }, | 258 { 2, false }, |
| 172 { 1, true}, | 259 { 1, true}, |
| 173 { 2, true}, | 260 { 2, true}, |
| 174 }; | 261 }; |
| 175 | 262 |
| 176 void PreconnectHelperForURL(int num_streams, | 263 void PreconnectHelperForURL(int num_streams, |
| 177 const GURL& url, | 264 const GURL& url, |
| 178 HttpNetworkSession* session) { | 265 HttpNetworkSession* session) { |
| 179 HttpNetworkSessionPeer peer(session); | 266 HttpNetworkSessionPeer peer(session); |
| 180 MockHttpStreamFactoryImpl* mock_factory = | 267 MockHttpStreamFactoryImplForPreconnect* mock_factory = |
| 181 new MockHttpStreamFactoryImpl(session); | 268 new MockHttpStreamFactoryImplForPreconnect(session, false); |
| 182 peer.SetHttpStreamFactory(mock_factory); | 269 peer.SetHttpStreamFactory(mock_factory); |
| 183 SSLConfig ssl_config; | 270 SSLConfig ssl_config; |
| 184 session->ssl_config_service()->GetSSLConfig(&ssl_config); | 271 session->ssl_config_service()->GetSSLConfig(&ssl_config); |
| 185 | 272 |
| 186 HttpRequestInfo request; | 273 HttpRequestInfo request; |
| 187 request.method = "GET"; | 274 request.method = "GET"; |
| 188 request.url = url; | 275 request.url = url; |
| 189 request.load_flags = 0; | 276 request.load_flags = 0; |
| 190 | 277 |
| 191 session->http_stream_factory()->PreconnectStreams( | 278 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)); | 540 socket_data1.set_connect_data(MockConnect(ASYNC, ERR_ADDRESS_UNREACHABLE)); |
| 454 session_deps.socket_factory.AddSocketDataProvider(&socket_data1); | 541 session_deps.socket_factory.AddSocketDataProvider(&socket_data1); |
| 455 | 542 |
| 456 // Second connection attempt succeeds | 543 // Second connection attempt succeeds |
| 457 StaticSocketDataProvider socket_data2; | 544 StaticSocketDataProvider socket_data2; |
| 458 socket_data2.set_connect_data(MockConnect(ASYNC, OK)); | 545 socket_data2.set_connect_data(MockConnect(ASYNC, OK)); |
| 459 session_deps.socket_factory.AddSocketDataProvider(&socket_data2); | 546 session_deps.socket_factory.AddSocketDataProvider(&socket_data2); |
| 460 | 547 |
| 461 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps)); | 548 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps)); |
| 462 | 549 |
| 463 // Now request a stream. It should succeed using the second proxy in the | 550 // Now request a stream. |
| 464 // list. | |
| 465 HttpRequestInfo request_info; | 551 HttpRequestInfo request_info; |
| 466 request_info.method = "GET"; | 552 request_info.method = "GET"; |
| 467 request_info.url = GURL("http://www.google.com"); | 553 request_info.url = GURL("http://www.google.com"); |
| 468 | 554 |
| 469 SSLConfig ssl_config; | 555 SSLConfig ssl_config; |
| 470 StreamRequestWaiter waiter; | 556 StreamRequestWaiter waiter; |
| 471 scoped_ptr<HttpStreamRequest> request( | 557 scoped_ptr<HttpStreamRequest> request( |
| 472 session->http_stream_factory()->RequestStream( | 558 session->http_stream_factory()->RequestStream( |
| 473 request_info, DEFAULT_PRIORITY, ssl_config, ssl_config, | 559 request_info, DEFAULT_PRIORITY, ssl_config, ssl_config, |
| 474 &waiter, BoundNetLog())); | 560 &waiter, BoundNetLog())); |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 603 scoped_ptr<HttpStreamRequest> request( | 689 scoped_ptr<HttpStreamRequest> request( |
| 604 session->http_stream_factory()->RequestStream( | 690 session->http_stream_factory()->RequestStream( |
| 605 request_info, DEFAULT_PRIORITY, ssl_config, ssl_config, | 691 request_info, DEFAULT_PRIORITY, ssl_config, ssl_config, |
| 606 &waiter, BoundNetLog())); | 692 &waiter, BoundNetLog())); |
| 607 | 693 |
| 608 EXPECT_EQ(LOAD_STATE_RESOLVING_HOST, request->GetLoadState()); | 694 EXPECT_EQ(LOAD_STATE_RESOLVING_HOST, request->GetLoadState()); |
| 609 | 695 |
| 610 waiter.WaitForStream(); | 696 waiter.WaitForStream(); |
| 611 } | 697 } |
| 612 | 698 |
| 699 TEST(HttpStreamFactoryTest, RequestHttpStream) { | |
| 700 SessionDependencies session_deps(ProxyService::CreateDirect()); | |
| 701 | |
| 702 StaticSocketDataProvider socket_data; | |
| 703 socket_data.set_connect_data(MockConnect(ASYNC, OK)); | |
| 704 session_deps.socket_factory.AddSocketDataProvider(&socket_data); | |
| 705 | |
| 706 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps)); | |
| 707 | |
| 708 // Now request a stream. It should succeed using the second proxy in the | |
| 709 // list. | |
| 710 HttpRequestInfo request_info; | |
| 711 request_info.method = "GET"; | |
| 712 request_info.url = GURL("http://www.google.com"); | |
| 713 request_info.load_flags = 0; | |
| 714 | |
| 715 SSLConfig ssl_config; | |
| 716 StreamRequestWaiter waiter; | |
| 717 scoped_ptr<HttpStreamRequest> request( | |
| 718 session->http_stream_factory()->RequestStream( | |
| 719 request_info, | |
| 720 DEFAULT_PRIORITY, | |
| 721 ssl_config, | |
| 722 ssl_config, | |
| 723 &waiter, | |
| 724 BoundNetLog())); | |
| 725 waiter.WaitForStream(); | |
| 726 EXPECT_TRUE(waiter.stream_done()); | |
| 727 EXPECT_TRUE(NULL == waiter.websocket_stream()); | |
| 728 | |
| 729 EXPECT_EQ(1, GetSocketPoolGroupCount( | |
| 730 session->GetTransportSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL))); | |
| 731 EXPECT_EQ(0, GetSocketPoolGroupCount(session->GetSSLSocketPool( | |
| 732 HttpNetworkSession::NORMAL_SOCKET_POOL))); | |
| 733 EXPECT_TRUE(waiter.used_proxy_info().is_direct()); | |
| 734 } | |
| 735 | |
| 736 TEST(HttpStreamFactoryTest, RequestHttpStreamOverSSL) { | |
| 737 SessionDependencies session_deps(ProxyService::CreateDirect()); | |
| 738 | |
| 739 MockRead mock_read(ASYNC, ERR_IO_PENDING); | |
| 740 StaticSocketDataProvider socket_data(&mock_read, 1, NULL, 0); | |
| 741 socket_data.set_connect_data(MockConnect(ASYNC, OK)); | |
| 742 session_deps.socket_factory.AddSocketDataProvider(&socket_data); | |
| 743 | |
| 744 SSLSocketDataProvider ssl_socket_data(ASYNC, OK); | |
| 745 ssl_socket_data.protocol_negotiated = kProtoSPDY3; | |
|
mmenke
2013/05/30 19:46:14
As-is, looks like this test is actually using SPDY
yhirano
2013/05/31 08:36:45
Done.
| |
| 746 session_deps.socket_factory.AddSSLSocketDataProvider(&ssl_socket_data); | |
| 747 | |
| 748 SSLSocketDataProvider ssl_socket_data2(ASYNC, OK); | |
| 749 ssl_socket_data2.protocol_negotiated = kProtoSPDY3; | |
| 750 session_deps.socket_factory.AddSSLSocketDataProvider(&ssl_socket_data2); | |
|
mmenke
2013/05/30 19:46:14
I don't believe we need two of these.
yhirano
2013/05/31 08:36:45
Done.
| |
| 751 | |
| 752 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps)); | |
| 753 | |
| 754 // Now request a stream. It should succeed using the second proxy in the | |
| 755 // list. | |
| 756 HttpRequestInfo request_info; | |
| 757 request_info.method = "GET"; | |
| 758 request_info.url = GURL("https://www.google.com"); | |
| 759 request_info.load_flags = 0; | |
| 760 | |
| 761 SSLConfig ssl_config; | |
| 762 StreamRequestWaiter waiter; | |
| 763 scoped_ptr<HttpStreamRequest> request( | |
| 764 session->http_stream_factory()->RequestStream( | |
| 765 request_info, | |
| 766 DEFAULT_PRIORITY, | |
| 767 ssl_config, | |
| 768 ssl_config, | |
| 769 &waiter, | |
| 770 BoundNetLog())); | |
| 771 waiter.WaitForStream(); | |
| 772 EXPECT_TRUE(waiter.stream_done()); | |
| 773 EXPECT_TRUE(NULL == waiter.websocket_stream()); | |
| 774 EXPECT_TRUE(NULL != waiter.stream()); | |
| 775 EXPECT_EQ(1, GetSocketPoolGroupCount( | |
| 776 session->GetTransportSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL))); | |
| 777 EXPECT_EQ(1, GetSocketPoolGroupCount( | |
| 778 session->GetSSLSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL))); | |
| 779 EXPECT_TRUE(waiter.used_proxy_info().is_direct()); | |
| 780 } | |
| 781 | |
| 782 TEST(HttpStreamFactoryTest, RequestHttpStreamOverProxy) { | |
| 783 SessionDependencies session_deps(ProxyService::CreateFixed("myproxy:8888")); | |
| 784 | |
| 785 StaticSocketDataProvider socket_data; | |
| 786 socket_data.set_connect_data(MockConnect(ASYNC, OK)); | |
| 787 session_deps.socket_factory.AddSocketDataProvider(&socket_data); | |
| 788 | |
| 789 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps)); | |
| 790 | |
| 791 // Now request a stream. It should succeed using the second proxy in the | |
| 792 // list. | |
| 793 HttpRequestInfo request_info; | |
| 794 request_info.method = "GET"; | |
| 795 request_info.url = GURL("http://www.google.com"); | |
| 796 request_info.load_flags = 0; | |
| 797 | |
| 798 SSLConfig ssl_config; | |
| 799 StreamRequestWaiter waiter; | |
| 800 scoped_ptr<HttpStreamRequest> request( | |
| 801 session->http_stream_factory()->RequestStream( | |
| 802 request_info, | |
| 803 DEFAULT_PRIORITY, | |
| 804 ssl_config, | |
| 805 ssl_config, | |
| 806 &waiter, | |
| 807 BoundNetLog())); | |
| 808 waiter.WaitForStream(); | |
| 809 EXPECT_TRUE(waiter.stream_done()); | |
| 810 EXPECT_TRUE(NULL == waiter.websocket_stream()); | |
| 811 EXPECT_TRUE(NULL != waiter.stream()); | |
| 812 EXPECT_EQ(0, GetSocketPoolGroupCount( | |
| 813 session->GetTransportSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL))); | |
| 814 EXPECT_EQ(0, GetSocketPoolGroupCount( | |
| 815 session->GetSSLSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL))); | |
| 816 EXPECT_EQ(1, GetSocketPoolGroupCount(session->GetSocketPoolForHTTPProxy( | |
| 817 HttpNetworkSession::NORMAL_SOCKET_POOL, | |
| 818 HostPortPair("myproxy", 8888)))); | |
| 819 EXPECT_EQ(0, GetSocketPoolGroupCount(session->GetSocketPoolForSSLWithProxy( | |
| 820 HttpNetworkSession::NORMAL_SOCKET_POOL, | |
| 821 HostPortPair("myproxy", 8888)))); | |
| 822 EXPECT_FALSE(waiter.used_proxy_info().is_direct()); | |
| 823 } | |
| 824 | |
| 825 TEST(HttpStreamFactoryTest, RequestWebSocketBasicStream) { | |
| 826 SessionDependencies session_deps(ProxyService::CreateDirect()); | |
| 827 | |
| 828 StaticSocketDataProvider socket_data; | |
| 829 socket_data.set_connect_data(MockConnect(ASYNC, OK)); | |
| 830 session_deps.socket_factory.AddSocketDataProvider(&socket_data); | |
| 831 | |
| 832 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps)); | |
| 833 | |
| 834 // Now request a stream. | |
| 835 HttpRequestInfo request_info; | |
| 836 request_info.method = "GET"; | |
| 837 request_info.url = GURL("ws://www.google.com"); | |
| 838 request_info.load_flags = 0; | |
| 839 | |
| 840 SSLConfig ssl_config; | |
| 841 StreamRequestWaiter waiter; | |
| 842 WebSocketStreamFactory factory; | |
| 843 scoped_ptr<HttpStreamRequest> request( | |
| 844 session->websocket_stream_factory()->RequestWebSocketStream( | |
| 845 request_info, | |
| 846 DEFAULT_PRIORITY, | |
| 847 ssl_config, | |
| 848 ssl_config, | |
| 849 &waiter, | |
| 850 &factory, | |
| 851 BoundNetLog())); | |
| 852 waiter.WaitForStream(); | |
| 853 EXPECT_TRUE(waiter.stream_done()); | |
| 854 EXPECT_TRUE(NULL == waiter.stream()); | |
| 855 EXPECT_TRUE(NULL != waiter.websocket_stream()); | |
| 856 EXPECT_EQ(WebSocketStreamBase::kStreamTypeBasic, | |
| 857 waiter.websocket_stream()->type()); | |
| 858 EXPECT_EQ(1, GetSocketPoolGroupCount( | |
| 859 session->GetTransportSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL))); | |
| 860 EXPECT_EQ(0, GetSocketPoolGroupCount( | |
| 861 session->GetSSLSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL))); | |
| 862 EXPECT_TRUE(waiter.used_proxy_info().is_direct()); | |
| 863 } | |
| 864 | |
| 865 TEST(HttpStreamFactoryTest, RequestWebSocketBasicStreamOverSSL) { | |
| 866 ScopedForceSpdySsl use_spdy(false); | |
|
mmenke
2013/05/30 19:46:14
I don't believe this is needed. We only upgrade t
yhirano
2013/05/31 08:36:45
Done.
| |
| 867 SessionDependencies session_deps(ProxyService::CreateDirect()); | |
| 868 | |
| 869 MockRead mock_read(ASYNC, ERR_IO_PENDING); | |
| 870 StaticSocketDataProvider socket_data(&mock_read, 1, NULL, 0); | |
| 871 socket_data.set_connect_data(MockConnect(ASYNC, OK)); | |
| 872 session_deps.socket_factory.AddSocketDataProvider(&socket_data); | |
| 873 | |
| 874 SSLSocketDataProvider ssl_socket_data(ASYNC, OK); | |
| 875 ssl_socket_data.protocol_negotiated = kProtoSPDY3; | |
|
mmenke
2013/05/30 19:46:14
This indicates SPDY 3 is being negotiated. I don'
yhirano
2013/05/31 08:36:45
Done.
| |
| 876 session_deps.socket_factory.AddSSLSocketDataProvider(&ssl_socket_data); | |
| 877 | |
| 878 SSLSocketDataProvider ssl_socket_data2(ASYNC, OK); | |
| 879 ssl_socket_data2.protocol_negotiated = kProtoSPDY3; | |
| 880 session_deps.socket_factory.AddSSLSocketDataProvider(&ssl_socket_data2); | |
|
mmenke
2013/05/30 19:46:14
Why are these two needed?
yhirano
2013/05/31 08:36:45
Done.
| |
| 881 | |
| 882 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps)); | |
| 883 | |
| 884 // Now request a stream. | |
| 885 HttpRequestInfo request_info; | |
| 886 request_info.method = "GET"; | |
| 887 request_info.url = GURL("wss://www.google.com"); | |
| 888 request_info.load_flags = 0; | |
| 889 | |
| 890 SSLConfig ssl_config; | |
| 891 StreamRequestWaiter waiter; | |
| 892 WebSocketStreamFactory factory; | |
| 893 scoped_ptr<HttpStreamRequest> request( | |
| 894 session->websocket_stream_factory()->RequestWebSocketStream( | |
| 895 request_info, | |
| 896 DEFAULT_PRIORITY, | |
| 897 ssl_config, | |
| 898 ssl_config, | |
| 899 &waiter, | |
| 900 &factory, | |
| 901 BoundNetLog())); | |
| 902 waiter.WaitForStream(); | |
| 903 EXPECT_TRUE(waiter.stream_done()); | |
| 904 EXPECT_TRUE(NULL == waiter.stream()); | |
| 905 EXPECT_TRUE(NULL != waiter.websocket_stream()); | |
| 906 EXPECT_EQ(WebSocketStreamBase::kStreamTypeBasic, | |
| 907 waiter.websocket_stream()->type()); | |
| 908 EXPECT_EQ(1, GetSocketPoolGroupCount( | |
| 909 session->GetTransportSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL))); | |
| 910 EXPECT_EQ(1, GetSocketPoolGroupCount( | |
| 911 session->GetSSLSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL))); | |
| 912 EXPECT_TRUE(waiter.used_proxy_info().is_direct()); | |
| 913 } | |
| 914 | |
| 915 TEST(HttpStreamFactoryTest, RequestSpdyHttpStream) { | |
| 916 ScopedForceSpdySsl use_spdy(true); | |
| 917 SpdySessionDependencies session_deps(kProtoSPDY3, | |
| 918 ProxyService::CreateDirect()); | |
| 919 | |
| 920 MockRead mock_read(ASYNC, OK); | |
| 921 StaticSocketDataProvider socket_data(&mock_read, 1, NULL, 0); | |
| 922 socket_data.set_connect_data(MockConnect(ASYNC, OK)); | |
| 923 session_deps.socket_factory->AddSocketDataProvider(&socket_data); | |
| 924 | |
| 925 SSLSocketDataProvider ssl_socket_data(ASYNC, OK); | |
| 926 ssl_socket_data.protocol_negotiated = kProtoSPDY3; | |
| 927 session_deps.socket_factory->AddSSLSocketDataProvider(&ssl_socket_data); | |
| 928 | |
| 929 HostPortPair host_port_pair("www.google.com", 80); | |
| 930 scoped_refptr<HttpNetworkSession> | |
| 931 session(SpdySessionDependencies::SpdyCreateSession(&session_deps)); | |
| 932 | |
| 933 // Now request a stream. | |
| 934 HttpRequestInfo request_info; | |
| 935 request_info.method = "GET"; | |
| 936 request_info.url = GURL("https://www.google.com"); | |
| 937 request_info.load_flags = 0; | |
| 938 | |
| 939 SSLConfig ssl_config; | |
| 940 StreamRequestWaiter waiter; | |
| 941 scoped_ptr<HttpStreamRequest> request( | |
| 942 session->http_stream_factory()->RequestStream( | |
| 943 request_info, | |
| 944 DEFAULT_PRIORITY, | |
| 945 ssl_config, | |
| 946 ssl_config, | |
| 947 &waiter, | |
| 948 BoundNetLog())); | |
| 949 waiter.WaitForStream(); | |
| 950 EXPECT_TRUE(waiter.stream_done()); | |
| 951 EXPECT_TRUE(NULL == waiter.websocket_stream()); | |
| 952 EXPECT_TRUE(NULL != waiter.stream()); | |
| 953 EXPECT_TRUE(waiter.stream()->IsSpdyHttpStream()); | |
| 954 EXPECT_EQ(1, GetSocketPoolGroupCount( | |
| 955 session->GetTransportSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL))); | |
| 956 EXPECT_EQ(1, GetSocketPoolGroupCount( | |
| 957 session->GetSSLSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL))); | |
| 958 EXPECT_TRUE(waiter.used_proxy_info().is_direct()); | |
| 959 } | |
| 960 | |
| 961 TEST(HttpStreamFactoryTest, RequestWebSocketSpdyStream) { | |
| 962 ScopedForceSpdySsl use_spdy(true); | |
| 963 SpdySessionDependencies session_deps(kProtoSPDY3, | |
| 964 ProxyService::CreateDirect()); | |
| 965 | |
| 966 MockRead mock_read(ASYNC, ERR_IO_PENDING); | |
| 967 StaticSocketDataProvider socket_data(&mock_read, 1, NULL, 0); | |
| 968 socket_data.set_connect_data(MockConnect(ASYNC, OK)); | |
| 969 session_deps.socket_factory->AddSocketDataProvider(&socket_data); | |
| 970 | |
| 971 SSLSocketDataProvider ssl_socket_data(ASYNC, OK); | |
| 972 ssl_socket_data.protocol_negotiated = kProtoSPDY3; | |
| 973 session_deps.socket_factory->AddSSLSocketDataProvider(&ssl_socket_data); | |
| 974 | |
| 975 SSLSocketDataProvider ssl_socket_data2(ASYNC, OK); | |
| 976 ssl_socket_data2.protocol_negotiated = kProtoSPDY3; | |
| 977 session_deps.socket_factory->AddSSLSocketDataProvider(&ssl_socket_data2); | |
|
mmenke
2013/05/30 19:46:14
Again, I don't think we need two of these.
yhirano
2013/05/31 08:36:45
Done.
| |
| 978 | |
| 979 HostPortPair host_port_pair("www.google.com", 80); | |
| 980 scoped_refptr<HttpNetworkSession> | |
| 981 session(SpdySessionDependencies::SpdyCreateSession(&session_deps)); | |
| 982 | |
| 983 // Now request a stream. | |
| 984 HttpRequestInfo request_info; | |
| 985 request_info.method = "GET"; | |
| 986 request_info.url = GURL("wss://www.google.com"); | |
| 987 request_info.load_flags = 0; | |
| 988 | |
| 989 SSLConfig ssl_config; | |
| 990 StreamRequestWaiter waiter1; | |
| 991 WebSocketStreamFactory factory; | |
| 992 scoped_ptr<HttpStreamRequest> request1( | |
| 993 session->websocket_stream_factory()->RequestWebSocketStream( | |
| 994 request_info, | |
| 995 DEFAULT_PRIORITY, | |
| 996 ssl_config, | |
| 997 ssl_config, | |
| 998 &waiter1, | |
| 999 &factory, | |
| 1000 BoundNetLog())); | |
| 1001 waiter1.WaitForStream(); | |
| 1002 EXPECT_TRUE(waiter1.stream_done()); | |
| 1003 EXPECT_TRUE(NULL != waiter1.websocket_stream()); | |
| 1004 EXPECT_EQ(WebSocketStreamBase::kStreamTypeSpdy, | |
| 1005 waiter1.websocket_stream()->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(WebSocketStreamBase::kStreamTypeSpdy, | |
| 1022 waiter2.websocket_stream()->type()); | |
| 1023 EXPECT_TRUE(NULL == waiter2.stream()); | |
| 1024 EXPECT_NE(waiter2.websocket_stream(), waiter1.websocket_stream()); | |
| 1025 EXPECT_EQ(static_cast<WebSocketSpdyStream*>(waiter2.websocket_stream())-> | |
| 1026 spdy_session(), | |
| 1027 static_cast<WebSocketSpdyStream*>(waiter1.websocket_stream())-> | |
| 1028 spdy_session()); | |
| 1029 | |
| 1030 EXPECT_EQ(1, GetSocketPoolGroupCount( | |
| 1031 session->GetTransportSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL))); | |
| 1032 EXPECT_EQ(1, GetSocketPoolGroupCount( | |
| 1033 session->GetSSLSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL))); | |
| 1034 EXPECT_TRUE(waiter1.used_proxy_info().is_direct()); | |
| 1035 } | |
| 1036 | |
| 613 } // namespace | 1037 } // namespace |
| 614 | 1038 |
| 615 } // namespace net | 1039 } // namespace net |
| OLD | NEW |