OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/ftp/ftp_network_transaction.h" | 5 #include "net/ftp/ftp_network_transaction.h" |
6 | 6 |
7 #include "base/ref_counted.h" | 7 #include "base/ref_counted.h" |
8 #include "net/base/host_resolver.h" | |
9 #include "net/base/host_resolver_unittest.h" | |
10 #include "net/base/io_buffer.h" | 8 #include "net/base/io_buffer.h" |
| 9 #include "net/base/mock_host_resolver.h" |
11 #include "net/base/test_completion_callback.h" | 10 #include "net/base/test_completion_callback.h" |
12 #include "net/ftp/ftp_network_session.h" | 11 #include "net/ftp/ftp_network_session.h" |
13 #include "net/ftp/ftp_request_info.h" | 12 #include "net/ftp/ftp_request_info.h" |
14 #include "net/socket/socket_test_util.h" | 13 #include "net/socket/socket_test_util.h" |
15 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
16 #include "testing/platform_test.h" | 15 #include "testing/platform_test.h" |
17 | 16 |
18 namespace { | 17 namespace { |
19 | 18 |
20 // Size we use for IOBuffers used to receive data from the test data socket. | 19 // Size we use for IOBuffers used to receive data from the test data socket. |
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
230 } | 229 } |
231 } | 230 } |
232 | 231 |
233 private: | 232 private: |
234 DISALLOW_COPY_AND_ASSIGN(FtpMockControlSocketFileDownloadRetrFail); | 233 DISALLOW_COPY_AND_ASSIGN(FtpMockControlSocketFileDownloadRetrFail); |
235 }; | 234 }; |
236 | 235 |
237 class FtpNetworkTransactionTest : public PlatformTest { | 236 class FtpNetworkTransactionTest : public PlatformTest { |
238 public: | 237 public: |
239 FtpNetworkTransactionTest() | 238 FtpNetworkTransactionTest() |
240 : session_(new FtpNetworkSession(new HostResolver)), | 239 : host_resolver_(new MockHostResolver), |
| 240 session_(new FtpNetworkSession(host_resolver_)), |
241 transaction_(session_.get(), &mock_socket_factory_) { | 241 transaction_(session_.get(), &mock_socket_factory_) { |
242 } | 242 } |
243 | 243 |
244 protected: | 244 protected: |
245 FtpRequestInfo GetRequestInfo(const std::string& url) { | 245 FtpRequestInfo GetRequestInfo(const std::string& url) { |
246 FtpRequestInfo info; | 246 FtpRequestInfo info; |
247 info.url = GURL(url); | 247 info.url = GURL(url); |
248 return info; | 248 return info; |
249 } | 249 } |
250 | 250 |
(...skipping 28 matching lines...) Expand all Loading... |
279 void TransactionFailHelper(FtpMockControlSocket* ctrl_socket, | 279 void TransactionFailHelper(FtpMockControlSocket* ctrl_socket, |
280 const char* request, | 280 const char* request, |
281 FtpMockControlSocket::State state, | 281 FtpMockControlSocket::State state, |
282 FtpMockControlSocket::State next_state, | 282 FtpMockControlSocket::State next_state, |
283 const char* response, | 283 const char* response, |
284 int expected_result) { | 284 int expected_result) { |
285 ctrl_socket->InjectFailure(state, next_state, response); | 285 ctrl_socket->InjectFailure(state, next_state, response); |
286 ExecuteTransaction(ctrl_socket, request, expected_result); | 286 ExecuteTransaction(ctrl_socket, request, expected_result); |
287 } | 287 } |
288 | 288 |
| 289 scoped_refptr<MockHostResolver> host_resolver_; |
289 scoped_refptr<FtpNetworkSession> session_; | 290 scoped_refptr<FtpNetworkSession> session_; |
290 MockClientSocketFactory mock_socket_factory_; | 291 MockClientSocketFactory mock_socket_factory_; |
291 FtpNetworkTransaction transaction_; | 292 FtpNetworkTransaction transaction_; |
292 TestCompletionCallback callback_; | 293 TestCompletionCallback callback_; |
293 }; | 294 }; |
294 | 295 |
295 TEST_F(FtpNetworkTransactionTest, FailedLookup) { | 296 TEST_F(FtpNetworkTransactionTest, FailedLookup) { |
296 FtpRequestInfo request_info = GetRequestInfo("ftp://badhost"); | 297 FtpRequestInfo request_info = GetRequestInfo("ftp://badhost"); |
297 scoped_refptr<RuleBasedHostMapper> mapper(new RuleBasedHostMapper()); | 298 host_resolver_->rules()->AddSimulatedFailure("badhost"); |
298 mapper->AddSimulatedFailure("badhost"); | |
299 ScopedHostMapper scoped_mapper(mapper.get()); | |
300 ASSERT_EQ(ERR_IO_PENDING, transaction_.Start(&request_info, &callback_)); | 299 ASSERT_EQ(ERR_IO_PENDING, transaction_.Start(&request_info, &callback_)); |
301 EXPECT_EQ(ERR_FAILED, callback_.WaitForResult()); | 300 EXPECT_EQ(ERR_FAILED, callback_.WaitForResult()); |
302 } | 301 } |
303 | 302 |
304 TEST_F(FtpNetworkTransactionTest, DirectoryTransaction) { | 303 TEST_F(FtpNetworkTransactionTest, DirectoryTransaction) { |
305 FtpMockControlSocketDirectoryListing ctrl_socket; | 304 FtpMockControlSocketDirectoryListing ctrl_socket; |
306 ExecuteTransaction(&ctrl_socket, "ftp://host", OK); | 305 ExecuteTransaction(&ctrl_socket, "ftp://host", OK); |
307 } | 306 } |
308 | 307 |
309 TEST_F(FtpNetworkTransactionTest, DirectoryTransactionMultilineWelcome) { | 308 TEST_F(FtpNetworkTransactionTest, DirectoryTransactionMultilineWelcome) { |
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
541 FtpMockControlSocketFileDownloadRetrFail ctrl_socket; | 540 FtpMockControlSocketFileDownloadRetrFail ctrl_socket; |
542 TransactionFailHelper(&ctrl_socket, | 541 TransactionFailHelper(&ctrl_socket, |
543 "ftp://host/file", | 542 "ftp://host/file", |
544 FtpMockControlSocket::PRE_RETR, | 543 FtpMockControlSocket::PRE_RETR, |
545 FtpMockControlSocket::PRE_PASV2, | 544 FtpMockControlSocket::PRE_PASV2, |
546 "500 failed retr\r\n", | 545 "500 failed retr\r\n", |
547 ERR_FAILED); | 546 ERR_FAILED); |
548 } | 547 } |
549 | 548 |
550 } // namespace net | 549 } // namespace net |
OLD | NEW |