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/io_buffer.h" | 8 #include "net/base/io_buffer.h" |
9 #include "net/base/mock_host_resolver.h" | 9 #include "net/base/mock_host_resolver.h" |
10 #include "net/base/test_completion_callback.h" | 10 #include "net/base/test_completion_callback.h" |
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
302 MockRead data_reads[] = { | 302 MockRead data_reads[] = { |
303 MockRead(mock_data.c_str()), | 303 MockRead(mock_data.c_str()), |
304 }; | 304 }; |
305 // TODO(phajdan.jr): FTP transaction should not open two data sockets. | 305 // TODO(phajdan.jr): FTP transaction should not open two data sockets. |
306 StaticMockSocket data_socket1(data_reads, NULL); | 306 StaticMockSocket data_socket1(data_reads, NULL); |
307 StaticMockSocket data_socket2(data_reads, NULL); | 307 StaticMockSocket data_socket2(data_reads, NULL); |
308 mock_socket_factory_.AddMockSocket(ctrl_socket); | 308 mock_socket_factory_.AddMockSocket(ctrl_socket); |
309 mock_socket_factory_.AddMockSocket(&data_socket1); | 309 mock_socket_factory_.AddMockSocket(&data_socket1); |
310 mock_socket_factory_.AddMockSocket(&data_socket2); | 310 mock_socket_factory_.AddMockSocket(&data_socket2); |
311 FtpRequestInfo request_info = GetRequestInfo(request); | 311 FtpRequestInfo request_info = GetRequestInfo(request); |
312 ASSERT_EQ(ERR_IO_PENDING, transaction_.Start(&request_info, &callback_)); | 312 ASSERT_EQ(ERR_IO_PENDING, |
| 313 transaction_.Start(NULL, &request_info, &callback_)); |
313 EXPECT_EQ(expected_result, callback_.WaitForResult()); | 314 EXPECT_EQ(expected_result, callback_.WaitForResult()); |
314 EXPECT_EQ(FtpMockControlSocket::QUIT, ctrl_socket->state()); | 315 EXPECT_EQ(FtpMockControlSocket::QUIT, ctrl_socket->state()); |
315 if (expected_result == OK) { | 316 if (expected_result == OK) { |
316 scoped_refptr<IOBuffer> io_buffer(new IOBuffer(kBufferSize)); | 317 scoped_refptr<IOBuffer> io_buffer(new IOBuffer(kBufferSize)); |
317 memset(io_buffer->data(), 0, kBufferSize); | 318 memset(io_buffer->data(), 0, kBufferSize); |
318 ASSERT_EQ(ERR_IO_PENDING, | 319 ASSERT_EQ(ERR_IO_PENDING, |
319 transaction_.Read(io_buffer.get(), kBufferSize, &callback_)); | 320 transaction_.Read(io_buffer.get(), kBufferSize, &callback_)); |
320 EXPECT_EQ(static_cast<int>(mock_data.length()), | 321 EXPECT_EQ(static_cast<int>(mock_data.length()), |
321 callback_.WaitForResult()); | 322 callback_.WaitForResult()); |
322 EXPECT_EQ(mock_data, std::string(io_buffer->data(), mock_data.length())); | 323 EXPECT_EQ(mock_data, std::string(io_buffer->data(), mock_data.length())); |
(...skipping 13 matching lines...) Expand all Loading... |
336 scoped_refptr<MockHostResolver> host_resolver_; | 337 scoped_refptr<MockHostResolver> host_resolver_; |
337 scoped_refptr<FtpNetworkSession> session_; | 338 scoped_refptr<FtpNetworkSession> session_; |
338 MockClientSocketFactory mock_socket_factory_; | 339 MockClientSocketFactory mock_socket_factory_; |
339 FtpNetworkTransaction transaction_; | 340 FtpNetworkTransaction transaction_; |
340 TestCompletionCallback callback_; | 341 TestCompletionCallback callback_; |
341 }; | 342 }; |
342 | 343 |
343 TEST_F(FtpNetworkTransactionTest, FailedLookup) { | 344 TEST_F(FtpNetworkTransactionTest, FailedLookup) { |
344 FtpRequestInfo request_info = GetRequestInfo("ftp://badhost"); | 345 FtpRequestInfo request_info = GetRequestInfo("ftp://badhost"); |
345 host_resolver_->rules()->AddSimulatedFailure("badhost"); | 346 host_resolver_->rules()->AddSimulatedFailure("badhost"); |
346 ASSERT_EQ(ERR_IO_PENDING, transaction_.Start(&request_info, &callback_)); | 347 ASSERT_EQ(ERR_IO_PENDING, |
| 348 transaction_.Start(NULL, &request_info, &callback_)); |
347 EXPECT_EQ(ERR_NAME_NOT_RESOLVED, callback_.WaitForResult()); | 349 EXPECT_EQ(ERR_NAME_NOT_RESOLVED, callback_.WaitForResult()); |
348 } | 350 } |
349 | 351 |
350 TEST_F(FtpNetworkTransactionTest, DirectoryTransaction) { | 352 TEST_F(FtpNetworkTransactionTest, DirectoryTransaction) { |
351 FtpMockControlSocketDirectoryListing ctrl_socket; | 353 FtpMockControlSocketDirectoryListing ctrl_socket; |
352 ExecuteTransaction(&ctrl_socket, "ftp://host", OK); | 354 ExecuteTransaction(&ctrl_socket, "ftp://host", OK); |
353 } | 355 } |
354 | 356 |
355 TEST_F(FtpNetworkTransactionTest, DirectoryTransactionMultilineWelcome) { | 357 TEST_F(FtpNetworkTransactionTest, DirectoryTransactionMultilineWelcome) { |
356 FtpMockControlSocketDirectoryListing ctrl_socket; | 358 FtpMockControlSocketDirectoryListing ctrl_socket; |
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
597 FtpMockControlSocketFileDownloadRetrFail ctrl_socket; | 599 FtpMockControlSocketFileDownloadRetrFail ctrl_socket; |
598 TransactionFailHelper(&ctrl_socket, | 600 TransactionFailHelper(&ctrl_socket, |
599 "ftp://host/file", | 601 "ftp://host/file", |
600 FtpMockControlSocket::PRE_RETR, | 602 FtpMockControlSocket::PRE_RETR, |
601 FtpMockControlSocket::PRE_PASV2, | 603 FtpMockControlSocket::PRE_PASV2, |
602 "500 failed retr\r\n", | 604 "500 failed retr\r\n", |
603 ERR_FAILED); | 605 ERR_FAILED); |
604 } | 606 } |
605 | 607 |
606 } // namespace net | 608 } // namespace net |
OLD | NEW |