Index: net/url_request/url_request_ftp_job_unittest.cc |
diff --git a/net/url_request/url_request_ftp_job_unittest.cc b/net/url_request/url_request_ftp_job_unittest.cc |
index 040f8967d34f2d6abe15741389725908c6e0fd75..189451da826045e58fbdaa72330832dca58ae0fe 100644 |
--- a/net/url_request/url_request_ftp_job_unittest.cc |
+++ b/net/url_request/url_request_ftp_job_unittest.cc |
@@ -8,19 +8,47 @@ |
#include "base/memory/scoped_vector.h" |
#include "base/run_loop.h" |
#include "googleurl/src/gurl.h" |
+#include "net/ftp/ftp_auth_cache.h" |
#include "net/http/http_transaction_unittest.h" |
#include "net/proxy/mock_proxy_resolver.h" |
#include "net/proxy/proxy_config_service.h" |
#include "net/proxy/proxy_config_service_fixed.h" |
#include "net/socket/socket_test_util.h" |
+#include "net/url_request/ftp_protocol_handler.h" |
#include "net/url_request/url_request.h" |
#include "net/url_request/url_request_context.h" |
+#include "net/url_request/url_request_job_factory_impl.h" |
#include "net/url_request/url_request_status.h" |
#include "net/url_request/url_request_test_util.h" |
#include "testing/gtest/include/gtest/gtest.h" |
namespace net { |
+class FtpTestURLRequestContext : public TestURLRequestContext { |
+ public: |
+ FtpTestURLRequestContext(ClientSocketFactory* socket_factory, |
+ ProxyService* proxy_service, |
+ NetworkDelegate* network_delegate, |
+ FtpTransactionFactory* ftp_transaction_factory) |
+ : TestURLRequestContext(true), |
+ ftp_protocol_handler_(new FtpProtocolHandler(ftp_transaction_factory)) { |
+ set_client_socket_factory(socket_factory); |
+ context_storage_.set_proxy_service(proxy_service); |
+ set_network_delegate(network_delegate); |
+ URLRequestJobFactoryImpl* job_factory = new URLRequestJobFactoryImpl; |
+ job_factory->SetProtocolHandler("ftp", ftp_protocol_handler_); |
+ context_storage_.set_job_factory(job_factory); |
+ Init(); |
+ } |
+ |
+ FtpAuthCache* GetFtpAuthCache() { |
+ return ftp_protocol_handler_->ftp_auth_cache_.get(); |
+ } |
+ |
+ private: |
+ FtpProtocolHandler* ftp_protocol_handler_; |
+}; |
+ |
namespace { |
class SimpleProxyConfigService : public ProxyConfigService { |
@@ -60,10 +88,10 @@ class SimpleProxyConfigService : public ProxyConfigService { |
// other hidden functions. |
class TestURLRequestFtpJob : public URLRequestFtpJob { |
public: |
- explicit TestURLRequestFtpJob(URLRequest* request) |
- : URLRequestFtpJob(request, NULL, |
- request->context()->ftp_transaction_factory(), |
- request->context()->ftp_auth_cache()) {} |
+ TestURLRequestFtpJob(URLRequest* request, |
+ FtpTransactionFactory* ftp_factory, |
+ FtpAuthCache* ftp_auth_cache) |
+ : URLRequestFtpJob(request, NULL, ftp_factory, ftp_auth_cache) {} |
using URLRequestFtpJob::SetPriority; |
using URLRequestFtpJob::Start; |
@@ -74,6 +102,15 @@ class TestURLRequestFtpJob : public URLRequestFtpJob { |
virtual ~TestURLRequestFtpJob() {} |
}; |
+class MockFtpTransactionFactory : public FtpTransactionFactory { |
+ public: |
+ virtual FtpTransaction* CreateTransaction() OVERRIDE { |
+ return NULL; |
+ } |
+ |
+ virtual void Suspend(bool suspend) OVERRIDE {} |
+}; |
+ |
// Fixture for priority-related tests. Priority matters when there is |
// an HTTP proxy. |
class URLRequestFtpJobPriorityTest : public testing::Test { |
@@ -87,6 +124,8 @@ class URLRequestFtpJobPriorityTest : public testing::Test { |
ProxyService proxy_service_; |
MockNetworkLayer network_layer_; |
+ MockFtpTransactionFactory ftp_factory_; |
+ FtpAuthCache ftp_auth_cache_; |
TestURLRequestContext context_; |
TestDelegate delegate_; |
TestURLRequest req_; |
@@ -95,7 +134,8 @@ class URLRequestFtpJobPriorityTest : public testing::Test { |
// Make sure that SetPriority actually sets the URLRequestFtpJob's |
// priority, both before and after start. |
TEST_F(URLRequestFtpJobPriorityTest, SetPriorityBasic) { |
- scoped_refptr<TestURLRequestFtpJob> job(new TestURLRequestFtpJob(&req_)); |
+ scoped_refptr<TestURLRequestFtpJob> job(new TestURLRequestFtpJob( |
+ &req_, &ftp_factory_, &ftp_auth_cache_)); |
EXPECT_EQ(DEFAULT_PRIORITY, job->priority()); |
job->SetPriority(LOWEST); |
@@ -114,7 +154,8 @@ TEST_F(URLRequestFtpJobPriorityTest, SetPriorityBasic) { |
// Make sure that URLRequestFtpJob passes on its priority to its |
// transaction on start. |
TEST_F(URLRequestFtpJobPriorityTest, SetTransactionPriorityOnStart) { |
- scoped_refptr<TestURLRequestFtpJob> job(new TestURLRequestFtpJob(&req_)); |
+ scoped_refptr<TestURLRequestFtpJob> job(new TestURLRequestFtpJob( |
+ &req_, &ftp_factory_, &ftp_auth_cache_)); |
job->SetPriority(LOW); |
EXPECT_FALSE(network_layer_.last_transaction()); |
@@ -128,7 +169,8 @@ TEST_F(URLRequestFtpJobPriorityTest, SetTransactionPriorityOnStart) { |
// Make sure that URLRequestFtpJob passes on its priority updates to |
// its transaction. |
TEST_F(URLRequestFtpJobPriorityTest, SetTransactionPriority) { |
- scoped_refptr<TestURLRequestFtpJob> job(new TestURLRequestFtpJob(&req_)); |
+ scoped_refptr<TestURLRequestFtpJob> job(new TestURLRequestFtpJob( |
+ &req_, &ftp_factory_, &ftp_auth_cache_)); |
job->SetPriority(LOW); |
job->Start(); |
ASSERT_TRUE(network_layer_.last_transaction()); |
@@ -141,7 +183,8 @@ TEST_F(URLRequestFtpJobPriorityTest, SetTransactionPriority) { |
// Make sure that URLRequestFtpJob passes on its priority updates to |
// newly-created transactions after the first one. |
TEST_F(URLRequestFtpJobPriorityTest, SetSubsequentTransactionPriority) { |
- scoped_refptr<TestURLRequestFtpJob> job(new TestURLRequestFtpJob(&req_)); |
+ scoped_refptr<TestURLRequestFtpJob> job(new TestURLRequestFtpJob( |
+ &req_, &ftp_factory_, &ftp_auth_cache_)); |
job->Start(); |
job->SetPriority(LOW); |
@@ -157,19 +200,6 @@ TEST_F(URLRequestFtpJobPriorityTest, SetSubsequentTransactionPriority) { |
EXPECT_EQ(LOW, network_layer_.last_transaction()->priority()); |
} |
-class FtpTestURLRequestContext : public TestURLRequestContext { |
- public: |
- FtpTestURLRequestContext(ClientSocketFactory* socket_factory, |
- ProxyService* proxy_service, |
- NetworkDelegate* network_delegate) |
- : TestURLRequestContext(true) { |
- set_client_socket_factory(socket_factory); |
- context_storage_.set_proxy_service(proxy_service); |
- set_network_delegate(network_delegate); |
- Init(); |
- } |
-}; |
- |
class URLRequestFtpJobTest : public testing::Test { |
public: |
URLRequestFtpJobTest() |
@@ -177,7 +207,8 @@ class URLRequestFtpJobTest : public testing::Test { |
new SimpleProxyConfigService, NULL, NULL)), |
request_context_(&socket_factory_, |
proxy_service_, |
- &network_delegate_) { |
+ &network_delegate_, |
+ &ftp_transaction_factory_) { |
} |
virtual ~URLRequestFtpJobTest() { |
@@ -197,7 +228,7 @@ class URLRequestFtpJobTest : public testing::Test { |
socket_data_.push_back(socket_data); |
} |
- URLRequestContext* request_context() { return &request_context_; } |
+ FtpTestURLRequestContext* request_context() { return &request_context_; } |
TestNetworkDelegate* network_delegate() { return &network_delegate_; } |
DeterministicSocketData* socket_data(size_t index) { |
return socket_data_[index]; |
@@ -207,6 +238,7 @@ class URLRequestFtpJobTest : public testing::Test { |
ScopedVector<DeterministicSocketData> socket_data_; |
DeterministicMockClientSocketFactory socket_factory_; |
TestNetworkDelegate network_delegate_; |
+ MockFtpTransactionFactory ftp_transaction_factory_; |
// Owned by |request_context_|: |
ProxyService* proxy_service_; |
@@ -461,7 +493,7 @@ TEST_F(URLRequestFtpJobTest, FtpProxyRequestNeedProxyAndServerAuth) { |
GURL url("ftp://ftp.example.com"); |
// Make sure cached FTP credentials are not used for proxy authentication. |
- request_context()->ftp_auth_cache()->Add( |
+ request_context()->GetFtpAuthCache()->Add( |
url.GetOrigin(), |
AuthCredentials(ASCIIToUTF16("userdonotuse"), |
ASCIIToUTF16("passworddonotuse"))); |