| 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 "build/build_config.h" | 7 #include "build/build_config.h" |
| 8 | 8 |
| 9 #if defined(OS_WIN) | 9 #if defined(OS_WIN) |
| 10 #include <ws2tcpip.h> | 10 #include <ws2tcpip.h> |
| (...skipping 484 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 495 } | 495 } |
| 496 } | 496 } |
| 497 | 497 |
| 498 private: | 498 private: |
| 499 const char* expected_user_; | 499 const char* expected_user_; |
| 500 const char* expected_password_; | 500 const char* expected_password_; |
| 501 | 501 |
| 502 DISALLOW_COPY_AND_ASSIGN(FtpMockControlSocketEvilLogin); | 502 DISALLOW_COPY_AND_ASSIGN(FtpMockControlSocketEvilLogin); |
| 503 }; | 503 }; |
| 504 | 504 |
| 505 class FtpMockControlSocketCloseConnection : public FtpMockControlSocket { |
| 506 public: |
| 507 FtpMockControlSocketCloseConnection() { |
| 508 } |
| 509 |
| 510 virtual MockWriteResult OnWrite(const std::string& data) { |
| 511 if (InjectFault()) |
| 512 return MockWriteResult(true, data.length()); |
| 513 switch (state()) { |
| 514 case PRE_USER: |
| 515 return Verify("USER anonymous\r\n", data, |
| 516 PRE_QUIT, ""); |
| 517 default: |
| 518 return FtpMockControlSocket::OnWrite(data); |
| 519 } |
| 520 } |
| 521 |
| 522 private: |
| 523 DISALLOW_COPY_AND_ASSIGN(FtpMockControlSocketCloseConnection); |
| 524 }; |
| 525 |
| 505 class FtpNetworkTransactionTest : public PlatformTest { | 526 class FtpNetworkTransactionTest : public PlatformTest { |
| 506 public: | 527 public: |
| 507 FtpNetworkTransactionTest() | 528 FtpNetworkTransactionTest() |
| 508 : host_resolver_(new MockHostResolver), | 529 : host_resolver_(new MockHostResolver), |
| 509 session_(new FtpNetworkSession(host_resolver_)), | 530 session_(new FtpNetworkSession(host_resolver_)), |
| 510 transaction_(session_.get(), &mock_socket_factory_) { | 531 transaction_(session_.get(), &mock_socket_factory_) { |
| 511 } | 532 } |
| 512 | 533 |
| 513 protected: | 534 protected: |
| 514 FtpRequestInfo GetRequestInfo(const std::string& url) { | 535 FtpRequestInfo GetRequestInfo(const std::string& url) { |
| (...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 842 &callback_)); | 863 &callback_)); |
| 843 EXPECT_EQ(ERR_MALFORMED_IDENTITY, callback_.WaitForResult()); | 864 EXPECT_EQ(ERR_MALFORMED_IDENTITY, callback_.WaitForResult()); |
| 844 } | 865 } |
| 845 | 866 |
| 846 TEST_F(FtpNetworkTransactionTest, Escaping) { | 867 TEST_F(FtpNetworkTransactionTest, Escaping) { |
| 847 FtpMockControlSocketEscaping ctrl_socket; | 868 FtpMockControlSocketEscaping ctrl_socket; |
| 848 ExecuteTransaction(&ctrl_socket, "ftp://host/%20%21%22%23%24%25%79%80%81", | 869 ExecuteTransaction(&ctrl_socket, "ftp://host/%20%21%22%23%24%25%79%80%81", |
| 849 OK); | 870 OK); |
| 850 } | 871 } |
| 851 | 872 |
| 873 // Regression test for http://crbug.com/25023. |
| 874 TEST_F(FtpNetworkTransactionTest, CloseConnection) { |
| 875 FtpMockControlSocketCloseConnection ctrl_socket; |
| 876 ExecuteTransaction(&ctrl_socket, "ftp://host", ERR_EMPTY_RESPONSE); |
| 877 } |
| 878 |
| 852 TEST_F(FtpNetworkTransactionTest, DirectoryTransactionFailUser) { | 879 TEST_F(FtpNetworkTransactionTest, DirectoryTransactionFailUser) { |
| 853 FtpMockControlSocketDirectoryListing ctrl_socket; | 880 FtpMockControlSocketDirectoryListing ctrl_socket; |
| 854 TransactionFailHelper(&ctrl_socket, | 881 TransactionFailHelper(&ctrl_socket, |
| 855 "ftp://host", | 882 "ftp://host", |
| 856 FtpMockControlSocket::PRE_USER, | 883 FtpMockControlSocket::PRE_USER, |
| 857 FtpMockControlSocket::PRE_QUIT, | 884 FtpMockControlSocket::PRE_QUIT, |
| 858 "500 no such user\r\n", | 885 "500 no such user\r\n", |
| 859 ERR_FAILED); | 886 ERR_FAILED); |
| 860 } | 887 } |
| 861 | 888 |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1053 FtpMockControlSocketFileDownloadRetrFail ctrl_socket; | 1080 FtpMockControlSocketFileDownloadRetrFail ctrl_socket; |
| 1054 TransactionFailHelper(&ctrl_socket, | 1081 TransactionFailHelper(&ctrl_socket, |
| 1055 "ftp://host/file", | 1082 "ftp://host/file", |
| 1056 FtpMockControlSocket::PRE_RETR, | 1083 FtpMockControlSocket::PRE_RETR, |
| 1057 FtpMockControlSocket::PRE_PASV2, | 1084 FtpMockControlSocket::PRE_PASV2, |
| 1058 "550 cannot open file\r\n", | 1085 "550 cannot open file\r\n", |
| 1059 ERR_FILE_NOT_FOUND); | 1086 ERR_FILE_NOT_FOUND); |
| 1060 } | 1087 } |
| 1061 | 1088 |
| 1062 } // namespace net | 1089 } // namespace net |
| OLD | NEW |