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