OLD | NEW |
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 "net/url_request/url_request_ftp_job.h" | 5 #include "net/url_request/url_request_ftp_job.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include <utility> | 8 #include <utility> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
13 #include "base/run_loop.h" | 13 #include "base/run_loop.h" |
14 #include "net/base/host_port_pair.h" | 14 #include "net/base/host_port_pair.h" |
15 #include "net/base/load_states.h" | 15 #include "net/base/load_states.h" |
16 #include "net/base/request_priority.h" | 16 #include "net/base/request_priority.h" |
17 #include "net/ftp/ftp_auth_cache.h" | 17 #include "net/ftp/ftp_auth_cache.h" |
18 #include "net/http/http_transaction_test_util.h" | 18 #include "net/http/http_transaction_test_util.h" |
19 #include "net/proxy/mock_proxy_resolver.h" | 19 #include "net/proxy/mock_proxy_resolver.h" |
20 #include "net/proxy/proxy_config_service.h" | 20 #include "net/proxy/proxy_config_service.h" |
21 #include "net/proxy/proxy_config_service_fixed.h" | 21 #include "net/proxy/proxy_config_service_fixed.h" |
| 22 #include "net/proxy/proxy_server.h" |
22 #include "net/socket/socket_test_util.h" | 23 #include "net/socket/socket_test_util.h" |
23 #include "net/test/gtest_util.h" | 24 #include "net/test/gtest_util.h" |
24 #include "net/url_request/ftp_protocol_handler.h" | 25 #include "net/url_request/ftp_protocol_handler.h" |
25 #include "net/url_request/url_request.h" | 26 #include "net/url_request/url_request.h" |
26 #include "net/url_request/url_request_context.h" | 27 #include "net/url_request/url_request_context.h" |
27 #include "net/url_request/url_request_job_factory_impl.h" | 28 #include "net/url_request/url_request_job_factory_impl.h" |
28 #include "net/url_request/url_request_status.h" | 29 #include "net/url_request/url_request_status.h" |
29 #include "net/url_request/url_request_test_util.h" | 30 #include "net/url_request/url_request_test_util.h" |
30 #include "testing/gmock/include/gmock/gmock.h" | 31 #include "testing/gmock/include/gmock/gmock.h" |
31 #include "testing/gtest/include/gtest/gtest.h" | 32 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
304 TestDelegate request_delegate; | 305 TestDelegate request_delegate; |
305 std::unique_ptr<URLRequest> url_request(request_context()->CreateRequest( | 306 std::unique_ptr<URLRequest> url_request(request_context()->CreateRequest( |
306 GURL("ftp://ftp.example.com/"), DEFAULT_PRIORITY, &request_delegate)); | 307 GURL("ftp://ftp.example.com/"), DEFAULT_PRIORITY, &request_delegate)); |
307 url_request->Start(); | 308 url_request->Start(); |
308 ASSERT_TRUE(url_request->is_pending()); | 309 ASSERT_TRUE(url_request->is_pending()); |
309 | 310 |
310 // The TestDelegate will by default quit the message loop on completion. | 311 // The TestDelegate will by default quit the message loop on completion. |
311 base::RunLoop().Run(); | 312 base::RunLoop().Run(); |
312 | 313 |
313 EXPECT_THAT(request_delegate.request_status(), IsOk()); | 314 EXPECT_THAT(request_delegate.request_status(), IsOk()); |
314 EXPECT_TRUE(url_request->proxy_server().Equals( | 315 EXPECT_EQ(ProxyServer(ProxyServer::SCHEME_HTTP, |
315 HostPortPair::FromString("localhost:80"))); | 316 HostPortPair::FromString("localhost:80")), |
| 317 url_request->proxy_server()); |
316 EXPECT_EQ(1, network_delegate()->completed_requests()); | 318 EXPECT_EQ(1, network_delegate()->completed_requests()); |
317 EXPECT_EQ(0, network_delegate()->error_count()); | 319 EXPECT_EQ(0, network_delegate()->error_count()); |
318 EXPECT_FALSE(request_delegate.auth_required_called()); | 320 EXPECT_FALSE(request_delegate.auth_required_called()); |
319 EXPECT_EQ("test.html", request_delegate.data_received()); | 321 EXPECT_EQ("test.html", request_delegate.data_received()); |
320 } | 322 } |
321 | 323 |
322 // Regression test for http://crbug.com/237526. | 324 // Regression test for http://crbug.com/237526. |
323 TEST_F(URLRequestFtpJobTest, FtpProxyRequestOrphanJob) { | 325 TEST_F(URLRequestFtpJobTest, FtpProxyRequestOrphanJob) { |
324 std::unique_ptr<MockProxyResolverFactory> owned_resolver_factory( | 326 std::unique_ptr<MockProxyResolverFactory> owned_resolver_factory( |
325 new MockProxyResolverFactory()); | 327 new MockProxyResolverFactory()); |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
400 TestDelegate request_delegate; | 402 TestDelegate request_delegate; |
401 std::unique_ptr<URLRequest> url_request(request_context()->CreateRequest( | 403 std::unique_ptr<URLRequest> url_request(request_context()->CreateRequest( |
402 GURL("ftp://ftp.example.com/"), DEFAULT_PRIORITY, &request_delegate)); | 404 GURL("ftp://ftp.example.com/"), DEFAULT_PRIORITY, &request_delegate)); |
403 url_request->Start(); | 405 url_request->Start(); |
404 ASSERT_TRUE(url_request->is_pending()); | 406 ASSERT_TRUE(url_request->is_pending()); |
405 | 407 |
406 // The TestDelegate will by default quit the message loop on completion. | 408 // The TestDelegate will by default quit the message loop on completion. |
407 base::RunLoop().Run(); | 409 base::RunLoop().Run(); |
408 | 410 |
409 EXPECT_THAT(request_delegate.request_status(), IsOk()); | 411 EXPECT_THAT(request_delegate.request_status(), IsOk()); |
410 EXPECT_TRUE(url_request->proxy_server().Equals( | 412 EXPECT_EQ(ProxyServer(ProxyServer::SCHEME_HTTP, |
411 HostPortPair::FromString("localhost:80"))); | 413 HostPortPair::FromString("localhost:80")), |
| 414 url_request->proxy_server()); |
412 EXPECT_EQ(1, network_delegate()->completed_requests()); | 415 EXPECT_EQ(1, network_delegate()->completed_requests()); |
413 EXPECT_EQ(0, network_delegate()->error_count()); | 416 EXPECT_EQ(0, network_delegate()->error_count()); |
414 EXPECT_TRUE(request_delegate.auth_required_called()); | 417 EXPECT_TRUE(request_delegate.auth_required_called()); |
415 EXPECT_EQ("test.html", request_delegate.data_received()); | 418 EXPECT_EQ("test.html", request_delegate.data_received()); |
416 } | 419 } |
417 | 420 |
418 TEST_F(URLRequestFtpJobTest, FtpProxyRequestNeedProxyAuthWithCredentials) { | 421 TEST_F(URLRequestFtpJobTest, FtpProxyRequestNeedProxyAuthWithCredentials) { |
419 MockWrite writes[] = { | 422 MockWrite writes[] = { |
420 MockWrite(ASYNC, 0, "GET ftp://ftp.example.com/ HTTP/1.1\r\n" | 423 MockWrite(ASYNC, 0, "GET ftp://ftp.example.com/ HTTP/1.1\r\n" |
421 "Host: ftp.example.com\r\n" | 424 "Host: ftp.example.com\r\n" |
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
707 std::unique_ptr<URLRequest> url_request1( | 710 std::unique_ptr<URLRequest> url_request1( |
708 request_context()->CreateRequest(GURL("ftp://ftp.example.com/first"), | 711 request_context()->CreateRequest(GURL("ftp://ftp.example.com/first"), |
709 DEFAULT_PRIORITY, &request_delegate1)); | 712 DEFAULT_PRIORITY, &request_delegate1)); |
710 url_request1->Start(); | 713 url_request1->Start(); |
711 ASSERT_TRUE(url_request1->is_pending()); | 714 ASSERT_TRUE(url_request1->is_pending()); |
712 | 715 |
713 // The TestDelegate will by default quit the message loop on completion. | 716 // The TestDelegate will by default quit the message loop on completion. |
714 base::RunLoop().Run(); | 717 base::RunLoop().Run(); |
715 | 718 |
716 EXPECT_TRUE(url_request1->status().is_success()); | 719 EXPECT_TRUE(url_request1->status().is_success()); |
717 EXPECT_TRUE(url_request1->proxy_server().Equals( | 720 EXPECT_EQ(ProxyServer(ProxyServer::SCHEME_HTTP, |
718 HostPortPair::FromString("localhost:80"))); | 721 HostPortPair::FromString("localhost:80")), |
| 722 url_request1->proxy_server()); |
719 EXPECT_EQ(1, network_delegate()->completed_requests()); | 723 EXPECT_EQ(1, network_delegate()->completed_requests()); |
720 EXPECT_EQ(0, network_delegate()->error_count()); | 724 EXPECT_EQ(0, network_delegate()->error_count()); |
721 EXPECT_FALSE(request_delegate1.auth_required_called()); | 725 EXPECT_FALSE(request_delegate1.auth_required_called()); |
722 EXPECT_EQ("test1.html", request_delegate1.data_received()); | 726 EXPECT_EQ("test1.html", request_delegate1.data_received()); |
723 | 727 |
724 TestDelegate request_delegate2; | 728 TestDelegate request_delegate2; |
725 std::unique_ptr<URLRequest> url_request2( | 729 std::unique_ptr<URLRequest> url_request2( |
726 request_context()->CreateRequest(GURL("ftp://ftp.example.com/second"), | 730 request_context()->CreateRequest(GURL("ftp://ftp.example.com/second"), |
727 DEFAULT_PRIORITY, &request_delegate2)); | 731 DEFAULT_PRIORITY, &request_delegate2)); |
728 url_request2->Start(); | 732 url_request2->Start(); |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
797 EXPECT_TRUE(url_request2->status().is_success()); | 801 EXPECT_TRUE(url_request2->status().is_success()); |
798 EXPECT_EQ(2, network_delegate()->completed_requests()); | 802 EXPECT_EQ(2, network_delegate()->completed_requests()); |
799 EXPECT_EQ(0, network_delegate()->error_count()); | 803 EXPECT_EQ(0, network_delegate()->error_count()); |
800 EXPECT_FALSE(request_delegate2.auth_required_called()); | 804 EXPECT_FALSE(request_delegate2.auth_required_called()); |
801 EXPECT_EQ("test2.html", request_delegate2.data_received()); | 805 EXPECT_EQ("test2.html", request_delegate2.data_received()); |
802 } | 806 } |
803 | 807 |
804 } // namespace | 808 } // namespace |
805 | 809 |
806 } // namespace net | 810 } // namespace net |
OLD | NEW |