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

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

Issue 2334623003: Store net::ProxyServer in HttpResponseInfo object (Closed)
Patch Set: PS Created 4 years, 3 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 (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.h" 80 #include "net/log/net_log.h"
81 #include "net/log/net_log_event_type.h" 81 #include "net/log/net_log_event_type.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 2055 matching lines...) Expand 10 before | Expand all | Expand 10 after
2151 std::unique_ptr<URLRequest> req( 2152 std::unique_ptr<URLRequest> req(
2152 context.CreateRequest(GURL("http://example.com"), DEFAULT_PRIORITY, &d)); 2153 context.CreateRequest(GURL("http://example.com"), DEFAULT_PRIORITY, &d));
2153 req->set_method("GET"); 2154 req->set_method("GET");
2154 2155
2155 req->Start(); 2156 req->Start();
2156 base::RunLoop().Run(); 2157 base::RunLoop().Run();
2157 2158
2158 // Check we see a failed request. 2159 // Check we see a failed request.
2159 EXPECT_FALSE(req->status().is_success()); 2160 EXPECT_FALSE(req->status().is_success());
2160 // The proxy server is not set before failure. 2161 // The proxy server is not set before failure.
2161 EXPECT_TRUE(req->proxy_server().IsEmpty()); 2162 EXPECT_FALSE(req->proxy_server().is_valid());
2162 EXPECT_EQ(URLRequestStatus::FAILED, req->status().status()); 2163 EXPECT_EQ(URLRequestStatus::FAILED, req->status().status());
2163 EXPECT_THAT(req->status().error(), IsError(ERR_PROXY_CONNECTION_FAILED)); 2164 EXPECT_THAT(req->status().error(), IsError(ERR_PROXY_CONNECTION_FAILED));
2164 2165
2165 EXPECT_EQ(1, network_delegate.error_count()); 2166 EXPECT_EQ(1, network_delegate.error_count());
2166 EXPECT_THAT(network_delegate.last_error(), 2167 EXPECT_THAT(network_delegate.last_error(),
2167 IsError(ERR_PROXY_CONNECTION_FAILED)); 2168 IsError(ERR_PROXY_CONNECTION_FAILED));
2168 EXPECT_EQ(1, network_delegate.completed_requests()); 2169 EXPECT_EQ(1, network_delegate.completed_requests());
2169 } 2170 }
2170 2171
2171 // Make sure that NetworkDelegate::NotifyCompleted is called if 2172 // Make sure that NetworkDelegate::NotifyCompleted is called if
(...skipping 1423 matching lines...) Expand 10 before | Expand all | Expand 10 after
3595 { 3596 {
3596 std::unique_ptr<URLRequest> r(context.CreateRequest( 3597 std::unique_ptr<URLRequest> r(context.CreateRequest(
3597 GURL("https://www.redirect.com/"), DEFAULT_PRIORITY, &d)); 3598 GURL("https://www.redirect.com/"), DEFAULT_PRIORITY, &d));
3598 r->Start(); 3599 r->Start();
3599 EXPECT_TRUE(r->is_pending()); 3600 EXPECT_TRUE(r->is_pending());
3600 3601
3601 base::RunLoop().Run(); 3602 base::RunLoop().Run();
3602 3603
3603 EXPECT_EQ(URLRequestStatus::FAILED, r->status().status()); 3604 EXPECT_EQ(URLRequestStatus::FAILED, r->status().status());
3604 // The proxy server is not set before failure. 3605 // The proxy server is not set before failure.
3605 EXPECT_TRUE(r->proxy_server().IsEmpty()); 3606 EXPECT_FALSE(r->proxy_server().is_valid());
3606 EXPECT_THAT(r->status().error(), IsError(ERR_TUNNEL_CONNECTION_FAILED)); 3607 EXPECT_THAT(r->status().error(), IsError(ERR_TUNNEL_CONNECTION_FAILED));
3607 EXPECT_EQ(1, d.response_started_count()); 3608 EXPECT_EQ(1, d.response_started_count());
3608 // We should not have followed the redirect. 3609 // We should not have followed the redirect.
3609 EXPECT_EQ(0, d.received_redirect_count()); 3610 EXPECT_EQ(0, d.received_redirect_count());
3610 } 3611 }
3611 } 3612 }
3612 3613
3613 // This is the same as the previous test, but checks that the network delegate 3614 // This is the same as the previous test, but checks that the network delegate
3614 // registers the error. 3615 // registers the error.
3615 TEST_F(URLRequestTestHTTP, NetworkDelegateTunnelConnectionFailed) { 3616 TEST_F(URLRequestTestHTTP, NetworkDelegateTunnelConnectionFailed) {
3616 ASSERT_TRUE(http_test_server()->Start()); 3617 ASSERT_TRUE(http_test_server()->Start());
3617 3618
3618 TestNetworkDelegate network_delegate; // Must outlive URLRequest. 3619 TestNetworkDelegate network_delegate; // Must outlive URLRequest.
3619 TestURLRequestContextWithProxy context( 3620 TestURLRequestContextWithProxy context(
3620 http_test_server()->host_port_pair().ToString(), &network_delegate); 3621 http_test_server()->host_port_pair().ToString(), &network_delegate);
3621 3622
3622 TestDelegate d; 3623 TestDelegate d;
3623 { 3624 {
3624 std::unique_ptr<URLRequest> r(context.CreateRequest( 3625 std::unique_ptr<URLRequest> r(context.CreateRequest(
3625 GURL("https://www.redirect.com/"), DEFAULT_PRIORITY, &d)); 3626 GURL("https://www.redirect.com/"), DEFAULT_PRIORITY, &d));
3626 r->Start(); 3627 r->Start();
3627 EXPECT_TRUE(r->is_pending()); 3628 EXPECT_TRUE(r->is_pending());
3628 3629
3629 base::RunLoop().Run(); 3630 base::RunLoop().Run();
3630 3631
3631 EXPECT_EQ(URLRequestStatus::FAILED, r->status().status()); 3632 EXPECT_EQ(URLRequestStatus::FAILED, r->status().status());
3632 // The proxy server is not set before failure. 3633 // The proxy server is not set before failure.
3633 EXPECT_TRUE(r->proxy_server().IsEmpty()); 3634 EXPECT_FALSE(r->proxy_server().is_valid());
3634 EXPECT_THAT(r->status().error(), IsError(ERR_TUNNEL_CONNECTION_FAILED)); 3635 EXPECT_THAT(r->status().error(), IsError(ERR_TUNNEL_CONNECTION_FAILED));
3635 EXPECT_EQ(1, d.response_started_count()); 3636 EXPECT_EQ(1, d.response_started_count());
3636 // We should not have followed the redirect. 3637 // We should not have followed the redirect.
3637 EXPECT_EQ(0, d.received_redirect_count()); 3638 EXPECT_EQ(0, d.received_redirect_count());
3638 3639
3639 EXPECT_EQ(1, network_delegate.error_count()); 3640 EXPECT_EQ(1, network_delegate.error_count());
3640 EXPECT_THAT(network_delegate.last_error(), 3641 EXPECT_THAT(network_delegate.last_error(),
3641 IsError(ERR_TUNNEL_CONNECTION_FAILED)); 3642 IsError(ERR_TUNNEL_CONNECTION_FAILED));
3642 } 3643 }
3643 } 3644 }
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
3700 3701
3701 { 3702 {
3702 std::unique_ptr<URLRequest> r(context.CreateRequest( 3703 std::unique_ptr<URLRequest> r(context.CreateRequest(
3703 http_test_server()->GetURL("/"), DEFAULT_PRIORITY, &d)); 3704 http_test_server()->GetURL("/"), DEFAULT_PRIORITY, &d));
3704 3705
3705 r->Start(); 3706 r->Start();
3706 base::RunLoop().Run(); 3707 base::RunLoop().Run();
3707 3708
3708 EXPECT_EQ(URLRequestStatus::FAILED, r->status().status()); 3709 EXPECT_EQ(URLRequestStatus::FAILED, r->status().status());
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_THAT(r->status().error(), IsError(ERR_EMPTY_RESPONSE)); 3712 EXPECT_THAT(r->status().error(), IsError(ERR_EMPTY_RESPONSE));
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 12 matching lines...) Expand all
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 EXPECT_EQ(URLRequestStatus::FAILED, r->status().status()); 3742 EXPECT_EQ(URLRequestStatus::FAILED, r->status().status());
3742 // The proxy server is not set before cancellation. 3743 // The proxy server is not set before cancellation.
3743 EXPECT_TRUE(r->proxy_server().IsEmpty()); 3744 EXPECT_FALSE(r->proxy_server().is_valid());
3744 EXPECT_THAT(r->status().error(), IsError(ERR_BLOCKED_BY_CLIENT)); 3745 EXPECT_THAT(r->status().error(), IsError(ERR_BLOCKED_BY_CLIENT));
3745 EXPECT_EQ(1, network_delegate.created_requests()); 3746 EXPECT_EQ(1, network_delegate.created_requests());
3746 EXPECT_EQ(0, network_delegate.destroyed_requests()); 3747 EXPECT_EQ(0, network_delegate.destroyed_requests());
3747 } 3748 }
3748 EXPECT_EQ(1, network_delegate.destroyed_requests()); 3749 EXPECT_EQ(1, network_delegate.destroyed_requests());
3749 } 3750 }
3750 3751
3751 // The following 3 tests check that the network delegate can cancel a request 3752 // The following 3 tests check that the network delegate can cancel a request
3752 // synchronously in various stages of the request. 3753 // synchronously in various stages of the request.
3753 TEST_F(URLRequestTestHTTP, NetworkDelegateCancelRequestSynchronously1) { 3754 TEST_F(URLRequestTestHTTP, NetworkDelegateCancelRequestSynchronously1) {
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
3825 EXPECT_EQ(307, r->response_headers()->response_code()); 3826 EXPECT_EQ(307, r->response_headers()->response_code());
3826 std::string location; 3827 std::string location;
3827 ASSERT_TRUE(r->response_headers()->EnumerateHeader(NULL, "Location", 3828 ASSERT_TRUE(r->response_headers()->EnumerateHeader(NULL, "Location",
3828 &location)); 3829 &location));
3829 EXPECT_EQ(redirect_url, GURL(location)); 3830 EXPECT_EQ(redirect_url, GURL(location));
3830 3831
3831 // Let the request finish. 3832 // Let the request finish.
3832 r->FollowDeferredRedirect(); 3833 r->FollowDeferredRedirect();
3833 base::RunLoop().Run(); 3834 base::RunLoop().Run();
3834 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status()); 3835 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status());
3835 EXPECT_TRUE(r->proxy_server().Equals(http_test_server()->host_port_pair())); 3836 EXPECT_EQ(ProxyServer(ProxyServer::SCHEME_HTTP,
3837 http_test_server()->host_port_pair()),
3838 r->proxy_server());
3836 // before_send_headers_with_proxy_count only increments for headers sent 3839 // before_send_headers_with_proxy_count only increments for headers sent
3837 // through an untunneled proxy. 3840 // through an untunneled proxy.
3838 EXPECT_EQ(1, network_delegate.before_send_headers_with_proxy_count()); 3841 EXPECT_EQ(1, network_delegate.before_send_headers_with_proxy_count());
3839 EXPECT_TRUE(network_delegate.last_observed_proxy().Equals( 3842 EXPECT_TRUE(network_delegate.last_observed_proxy().Equals(
3840 http_test_server()->host_port_pair())); 3843 http_test_server()->host_port_pair()));
3841 3844
3842 EXPECT_EQ(0, r->status().error()); 3845 EXPECT_EQ(0, r->status().error());
3843 EXPECT_EQ(redirect_url, r->url()); 3846 EXPECT_EQ(redirect_url, r->url());
3844 EXPECT_EQ(original_url, r->original_url()); 3847 EXPECT_EQ(original_url, r->original_url());
3845 EXPECT_EQ(2U, r->url_chain().size()); 3848 EXPECT_EQ(2U, r->url_chain().size());
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
3880 std::string location; 3883 std::string location;
3881 ASSERT_TRUE(r->response_headers()->EnumerateHeader(NULL, "Location", 3884 ASSERT_TRUE(r->response_headers()->EnumerateHeader(NULL, "Location",
3882 &location)); 3885 &location));
3883 EXPECT_EQ(redirect_url, GURL(location)); 3886 EXPECT_EQ(redirect_url, GURL(location));
3884 3887
3885 // Let the request finish. 3888 // Let the request finish.
3886 r->FollowDeferredRedirect(); 3889 r->FollowDeferredRedirect();
3887 base::RunLoop().Run(); 3890 base::RunLoop().Run();
3888 3891
3889 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status()); 3892 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status());
3890 EXPECT_TRUE(r->proxy_server().Equals(http_test_server()->host_port_pair())); 3893 EXPECT_EQ(ProxyServer(ProxyServer::SCHEME_HTTP,
3894 http_test_server()->host_port_pair()),
3895 r->proxy_server());
3891 // before_send_headers_with_proxy_count only increments for headers sent 3896 // before_send_headers_with_proxy_count only increments for headers sent
3892 // through an untunneled proxy. 3897 // through an untunneled proxy.
3893 EXPECT_EQ(1, network_delegate.before_send_headers_with_proxy_count()); 3898 EXPECT_EQ(1, network_delegate.before_send_headers_with_proxy_count());
3894 EXPECT_TRUE(network_delegate.last_observed_proxy().Equals( 3899 EXPECT_TRUE(network_delegate.last_observed_proxy().Equals(
3895 http_test_server()->host_port_pair())); 3900 http_test_server()->host_port_pair()));
3896 EXPECT_EQ(0, r->status().error()); 3901 EXPECT_EQ(0, r->status().error());
3897 EXPECT_EQ(redirect_url, r->url()); 3902 EXPECT_EQ(redirect_url, r->url());
3898 EXPECT_EQ(original_url, r->original_url()); 3903 EXPECT_EQ(original_url, r->original_url());
3899 EXPECT_EQ(2U, r->url_chain().size()); 3904 EXPECT_EQ(2U, r->url_chain().size());
3900 EXPECT_EQ(1, network_delegate.created_requests()); 3905 EXPECT_EQ(1, network_delegate.created_requests());
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
3979 3984
3980 { 3985 {
3981 GURL original_url(http_test_server()->GetURL("/defaultresponse")); 3986 GURL original_url(http_test_server()->GetURL("/defaultresponse"));
3982 std::unique_ptr<URLRequest> r( 3987 std::unique_ptr<URLRequest> r(
3983 context.CreateRequest(original_url, DEFAULT_PRIORITY, &d)); 3988 context.CreateRequest(original_url, DEFAULT_PRIORITY, &d));
3984 3989
3985 r->Start(); 3990 r->Start();
3986 base::RunLoop().Run(); 3991 base::RunLoop().Run();
3987 3992
3988 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status()); 3993 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status());
3989 EXPECT_TRUE(r->proxy_server().Equals(http_test_server()->host_port_pair())); 3994 EXPECT_EQ(ProxyServer(ProxyServer::SCHEME_HTTP,
3995 http_test_server()->host_port_pair()),
3996 r->proxy_server());
3990 // before_send_headers_with_proxy_count only increments for headers sent 3997 // before_send_headers_with_proxy_count only increments for headers sent
3991 // through an untunneled proxy. 3998 // through an untunneled proxy.
3992 EXPECT_EQ(2, network_delegate.before_send_headers_with_proxy_count()); 3999 EXPECT_EQ(2, network_delegate.before_send_headers_with_proxy_count());
3993 EXPECT_TRUE(network_delegate.last_observed_proxy().Equals( 4000 EXPECT_TRUE(network_delegate.last_observed_proxy().Equals(
3994 http_test_server()->host_port_pair())); 4001 http_test_server()->host_port_pair()));
3995 4002
3996 EXPECT_THAT(r->status().error(), IsOk()); 4003 EXPECT_THAT(r->status().error(), IsOk());
3997 EXPECT_EQ(redirect_url, r->url()); 4004 EXPECT_EQ(redirect_url, r->url());
3998 EXPECT_EQ(original_url, r->original_url()); 4005 EXPECT_EQ(original_url, r->original_url());
3999 EXPECT_EQ(2U, r->url_chain().size()); 4006 EXPECT_EQ(2U, r->url_chain().size());
(...skipping 474 matching lines...) Expand 10 before | Expand all | Expand 10 after
4474 std::unique_ptr<URLRequest> r(context.CreateRequest( 4481 std::unique_ptr<URLRequest> r(context.CreateRequest(
4475 GURL("https://www.server-auth.com/"), DEFAULT_PRIORITY, &d)); 4482 GURL("https://www.server-auth.com/"), DEFAULT_PRIORITY, &d));
4476 4483
4477 r->Start(); 4484 r->Start();
4478 EXPECT_TRUE(r->is_pending()); 4485 EXPECT_TRUE(r->is_pending());
4479 4486
4480 base::RunLoop().Run(); 4487 base::RunLoop().Run();
4481 4488
4482 EXPECT_EQ(URLRequestStatus::FAILED, r->status().status()); 4489 EXPECT_EQ(URLRequestStatus::FAILED, r->status().status());
4483 // The proxy server is not set before failure. 4490 // The proxy server is not set before failure.
4484 EXPECT_TRUE(r->proxy_server().IsEmpty()); 4491 EXPECT_FALSE(r->proxy_server().is_valid());
4485 EXPECT_THAT(r->status().error(), IsError(ERR_TUNNEL_CONNECTION_FAILED)); 4492 EXPECT_THAT(r->status().error(), IsError(ERR_TUNNEL_CONNECTION_FAILED));
4486 } 4493 }
4487 } 4494 }
4488 4495
4489 TEST_F(URLRequestTestHTTP, GetTest_NoCache) { 4496 TEST_F(URLRequestTestHTTP, GetTest_NoCache) {
4490 ASSERT_TRUE(http_test_server()->Start()); 4497 ASSERT_TRUE(http_test_server()->Start());
4491 4498
4492 TestDelegate d; 4499 TestDelegate d;
4493 { 4500 {
4494 std::unique_ptr<URLRequest> r(default_context_.CreateRequest( 4501 std::unique_ptr<URLRequest> r(default_context_.CreateRequest(
(...skipping 5744 matching lines...) Expand 10 before | Expand all | Expand 10 after
10239 AddTestInterceptor()->set_main_intercept_job(std::move(job)); 10246 AddTestInterceptor()->set_main_intercept_job(std::move(job));
10240 10247
10241 req->Start(); 10248 req->Start();
10242 req->Cancel(); 10249 req->Cancel();
10243 base::RunLoop().RunUntilIdle(); 10250 base::RunLoop().RunUntilIdle();
10244 EXPECT_EQ(URLRequestStatus::CANCELED, req->status().status()); 10251 EXPECT_EQ(URLRequestStatus::CANCELED, req->status().status());
10245 EXPECT_EQ(0, d.received_redirect_count()); 10252 EXPECT_EQ(0, d.received_redirect_count());
10246 } 10253 }
10247 10254
10248 } // namespace net 10255 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698