Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(472)

Side by Side Diff: net/http/http_network_transaction_unittest.cc

Issue 2910463004: Revert "Revert CLs landed in HttpStreamFactoryImpl to track down a crasher" (Closed)
Patch Set: Fix Preconnect AltSvc Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 #include "net/log/net_log.h" 64 #include "net/log/net_log.h"
65 #include "net/log/net_log_event_type.h" 65 #include "net/log/net_log_event_type.h"
66 #include "net/log/net_log_source.h" 66 #include "net/log/net_log_source.h"
67 #include "net/log/test_net_log.h" 67 #include "net/log/test_net_log.h"
68 #include "net/log/test_net_log_entry.h" 68 #include "net/log/test_net_log_entry.h"
69 #include "net/log/test_net_log_util.h" 69 #include "net/log/test_net_log_util.h"
70 #include "net/proxy/mock_proxy_resolver.h" 70 #include "net/proxy/mock_proxy_resolver.h"
71 #include "net/proxy/proxy_config_service_fixed.h" 71 #include "net/proxy/proxy_config_service_fixed.h"
72 #include "net/proxy/proxy_info.h" 72 #include "net/proxy/proxy_info.h"
73 #include "net/proxy/proxy_resolver.h" 73 #include "net/proxy/proxy_resolver.h"
74 #include "net/proxy/proxy_resolver_factory.h"
74 #include "net/proxy/proxy_server.h" 75 #include "net/proxy/proxy_server.h"
75 #include "net/proxy/proxy_service.h" 76 #include "net/proxy/proxy_service.h"
76 #include "net/socket/client_socket_factory.h" 77 #include "net/socket/client_socket_factory.h"
77 #include "net/socket/client_socket_pool.h" 78 #include "net/socket/client_socket_pool.h"
78 #include "net/socket/client_socket_pool_manager.h" 79 #include "net/socket/client_socket_pool_manager.h"
79 #include "net/socket/connection_attempts.h" 80 #include "net/socket/connection_attempts.h"
80 #include "net/socket/mock_client_socket_pool_manager.h" 81 #include "net/socket/mock_client_socket_pool_manager.h"
81 #include "net/socket/next_proto.h" 82 #include "net/socket/next_proto.h"
82 #include "net/socket/socket_test_util.h" 83 #include "net/socket/socket_test_util.h"
83 #include "net/socket/ssl_client_socket.h" 84 #include "net/socket/ssl_client_socket.h"
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after
369 370
370 auto owned_throttler = base::MakeUnique<TestNetworkStreamThrottler>(); 371 auto owned_throttler = base::MakeUnique<TestNetworkStreamThrottler>();
371 *throttler = owned_throttler.get(); 372 *throttler = owned_throttler.get();
372 373
373 HttpNetworkSessionPeer peer(session.get()); 374 HttpNetworkSessionPeer peer(session.get());
374 peer.SetNetworkStreamThrottler(std::move(owned_throttler)); 375 peer.SetNetworkStreamThrottler(std::move(owned_throttler));
375 376
376 return session; 377 return session;
377 } 378 }
378 379
380 class FailingProxyResolverFactory : public ProxyResolverFactory {
381 public:
382 FailingProxyResolverFactory() : ProxyResolverFactory(false) {}
383
384 // ProxyResolverFactory override.
385 int CreateProxyResolver(
386 const scoped_refptr<ProxyResolverScriptData>& script_data,
387 std::unique_ptr<ProxyResolver>* result,
388 const CompletionCallback& callback,
389 std::unique_ptr<Request>* request) override {
390 return ERR_PAC_SCRIPT_FAILED;
391 }
392 };
393
379 } // namespace 394 } // namespace
380 395
381 class HttpNetworkTransactionTest : public PlatformTest { 396 class HttpNetworkTransactionTest : public PlatformTest {
382 public: 397 public:
383 ~HttpNetworkTransactionTest() override { 398 ~HttpNetworkTransactionTest() override {
384 // Important to restore the per-pool limit first, since the pool limit must 399 // Important to restore the per-pool limit first, since the pool limit must
385 // always be greater than group limit, and the tests reduce both limits. 400 // always be greater than group limit, and the tests reduce both limits.
386 ClientSocketPoolManager::set_max_sockets_per_pool( 401 ClientSocketPoolManager::set_max_sockets_per_pool(
387 HttpNetworkSession::NORMAL_SOCKET_POOL, old_max_pool_sockets_); 402 HttpNetworkSession::NORMAL_SOCKET_POOL, old_max_pool_sockets_);
388 ClientSocketPoolManager::set_max_sockets_per_group( 403 ClientSocketPoolManager::set_max_sockets_per_group(
(...skipping 14787 matching lines...) Expand 10 before | Expand all | Expand 10 after
15176 public: 15191 public:
15177 FakeStreamFactory() {} 15192 FakeStreamFactory() {}
15178 ~FakeStreamFactory() override {} 15193 ~FakeStreamFactory() override {}
15179 15194
15180 // Returns a WeakPtr<> to the last HttpStreamRequest returned by 15195 // Returns a WeakPtr<> to the last HttpStreamRequest returned by
15181 // RequestStream() (which may be NULL if it was destroyed already). 15196 // RequestStream() (which may be NULL if it was destroyed already).
15182 base::WeakPtr<FakeStreamRequest> last_stream_request() { 15197 base::WeakPtr<FakeStreamRequest> last_stream_request() {
15183 return last_stream_request_; 15198 return last_stream_request_;
15184 } 15199 }
15185 15200
15186 HttpStreamRequest* RequestStream(const HttpRequestInfo& info, 15201 std::unique_ptr<HttpStreamRequest> RequestStream(
15187 RequestPriority priority,
15188 const SSLConfig& server_ssl_config,
15189 const SSLConfig& proxy_ssl_config,
15190 HttpStreamRequest::Delegate* delegate,
15191 bool enable_ip_based_pooling,
15192 bool enable_alternative_services,
15193 const NetLogWithSource& net_log) override {
15194 FakeStreamRequest* fake_request = new FakeStreamRequest(priority, delegate);
15195 last_stream_request_ = fake_request->AsWeakPtr();
15196 return fake_request;
15197 }
15198
15199 HttpStreamRequest* RequestBidirectionalStreamImpl(
15200 const HttpRequestInfo& info, 15202 const HttpRequestInfo& info,
15201 RequestPriority priority, 15203 RequestPriority priority,
15202 const SSLConfig& server_ssl_config, 15204 const SSLConfig& server_ssl_config,
15205 const SSLConfig& proxy_ssl_config,
15206 HttpStreamRequest::Delegate* delegate,
15207 bool enable_ip_based_pooling,
15208 bool enable_alternative_services,
15209 const NetLogWithSource& net_log) override {
15210 auto fake_request = base::MakeUnique<FakeStreamRequest>(priority, delegate);
15211 last_stream_request_ = fake_request->AsWeakPtr();
15212 return std::move(fake_request);
15213 }
15214
15215 std::unique_ptr<HttpStreamRequest> RequestBidirectionalStreamImpl(
15216 const HttpRequestInfo& info,
15217 RequestPriority priority,
15218 const SSLConfig& server_ssl_config,
15203 const SSLConfig& proxy_ssl_config, 15219 const SSLConfig& proxy_ssl_config,
15204 HttpStreamRequest::Delegate* delegate, 15220 HttpStreamRequest::Delegate* delegate,
15205 bool enable_ip_based_pooling, 15221 bool enable_ip_based_pooling,
15206 bool enable_alternative_services, 15222 bool enable_alternative_services,
15207 const NetLogWithSource& net_log) override { 15223 const NetLogWithSource& net_log) override {
15208 NOTREACHED(); 15224 NOTREACHED();
15209 return nullptr; 15225 return nullptr;
15210 } 15226 }
15211 15227
15212 HttpStreamRequest* RequestWebSocketHandshakeStream( 15228 std::unique_ptr<HttpStreamRequest> RequestWebSocketHandshakeStream(
15213 const HttpRequestInfo& info, 15229 const HttpRequestInfo& info,
15214 RequestPriority priority, 15230 RequestPriority priority,
15215 const SSLConfig& server_ssl_config, 15231 const SSLConfig& server_ssl_config,
15216 const SSLConfig& proxy_ssl_config, 15232 const SSLConfig& proxy_ssl_config,
15217 HttpStreamRequest::Delegate* delegate, 15233 HttpStreamRequest::Delegate* delegate,
15218 WebSocketHandshakeStreamBase::CreateHelper* create_helper, 15234 WebSocketHandshakeStreamBase::CreateHelper* create_helper,
15219 bool enable_ip_based_pooling, 15235 bool enable_ip_based_pooling,
15220 bool enable_alternative_services, 15236 bool enable_alternative_services,
15221 const NetLogWithSource& net_log) override { 15237 const NetLogWithSource& net_log) override {
15222 FakeStreamRequest* fake_request = 15238 auto fake_request =
15223 new FakeStreamRequest(priority, delegate, create_helper); 15239 base::MakeUnique<FakeStreamRequest>(priority, delegate, create_helper);
15224 last_stream_request_ = fake_request->AsWeakPtr(); 15240 last_stream_request_ = fake_request->AsWeakPtr();
15225 return fake_request; 15241 return std::move(fake_request);
15226 } 15242 }
15227 15243
15228 void PreconnectStreams(int num_streams, 15244 void PreconnectStreams(int num_streams,
15229 const HttpRequestInfo& info) override { 15245 const HttpRequestInfo& info) override {
15230 ADD_FAILURE(); 15246 ADD_FAILURE();
15231 } 15247 }
15232 15248
15233 const HostMappingRules* GetHostMappingRules() const override { 15249 const HostMappingRules* GetHostMappingRules() const override {
15234 ADD_FAILURE(); 15250 ADD_FAILURE();
15235 return NULL; 15251 return NULL;
(...skipping 1590 matching lines...) Expand 10 before | Expand all | Expand 10 after
16826 TEST_F(HttpNetworkTransactionTest, MatchContentEncoding3) { 16842 TEST_F(HttpNetworkTransactionTest, MatchContentEncoding3) {
16827 CheckContentEncodingMatching(&session_deps_, "identity;q=1, *;q=0", "gzip", 16843 CheckContentEncodingMatching(&session_deps_, "identity;q=1, *;q=0", "gzip",
16828 "", false); 16844 "", false);
16829 } 16845 }
16830 16846
16831 TEST_F(HttpNetworkTransactionTest, MatchContentEncoding4) { 16847 TEST_F(HttpNetworkTransactionTest, MatchContentEncoding4) {
16832 CheckContentEncodingMatching(&session_deps_, "identity;q=1, *;q=0", "gzip", 16848 CheckContentEncodingMatching(&session_deps_, "identity;q=1, *;q=0", "gzip",
16833 "www.foo.com/other", true); 16849 "www.foo.com/other", true);
16834 } 16850 }
16835 16851
16852 TEST_F(HttpNetworkTransactionTest, ProxyResolutionFailsSync) {
16853 ProxyConfig proxy_config;
16854 proxy_config.set_pac_url(GURL("http://fooproxyurl"));
16855 proxy_config.set_pac_mandatory(true);
16856 MockAsyncProxyResolver resolver;
16857 session_deps_.proxy_service.reset(new ProxyService(
16858 base::MakeUnique<ProxyConfigServiceFixed>(proxy_config),
16859 base::WrapUnique(new FailingProxyResolverFactory), nullptr));
16860
16861 HttpRequestInfo request;
16862 request.method = "GET";
16863 request.url = GURL("http://www.example.org/");
16864
16865 std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_));
16866 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get());
16867
16868 TestCompletionCallback callback;
16869
16870 int rv = trans.Start(&request, callback.callback(), NetLogWithSource());
16871 EXPECT_THAT(rv, IsError(ERR_IO_PENDING));
16872 EXPECT_THAT(callback.WaitForResult(),
16873 IsError(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED));
16874 }
16875
16876 TEST_F(HttpNetworkTransactionTest, ProxyResolutionFailsAsync) {
16877 ProxyConfig proxy_config;
16878 proxy_config.set_pac_url(GURL("http://fooproxyurl"));
16879 proxy_config.set_pac_mandatory(true);
16880 MockAsyncProxyResolverFactory* proxy_resolver_factory =
16881 new MockAsyncProxyResolverFactory(false);
16882 MockAsyncProxyResolver resolver;
16883 session_deps_.proxy_service.reset(
16884 new ProxyService(base::MakeUnique<ProxyConfigServiceFixed>(proxy_config),
16885 base::WrapUnique(proxy_resolver_factory), nullptr));
16886 HttpRequestInfo request;
16887 request.method = "GET";
16888 request.url = GURL("http://www.example.org/");
16889
16890 std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_));
16891 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get());
16892
16893 TestCompletionCallback callback;
16894 int rv = trans.Start(&request, callback.callback(), NetLogWithSource());
16895 EXPECT_THAT(rv, IsError(ERR_IO_PENDING));
16896
16897 proxy_resolver_factory->pending_requests()[0]->CompleteNowWithForwarder(
16898 ERR_FAILED, &resolver);
16899 EXPECT_THAT(callback.WaitForResult(),
16900 IsError(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED));
16901 }
16902
16903 TEST_F(HttpNetworkTransactionTest, NoSupportedProxies) {
16904 session_deps_.proxy_service =
16905 ProxyService::CreateFixedFromPacResult("QUIC myproxy.org:443");
16906 session_deps_.enable_quic = false;
16907 std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_));
16908
16909 HttpRequestInfo request;
16910 request.method = "GET";
16911 request.url = GURL("http://www.example.org/");
16912
16913 TestCompletionCallback callback;
16914 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get());
16915 int rv = trans.Start(&request, callback.callback(), NetLogWithSource());
16916 EXPECT_THAT(rv, IsError(ERR_IO_PENDING));
16917
16918 EXPECT_THAT(callback.WaitForResult(), IsError(ERR_NO_SUPPORTED_PROXIES));
16919 }
16920
16836 } // namespace net 16921 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698