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

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

Issue 2814633003: Extract Proxy Resolution out of HttpStreamFactoryImpl::Job (Closed)
Patch Set: rebased Created 3 years, 7 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
« no previous file with comments | « no previous file | net/http/http_stream_factory_impl.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
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"
75 #include "net/proxy/proxy_server.h" 76 #include "net/proxy/proxy_server.h"
76 #include "net/proxy/proxy_service.h" 77 #include "net/proxy/proxy_service.h"
77 #include "net/socket/client_socket_factory.h" 78 #include "net/socket/client_socket_factory.h"
78 #include "net/socket/client_socket_pool.h" 79 #include "net/socket/client_socket_pool.h"
79 #include "net/socket/client_socket_pool_manager.h" 80 #include "net/socket/client_socket_pool_manager.h"
80 #include "net/socket/connection_attempts.h" 81 #include "net/socket/connection_attempts.h"
81 #include "net/socket/mock_client_socket_pool_manager.h" 82 #include "net/socket/mock_client_socket_pool_manager.h"
82 #include "net/socket/next_proto.h" 83 #include "net/socket/next_proto.h"
83 #include "net/socket/socket_test_util.h" 84 #include "net/socket/socket_test_util.h"
84 #include "net/socket/ssl_client_socket.h" 85 #include "net/socket/ssl_client_socket.h"
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after
371 std::unique_ptr<TestNetworkStreamThrottler> owned_throttler( 372 std::unique_ptr<TestNetworkStreamThrottler> owned_throttler(
372 new TestNetworkStreamThrottler); 373 new TestNetworkStreamThrottler);
373 *throttler = owned_throttler.get(); 374 *throttler = owned_throttler.get();
374 375
375 HttpNetworkSessionPeer peer(session.get()); 376 HttpNetworkSessionPeer peer(session.get());
376 peer.SetNetworkStreamThrottler(std::move(owned_throttler)); 377 peer.SetNetworkStreamThrottler(std::move(owned_throttler));
377 378
378 return session; 379 return session;
379 } 380 }
380 381
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
381 } // namespace 396 } // namespace
382 397
383 class HttpNetworkTransactionTest : public PlatformTest { 398 class HttpNetworkTransactionTest : public PlatformTest {
384 public: 399 public:
385 ~HttpNetworkTransactionTest() override { 400 ~HttpNetworkTransactionTest() override {
386 // Important to restore the per-pool limit first, since the pool limit must 401 // Important to restore the per-pool limit first, since the pool limit must
387 // always be greater than group limit, and the tests reduce both limits. 402 // always be greater than group limit, and the tests reduce both limits.
388 ClientSocketPoolManager::set_max_sockets_per_pool( 403 ClientSocketPoolManager::set_max_sockets_per_pool(
389 HttpNetworkSession::NORMAL_SOCKET_POOL, old_max_pool_sockets_); 404 HttpNetworkSession::NORMAL_SOCKET_POOL, old_max_pool_sockets_);
390 ClientSocketPoolManager::set_max_sockets_per_group( 405 ClientSocketPoolManager::set_max_sockets_per_group(
(...skipping 16473 matching lines...) Expand 10 before | Expand all | Expand 10 after
16864 TEST_F(HttpNetworkTransactionTest, MatchContentEncoding3) { 16879 TEST_F(HttpNetworkTransactionTest, MatchContentEncoding3) {
16865 CheckContentEncodingMatching(&session_deps_, "identity;q=1, *;q=0", "gzip", 16880 CheckContentEncodingMatching(&session_deps_, "identity;q=1, *;q=0", "gzip",
16866 "", false); 16881 "", false);
16867 } 16882 }
16868 16883
16869 TEST_F(HttpNetworkTransactionTest, MatchContentEncoding4) { 16884 TEST_F(HttpNetworkTransactionTest, MatchContentEncoding4) {
16870 CheckContentEncodingMatching(&session_deps_, "identity;q=1, *;q=0", "gzip", 16885 CheckContentEncodingMatching(&session_deps_, "identity;q=1, *;q=0", "gzip",
16871 "www.foo.com/other", true); 16886 "www.foo.com/other", true);
16872 } 16887 }
16873 16888
16889 TEST_F(HttpNetworkTransactionTest, ProxyResolutionFailsSync) {
16890 ProxyConfig proxy_config;
16891 proxy_config.set_pac_url(GURL("http://fooproxyurl"));
16892 proxy_config.set_pac_mandatory(true);
16893 MockAsyncProxyResolver resolver;
16894 session_deps_.proxy_service.reset(new ProxyService(
16895 base::MakeUnique<ProxyConfigServiceFixed>(proxy_config),
16896 base::WrapUnique(new FailingProxyResolverFactory), nullptr));
16897
16898 HttpRequestInfo request;
16899 request.method = "GET";
16900 request.url = GURL("http://www.example.org/");
16901
16902 std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_));
16903 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get());
16904
16905 TestCompletionCallback callback;
16906
16907 int rv = trans.Start(&request, callback.callback(), NetLogWithSource());
16908 EXPECT_THAT(rv, IsError(ERR_IO_PENDING));
16909 EXPECT_THAT(callback.WaitForResult(),
16910 IsError(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED));
16911 }
16912
16913 TEST_F(HttpNetworkTransactionTest, ProxyResolutionFailsAsync) {
16914 ProxyConfig proxy_config;
16915 proxy_config.set_pac_url(GURL("http://fooproxyurl"));
16916 proxy_config.set_pac_mandatory(true);
16917 MockAsyncProxyResolverFactory* proxy_resolver_factory =
16918 new MockAsyncProxyResolverFactory(false);
16919 MockAsyncProxyResolver resolver;
16920 session_deps_.proxy_service.reset(
16921 new ProxyService(base::MakeUnique<ProxyConfigServiceFixed>(proxy_config),
16922 base::WrapUnique(proxy_resolver_factory), nullptr));
16923 HttpRequestInfo request;
16924 request.method = "GET";
16925 request.url = GURL("http://www.example.org/");
16926
16927 std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_));
16928 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get());
16929
16930 TestCompletionCallback callback;
16931 int rv = trans.Start(&request, callback.callback(), NetLogWithSource());
16932 EXPECT_THAT(rv, IsError(ERR_IO_PENDING));
16933
16934 proxy_resolver_factory->pending_requests()[0]->CompleteNowWithForwarder(
16935 ERR_FAILED, &resolver);
16936 EXPECT_THAT(callback.WaitForResult(),
16937 IsError(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED));
16938 }
16939
16940 TEST_F(HttpNetworkTransactionTest, NoSupportedProxies) {
16941 session_deps_.proxy_service =
16942 ProxyService::CreateFixedFromPacResult("QUIC myproxy.org:443");
16943 session_deps_.enable_quic = false;
16944 std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_));
16945
16946 HttpRequestInfo request;
16947 request.method = "GET";
16948 request.url = GURL("http://www.example.org/");
16949
16950 TestCompletionCallback callback;
16951 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get());
16952 int rv = trans.Start(&request, callback.callback(), NetLogWithSource());
16953 EXPECT_THAT(rv, IsError(ERR_IO_PENDING));
16954
16955 EXPECT_THAT(callback.WaitForResult(), IsError(ERR_NO_SUPPORTED_PROXIES));
16956 }
16957
16874 } // namespace net 16958 } // namespace net
OLDNEW
« no previous file with comments | « no previous file | net/http/http_stream_factory_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698