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/socket/socket_test_util.h" | 22 #include "net/socket/socket_test_util.h" |
| 23 #include "net/test/gtest_util.h" |
23 #include "net/url_request/ftp_protocol_handler.h" | 24 #include "net/url_request/ftp_protocol_handler.h" |
24 #include "net/url_request/url_request.h" | 25 #include "net/url_request/url_request.h" |
25 #include "net/url_request/url_request_context.h" | 26 #include "net/url_request/url_request_context.h" |
26 #include "net/url_request/url_request_job_factory_impl.h" | 27 #include "net/url_request/url_request_job_factory_impl.h" |
27 #include "net/url_request/url_request_status.h" | 28 #include "net/url_request/url_request_status.h" |
28 #include "net/url_request/url_request_test_util.h" | 29 #include "net/url_request/url_request_test_util.h" |
| 30 #include "testing/gmock/include/gmock/gmock.h" |
29 #include "testing/gtest/include/gtest/gtest.h" | 31 #include "testing/gtest/include/gtest/gtest.h" |
30 #include "url/gurl.h" | 32 #include "url/gurl.h" |
31 | 33 |
| 34 using net::test::IsError; |
| 35 using net::test::IsOk; |
| 36 |
32 using base::ASCIIToUTF16; | 37 using base::ASCIIToUTF16; |
33 | 38 |
34 namespace net { | 39 namespace net { |
35 namespace { | 40 namespace { |
36 | 41 |
37 class MockProxyResolverFactory : public ProxyResolverFactory { | 42 class MockProxyResolverFactory : public ProxyResolverFactory { |
38 public: | 43 public: |
39 MockProxyResolverFactory() | 44 MockProxyResolverFactory() |
40 : ProxyResolverFactory(false), resolver_(nullptr) {} | 45 : ProxyResolverFactory(false), resolver_(nullptr) {} |
41 | 46 |
(...skipping 624 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
666 GURL("ftp://ftp.example.com/"), DEFAULT_PRIORITY, &request_delegate)); | 671 GURL("ftp://ftp.example.com/"), DEFAULT_PRIORITY, &request_delegate)); |
667 url_request->Start(); | 672 url_request->Start(); |
668 EXPECT_TRUE(url_request->is_pending()); | 673 EXPECT_TRUE(url_request->is_pending()); |
669 | 674 |
670 // The TestDelegate will by default quit the message loop on completion. | 675 // The TestDelegate will by default quit the message loop on completion. |
671 base::RunLoop().Run(); | 676 base::RunLoop().Run(); |
672 | 677 |
673 EXPECT_EQ(1, network_delegate()->completed_requests()); | 678 EXPECT_EQ(1, network_delegate()->completed_requests()); |
674 EXPECT_EQ(1, network_delegate()->error_count()); | 679 EXPECT_EQ(1, network_delegate()->error_count()); |
675 EXPECT_FALSE(url_request->status().is_success()); | 680 EXPECT_FALSE(url_request->status().is_success()); |
676 EXPECT_EQ(ERR_UNSAFE_REDIRECT, url_request->status().error()); | 681 EXPECT_THAT(url_request->status().error(), IsError(ERR_UNSAFE_REDIRECT)); |
677 } | 682 } |
678 | 683 |
679 // We should re-use socket for requests using the same scheme, host, and port. | 684 // We should re-use socket for requests using the same scheme, host, and port. |
680 TEST_F(URLRequestFtpJobTest, FtpProxyRequestReuseSocket) { | 685 TEST_F(URLRequestFtpJobTest, FtpProxyRequestReuseSocket) { |
681 MockWrite writes[] = { | 686 MockWrite writes[] = { |
682 MockWrite(ASYNC, 0, "GET ftp://ftp.example.com/first HTTP/1.1\r\n" | 687 MockWrite(ASYNC, 0, "GET ftp://ftp.example.com/first HTTP/1.1\r\n" |
683 "Host: ftp.example.com\r\n" | 688 "Host: ftp.example.com\r\n" |
684 "Proxy-Connection: keep-alive\r\n\r\n"), | 689 "Proxy-Connection: keep-alive\r\n\r\n"), |
685 MockWrite(ASYNC, 4, "GET ftp://ftp.example.com/second HTTP/1.1\r\n" | 690 MockWrite(ASYNC, 4, "GET ftp://ftp.example.com/second HTTP/1.1\r\n" |
686 "Host: ftp.example.com\r\n" | 691 "Host: ftp.example.com\r\n" |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
792 EXPECT_TRUE(url_request2->status().is_success()); | 797 EXPECT_TRUE(url_request2->status().is_success()); |
793 EXPECT_EQ(2, network_delegate()->completed_requests()); | 798 EXPECT_EQ(2, network_delegate()->completed_requests()); |
794 EXPECT_EQ(0, network_delegate()->error_count()); | 799 EXPECT_EQ(0, network_delegate()->error_count()); |
795 EXPECT_FALSE(request_delegate2.auth_required_called()); | 800 EXPECT_FALSE(request_delegate2.auth_required_called()); |
796 EXPECT_EQ("test2.html", request_delegate2.data_received()); | 801 EXPECT_EQ("test2.html", request_delegate2.data_received()); |
797 } | 802 } |
798 | 803 |
799 } // namespace | 804 } // namespace |
800 | 805 |
801 } // namespace net | 806 } // namespace net |
OLD | NEW |