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

Side by Side Diff: net/url_request/url_request_unittest.cc

Issue 2334623003: Store net::ProxyServer in HttpResponseInfo object (Closed)
Patch Set: Rebased, fix compile error Created 4 years, 2 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 | « net/url_request/url_request_job.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <memory> 5 #include <memory>
6 #include <utility> 6 #include <utility>
7 7
8 #include "base/memory/ptr_util.h" 8 #include "base/memory/ptr_util.h"
9 #include "base/run_loop.h" 9 #include "base/run_loop.h"
10 #include "build/build_config.h" 10 #include "build/build_config.h"
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 #include "net/http/http_network_session.h" 76 #include "net/http/http_network_session.h"
77 #include "net/http/http_request_headers.h" 77 #include "net/http/http_request_headers.h"
78 #include "net/http/http_response_headers.h" 78 #include "net/http/http_response_headers.h"
79 #include "net/http/http_util.h" 79 #include "net/http/http_util.h"
80 #include "net/log/net_log_event_type.h" 80 #include "net/log/net_log_event_type.h"
81 #include "net/log/net_log_source.h" 81 #include "net/log/net_log_source.h"
82 #include "net/log/test_net_log.h" 82 #include "net/log/test_net_log.h"
83 #include "net/log/test_net_log_entry.h" 83 #include "net/log/test_net_log_entry.h"
84 #include "net/log/test_net_log_util.h" 84 #include "net/log/test_net_log_util.h"
85 #include "net/nqe/external_estimate_provider.h" 85 #include "net/nqe/external_estimate_provider.h"
86 #include "net/proxy/proxy_server.h"
86 #include "net/proxy/proxy_service.h" 87 #include "net/proxy/proxy_service.h"
87 #include "net/socket/ssl_client_socket.h" 88 #include "net/socket/ssl_client_socket.h"
88 #include "net/ssl/channel_id_service.h" 89 #include "net/ssl/channel_id_service.h"
89 #include "net/ssl/default_channel_id_store.h" 90 #include "net/ssl/default_channel_id_store.h"
90 #include "net/ssl/ssl_connection_status_flags.h" 91 #include "net/ssl/ssl_connection_status_flags.h"
91 #include "net/ssl/ssl_server_config.h" 92 #include "net/ssl/ssl_server_config.h"
92 #include "net/ssl/token_binding.h" 93 #include "net/ssl/token_binding.h"
93 #include "net/test/cert_test_util.h" 94 #include "net/test/cert_test_util.h"
94 #include "net/test/embedded_test_server/embedded_test_server.h" 95 #include "net/test/embedded_test_server/embedded_test_server.h"
95 #include "net/test/embedded_test_server/http_request.h" 96 #include "net/test/embedded_test_server/http_request.h"
(...skipping 2057 matching lines...) Expand 10 before | Expand all | Expand 10 after
2153 TestDelegate d; 2154 TestDelegate d;
2154 std::unique_ptr<URLRequest> req( 2155 std::unique_ptr<URLRequest> req(
2155 context.CreateRequest(GURL("http://example.com"), DEFAULT_PRIORITY, &d)); 2156 context.CreateRequest(GURL("http://example.com"), DEFAULT_PRIORITY, &d));
2156 req->set_method("GET"); 2157 req->set_method("GET");
2157 2158
2158 req->Start(); 2159 req->Start();
2159 base::RunLoop().Run(); 2160 base::RunLoop().Run();
2160 2161
2161 // Check we see a failed request. 2162 // Check we see a failed request.
2162 // The proxy server is not set before failure. 2163 // The proxy server is not set before failure.
2163 EXPECT_TRUE(req->proxy_server().IsEmpty()); 2164 EXPECT_FALSE(req->proxy_server().is_valid());
2164 EXPECT_EQ(ERR_PROXY_CONNECTION_FAILED, d.request_status()); 2165 EXPECT_EQ(ERR_PROXY_CONNECTION_FAILED, d.request_status());
2165 2166
2166 EXPECT_EQ(1, network_delegate.error_count()); 2167 EXPECT_EQ(1, network_delegate.error_count());
2167 EXPECT_THAT(network_delegate.last_error(), 2168 EXPECT_THAT(network_delegate.last_error(),
2168 IsError(ERR_PROXY_CONNECTION_FAILED)); 2169 IsError(ERR_PROXY_CONNECTION_FAILED));
2169 EXPECT_EQ(1, network_delegate.completed_requests()); 2170 EXPECT_EQ(1, network_delegate.completed_requests());
2170 } 2171 }
2171 2172
2172 // Make sure that NetworkDelegate::NotifyCompleted is called if 2173 // Make sure that NetworkDelegate::NotifyCompleted is called if
2173 // content is empty. 2174 // content is empty.
(...skipping 1423 matching lines...) Expand 10 before | Expand all | Expand 10 after
3597 TestDelegate d; 3598 TestDelegate d;
3598 { 3599 {
3599 std::unique_ptr<URLRequest> r(context.CreateRequest( 3600 std::unique_ptr<URLRequest> r(context.CreateRequest(
3600 GURL("https://www.redirect.com/"), DEFAULT_PRIORITY, &d)); 3601 GURL("https://www.redirect.com/"), DEFAULT_PRIORITY, &d));
3601 r->Start(); 3602 r->Start();
3602 EXPECT_TRUE(r->is_pending()); 3603 EXPECT_TRUE(r->is_pending());
3603 3604
3604 base::RunLoop().Run(); 3605 base::RunLoop().Run();
3605 3606
3606 // The proxy server is not set before failure. 3607 // The proxy server is not set before failure.
3607 EXPECT_TRUE(r->proxy_server().IsEmpty()); 3608 EXPECT_FALSE(r->proxy_server().is_valid());
3608 EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, d.request_status()); 3609 EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, d.request_status());
3609 EXPECT_EQ(1, d.response_started_count()); 3610 EXPECT_EQ(1, d.response_started_count());
3610 // We should not have followed the redirect. 3611 // We should not have followed the redirect.
3611 EXPECT_EQ(0, d.received_redirect_count()); 3612 EXPECT_EQ(0, d.received_redirect_count());
3612 } 3613 }
3613 } 3614 }
3614 3615
3615 // This is the same as the previous test, but checks that the network delegate 3616 // This is the same as the previous test, but checks that the network delegate
3616 // registers the error. 3617 // registers the error.
3617 TEST_F(URLRequestTestHTTP, NetworkDelegateTunnelConnectionFailed) { 3618 TEST_F(URLRequestTestHTTP, NetworkDelegateTunnelConnectionFailed) {
3618 ASSERT_TRUE(http_test_server()->Start()); 3619 ASSERT_TRUE(http_test_server()->Start());
3619 3620
3620 TestNetworkDelegate network_delegate; // Must outlive URLRequest. 3621 TestNetworkDelegate network_delegate; // Must outlive URLRequest.
3621 TestURLRequestContextWithProxy context( 3622 TestURLRequestContextWithProxy context(
3622 http_test_server()->host_port_pair().ToString(), &network_delegate); 3623 http_test_server()->host_port_pair().ToString(), &network_delegate);
3623 3624
3624 TestDelegate d; 3625 TestDelegate d;
3625 { 3626 {
3626 std::unique_ptr<URLRequest> r(context.CreateRequest( 3627 std::unique_ptr<URLRequest> r(context.CreateRequest(
3627 GURL("https://www.redirect.com/"), DEFAULT_PRIORITY, &d)); 3628 GURL("https://www.redirect.com/"), DEFAULT_PRIORITY, &d));
3628 r->Start(); 3629 r->Start();
3629 EXPECT_TRUE(r->is_pending()); 3630 EXPECT_TRUE(r->is_pending());
3630 3631
3631 base::RunLoop().Run(); 3632 base::RunLoop().Run();
3632 3633
3633 // The proxy server is not set before failure. 3634 // The proxy server is not set before failure.
3634 EXPECT_TRUE(r->proxy_server().IsEmpty()); 3635 EXPECT_FALSE(r->proxy_server().is_valid());
3635 EXPECT_EQ(1, d.response_started_count()); 3636 EXPECT_EQ(1, d.response_started_count());
3636 EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, d.request_status()); 3637 EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, d.request_status());
3637 // We should not have followed the redirect. 3638 // We should not have followed the redirect.
3638 EXPECT_EQ(0, d.received_redirect_count()); 3639 EXPECT_EQ(0, d.received_redirect_count());
3639 3640
3640 EXPECT_EQ(1, network_delegate.error_count()); 3641 EXPECT_EQ(1, network_delegate.error_count());
3641 EXPECT_THAT(network_delegate.last_error(), 3642 EXPECT_THAT(network_delegate.last_error(),
3642 IsError(ERR_TUNNEL_CONNECTION_FAILED)); 3643 IsError(ERR_TUNNEL_CONNECTION_FAILED));
3643 } 3644 }
3644 } 3645 }
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
3700 http_test_server()->host_port_pair().ToString(), &network_delegate); 3701 http_test_server()->host_port_pair().ToString(), &network_delegate);
3701 3702
3702 { 3703 {
3703 std::unique_ptr<URLRequest> r(context.CreateRequest( 3704 std::unique_ptr<URLRequest> r(context.CreateRequest(
3704 http_test_server()->GetURL("/"), DEFAULT_PRIORITY, &d)); 3705 http_test_server()->GetURL("/"), DEFAULT_PRIORITY, &d));
3705 3706
3706 r->Start(); 3707 r->Start();
3707 base::RunLoop().Run(); 3708 base::RunLoop().Run();
3708 3709
3709 // The proxy server is not set before cancellation. 3710 // The proxy server is not set before cancellation.
3710 EXPECT_TRUE(r->proxy_server().IsEmpty()); 3711 EXPECT_FALSE(r->proxy_server().is_valid());
3711 EXPECT_EQ(ERR_EMPTY_RESPONSE, d.request_status()); 3712 EXPECT_EQ(ERR_EMPTY_RESPONSE, d.request_status());
3712 EXPECT_EQ(1, network_delegate.created_requests()); 3713 EXPECT_EQ(1, network_delegate.created_requests());
3713 EXPECT_EQ(0, network_delegate.destroyed_requests()); 3714 EXPECT_EQ(0, network_delegate.destroyed_requests());
3714 } 3715 }
3715 EXPECT_EQ(1, network_delegate.destroyed_requests()); 3716 EXPECT_EQ(1, network_delegate.destroyed_requests());
3716 } 3717 }
3717 3718
3718 // Helper function for NetworkDelegateCancelRequestAsynchronously and 3719 // Helper function for NetworkDelegateCancelRequestAsynchronously and
3719 // NetworkDelegateCancelRequestSynchronously. Sets up a blocking network 3720 // NetworkDelegateCancelRequestSynchronously. Sets up a blocking network
3720 // delegate operating in |block_mode| and a request for |url|. It blocks the 3721 // delegate operating in |block_mode| and a request for |url|. It blocks the
(...skipping 11 matching lines...) Expand all
3732 context.Init(); 3733 context.Init();
3733 3734
3734 { 3735 {
3735 std::unique_ptr<URLRequest> r( 3736 std::unique_ptr<URLRequest> r(
3736 context.CreateRequest(url, DEFAULT_PRIORITY, &d)); 3737 context.CreateRequest(url, DEFAULT_PRIORITY, &d));
3737 3738
3738 r->Start(); 3739 r->Start();
3739 base::RunLoop().Run(); 3740 base::RunLoop().Run();
3740 3741
3741 // The proxy server is not set before cancellation. 3742 // The proxy server is not set before cancellation.
3742 EXPECT_TRUE(r->proxy_server().IsEmpty()); 3743 if (stage == BlockingNetworkDelegate::ON_BEFORE_URL_REQUEST ||
3744 stage == BlockingNetworkDelegate::ON_BEFORE_SEND_HEADERS) {
3745 EXPECT_FALSE(r->proxy_server().is_valid());
3746 } else if (stage == BlockingNetworkDelegate::ON_HEADERS_RECEIVED) {
3747 EXPECT_TRUE(r->proxy_server().is_direct());
3748 } else {
3749 NOTREACHED();
3750 }
3743 EXPECT_EQ(ERR_BLOCKED_BY_CLIENT, d.request_status()); 3751 EXPECT_EQ(ERR_BLOCKED_BY_CLIENT, d.request_status());
3744 EXPECT_EQ(1, network_delegate.created_requests()); 3752 EXPECT_EQ(1, network_delegate.created_requests());
3745 EXPECT_EQ(0, network_delegate.destroyed_requests()); 3753 EXPECT_EQ(0, network_delegate.destroyed_requests());
3746 } 3754 }
3747 EXPECT_EQ(1, network_delegate.destroyed_requests()); 3755 EXPECT_EQ(1, network_delegate.destroyed_requests());
3748 } 3756 }
3749 3757
3750 // The following 3 tests check that the network delegate can cancel a request 3758 // The following 3 tests check that the network delegate can cancel a request
3751 // synchronously in various stages of the request. 3759 // synchronously in various stages of the request.
3752 TEST_F(URLRequestTestHTTP, NetworkDelegateCancelRequestSynchronously1) { 3760 TEST_F(URLRequestTestHTTP, NetworkDelegateCancelRequestSynchronously1) {
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
3823 EXPECT_EQ(307, r->response_headers()->response_code()); 3831 EXPECT_EQ(307, r->response_headers()->response_code());
3824 std::string location; 3832 std::string location;
3825 ASSERT_TRUE(r->response_headers()->EnumerateHeader(NULL, "Location", 3833 ASSERT_TRUE(r->response_headers()->EnumerateHeader(NULL, "Location",
3826 &location)); 3834 &location));
3827 EXPECT_EQ(redirect_url, GURL(location)); 3835 EXPECT_EQ(redirect_url, GURL(location));
3828 3836
3829 // Let the request finish. 3837 // Let the request finish.
3830 r->FollowDeferredRedirect(); 3838 r->FollowDeferredRedirect();
3831 base::RunLoop().Run(); 3839 base::RunLoop().Run();
3832 EXPECT_EQ(OK, d.request_status()); 3840 EXPECT_EQ(OK, d.request_status());
3833 EXPECT_TRUE(r->proxy_server().Equals(http_test_server()->host_port_pair())); 3841 EXPECT_EQ(ProxyServer(ProxyServer::SCHEME_HTTP,
3842 http_test_server()->host_port_pair()),
3843 r->proxy_server());
3834 // before_send_headers_with_proxy_count only increments for headers sent 3844 // before_send_headers_with_proxy_count only increments for headers sent
3835 // through an untunneled proxy. 3845 // through an untunneled proxy.
3836 EXPECT_EQ(1, network_delegate.before_send_headers_with_proxy_count()); 3846 EXPECT_EQ(1, network_delegate.before_send_headers_with_proxy_count());
3837 EXPECT_TRUE(network_delegate.last_observed_proxy().Equals( 3847 EXPECT_TRUE(network_delegate.last_observed_proxy().Equals(
3838 http_test_server()->host_port_pair())); 3848 http_test_server()->host_port_pair()));
3839 3849
3840 EXPECT_EQ(OK, d.request_status()); 3850 EXPECT_EQ(OK, d.request_status());
3841 EXPECT_EQ(redirect_url, r->url()); 3851 EXPECT_EQ(redirect_url, r->url());
3842 EXPECT_EQ(original_url, r->original_url()); 3852 EXPECT_EQ(original_url, r->original_url());
3843 EXPECT_EQ(2U, r->url_chain().size()); 3853 EXPECT_EQ(2U, r->url_chain().size());
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
3877 std::string location; 3887 std::string location;
3878 ASSERT_TRUE(r->response_headers()->EnumerateHeader(NULL, "Location", 3888 ASSERT_TRUE(r->response_headers()->EnumerateHeader(NULL, "Location",
3879 &location)); 3889 &location));
3880 EXPECT_EQ(redirect_url, GURL(location)); 3890 EXPECT_EQ(redirect_url, GURL(location));
3881 3891
3882 // Let the request finish. 3892 // Let the request finish.
3883 r->FollowDeferredRedirect(); 3893 r->FollowDeferredRedirect();
3884 base::RunLoop().Run(); 3894 base::RunLoop().Run();
3885 3895
3886 EXPECT_EQ(OK, d.request_status()); 3896 EXPECT_EQ(OK, d.request_status());
3887 EXPECT_TRUE(r->proxy_server().Equals(http_test_server()->host_port_pair())); 3897 EXPECT_EQ(ProxyServer(ProxyServer::SCHEME_HTTP,
3898 http_test_server()->host_port_pair()),
3899 r->proxy_server());
3888 // before_send_headers_with_proxy_count only increments for headers sent 3900 // before_send_headers_with_proxy_count only increments for headers sent
3889 // through an untunneled proxy. 3901 // through an untunneled proxy.
3890 EXPECT_EQ(1, network_delegate.before_send_headers_with_proxy_count()); 3902 EXPECT_EQ(1, network_delegate.before_send_headers_with_proxy_count());
3891 EXPECT_TRUE(network_delegate.last_observed_proxy().Equals( 3903 EXPECT_TRUE(network_delegate.last_observed_proxy().Equals(
3892 http_test_server()->host_port_pair())); 3904 http_test_server()->host_port_pair()));
3893 EXPECT_EQ(OK, d.request_status()); 3905 EXPECT_EQ(OK, d.request_status());
3894 EXPECT_EQ(redirect_url, r->url()); 3906 EXPECT_EQ(redirect_url, r->url());
3895 EXPECT_EQ(original_url, r->original_url()); 3907 EXPECT_EQ(original_url, r->original_url());
3896 EXPECT_EQ(2U, r->url_chain().size()); 3908 EXPECT_EQ(2U, r->url_chain().size());
3897 EXPECT_EQ(1, network_delegate.created_requests()); 3909 EXPECT_EQ(1, network_delegate.created_requests());
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
3974 3986
3975 { 3987 {
3976 GURL original_url(http_test_server()->GetURL("/defaultresponse")); 3988 GURL original_url(http_test_server()->GetURL("/defaultresponse"));
3977 std::unique_ptr<URLRequest> r( 3989 std::unique_ptr<URLRequest> r(
3978 context.CreateRequest(original_url, DEFAULT_PRIORITY, &d)); 3990 context.CreateRequest(original_url, DEFAULT_PRIORITY, &d));
3979 3991
3980 r->Start(); 3992 r->Start();
3981 base::RunLoop().Run(); 3993 base::RunLoop().Run();
3982 3994
3983 EXPECT_EQ(OK, d.request_status()); 3995 EXPECT_EQ(OK, d.request_status());
3984 EXPECT_TRUE(r->proxy_server().Equals(http_test_server()->host_port_pair())); 3996 EXPECT_EQ(ProxyServer(ProxyServer::SCHEME_HTTP,
3997 http_test_server()->host_port_pair()),
3998 r->proxy_server());
3985 // before_send_headers_with_proxy_count only increments for headers sent 3999 // before_send_headers_with_proxy_count only increments for headers sent
3986 // through an untunneled proxy. 4000 // through an untunneled proxy.
3987 EXPECT_EQ(2, network_delegate.before_send_headers_with_proxy_count()); 4001 EXPECT_EQ(2, network_delegate.before_send_headers_with_proxy_count());
3988 EXPECT_TRUE(network_delegate.last_observed_proxy().Equals( 4002 EXPECT_TRUE(network_delegate.last_observed_proxy().Equals(
3989 http_test_server()->host_port_pair())); 4003 http_test_server()->host_port_pair()));
3990 4004
3991 EXPECT_EQ(OK, d.request_status()); 4005 EXPECT_EQ(OK, d.request_status());
3992 EXPECT_EQ(redirect_url, r->url()); 4006 EXPECT_EQ(redirect_url, r->url());
3993 EXPECT_EQ(original_url, r->original_url()); 4007 EXPECT_EQ(original_url, r->original_url());
3994 EXPECT_EQ(2U, r->url_chain().size()); 4008 EXPECT_EQ(2U, r->url_chain().size());
(...skipping 460 matching lines...) Expand 10 before | Expand all | Expand 10 after
4455 { 4469 {
4456 std::unique_ptr<URLRequest> r(context.CreateRequest( 4470 std::unique_ptr<URLRequest> r(context.CreateRequest(
4457 GURL("https://www.server-auth.com/"), DEFAULT_PRIORITY, &d)); 4471 GURL("https://www.server-auth.com/"), DEFAULT_PRIORITY, &d));
4458 4472
4459 r->Start(); 4473 r->Start();
4460 EXPECT_TRUE(r->is_pending()); 4474 EXPECT_TRUE(r->is_pending());
4461 4475
4462 base::RunLoop().Run(); 4476 base::RunLoop().Run();
4463 4477
4464 // The proxy server is not set before failure. 4478 // The proxy server is not set before failure.
4465 EXPECT_TRUE(r->proxy_server().IsEmpty()); 4479 EXPECT_FALSE(r->proxy_server().is_valid());
4466 EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, d.request_status()); 4480 EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, d.request_status());
4467 } 4481 }
4468 } 4482 }
4469 4483
4470 TEST_F(URLRequestTestHTTP, GetTest_NoCache) { 4484 TEST_F(URLRequestTestHTTP, GetTest_NoCache) {
4471 ASSERT_TRUE(http_test_server()->Start()); 4485 ASSERT_TRUE(http_test_server()->Start());
4472 4486
4473 TestDelegate d; 4487 TestDelegate d;
4474 { 4488 {
4475 std::unique_ptr<URLRequest> r(default_context_.CreateRequest( 4489 std::unique_ptr<URLRequest> r(default_context_.CreateRequest(
(...skipping 5736 matching lines...) Expand 10 before | Expand all | Expand 10 after
10212 AddTestInterceptor()->set_main_intercept_job(std::move(job)); 10226 AddTestInterceptor()->set_main_intercept_job(std::move(job));
10213 10227
10214 req->Start(); 10228 req->Start();
10215 req->Cancel(); 10229 req->Cancel();
10216 base::RunLoop().RunUntilIdle(); 10230 base::RunLoop().RunUntilIdle();
10217 EXPECT_EQ(ERR_ABORTED, d.request_status()); 10231 EXPECT_EQ(ERR_ABORTED, d.request_status());
10218 EXPECT_EQ(0, d.received_redirect_count()); 10232 EXPECT_EQ(0, d.received_redirect_count());
10219 } 10233 }
10220 10234
10221 } // namespace net 10235 } // namespace net
OLDNEW
« no previous file with comments | « net/url_request/url_request_job.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698