Chromium Code Reviews| 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 1031de2bcecf4fe61311b1ca785af4987b1f580c..3fd078622fd247f85803ee7c40cd7d6149fd2991 100644 |
| --- a/net/url_request/url_request_ftp_job_unittest.cc |
| +++ b/net/url_request/url_request_ftp_job_unittest.cc |
| @@ -11,14 +11,42 @@ |
| #include "net/http/http_transaction_unittest.h" |
| #include "net/proxy/proxy_config_service.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/gmock/include/gmock/gmock.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_; |
| + } |
| + |
| + private: |
| + FtpProtocolHandler* ftp_protocol_handler_; |
| +}; |
| + |
| namespace { |
| class SimpleProxyConfigService : public ProxyConfigService { |
| @@ -58,10 +86,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; |
| @@ -72,6 +100,12 @@ class TestURLRequestFtpJob : public URLRequestFtpJob { |
| virtual ~TestURLRequestFtpJob() {} |
| }; |
| +class MockFtpTransactionFactory : public FtpTransactionFactory { |
|
Paweł Hajdan Jr.
2013/04/29 18:45:26
Please don't use gmock for FTP unit tests.
|
| + public: |
| + MOCK_METHOD0(CreateTransaction, FtpTransaction*()); |
| + MOCK_METHOD1(Suspend, void(bool suspend)); |
| +}; |
| + |
| // Fixture for priority-related tests. Priority matters when there is |
| // an HTTP proxy. |
| class URLRequestFtpJobPriorityTest : public testing::Test { |
| @@ -85,6 +119,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_; |
| @@ -93,7 +129,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); |
| @@ -112,7 +149,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()); |
| @@ -126,7 +164,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()); |
| @@ -139,7 +178,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); |
| @@ -155,19 +195,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() |
| @@ -175,7 +202,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() { |
| @@ -195,7 +223,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]; |
| @@ -205,6 +233,7 @@ class URLRequestFtpJobTest : public testing::Test { |
| ScopedVector<DeterministicSocketData> socket_data_; |
| DeterministicMockClientSocketFactory socket_factory_; |
| TestNetworkDelegate network_delegate_; |
| + ::testing::StrictMock<MockFtpTransactionFactory> ftp_transaction_factory_; |
| // Owned by |request_context_|: |
| ProxyService* proxy_service_; |
| @@ -439,7 +468,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"))); |