| 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 "base/memory/ref_counted.h" | 7 #include "base/memory/ref_counted.h" |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/memory/scoped_vector.h" | 9 #include "base/memory/scoped_vector.h" |
| 10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
| (...skipping 30 matching lines...) Expand all Loading... |
| 41 resolver->reset(new MockAsyncProxyResolver()); | 41 resolver->reset(new MockAsyncProxyResolver()); |
| 42 return OK; | 42 return OK; |
| 43 } | 43 } |
| 44 }; | 44 }; |
| 45 | 45 |
| 46 } // namespace | 46 } // namespace |
| 47 | 47 |
| 48 class FtpTestURLRequestContext : public TestURLRequestContext { | 48 class FtpTestURLRequestContext : public TestURLRequestContext { |
| 49 public: | 49 public: |
| 50 FtpTestURLRequestContext(ClientSocketFactory* socket_factory, | 50 FtpTestURLRequestContext(ClientSocketFactory* socket_factory, |
| 51 ProxyService* proxy_service, | 51 scoped_ptr<ProxyService> proxy_service, |
| 52 NetworkDelegate* network_delegate, | 52 NetworkDelegate* network_delegate, |
| 53 FtpTransactionFactory* ftp_transaction_factory) | 53 FtpTransactionFactory* ftp_transaction_factory) |
| 54 : TestURLRequestContext(true), | 54 : TestURLRequestContext(true), |
| 55 ftp_protocol_handler_(new FtpProtocolHandler(ftp_transaction_factory)) { | 55 ftp_protocol_handler_(new FtpProtocolHandler(ftp_transaction_factory)) { |
| 56 set_client_socket_factory(socket_factory); | 56 set_client_socket_factory(socket_factory); |
| 57 context_storage_.set_proxy_service(proxy_service); | 57 context_storage_.set_proxy_service(proxy_service.Pass()); |
| 58 set_network_delegate(network_delegate); | 58 set_network_delegate(network_delegate); |
| 59 URLRequestJobFactoryImpl* job_factory = new URLRequestJobFactoryImpl; | 59 scoped_ptr<URLRequestJobFactoryImpl> job_factory = |
| 60 make_scoped_ptr(new URLRequestJobFactoryImpl); |
| 60 job_factory->SetProtocolHandler("ftp", | 61 job_factory->SetProtocolHandler("ftp", |
| 61 make_scoped_ptr(ftp_protocol_handler_)); | 62 make_scoped_ptr(ftp_protocol_handler_)); |
| 62 context_storage_.set_job_factory(job_factory); | 63 context_storage_.set_job_factory(job_factory.Pass()); |
| 63 Init(); | 64 Init(); |
| 64 } | 65 } |
| 65 | 66 |
| 66 FtpAuthCache* GetFtpAuthCache() { | 67 FtpAuthCache* GetFtpAuthCache() { |
| 67 return ftp_protocol_handler_->ftp_auth_cache_.get(); | 68 return ftp_protocol_handler_->ftp_auth_cache_.get(); |
| 68 } | 69 } |
| 69 | 70 |
| 70 void set_proxy_service(ProxyService* proxy_service) { | 71 void set_proxy_service(scoped_ptr<ProxyService> proxy_service) { |
| 71 context_storage_.set_proxy_service(proxy_service); | 72 context_storage_.set_proxy_service(proxy_service.Pass()); |
| 72 } | 73 } |
| 73 | 74 |
| 74 private: | 75 private: |
| 75 FtpProtocolHandler* ftp_protocol_handler_; | 76 FtpProtocolHandler* ftp_protocol_handler_; |
| 76 }; | 77 }; |
| 77 | 78 |
| 78 namespace { | 79 namespace { |
| 79 | 80 |
| 80 class SimpleProxyConfigService : public ProxyConfigService { | 81 class SimpleProxyConfigService : public ProxyConfigService { |
| 81 public: | 82 public: |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 219 | 220 |
| 220 // Creates a second transaction. | 221 // Creates a second transaction. |
| 221 job->Start(); | 222 job->Start(); |
| 222 ASSERT_TRUE(network_layer_.last_transaction()); | 223 ASSERT_TRUE(network_layer_.last_transaction()); |
| 223 EXPECT_EQ(LOW, network_layer_.last_transaction()->priority()); | 224 EXPECT_EQ(LOW, network_layer_.last_transaction()->priority()); |
| 224 } | 225 } |
| 225 | 226 |
| 226 class URLRequestFtpJobTest : public testing::Test { | 227 class URLRequestFtpJobTest : public testing::Test { |
| 227 public: | 228 public: |
| 228 URLRequestFtpJobTest() | 229 URLRequestFtpJobTest() |
| 229 : request_context_(&socket_factory_, | 230 : request_context_( |
| 230 new ProxyService( | 231 &socket_factory_, |
| 231 new SimpleProxyConfigService, NULL, NULL), | 232 make_scoped_ptr( |
| 232 &network_delegate_, | 233 new ProxyService(new SimpleProxyConfigService, NULL, NULL)), |
| 233 &ftp_transaction_factory_) { | 234 &network_delegate_, |
| 234 } | 235 &ftp_transaction_factory_) {} |
| 235 | 236 |
| 236 ~URLRequestFtpJobTest() override { | 237 ~URLRequestFtpJobTest() override { |
| 237 // Clean up any remaining tasks that mess up unrelated tests. | 238 // Clean up any remaining tasks that mess up unrelated tests. |
| 238 base::RunLoop().RunUntilIdle(); | 239 base::RunLoop().RunUntilIdle(); |
| 239 } | 240 } |
| 240 | 241 |
| 241 void AddSocket(MockRead* reads, size_t reads_size, | 242 void AddSocket(MockRead* reads, size_t reads_size, |
| 242 MockWrite* writes, size_t writes_size) { | 243 MockWrite* writes, size_t writes_size) { |
| 243 SequencedSocketData* socket_data = | 244 SequencedSocketData* socket_data = |
| 244 new SequencedSocketData(reads, reads_size, writes, writes_size); | 245 new SequencedSocketData(reads, reads_size, writes, writes_size); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 288 HostPortPair::FromString("localhost:80"))); | 289 HostPortPair::FromString("localhost:80"))); |
| 289 EXPECT_EQ(1, network_delegate()->completed_requests()); | 290 EXPECT_EQ(1, network_delegate()->completed_requests()); |
| 290 EXPECT_EQ(0, network_delegate()->error_count()); | 291 EXPECT_EQ(0, network_delegate()->error_count()); |
| 291 EXPECT_FALSE(request_delegate.auth_required_called()); | 292 EXPECT_FALSE(request_delegate.auth_required_called()); |
| 292 EXPECT_EQ("test.html", request_delegate.data_received()); | 293 EXPECT_EQ("test.html", request_delegate.data_received()); |
| 293 } | 294 } |
| 294 | 295 |
| 295 // Regression test for http://crbug.com/237526 . | 296 // Regression test for http://crbug.com/237526 . |
| 296 TEST_F(URLRequestFtpJobTest, FtpProxyRequestOrphanJob) { | 297 TEST_F(URLRequestFtpJobTest, FtpProxyRequestOrphanJob) { |
| 297 // Use a PAC URL so that URLRequestFtpJob's |pac_request_| field is non-NULL. | 298 // Use a PAC URL so that URLRequestFtpJob's |pac_request_| field is non-NULL. |
| 298 request_context()->set_proxy_service(new ProxyService( | 299 request_context()->set_proxy_service(make_scoped_ptr(new ProxyService( |
| 299 new ProxyConfigServiceFixed( | 300 new ProxyConfigServiceFixed( |
| 300 ProxyConfig::CreateFromCustomPacURL(GURL("http://foo"))), | 301 ProxyConfig::CreateFromCustomPacURL(GURL("http://foo"))), |
| 301 make_scoped_ptr(new MockProxyResolverFactory), NULL)); | 302 make_scoped_ptr(new MockProxyResolverFactory), NULL))); |
| 302 | 303 |
| 303 TestDelegate request_delegate; | 304 TestDelegate request_delegate; |
| 304 scoped_ptr<URLRequest> url_request(request_context()->CreateRequest( | 305 scoped_ptr<URLRequest> url_request(request_context()->CreateRequest( |
| 305 GURL("ftp://ftp.example.com/"), DEFAULT_PRIORITY, &request_delegate)); | 306 GURL("ftp://ftp.example.com/"), DEFAULT_PRIORITY, &request_delegate)); |
| 306 url_request->Start(); | 307 url_request->Start(); |
| 307 | 308 |
| 308 // Now |url_request| will be deleted before its completion, | 309 // Now |url_request| will be deleted before its completion, |
| 309 // resulting in it being orphaned. It should not crash. | 310 // resulting in it being orphaned. It should not crash. |
| 310 } | 311 } |
| 311 | 312 |
| (...skipping 415 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 727 EXPECT_TRUE(url_request2->status().is_success()); | 728 EXPECT_TRUE(url_request2->status().is_success()); |
| 728 EXPECT_EQ(2, network_delegate()->completed_requests()); | 729 EXPECT_EQ(2, network_delegate()->completed_requests()); |
| 729 EXPECT_EQ(0, network_delegate()->error_count()); | 730 EXPECT_EQ(0, network_delegate()->error_count()); |
| 730 EXPECT_FALSE(request_delegate2.auth_required_called()); | 731 EXPECT_FALSE(request_delegate2.auth_required_called()); |
| 731 EXPECT_EQ("test2.html", request_delegate2.data_received()); | 732 EXPECT_EQ("test2.html", request_delegate2.data_received()); |
| 732 } | 733 } |
| 733 | 734 |
| 734 } // namespace | 735 } // namespace |
| 735 | 736 |
| 736 } // namespace net | 737 } // namespace net |
| OLD | NEW |