| 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 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 return Verify("RETR /file\r\n", data, PRE_QUIT, "200 OK\r\n"); | 201 return Verify("RETR /file\r\n", data, PRE_QUIT, "200 OK\r\n"); |
| 202 default: | 202 default: |
| 203 return FtpMockControlSocket::OnWrite(data); | 203 return FtpMockControlSocket::OnWrite(data); |
| 204 } | 204 } |
| 205 } | 205 } |
| 206 | 206 |
| 207 private: | 207 private: |
| 208 DISALLOW_COPY_AND_ASSIGN(FtpMockControlSocketFileDownload); | 208 DISALLOW_COPY_AND_ASSIGN(FtpMockControlSocketFileDownload); |
| 209 }; | 209 }; |
| 210 | 210 |
| 211 class FtpMockControlSocketFileDownloadTransferStarting |
| 212 : public FtpMockControlSocketFileDownload { |
| 213 public: |
| 214 FtpMockControlSocketFileDownloadTransferStarting() { |
| 215 } |
| 216 |
| 217 virtual MockWriteResult OnWrite(const std::string& data) { |
| 218 if (InjectFault()) |
| 219 return MockWriteResult(true, data.length()); |
| 220 switch (state()) { |
| 221 case PRE_RETR: |
| 222 return Verify("RETR /file\r\n", data, PRE_QUIT, |
| 223 "125-Data connection already open.\r\n" |
| 224 "125 Transfer starting.\r\n" |
| 225 "226 Transfer complete.\r\n"); |
| 226 default: |
| 227 return FtpMockControlSocketFileDownload::OnWrite(data); |
| 228 } |
| 229 } |
| 230 |
| 231 private: |
| 232 DISALLOW_COPY_AND_ASSIGN(FtpMockControlSocketFileDownloadTransferStarting); |
| 233 }; |
| 234 |
| 211 class FtpMockControlSocketFileDownloadRetrFail | 235 class FtpMockControlSocketFileDownloadRetrFail |
| 212 : public FtpMockControlSocketFileDownload { | 236 : public FtpMockControlSocketFileDownload { |
| 213 public: | 237 public: |
| 214 FtpMockControlSocketFileDownloadRetrFail() { | 238 FtpMockControlSocketFileDownloadRetrFail() { |
| 215 } | 239 } |
| 216 | 240 |
| 217 virtual MockWriteResult OnWrite(const std::string& data) { | 241 virtual MockWriteResult OnWrite(const std::string& data) { |
| 218 if (InjectFault()) | 242 if (InjectFault()) |
| 219 return MockWriteResult(true, data.length()); | 243 return MockWriteResult(true, data.length()); |
| 220 switch (state()) { | 244 switch (state()) { |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 349 ctrl_socket.set_short_read_limit(2); | 373 ctrl_socket.set_short_read_limit(2); |
| 350 ExecuteTransaction(&ctrl_socket, "ftp://host/file", OK); | 374 ExecuteTransaction(&ctrl_socket, "ftp://host/file", OK); |
| 351 } | 375 } |
| 352 | 376 |
| 353 TEST_F(FtpNetworkTransactionTest, DownloadTransactionShortReads5) { | 377 TEST_F(FtpNetworkTransactionTest, DownloadTransactionShortReads5) { |
| 354 FtpMockControlSocketFileDownload ctrl_socket; | 378 FtpMockControlSocketFileDownload ctrl_socket; |
| 355 ctrl_socket.set_short_read_limit(5); | 379 ctrl_socket.set_short_read_limit(5); |
| 356 ExecuteTransaction(&ctrl_socket, "ftp://host/file", OK); | 380 ExecuteTransaction(&ctrl_socket, "ftp://host/file", OK); |
| 357 } | 381 } |
| 358 | 382 |
| 383 TEST_F(FtpNetworkTransactionTest, DownloadTransactionTransferStarting) { |
| 384 FtpMockControlSocketFileDownloadTransferStarting ctrl_socket; |
| 385 ExecuteTransaction(&ctrl_socket, "ftp://host/file", OK); |
| 386 } |
| 387 |
| 388 |
| 359 TEST_F(FtpNetworkTransactionTest, DirectoryTransactionFailUser) { | 389 TEST_F(FtpNetworkTransactionTest, DirectoryTransactionFailUser) { |
| 360 FtpMockControlSocketDirectoryListing ctrl_socket; | 390 FtpMockControlSocketDirectoryListing ctrl_socket; |
| 361 TransactionFailHelper(&ctrl_socket, | 391 TransactionFailHelper(&ctrl_socket, |
| 362 "ftp://host", | 392 "ftp://host", |
| 363 FtpMockControlSocket::PRE_USER, | 393 FtpMockControlSocket::PRE_USER, |
| 364 FtpMockControlSocket::PRE_QUIT, | 394 FtpMockControlSocket::PRE_QUIT, |
| 365 "500 no such user\r\n", | 395 "500 no such user\r\n", |
| 366 ERR_FAILED); | 396 ERR_FAILED); |
| 367 } | 397 } |
| 368 | 398 |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 540 FtpMockControlSocketFileDownloadRetrFail ctrl_socket; | 570 FtpMockControlSocketFileDownloadRetrFail ctrl_socket; |
| 541 TransactionFailHelper(&ctrl_socket, | 571 TransactionFailHelper(&ctrl_socket, |
| 542 "ftp://host/file", | 572 "ftp://host/file", |
| 543 FtpMockControlSocket::PRE_RETR, | 573 FtpMockControlSocket::PRE_RETR, |
| 544 FtpMockControlSocket::PRE_PASV2, | 574 FtpMockControlSocket::PRE_PASV2, |
| 545 "500 failed retr\r\n", | 575 "500 failed retr\r\n", |
| 546 ERR_FAILED); | 576 ERR_FAILED); |
| 547 } | 577 } |
| 548 | 578 |
| 549 } // namespace net | 579 } // namespace net |
| OLD | NEW |