| 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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 scoped_ptr<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.Pass()); | 57 context_storage_.set_proxy_service(proxy_service.Pass()); |
| 58 set_network_delegate(network_delegate); | 58 set_network_delegate(network_delegate); |
| 59 scoped_ptr<URLRequestJobFactoryImpl> job_factory = | 59 scoped_ptr<URLRequestJobFactoryImpl> job_factory = |
| 60 make_scoped_ptr(new URLRequestJobFactoryImpl); | 60 make_scoped_ptr(new URLRequestJobFactoryImpl); |
| 61 job_factory->SetProtocolHandler("ftp", make_scoped_ptr(ftp_protocol_handler_
)); | 61 job_factory->SetProtocolHandler("ftp", |
| 62 make_scoped_ptr(ftp_protocol_handler_)); |
| 62 context_storage_.set_job_factory(job_factory.Pass()); | 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(scoped_ptr<ProxyService> proxy_service) { | 71 void set_proxy_service(scoped_ptr<ProxyService> proxy_service) { |
| 71 context_storage_.set_proxy_service(proxy_service.Pass()); | 72 context_storage_.set_proxy_service(proxy_service.Pass()); |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 FtpTransaction* CreateTransaction() override { return NULL; } | 131 FtpTransaction* CreateTransaction() override { return NULL; } |
| 131 | 132 |
| 132 void Suspend(bool suspend) override {} | 133 void Suspend(bool suspend) override {} |
| 133 }; | 134 }; |
| 134 | 135 |
| 135 // Fixture for priority-related tests. Priority matters when there is | 136 // Fixture for priority-related tests. Priority matters when there is |
| 136 // an HTTP proxy. | 137 // an HTTP proxy. |
| 137 class URLRequestFtpJobPriorityTest : public testing::Test { | 138 class URLRequestFtpJobPriorityTest : public testing::Test { |
| 138 protected: | 139 protected: |
| 139 URLRequestFtpJobPriorityTest() | 140 URLRequestFtpJobPriorityTest() |
| 140 : proxy_service_(new SimpleProxyConfigService, NULL, NULL), | 141 : proxy_service_(make_scoped_ptr(new SimpleProxyConfigService), |
| 142 NULL, |
| 143 NULL), |
| 141 req_(context_.CreateRequest(GURL("ftp://ftp.example.com"), | 144 req_(context_.CreateRequest(GURL("ftp://ftp.example.com"), |
| 142 DEFAULT_PRIORITY, | 145 DEFAULT_PRIORITY, |
| 143 &delegate_)) { | 146 &delegate_)) { |
| 144 context_.set_proxy_service(&proxy_service_); | 147 context_.set_proxy_service(&proxy_service_); |
| 145 context_.set_http_transaction_factory(&network_layer_); | 148 context_.set_http_transaction_factory(&network_layer_); |
| 146 } | 149 } |
| 147 | 150 |
| 148 ProxyService proxy_service_; | 151 ProxyService proxy_service_; |
| 149 MockNetworkLayer network_layer_; | 152 MockNetworkLayer network_layer_; |
| 150 MockFtpTransactionFactory ftp_factory_; | 153 MockFtpTransactionFactory ftp_factory_; |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 219 | 222 |
| 220 // Creates a second transaction. | 223 // Creates a second transaction. |
| 221 job->Start(); | 224 job->Start(); |
| 222 ASSERT_TRUE(network_layer_.last_transaction()); | 225 ASSERT_TRUE(network_layer_.last_transaction()); |
| 223 EXPECT_EQ(LOW, network_layer_.last_transaction()->priority()); | 226 EXPECT_EQ(LOW, network_layer_.last_transaction()->priority()); |
| 224 } | 227 } |
| 225 | 228 |
| 226 class URLRequestFtpJobTest : public testing::Test { | 229 class URLRequestFtpJobTest : public testing::Test { |
| 227 public: | 230 public: |
| 228 URLRequestFtpJobTest() | 231 URLRequestFtpJobTest() |
| 229 : request_context_( | 232 : request_context_(&socket_factory_, |
| 230 &socket_factory_, | 233 make_scoped_ptr(new ProxyService( |
| 231 make_scoped_ptr( | 234 make_scoped_ptr(new SimpleProxyConfigService), |
| 232 new ProxyService(new SimpleProxyConfigService, NULL, NULL)), | 235 NULL, |
| 233 &network_delegate_, | 236 NULL)), |
| 234 &ftp_transaction_factory_) {} | 237 &network_delegate_, |
| 238 &ftp_transaction_factory_) {} |
| 235 | 239 |
| 236 ~URLRequestFtpJobTest() override { | 240 ~URLRequestFtpJobTest() override { |
| 237 // Clean up any remaining tasks that mess up unrelated tests. | 241 // Clean up any remaining tasks that mess up unrelated tests. |
| 238 base::RunLoop().RunUntilIdle(); | 242 base::RunLoop().RunUntilIdle(); |
| 239 } | 243 } |
| 240 | 244 |
| 241 void AddSocket(MockRead* reads, size_t reads_size, | 245 void AddSocket(MockRead* reads, size_t reads_size, |
| 242 MockWrite* writes, size_t writes_size) { | 246 MockWrite* writes, size_t writes_size) { |
| 243 SequencedSocketData* socket_data = | 247 SequencedSocketData* socket_data = |
| 244 new SequencedSocketData(reads, reads_size, writes, writes_size); | 248 new SequencedSocketData(reads, reads_size, writes, writes_size); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 289 EXPECT_EQ(1, network_delegate()->completed_requests()); | 293 EXPECT_EQ(1, network_delegate()->completed_requests()); |
| 290 EXPECT_EQ(0, network_delegate()->error_count()); | 294 EXPECT_EQ(0, network_delegate()->error_count()); |
| 291 EXPECT_FALSE(request_delegate.auth_required_called()); | 295 EXPECT_FALSE(request_delegate.auth_required_called()); |
| 292 EXPECT_EQ("test.html", request_delegate.data_received()); | 296 EXPECT_EQ("test.html", request_delegate.data_received()); |
| 293 } | 297 } |
| 294 | 298 |
| 295 // Regression test for http://crbug.com/237526 . | 299 // Regression test for http://crbug.com/237526 . |
| 296 TEST_F(URLRequestFtpJobTest, FtpProxyRequestOrphanJob) { | 300 TEST_F(URLRequestFtpJobTest, FtpProxyRequestOrphanJob) { |
| 297 // Use a PAC URL so that URLRequestFtpJob's |pac_request_| field is non-NULL. | 301 // Use a PAC URL so that URLRequestFtpJob's |pac_request_| field is non-NULL. |
| 298 request_context()->set_proxy_service(make_scoped_ptr(new ProxyService( | 302 request_context()->set_proxy_service(make_scoped_ptr(new ProxyService( |
| 299 new ProxyConfigServiceFixed( | 303 make_scoped_ptr(new ProxyConfigServiceFixed( |
| 300 ProxyConfig::CreateFromCustomPacURL(GURL("http://foo"))), | 304 ProxyConfig::CreateFromCustomPacURL(GURL("http://foo")))), |
| 301 make_scoped_ptr(new MockProxyResolverFactory), NULL))); | 305 make_scoped_ptr(new MockProxyResolverFactory), NULL))); |
| 302 | 306 |
| 303 TestDelegate request_delegate; | 307 TestDelegate request_delegate; |
| 304 scoped_ptr<URLRequest> url_request(request_context()->CreateRequest( | 308 scoped_ptr<URLRequest> url_request(request_context()->CreateRequest( |
| 305 GURL("ftp://ftp.example.com/"), DEFAULT_PRIORITY, &request_delegate)); | 309 GURL("ftp://ftp.example.com/"), DEFAULT_PRIORITY, &request_delegate)); |
| 306 url_request->Start(); | 310 url_request->Start(); |
| 307 | 311 |
| 308 // Now |url_request| will be deleted before its completion, | 312 // Now |url_request| will be deleted before its completion, |
| 309 // resulting in it being orphaned. It should not crash. | 313 // resulting in it being orphaned. It should not crash. |
| 310 } | 314 } |
| (...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 727 EXPECT_TRUE(url_request2->status().is_success()); | 731 EXPECT_TRUE(url_request2->status().is_success()); |
| 728 EXPECT_EQ(2, network_delegate()->completed_requests()); | 732 EXPECT_EQ(2, network_delegate()->completed_requests()); |
| 729 EXPECT_EQ(0, network_delegate()->error_count()); | 733 EXPECT_EQ(0, network_delegate()->error_count()); |
| 730 EXPECT_FALSE(request_delegate2.auth_required_called()); | 734 EXPECT_FALSE(request_delegate2.auth_required_called()); |
| 731 EXPECT_EQ("test2.html", request_delegate2.data_received()); | 735 EXPECT_EQ("test2.html", request_delegate2.data_received()); |
| 732 } | 736 } |
| 733 | 737 |
| 734 } // namespace | 738 } // namespace |
| 735 | 739 |
| 736 } // namespace net | 740 } // namespace net |
| OLD | NEW |