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 |
| 40 class ScopedForceSpdySsl { | |
| 41 public: | |
| 42 explicit ScopedForceSpdySsl(bool enabled): | |
| 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 | |
| 34 class MockHttpStreamFactoryImpl : public HttpStreamFactoryImpl { | 62 class MockHttpStreamFactoryImpl : public HttpStreamFactoryImpl { |
| 35 public: | 63 public: |
| 36 MockHttpStreamFactoryImpl(HttpNetworkSession* session) | 64 MockHttpStreamFactoryImpl(HttpNetworkSession* session, bool for_websockets) |
| 37 : HttpStreamFactoryImpl(session), | 65 : HttpStreamFactoryImpl(session, for_websockets) {} |
| 66 | |
| 67 struct InitSocketHandleParams { | |
| 68 InitSocketHandleParams() | |
| 69 : force_spdy_over_ssl(false), want_spdy_over_npn(false) {} | |
| 70 | |
| 71 InitSocketHandleParams( | |
| 72 const GURL& request_url, | |
| 73 const HttpRequestInfo& request_info, | |
| 74 RequestPriority request_priority, | |
| 75 const ProxyInfo& proxy_info, | |
| 76 bool force_spdy_over_ssl, | |
| 77 bool want_spdy_over_npn, | |
| 78 const SSLConfig& ssl_config_for_origin, | |
| 79 const SSLConfig& ssl_config_for_proxy, | |
| 80 ClientSocketHandle* socket_handle) | |
| 81 : request_url(request_url), request_info(request_info), | |
| 82 request_priority(request_priority), proxy_info(proxy_info), | |
| 83 force_spdy_over_ssl(force_spdy_over_ssl), | |
| 84 want_spdy_over_npn(want_spdy_over_npn), | |
| 85 ssl_config_for_origin(ssl_config_for_origin), | |
| 86 ssl_config_for_proxy(ssl_config_for_proxy), | |
| 87 socket_handle(socket_handle) {} | |
| 88 | |
| 89 GURL request_url; | |
| 90 HttpRequestInfo request_info; | |
| 91 RequestPriority request_priority; | |
| 92 ProxyInfo proxy_info; | |
| 93 bool force_spdy_over_ssl; | |
| 94 bool want_spdy_over_npn; | |
| 95 SSLConfig ssl_config_for_origin; | |
| 96 SSLConfig ssl_config_for_proxy; | |
| 97 // can be a dangling pointer. | |
| 98 ClientSocketHandle* socket_handle; | |
| 99 }; | |
| 100 std::vector<InitSocketHandleParams> calls_init_socket_handle_for_http; | |
| 101 | |
| 102 private: | |
| 103 virtual int InitSocketHandleForHttpRequest( | |
| 104 const GURL& request_url, | |
| 105 const HttpRequestInfo& request_info, | |
| 106 RequestPriority request_priority, | |
| 107 const ProxyInfo& proxy_info, | |
| 108 bool force_spdy_over_ssl, | |
| 109 bool want_spdy_over_npn, | |
| 110 const SSLConfig& ssl_config_for_origin, | |
| 111 const SSLConfig& ssl_config_for_proxy, | |
| 112 const BoundNetLog& net_log, | |
| 113 ClientSocketHandle* socket_handle, | |
| 114 const OnHostResolutionCallback& resolution_callback, | |
| 115 const CompletionCallback& callback) OVERRIDE { | |
| 116 calls_init_socket_handle_for_http.push_back(InitSocketHandleParams( | |
| 117 request_url, | |
| 118 request_info, | |
| 119 request_priority, | |
| 120 proxy_info, | |
| 121 force_spdy_over_ssl, | |
| 122 want_spdy_over_npn, | |
| 123 ssl_config_for_origin, | |
| 124 ssl_config_for_proxy, | |
| 125 socket_handle)); | |
| 126 return HttpStreamFactoryImpl::InitSocketHandleForHttpRequest( | |
| 127 request_url, | |
| 128 request_info, | |
| 129 request_priority, | |
| 130 proxy_info, | |
| 131 force_spdy_over_ssl, | |
| 132 want_spdy_over_npn, | |
| 133 ssl_config_for_origin, | |
| 134 ssl_config_for_proxy, | |
| 135 net_log, | |
| 136 socket_handle, | |
| 137 resolution_callback, | |
| 138 callback); | |
| 139 } | |
| 140 }; | |
| 141 | |
| 142 class MockHttpStreamFactoryImplForPreconnect : public HttpStreamFactoryImpl { | |
| 143 public: | |
| 144 MockHttpStreamFactoryImplForPreconnect(HttpNetworkSession* session, | |
| 145 bool for_websockets) | |
| 146 : HttpStreamFactoryImpl(session, for_websockets), | |
| 38 preconnect_done_(false), | 147 preconnect_done_(false), |
| 39 waiting_for_preconnect_(false) {} | 148 waiting_for_preconnect_(false) {} |
| 40 | 149 |
| 41 | 150 |
| 42 void WaitForPreconnects() { | 151 void WaitForPreconnects() { |
| 43 while (!preconnect_done_) { | 152 while (!preconnect_done_) { |
| 44 waiting_for_preconnect_ = true; | 153 waiting_for_preconnect_ = true; |
| 45 base::MessageLoop::current()->Run(); | 154 base::MessageLoop::current()->Run(); |
| 46 waiting_for_preconnect_ = false; | 155 waiting_for_preconnect_ = false; |
| 47 } | 156 } |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 71 const SSLConfig& used_ssl_config, | 180 const SSLConfig& used_ssl_config, |
| 72 const ProxyInfo& used_proxy_info, | 181 const ProxyInfo& used_proxy_info, |
| 73 HttpStreamBase* stream) OVERRIDE { | 182 HttpStreamBase* stream) OVERRIDE { |
| 74 stream_done_ = true; | 183 stream_done_ = true; |
| 75 if (waiting_for_stream_) | 184 if (waiting_for_stream_) |
| 76 base::MessageLoop::current()->Quit(); | 185 base::MessageLoop::current()->Quit(); |
| 77 stream_.reset(stream); | 186 stream_.reset(stream); |
| 78 used_ssl_config_ = used_ssl_config; | 187 used_ssl_config_ = used_ssl_config; |
| 79 } | 188 } |
| 80 | 189 |
| 190 virtual void OnWebSocketStreamReady( | |
| 191 const SSLConfig& used_ssl_config, | |
| 192 const ProxyInfo& used_proxy_info, | |
| 193 WebSocketStreamBase* stream) OVERRIDE { | |
| 194 stream_done_ = true; | |
| 195 if (waiting_for_stream_) | |
| 196 MessageLoop::current()->Quit(); | |
| 197 websocket_stream_.reset(stream); | |
| 198 } | |
| 199 | |
| 81 virtual void OnStreamFailed( | 200 virtual void OnStreamFailed( |
| 82 int status, | 201 int status, |
| 83 const SSLConfig& used_ssl_config) OVERRIDE {} | 202 const SSLConfig& used_ssl_config) OVERRIDE {} |
| 84 | 203 |
| 85 virtual void OnCertificateError( | 204 virtual void OnCertificateError( |
| 86 int status, | 205 int status, |
| 87 const SSLConfig& used_ssl_config, | 206 const SSLConfig& used_ssl_config, |
| 88 const SSLInfo& ssl_info) OVERRIDE {} | 207 const SSLInfo& ssl_info) OVERRIDE {} |
| 89 | 208 |
| 90 virtual void OnNeedsProxyAuth(const HttpResponseInfo& proxy_response, | 209 virtual void OnNeedsProxyAuth(const HttpResponseInfo& proxy_response, |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 109 } | 228 } |
| 110 | 229 |
| 111 const SSLConfig& used_ssl_config() const { | 230 const SSLConfig& used_ssl_config() const { |
| 112 return used_ssl_config_; | 231 return used_ssl_config_; |
| 113 } | 232 } |
| 114 | 233 |
| 115 HttpStreamBase* stream() { | 234 HttpStreamBase* stream() { |
| 116 return stream_.get(); | 235 return stream_.get(); |
| 117 } | 236 } |
| 118 | 237 |
| 238 WebSocketStreamBase* websocket_stream() { | |
| 239 return websocket_stream_.get(); | |
| 240 } | |
| 241 | |
| 242 bool stream_done() const { return stream_done_; } | |
| 243 SpdySession* spdy_session() {return spdy_session_.get(); } | |
| 244 ClientSocketHandle* connection() { return connection_.get(); } | |
| 119 | 245 |
| 120 private: | 246 private: |
| 121 bool waiting_for_stream_; | 247 bool waiting_for_stream_; |
| 122 bool stream_done_; | 248 bool stream_done_; |
| 123 scoped_ptr<HttpStreamBase> stream_; | 249 scoped_ptr<HttpStreamBase> stream_; |
| 250 scoped_ptr<WebSocketStreamBase> websocket_stream_; | |
| 124 SSLConfig used_ssl_config_; | 251 SSLConfig used_ssl_config_; |
| 252 scoped_ptr<ClientSocketHandle> connection_; | |
| 253 scoped_refptr<SpdySession> spdy_session_; | |
|
mmenke
2013/05/28 21:22:37
These two are no longer in use.
yhirano
2013/05/30 04:44:32
Done.
| |
| 125 | 254 |
| 126 DISALLOW_COPY_AND_ASSIGN(StreamRequestWaiter); | 255 DISALLOW_COPY_AND_ASSIGN(StreamRequestWaiter); |
| 127 }; | 256 }; |
| 128 | 257 |
| 258 class WebSocketSpdyStream : public WebSocketStreamBase { | |
| 259 public: | |
| 260 explicit WebSocketSpdyStream(SpdySession* spdy_session): | |
| 261 WebSocketStreamBase(kStreamTypeSpdy), spdy_session_(spdy_session) {} | |
| 262 SpdySession* spdy_session() {return spdy_session_.get();} | |
| 263 | |
| 264 private: | |
| 265 scoped_refptr<SpdySession> spdy_session_; | |
| 266 }; | |
| 267 | |
| 268 class WebSocketBasicStream : public WebSocketStreamBase { | |
| 269 public: | |
| 270 explicit WebSocketBasicStream(ClientSocketHandle* connection): | |
| 271 WebSocketStreamBase(kStreamTypeBasic), connection_(connection) {} | |
| 272 ClientSocketHandle* connection() {return connection_.get();} | |
| 273 | |
| 274 private: | |
| 275 scoped_ptr<ClientSocketHandle> connection_; | |
| 276 }; | |
| 277 | |
| 278 class WebSocketStreamFactory : public WebSocketStreamBase::Factory { | |
| 279 public: | |
| 280 virtual WebSocketStreamBase* CreateBasicStream(ClientSocketHandle* connection, | |
| 281 bool using_proxy) OVERRIDE { | |
| 282 return new WebSocketBasicStream(connection); | |
| 283 } | |
| 284 virtual WebSocketStreamBase* CreateSpdyStream( | |
| 285 SpdySession* spdy_session, | |
| 286 bool use_relative_url) OVERRIDE { | |
| 287 return new WebSocketSpdyStream(spdy_session); | |
| 288 } | |
| 289 }; | |
| 290 | |
| 129 struct SessionDependencies { | 291 struct SessionDependencies { |
| 130 // Custom proxy service dependency. | 292 // Custom proxy service dependency. |
| 131 explicit SessionDependencies(ProxyService* proxy_service) | 293 explicit SessionDependencies(ProxyService* proxy_service) |
| 132 : host_resolver(new MockHostResolver), | 294 : host_resolver(new MockHostResolver), |
| 133 cert_verifier(new MockCertVerifier), | 295 cert_verifier(new MockCertVerifier), |
| 134 proxy_service(proxy_service), | 296 proxy_service(proxy_service), |
| 135 ssl_config_service(new SSLConfigServiceDefaults), | 297 ssl_config_service(new SSLConfigServiceDefaults), |
| 136 http_auth_handler_factory( | 298 http_auth_handler_factory( |
| 137 HttpAuthHandlerFactory::CreateDefault(host_resolver.get())), | 299 HttpAuthHandlerFactory::CreateDefault(host_resolver.get())), |
| 138 net_log(NULL) {} | 300 net_log(NULL) {} |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 151 HttpNetworkSession::Params params; | 313 HttpNetworkSession::Params params; |
| 152 params.host_resolver = session_deps->host_resolver.get(); | 314 params.host_resolver = session_deps->host_resolver.get(); |
| 153 params.cert_verifier = session_deps->cert_verifier.get(); | 315 params.cert_verifier = session_deps->cert_verifier.get(); |
| 154 params.proxy_service = session_deps->proxy_service.get(); | 316 params.proxy_service = session_deps->proxy_service.get(); |
| 155 params.ssl_config_service = session_deps->ssl_config_service; | 317 params.ssl_config_service = session_deps->ssl_config_service; |
| 156 params.client_socket_factory = &session_deps->socket_factory; | 318 params.client_socket_factory = &session_deps->socket_factory; |
| 157 params.http_auth_handler_factory = | 319 params.http_auth_handler_factory = |
| 158 session_deps->http_auth_handler_factory.get(); | 320 session_deps->http_auth_handler_factory.get(); |
| 159 params.net_log = session_deps->net_log; | 321 params.net_log = session_deps->net_log; |
| 160 params.http_server_properties = &session_deps->http_server_properties; | 322 params.http_server_properties = &session_deps->http_server_properties; |
| 323 | |
| 161 return new HttpNetworkSession(params); | 324 return new HttpNetworkSession(params); |
| 162 } | 325 } |
| 163 | 326 |
| 164 struct TestCase { | 327 struct TestCase { |
| 165 int num_streams; | 328 int num_streams; |
| 166 bool ssl; | 329 bool ssl; |
| 167 }; | 330 }; |
| 168 | 331 |
| 169 TestCase kTests[] = { | 332 TestCase kTests[] = { |
| 170 { 1, false }, | 333 { 1, false }, |
| 171 { 2, false }, | 334 { 2, false }, |
| 172 { 1, true}, | 335 { 1, true}, |
| 173 { 2, true}, | 336 { 2, true}, |
| 174 }; | 337 }; |
| 175 | 338 |
| 176 void PreconnectHelperForURL(int num_streams, | 339 void PreconnectHelperForURL(int num_streams, |
| 177 const GURL& url, | 340 const GURL& url, |
| 178 HttpNetworkSession* session) { | 341 HttpNetworkSession* session) { |
| 179 HttpNetworkSessionPeer peer(session); | 342 HttpNetworkSessionPeer peer(session); |
| 180 MockHttpStreamFactoryImpl* mock_factory = | 343 MockHttpStreamFactoryImplForPreconnect* mock_factory = |
| 181 new MockHttpStreamFactoryImpl(session); | 344 new MockHttpStreamFactoryImplForPreconnect(session, false); |
| 182 peer.SetHttpStreamFactory(mock_factory); | 345 peer.SetHttpStreamFactory(mock_factory); |
| 183 SSLConfig ssl_config; | 346 SSLConfig ssl_config; |
| 184 session->ssl_config_service()->GetSSLConfig(&ssl_config); | 347 session->ssl_config_service()->GetSSLConfig(&ssl_config); |
| 185 | 348 |
| 186 HttpRequestInfo request; | 349 HttpRequestInfo request; |
| 187 request.method = "GET"; | 350 request.method = "GET"; |
| 188 request.url = url; | 351 request.url = url; |
| 189 request.load_flags = 0; | 352 request.load_flags = 0; |
| 190 | 353 |
| 191 session->http_stream_factory()->PreconnectStreams( | 354 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)); | 616 socket_data1.set_connect_data(MockConnect(ASYNC, ERR_ADDRESS_UNREACHABLE)); |
| 454 session_deps.socket_factory.AddSocketDataProvider(&socket_data1); | 617 session_deps.socket_factory.AddSocketDataProvider(&socket_data1); |
| 455 | 618 |
| 456 // Second connection attempt succeeds | 619 // Second connection attempt succeeds |
| 457 StaticSocketDataProvider socket_data2; | 620 StaticSocketDataProvider socket_data2; |
| 458 socket_data2.set_connect_data(MockConnect(ASYNC, OK)); | 621 socket_data2.set_connect_data(MockConnect(ASYNC, OK)); |
| 459 session_deps.socket_factory.AddSocketDataProvider(&socket_data2); | 622 session_deps.socket_factory.AddSocketDataProvider(&socket_data2); |
| 460 | 623 |
| 461 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps)); | 624 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps)); |
| 462 | 625 |
| 463 // Now request a stream. It should succeed using the second proxy in the | 626 // Now request a stream. |
| 464 // list. | |
| 465 HttpRequestInfo request_info; | 627 HttpRequestInfo request_info; |
| 466 request_info.method = "GET"; | 628 request_info.method = "GET"; |
| 467 request_info.url = GURL("http://www.google.com"); | 629 request_info.url = GURL("http://www.google.com"); |
| 468 | 630 |
| 469 SSLConfig ssl_config; | 631 SSLConfig ssl_config; |
| 470 StreamRequestWaiter waiter; | 632 StreamRequestWaiter waiter; |
| 471 scoped_ptr<HttpStreamRequest> request( | 633 scoped_ptr<HttpStreamRequest> request( |
| 472 session->http_stream_factory()->RequestStream( | 634 session->http_stream_factory()->RequestStream( |
| 473 request_info, DEFAULT_PRIORITY, ssl_config, ssl_config, | 635 request_info, DEFAULT_PRIORITY, ssl_config, ssl_config, |
| 474 &waiter, BoundNetLog())); | 636 &waiter, BoundNetLog())); |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 603 scoped_ptr<HttpStreamRequest> request( | 765 scoped_ptr<HttpStreamRequest> request( |
| 604 session->http_stream_factory()->RequestStream( | 766 session->http_stream_factory()->RequestStream( |
| 605 request_info, DEFAULT_PRIORITY, ssl_config, ssl_config, | 767 request_info, DEFAULT_PRIORITY, ssl_config, ssl_config, |
| 606 &waiter, BoundNetLog())); | 768 &waiter, BoundNetLog())); |
| 607 | 769 |
| 608 EXPECT_EQ(LOAD_STATE_RESOLVING_HOST, request->GetLoadState()); | 770 EXPECT_EQ(LOAD_STATE_RESOLVING_HOST, request->GetLoadState()); |
| 609 | 771 |
| 610 waiter.WaitForStream(); | 772 waiter.WaitForStream(); |
| 611 } | 773 } |
| 612 | 774 |
| 775 TEST(HttpStreamFactoryTest, RequestHttpStream) { | |
| 776 SessionDependencies session_deps(ProxyService::CreateDirect()); | |
| 777 | |
| 778 StaticSocketDataProvider socket_data; | |
| 779 socket_data.set_connect_data(MockConnect(ASYNC, OK)); | |
| 780 session_deps.socket_factory.AddSocketDataProvider(&socket_data); | |
| 781 | |
| 782 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps)); | |
| 783 MockHttpStreamFactoryImpl* http_stream_factory = | |
| 784 new MockHttpStreamFactoryImpl(session.get(), false); | |
| 785 HttpNetworkSessionPeer(session).SetHttpStreamFactory(http_stream_factory); | |
| 786 | |
| 787 // Now request a stream. It should succeed using the second proxy in the | |
| 788 // list. | |
| 789 HttpRequestInfo request_info; | |
| 790 request_info.method = "GET"; | |
| 791 request_info.url = GURL("http://www.google.com"); | |
| 792 request_info.load_flags = 0; | |
| 793 | |
| 794 SSLConfig ssl_config; | |
| 795 StreamRequestWaiter waiter; | |
| 796 scoped_ptr<HttpStreamRequest> request( | |
| 797 session->http_stream_factory()->RequestStream( | |
| 798 request_info, | |
| 799 DEFAULT_PRIORITY, | |
| 800 ssl_config, | |
| 801 ssl_config, | |
| 802 &waiter, | |
| 803 BoundNetLog())); | |
| 804 waiter.WaitForStream(); | |
| 805 EXPECT_TRUE(waiter.stream_done()); | |
| 806 EXPECT_TRUE(NULL == waiter.spdy_session()); | |
| 807 EXPECT_TRUE(NULL == waiter.connection()); | |
|
mmenke
2013/05/28 21:22:37
There's no code to initialize these. Should be ch
yhirano
2013/05/30 04:44:32
Done.
| |
| 808 EXPECT_TRUE(NULL != waiter.stream()); | |
| 809 EXPECT_EQ(1u, http_stream_factory->calls_init_socket_handle_for_http.size()); | |
| 810 MockHttpStreamFactoryImpl::InitSocketHandleParams params = | |
| 811 http_stream_factory->calls_init_socket_handle_for_http[0]; | |
|
mmenke
2013/05/28 21:22:37
Is all this extra infrastructure necessary? The o
yhirano
2013/05/30 04:44:32
Thank you, you are right.
I deleted HttpStreamFact
| |
| 812 EXPECT_EQ(request_info.url, params.request_url); | |
| 813 EXPECT_TRUE(params.proxy_info.is_direct()); | |
| 814 SSLInfo ssl_info; | |
| 815 EXPECT_FALSE(params.socket_handle->socket()->GetSSLInfo(&ssl_info)); | |
| 816 } | |
| 817 | |
| 818 TEST(HttpStreamFactoryTest, RequestHttpStreamOverSSL) { | |
| 819 SessionDependencies session_deps(ProxyService::CreateDirect()); | |
| 820 | |
| 821 MockRead mock_read(ASYNC, ERR_IO_PENDING); | |
| 822 StaticSocketDataProvider socket_data(&mock_read, 1, NULL, 0); | |
| 823 socket_data.set_connect_data(MockConnect(ASYNC, OK)); | |
| 824 session_deps.socket_factory.AddSocketDataProvider(&socket_data); | |
| 825 | |
| 826 SSLSocketDataProvider ssl_socket_data(ASYNC, OK); | |
| 827 ssl_socket_data.protocol_negotiated = kProtoSPDY3; | |
| 828 session_deps.socket_factory.AddSSLSocketDataProvider(&ssl_socket_data); | |
| 829 | |
| 830 SSLSocketDataProvider ssl_socket_data2(ASYNC, OK); | |
| 831 ssl_socket_data2.protocol_negotiated = kProtoSPDY3; | |
| 832 session_deps.socket_factory.AddSSLSocketDataProvider(&ssl_socket_data2); | |
| 833 | |
| 834 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps)); | |
| 835 | |
| 836 MockHttpStreamFactoryImpl* http_stream_factory = | |
| 837 new MockHttpStreamFactoryImpl(session.get(), false); | |
| 838 HttpNetworkSessionPeer(session).SetHttpStreamFactory(http_stream_factory); | |
| 839 | |
| 840 // Now request a stream. It should succeed using the second proxy in the | |
| 841 // list. | |
| 842 HttpRequestInfo request_info; | |
| 843 request_info.method = "GET"; | |
| 844 request_info.url = GURL("https://www.google.com"); | |
| 845 request_info.load_flags = 0; | |
| 846 | |
| 847 SSLConfig ssl_config; | |
| 848 StreamRequestWaiter waiter; | |
| 849 scoped_ptr<HttpStreamRequest> request( | |
| 850 session->http_stream_factory()->RequestStream( | |
| 851 request_info, | |
| 852 DEFAULT_PRIORITY, | |
| 853 ssl_config, | |
| 854 ssl_config, | |
| 855 &waiter, | |
| 856 BoundNetLog())); | |
| 857 waiter.WaitForStream(); | |
| 858 EXPECT_TRUE(waiter.stream_done()); | |
| 859 EXPECT_TRUE(NULL == waiter.spdy_session()); | |
| 860 EXPECT_TRUE(NULL == waiter.connection()); | |
| 861 EXPECT_TRUE(NULL != waiter.stream()); | |
| 862 EXPECT_EQ(1u, http_stream_factory->calls_init_socket_handle_for_http.size()); | |
| 863 MockHttpStreamFactoryImpl::InitSocketHandleParams params = | |
| 864 http_stream_factory->calls_init_socket_handle_for_http[0]; | |
| 865 EXPECT_EQ(request_info.url, params.request_url); | |
| 866 EXPECT_TRUE(params.proxy_info.is_direct()); | |
| 867 SSLInfo ssl_info; | |
| 868 EXPECT_TRUE(params.socket_handle->socket()->GetSSLInfo(&ssl_info)); | |
| 869 } | |
| 870 | |
| 871 TEST(HttpStreamFactoryTest, RequestHttpStreamOverProxy) { | |
| 872 SessionDependencies session_deps(ProxyService::CreateFixed("myproxy:8888")); | |
| 873 | |
| 874 StaticSocketDataProvider socket_data; | |
| 875 socket_data.set_connect_data(MockConnect(ASYNC, OK)); | |
| 876 session_deps.socket_factory.AddSocketDataProvider(&socket_data); | |
| 877 | |
| 878 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps)); | |
| 879 MockHttpStreamFactoryImpl* http_stream_factory = | |
| 880 new MockHttpStreamFactoryImpl(session.get(), false); | |
| 881 HttpNetworkSessionPeer(session).SetHttpStreamFactory(http_stream_factory); | |
| 882 | |
| 883 // Now request a stream. It should succeed using the second proxy in the | |
| 884 // list. | |
| 885 HttpRequestInfo request_info; | |
| 886 request_info.method = "GET"; | |
| 887 request_info.url = GURL("http://www.google.com"); | |
| 888 request_info.load_flags = 0; | |
| 889 | |
| 890 SSLConfig ssl_config; | |
| 891 StreamRequestWaiter waiter; | |
| 892 scoped_ptr<HttpStreamRequest> request( | |
| 893 session->http_stream_factory()->RequestStream( | |
| 894 request_info, | |
| 895 DEFAULT_PRIORITY, | |
| 896 ssl_config, | |
| 897 ssl_config, | |
| 898 &waiter, | |
| 899 BoundNetLog())); | |
| 900 waiter.WaitForStream(); | |
| 901 EXPECT_TRUE(waiter.stream_done()); | |
| 902 EXPECT_TRUE(NULL == waiter.spdy_session()); | |
| 903 EXPECT_TRUE(NULL == waiter.connection()); | |
| 904 EXPECT_TRUE(NULL != waiter.stream()); | |
| 905 EXPECT_EQ(1u, http_stream_factory->calls_init_socket_handle_for_http.size()); | |
| 906 MockHttpStreamFactoryImpl::InitSocketHandleParams params = | |
| 907 http_stream_factory->calls_init_socket_handle_for_http[0]; | |
| 908 EXPECT_EQ(request_info.url, params.request_url); | |
| 909 EXPECT_FALSE(params.proxy_info.is_direct()); | |
| 910 SSLInfo ssl_info; | |
| 911 EXPECT_FALSE(params.socket_handle->socket()->GetSSLInfo(&ssl_info)); | |
| 912 } | |
| 913 | |
| 914 TEST(HttpStreamFactoryTest, RequestWebSocketBasicStream) { | |
| 915 SessionDependencies session_deps(ProxyService::CreateDirect()); | |
| 916 | |
| 917 StaticSocketDataProvider socket_data; | |
| 918 socket_data.set_connect_data(MockConnect(ASYNC, OK)); | |
| 919 session_deps.socket_factory.AddSocketDataProvider(&socket_data); | |
| 920 | |
| 921 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps)); | |
| 922 MockHttpStreamFactoryImpl* websocket_stream_factory = | |
| 923 new MockHttpStreamFactoryImpl(session.get(), true); | |
| 924 HttpNetworkSessionPeer(session).SetWebSocketStreamFactory( | |
| 925 websocket_stream_factory); | |
| 926 | |
| 927 // Now request a stream. | |
| 928 HttpRequestInfo request_info; | |
| 929 request_info.method = "GET"; | |
| 930 request_info.url = GURL("ws://www.google.com"); | |
| 931 request_info.load_flags = 0; | |
| 932 | |
| 933 SSLConfig ssl_config; | |
| 934 StreamRequestWaiter waiter; | |
| 935 WebSocketStreamFactory factory; | |
| 936 scoped_ptr<HttpStreamRequest> request( | |
| 937 session->websocket_stream_factory()->RequestWebSocketStream( | |
| 938 request_info, | |
| 939 DEFAULT_PRIORITY, | |
| 940 ssl_config, | |
| 941 ssl_config, | |
| 942 &waiter, | |
| 943 &factory, | |
| 944 BoundNetLog())); | |
| 945 waiter.WaitForStream(); | |
| 946 EXPECT_TRUE(waiter.stream_done()); | |
| 947 EXPECT_TRUE(NULL == waiter.stream()); | |
| 948 EXPECT_TRUE(NULL != waiter.websocket_stream()); | |
| 949 EXPECT_EQ(WebSocketStreamBase::kStreamTypeBasic, | |
| 950 waiter.websocket_stream()->type()); | |
| 951 EXPECT_EQ(1u, | |
| 952 websocket_stream_factory->calls_init_socket_handle_for_http.size()); | |
| 953 MockHttpStreamFactoryImpl::InitSocketHandleParams params = | |
| 954 websocket_stream_factory->calls_init_socket_handle_for_http[0]; | |
| 955 EXPECT_EQ(request_info.url, params.request_url); | |
| 956 EXPECT_TRUE(params.proxy_info.is_direct()); | |
| 957 SSLInfo ssl_info; | |
| 958 EXPECT_FALSE(params.socket_handle->socket()->GetSSLInfo(&ssl_info)); | |
| 959 } | |
| 960 | |
| 961 TEST(HttpStreamFactoryTest, RequestWebSocketBasicStreamOverSSL) { | |
| 962 ScopedForceSpdySsl use_spdy(false); | |
| 963 SessionDependencies session_deps(ProxyService::CreateDirect()); | |
| 964 | |
| 965 MockRead mock_read(ASYNC, ERR_IO_PENDING); | |
| 966 StaticSocketDataProvider socket_data(&mock_read, 1, NULL, 0); | |
| 967 socket_data.set_connect_data(MockConnect(ASYNC, OK)); | |
| 968 session_deps.socket_factory.AddSocketDataProvider(&socket_data); | |
| 969 | |
| 970 SSLSocketDataProvider ssl_socket_data(ASYNC, OK); | |
| 971 ssl_socket_data.protocol_negotiated = kProtoSPDY3; | |
| 972 session_deps.socket_factory.AddSSLSocketDataProvider(&ssl_socket_data); | |
| 973 | |
| 974 SSLSocketDataProvider ssl_socket_data2(ASYNC, OK); | |
| 975 ssl_socket_data2.protocol_negotiated = kProtoSPDY3; | |
| 976 session_deps.socket_factory.AddSSLSocketDataProvider(&ssl_socket_data2); | |
| 977 | |
| 978 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps)); | |
| 979 MockHttpStreamFactoryImpl* websocket_stream_factory = | |
| 980 new MockHttpStreamFactoryImpl(session.get(), true); | |
| 981 HttpNetworkSessionPeer(session).SetWebSocketStreamFactory( | |
| 982 websocket_stream_factory); | |
| 983 | |
| 984 // Now request a stream. | |
| 985 HttpRequestInfo request_info; | |
| 986 request_info.method = "GET"; | |
| 987 request_info.url = GURL("wss://www.google.com"); | |
| 988 request_info.load_flags = 0; | |
| 989 | |
| 990 SSLConfig ssl_config; | |
| 991 StreamRequestWaiter waiter; | |
| 992 WebSocketStreamFactory factory; | |
| 993 scoped_ptr<HttpStreamRequest> request( | |
| 994 session->websocket_stream_factory()->RequestWebSocketStream( | |
| 995 request_info, | |
| 996 DEFAULT_PRIORITY, | |
| 997 ssl_config, | |
| 998 ssl_config, | |
| 999 &waiter, | |
| 1000 &factory, | |
| 1001 BoundNetLog())); | |
| 1002 waiter.WaitForStream(); | |
| 1003 EXPECT_TRUE(waiter.stream_done()); | |
| 1004 EXPECT_TRUE(NULL == waiter.stream()); | |
| 1005 EXPECT_TRUE(NULL != waiter.websocket_stream()); | |
| 1006 EXPECT_EQ(WebSocketStreamBase::kStreamTypeBasic, | |
| 1007 waiter.websocket_stream()->type()); | |
| 1008 EXPECT_EQ(1u, | |
| 1009 websocket_stream_factory->calls_init_socket_handle_for_http.size()); | |
| 1010 MockHttpStreamFactoryImpl::InitSocketHandleParams params = | |
| 1011 websocket_stream_factory->calls_init_socket_handle_for_http[0]; | |
| 1012 EXPECT_EQ(request_info.url, params.request_url); | |
| 1013 EXPECT_TRUE(params.proxy_info.is_direct()); | |
| 1014 SSLInfo ssl_info; | |
| 1015 EXPECT_TRUE(params.socket_handle->socket()->GetSSLInfo(&ssl_info)); | |
| 1016 } | |
| 1017 | |
| 1018 TEST(HttpStreamFactoryTest, RequestSpdyHttpStream) { | |
| 1019 ScopedForceSpdySsl use_spdy(true); | |
| 1020 SpdySessionDependencies session_deps(kProtoSPDY3, | |
| 1021 ProxyService::CreateDirect()); | |
| 1022 | |
| 1023 MockRead mock_read(ASYNC, OK); | |
| 1024 StaticSocketDataProvider socket_data(&mock_read, 1, NULL, 0); | |
| 1025 socket_data.set_connect_data(MockConnect(ASYNC, OK)); | |
| 1026 session_deps.socket_factory->AddSocketDataProvider(&socket_data); | |
| 1027 | |
| 1028 SSLSocketDataProvider ssl_socket_data(ASYNC, OK); | |
| 1029 ssl_socket_data.protocol_negotiated = kProtoSPDY3; | |
| 1030 session_deps.socket_factory->AddSSLSocketDataProvider(&ssl_socket_data); | |
| 1031 | |
| 1032 HostPortPair host_port_pair("www.google.com", 80); | |
| 1033 scoped_refptr<HttpNetworkSession> | |
| 1034 session(SpdySessionDependencies::SpdyCreateSession(&session_deps)); | |
| 1035 MockHttpStreamFactoryImpl* http_stream_factory = | |
| 1036 new MockHttpStreamFactoryImpl(session.get(), false); | |
| 1037 HttpNetworkSessionPeer(session).SetHttpStreamFactory(http_stream_factory); | |
| 1038 | |
| 1039 // Now request a stream. | |
| 1040 HttpRequestInfo request_info; | |
| 1041 request_info.method = "GET"; | |
| 1042 request_info.url = GURL("https://www.google.com"); | |
| 1043 request_info.load_flags = 0; | |
| 1044 | |
| 1045 SSLConfig ssl_config; | |
| 1046 StreamRequestWaiter waiter; | |
| 1047 scoped_ptr<HttpStreamRequest> request( | |
| 1048 session->http_stream_factory()->RequestStream( | |
| 1049 request_info, | |
| 1050 DEFAULT_PRIORITY, | |
| 1051 ssl_config, | |
| 1052 ssl_config, | |
| 1053 &waiter, | |
| 1054 BoundNetLog())); | |
| 1055 waiter.WaitForStream(); | |
| 1056 EXPECT_TRUE(waiter.stream_done()); | |
| 1057 EXPECT_TRUE(NULL == waiter.websocket_stream()); | |
| 1058 EXPECT_TRUE(NULL != waiter.stream()); | |
| 1059 EXPECT_TRUE(waiter.stream()->IsSpdyHttpStream()); | |
| 1060 EXPECT_EQ(1u, http_stream_factory->calls_init_socket_handle_for_http.size()); | |
| 1061 MockHttpStreamFactoryImpl::InitSocketHandleParams params = | |
| 1062 http_stream_factory->calls_init_socket_handle_for_http[0]; | |
| 1063 EXPECT_EQ(request_info.url, params.request_url); | |
| 1064 EXPECT_TRUE(params.proxy_info.is_direct()); | |
| 1065 SSLInfo ssl_info; | |
| 1066 EXPECT_TRUE(params.socket_handle->socket()->GetSSLInfo(&ssl_info)); | |
| 1067 } | |
| 1068 | |
| 1069 TEST(HttpStreamFactoryTest, RequestWebSocketSpdyStream) { | |
| 1070 ScopedForceSpdySsl use_spdy(true); | |
| 1071 SpdySessionDependencies session_deps(kProtoSPDY3, | |
| 1072 ProxyService::CreateDirect()); | |
| 1073 | |
| 1074 MockRead mock_read(ASYNC, ERR_IO_PENDING); | |
| 1075 StaticSocketDataProvider socket_data(&mock_read, 1, NULL, 0); | |
| 1076 socket_data.set_connect_data(MockConnect(ASYNC, OK)); | |
| 1077 session_deps.socket_factory->AddSocketDataProvider(&socket_data); | |
| 1078 | |
| 1079 SSLSocketDataProvider ssl_socket_data(ASYNC, OK); | |
| 1080 ssl_socket_data.protocol_negotiated = kProtoSPDY3; | |
| 1081 session_deps.socket_factory->AddSSLSocketDataProvider(&ssl_socket_data); | |
| 1082 | |
| 1083 SSLSocketDataProvider ssl_socket_data2(ASYNC, OK); | |
| 1084 ssl_socket_data2.protocol_negotiated = kProtoSPDY3; | |
| 1085 session_deps.socket_factory->AddSSLSocketDataProvider(&ssl_socket_data2); | |
| 1086 | |
| 1087 HostPortPair host_port_pair("www.google.com", 80); | |
| 1088 scoped_refptr<HttpNetworkSession> | |
| 1089 session(SpdySessionDependencies::SpdyCreateSession(&session_deps)); | |
| 1090 MockHttpStreamFactoryImpl* websocket_stream_factory = | |
| 1091 new MockHttpStreamFactoryImpl(session.get(), true); | |
| 1092 HttpNetworkSessionPeer(session).SetWebSocketStreamFactory( | |
| 1093 websocket_stream_factory); | |
| 1094 | |
| 1095 // Now request a stream. | |
| 1096 HttpRequestInfo request_info; | |
| 1097 request_info.method = "GET"; | |
| 1098 request_info.url = GURL("wss://www.google.com"); | |
| 1099 request_info.load_flags = 0; | |
| 1100 | |
| 1101 SSLConfig ssl_config; | |
| 1102 StreamRequestWaiter waiter1; | |
| 1103 WebSocketStreamFactory factory; | |
| 1104 scoped_ptr<HttpStreamRequest> request1( | |
| 1105 session->websocket_stream_factory()->RequestWebSocketStream( | |
| 1106 request_info, | |
| 1107 DEFAULT_PRIORITY, | |
| 1108 ssl_config, | |
| 1109 ssl_config, | |
| 1110 &waiter1, | |
| 1111 &factory, | |
| 1112 BoundNetLog())); | |
| 1113 waiter1.WaitForStream(); | |
| 1114 EXPECT_TRUE(waiter1.stream_done()); | |
| 1115 EXPECT_TRUE(NULL != waiter1.websocket_stream()); | |
| 1116 EXPECT_EQ(WebSocketStreamBase::kStreamTypeSpdy, | |
| 1117 waiter1.websocket_stream()->type()); | |
| 1118 EXPECT_TRUE(NULL == waiter1.connection()); | |
| 1119 EXPECT_TRUE(NULL == waiter1.stream()); | |
| 1120 | |
| 1121 StreamRequestWaiter waiter2; | |
| 1122 scoped_ptr<HttpStreamRequest> request2( | |
| 1123 session->websocket_stream_factory()->RequestWebSocketStream( | |
| 1124 request_info, | |
| 1125 DEFAULT_PRIORITY, | |
| 1126 ssl_config, | |
| 1127 ssl_config, | |
| 1128 &waiter2, | |
| 1129 &factory, | |
| 1130 BoundNetLog())); | |
| 1131 waiter2.WaitForStream(); | |
| 1132 EXPECT_TRUE(waiter2.stream_done()); | |
| 1133 EXPECT_TRUE(NULL != waiter2.websocket_stream()); | |
| 1134 EXPECT_EQ(WebSocketStreamBase::kStreamTypeSpdy, | |
| 1135 waiter2.websocket_stream()->type()); | |
| 1136 EXPECT_TRUE(NULL == waiter2.connection()); | |
| 1137 EXPECT_TRUE(NULL == waiter2.stream()); | |
| 1138 EXPECT_NE(waiter2.websocket_stream(), waiter1.websocket_stream()); | |
| 1139 EXPECT_EQ(static_cast<WebSocketSpdyStream*>(waiter2.websocket_stream())-> | |
| 1140 spdy_session(), | |
| 1141 static_cast<WebSocketSpdyStream*>(waiter1.websocket_stream())-> | |
| 1142 spdy_session()); | |
| 1143 | |
| 1144 EXPECT_EQ(1u, | |
| 1145 websocket_stream_factory->calls_init_socket_handle_for_http.size()); | |
| 1146 MockHttpStreamFactoryImpl::InitSocketHandleParams params = | |
| 1147 websocket_stream_factory->calls_init_socket_handle_for_http[0]; | |
| 1148 EXPECT_EQ(request_info.url, params.request_url); | |
| 1149 EXPECT_TRUE(params.proxy_info.is_direct()); | |
| 1150 SSLInfo ssl_info; | |
| 1151 EXPECT_TRUE(params.socket_handle->socket()->GetSSLInfo(&ssl_info)); | |
| 1152 } | |
| 1153 | |
| 613 } // namespace | 1154 } // namespace |
| 614 | 1155 |
| 615 } // namespace net | 1156 } // namespace net |
| OLD | NEW |