| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_network_transaction.h" | 5 #include "net/http/http_network_transaction.h" |
| 6 | 6 |
| 7 #include <math.h> // ceil | 7 #include <math.h> // ceil |
| 8 #include <stdarg.h> | 8 #include <stdarg.h> |
| 9 #include <stdint.h> | 9 #include <stdint.h> |
| 10 | 10 |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 #include "net/log/net_log.h" | 65 #include "net/log/net_log.h" |
| 66 #include "net/log/net_log_event_type.h" | 66 #include "net/log/net_log_event_type.h" |
| 67 #include "net/log/net_log_source.h" | 67 #include "net/log/net_log_source.h" |
| 68 #include "net/log/test_net_log.h" | 68 #include "net/log/test_net_log.h" |
| 69 #include "net/log/test_net_log_entry.h" | 69 #include "net/log/test_net_log_entry.h" |
| 70 #include "net/log/test_net_log_util.h" | 70 #include "net/log/test_net_log_util.h" |
| 71 #include "net/proxy/mock_proxy_resolver.h" | 71 #include "net/proxy/mock_proxy_resolver.h" |
| 72 #include "net/proxy/proxy_config_service_fixed.h" | 72 #include "net/proxy/proxy_config_service_fixed.h" |
| 73 #include "net/proxy/proxy_info.h" | 73 #include "net/proxy/proxy_info.h" |
| 74 #include "net/proxy/proxy_resolver.h" | 74 #include "net/proxy/proxy_resolver.h" |
| 75 #include "net/proxy/proxy_resolver_factory.h" | |
| 76 #include "net/proxy/proxy_server.h" | 75 #include "net/proxy/proxy_server.h" |
| 77 #include "net/proxy/proxy_service.h" | 76 #include "net/proxy/proxy_service.h" |
| 78 #include "net/socket/client_socket_factory.h" | 77 #include "net/socket/client_socket_factory.h" |
| 79 #include "net/socket/client_socket_pool.h" | 78 #include "net/socket/client_socket_pool.h" |
| 80 #include "net/socket/client_socket_pool_manager.h" | 79 #include "net/socket/client_socket_pool_manager.h" |
| 81 #include "net/socket/connection_attempts.h" | 80 #include "net/socket/connection_attempts.h" |
| 82 #include "net/socket/mock_client_socket_pool_manager.h" | 81 #include "net/socket/mock_client_socket_pool_manager.h" |
| 83 #include "net/socket/next_proto.h" | 82 #include "net/socket/next_proto.h" |
| 84 #include "net/socket/socket_test_util.h" | 83 #include "net/socket/socket_test_util.h" |
| 85 #include "net/socket/ssl_client_socket.h" | 84 #include "net/socket/ssl_client_socket.h" |
| (...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 372 std::unique_ptr<TestNetworkStreamThrottler> owned_throttler( | 371 std::unique_ptr<TestNetworkStreamThrottler> owned_throttler( |
| 373 new TestNetworkStreamThrottler); | 372 new TestNetworkStreamThrottler); |
| 374 *throttler = owned_throttler.get(); | 373 *throttler = owned_throttler.get(); |
| 375 | 374 |
| 376 HttpNetworkSessionPeer peer(session.get()); | 375 HttpNetworkSessionPeer peer(session.get()); |
| 377 peer.SetNetworkStreamThrottler(std::move(owned_throttler)); | 376 peer.SetNetworkStreamThrottler(std::move(owned_throttler)); |
| 378 | 377 |
| 379 return session; | 378 return session; |
| 380 } | 379 } |
| 381 | 380 |
| 382 class FailingProxyResolverFactory : public ProxyResolverFactory { | |
| 383 public: | |
| 384 FailingProxyResolverFactory() : ProxyResolverFactory(false) {} | |
| 385 | |
| 386 // ProxyResolverFactory override. | |
| 387 int CreateProxyResolver( | |
| 388 const scoped_refptr<ProxyResolverScriptData>& script_data, | |
| 389 std::unique_ptr<ProxyResolver>* result, | |
| 390 const CompletionCallback& callback, | |
| 391 std::unique_ptr<Request>* request) override { | |
| 392 return ERR_PAC_SCRIPT_FAILED; | |
| 393 } | |
| 394 }; | |
| 395 | |
| 396 } // namespace | 381 } // namespace |
| 397 | 382 |
| 398 class HttpNetworkTransactionTest : public PlatformTest { | 383 class HttpNetworkTransactionTest : public PlatformTest { |
| 399 public: | 384 public: |
| 400 ~HttpNetworkTransactionTest() override { | 385 ~HttpNetworkTransactionTest() override { |
| 401 // Important to restore the per-pool limit first, since the pool limit must | 386 // Important to restore the per-pool limit first, since the pool limit must |
| 402 // always be greater than group limit, and the tests reduce both limits. | 387 // always be greater than group limit, and the tests reduce both limits. |
| 403 ClientSocketPoolManager::set_max_sockets_per_pool( | 388 ClientSocketPoolManager::set_max_sockets_per_pool( |
| 404 HttpNetworkSession::NORMAL_SOCKET_POOL, old_max_pool_sockets_); | 389 HttpNetworkSession::NORMAL_SOCKET_POOL, old_max_pool_sockets_); |
| 405 ClientSocketPoolManager::set_max_sockets_per_group( | 390 ClientSocketPoolManager::set_max_sockets_per_group( |
| (...skipping 14811 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 15217 public: | 15202 public: |
| 15218 FakeStreamFactory() {} | 15203 FakeStreamFactory() {} |
| 15219 ~FakeStreamFactory() override {} | 15204 ~FakeStreamFactory() override {} |
| 15220 | 15205 |
| 15221 // Returns a WeakPtr<> to the last HttpStreamRequest returned by | 15206 // Returns a WeakPtr<> to the last HttpStreamRequest returned by |
| 15222 // RequestStream() (which may be NULL if it was destroyed already). | 15207 // RequestStream() (which may be NULL if it was destroyed already). |
| 15223 base::WeakPtr<FakeStreamRequest> last_stream_request() { | 15208 base::WeakPtr<FakeStreamRequest> last_stream_request() { |
| 15224 return last_stream_request_; | 15209 return last_stream_request_; |
| 15225 } | 15210 } |
| 15226 | 15211 |
| 15227 std::unique_ptr<HttpStreamRequest> RequestStream( | 15212 HttpStreamRequest* RequestStream(const HttpRequestInfo& info, |
| 15213 RequestPriority priority, |
| 15214 const SSLConfig& server_ssl_config, |
| 15215 const SSLConfig& proxy_ssl_config, |
| 15216 HttpStreamRequest::Delegate* delegate, |
| 15217 bool enable_ip_based_pooling, |
| 15218 bool enable_alternative_services, |
| 15219 const NetLogWithSource& net_log) override { |
| 15220 FakeStreamRequest* fake_request = new FakeStreamRequest(priority, delegate); |
| 15221 last_stream_request_ = fake_request->AsWeakPtr(); |
| 15222 return fake_request; |
| 15223 } |
| 15224 |
| 15225 HttpStreamRequest* RequestBidirectionalStreamImpl( |
| 15228 const HttpRequestInfo& info, | 15226 const HttpRequestInfo& info, |
| 15229 RequestPriority priority, | 15227 RequestPriority priority, |
| 15230 const SSLConfig& server_ssl_config, | 15228 const SSLConfig& server_ssl_config, |
| 15231 const SSLConfig& proxy_ssl_config, | |
| 15232 HttpStreamRequest::Delegate* delegate, | |
| 15233 bool enable_ip_based_pooling, | |
| 15234 bool enable_alternative_services, | |
| 15235 const NetLogWithSource& net_log) override { | |
| 15236 auto fake_request = base::MakeUnique<FakeStreamRequest>(priority, delegate); | |
| 15237 last_stream_request_ = fake_request->AsWeakPtr(); | |
| 15238 return std::move(fake_request); | |
| 15239 } | |
| 15240 | |
| 15241 std::unique_ptr<HttpStreamRequest> RequestBidirectionalStreamImpl( | |
| 15242 const HttpRequestInfo& info, | |
| 15243 RequestPriority priority, | |
| 15244 const SSLConfig& server_ssl_config, | |
| 15245 const SSLConfig& proxy_ssl_config, | 15229 const SSLConfig& proxy_ssl_config, |
| 15246 HttpStreamRequest::Delegate* delegate, | 15230 HttpStreamRequest::Delegate* delegate, |
| 15247 bool enable_ip_based_pooling, | 15231 bool enable_ip_based_pooling, |
| 15248 bool enable_alternative_services, | 15232 bool enable_alternative_services, |
| 15249 const NetLogWithSource& net_log) override { | 15233 const NetLogWithSource& net_log) override { |
| 15250 NOTREACHED(); | 15234 NOTREACHED(); |
| 15251 return nullptr; | 15235 return nullptr; |
| 15252 } | 15236 } |
| 15253 | 15237 |
| 15254 std::unique_ptr<HttpStreamRequest> RequestWebSocketHandshakeStream( | 15238 HttpStreamRequest* RequestWebSocketHandshakeStream( |
| 15255 const HttpRequestInfo& info, | 15239 const HttpRequestInfo& info, |
| 15256 RequestPriority priority, | 15240 RequestPriority priority, |
| 15257 const SSLConfig& server_ssl_config, | 15241 const SSLConfig& server_ssl_config, |
| 15258 const SSLConfig& proxy_ssl_config, | 15242 const SSLConfig& proxy_ssl_config, |
| 15259 HttpStreamRequest::Delegate* delegate, | 15243 HttpStreamRequest::Delegate* delegate, |
| 15260 WebSocketHandshakeStreamBase::CreateHelper* create_helper, | 15244 WebSocketHandshakeStreamBase::CreateHelper* create_helper, |
| 15261 bool enable_ip_based_pooling, | 15245 bool enable_ip_based_pooling, |
| 15262 bool enable_alternative_services, | 15246 bool enable_alternative_services, |
| 15263 const NetLogWithSource& net_log) override { | 15247 const NetLogWithSource& net_log) override { |
| 15264 auto fake_request = | 15248 FakeStreamRequest* fake_request = |
| 15265 base::MakeUnique<FakeStreamRequest>(priority, delegate, create_helper); | 15249 new FakeStreamRequest(priority, delegate, create_helper); |
| 15266 last_stream_request_ = fake_request->AsWeakPtr(); | 15250 last_stream_request_ = fake_request->AsWeakPtr(); |
| 15267 return std::move(fake_request); | 15251 return fake_request; |
| 15268 } | 15252 } |
| 15269 | 15253 |
| 15270 void PreconnectStreams(int num_streams, | 15254 void PreconnectStreams(int num_streams, |
| 15271 const HttpRequestInfo& info) override { | 15255 const HttpRequestInfo& info) override { |
| 15272 ADD_FAILURE(); | 15256 ADD_FAILURE(); |
| 15273 } | 15257 } |
| 15274 | 15258 |
| 15275 const HostMappingRules* GetHostMappingRules() const override { | 15259 const HostMappingRules* GetHostMappingRules() const override { |
| 15276 ADD_FAILURE(); | 15260 ADD_FAILURE(); |
| 15277 return NULL; | 15261 return NULL; |
| (...skipping 1592 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 16870 TEST_F(HttpNetworkTransactionTest, MatchContentEncoding3) { | 16854 TEST_F(HttpNetworkTransactionTest, MatchContentEncoding3) { |
| 16871 CheckContentEncodingMatching(&session_deps_, "identity;q=1, *;q=0", "gzip", | 16855 CheckContentEncodingMatching(&session_deps_, "identity;q=1, *;q=0", "gzip", |
| 16872 "", false); | 16856 "", false); |
| 16873 } | 16857 } |
| 16874 | 16858 |
| 16875 TEST_F(HttpNetworkTransactionTest, MatchContentEncoding4) { | 16859 TEST_F(HttpNetworkTransactionTest, MatchContentEncoding4) { |
| 16876 CheckContentEncodingMatching(&session_deps_, "identity;q=1, *;q=0", "gzip", | 16860 CheckContentEncodingMatching(&session_deps_, "identity;q=1, *;q=0", "gzip", |
| 16877 "www.foo.com/other", true); | 16861 "www.foo.com/other", true); |
| 16878 } | 16862 } |
| 16879 | 16863 |
| 16880 TEST_F(HttpNetworkTransactionTest, ProxyResolutionFailsSync) { | |
| 16881 ProxyConfig proxy_config; | |
| 16882 proxy_config.set_pac_url(GURL("http://fooproxyurl")); | |
| 16883 proxy_config.set_pac_mandatory(true); | |
| 16884 MockAsyncProxyResolver resolver; | |
| 16885 session_deps_.proxy_service.reset(new ProxyService( | |
| 16886 base::MakeUnique<ProxyConfigServiceFixed>(proxy_config), | |
| 16887 base::WrapUnique(new FailingProxyResolverFactory), nullptr)); | |
| 16888 | |
| 16889 HttpRequestInfo request; | |
| 16890 request.method = "GET"; | |
| 16891 request.url = GURL("http://www.example.org/"); | |
| 16892 | |
| 16893 std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); | |
| 16894 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); | |
| 16895 | |
| 16896 TestCompletionCallback callback; | |
| 16897 | |
| 16898 int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); | |
| 16899 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | |
| 16900 EXPECT_THAT(callback.WaitForResult(), | |
| 16901 IsError(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED)); | |
| 16902 } | |
| 16903 | |
| 16904 TEST_F(HttpNetworkTransactionTest, ProxyResolutionFailsAsync) { | |
| 16905 ProxyConfig proxy_config; | |
| 16906 proxy_config.set_pac_url(GURL("http://fooproxyurl")); | |
| 16907 proxy_config.set_pac_mandatory(true); | |
| 16908 MockAsyncProxyResolverFactory* proxy_resolver_factory = | |
| 16909 new MockAsyncProxyResolverFactory(false); | |
| 16910 MockAsyncProxyResolver resolver; | |
| 16911 session_deps_.proxy_service.reset( | |
| 16912 new ProxyService(base::MakeUnique<ProxyConfigServiceFixed>(proxy_config), | |
| 16913 base::WrapUnique(proxy_resolver_factory), nullptr)); | |
| 16914 HttpRequestInfo request; | |
| 16915 request.method = "GET"; | |
| 16916 request.url = GURL("http://www.example.org/"); | |
| 16917 | |
| 16918 std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); | |
| 16919 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); | |
| 16920 | |
| 16921 TestCompletionCallback callback; | |
| 16922 int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); | |
| 16923 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | |
| 16924 | |
| 16925 proxy_resolver_factory->pending_requests()[0]->CompleteNowWithForwarder( | |
| 16926 ERR_FAILED, &resolver); | |
| 16927 EXPECT_THAT(callback.WaitForResult(), | |
| 16928 IsError(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED)); | |
| 16929 } | |
| 16930 | |
| 16931 TEST_F(HttpNetworkTransactionTest, NoSupportedProxies) { | |
| 16932 session_deps_.proxy_service = | |
| 16933 ProxyService::CreateFixedFromPacResult("QUIC myproxy.org:443"); | |
| 16934 session_deps_.enable_quic = false; | |
| 16935 std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); | |
| 16936 | |
| 16937 HttpRequestInfo request; | |
| 16938 request.method = "GET"; | |
| 16939 request.url = GURL("http://www.example.org/"); | |
| 16940 | |
| 16941 TestCompletionCallback callback; | |
| 16942 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); | |
| 16943 int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); | |
| 16944 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | |
| 16945 | |
| 16946 EXPECT_THAT(callback.WaitForResult(), IsError(ERR_NO_SUPPORTED_PROXIES)); | |
| 16947 } | |
| 16948 | |
| 16949 } // namespace net | 16864 } // namespace net |
| OLD | NEW |