| 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_ctrl_response_buffer.h" | 5 #include "net/ftp/ftp_ctrl_response_buffer.h" |
| 6 | 6 |
| 7 #include <string.h> | 7 #include <string.h> |
| 8 | 8 |
| 9 #include "net/base/net_errors.h" | 9 #include "net/base/net_errors.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 | 89 |
| 90 net::FtpCtrlResponse response = buffer_.PopResponse(); | 90 net::FtpCtrlResponse response = buffer_.PopResponse(); |
| 91 EXPECT_FALSE(buffer_.ResponseAvailable()); | 91 EXPECT_FALSE(buffer_.ResponseAvailable()); |
| 92 EXPECT_EQ(230, response.status_code); | 92 EXPECT_EQ(230, response.status_code); |
| 93 ASSERT_EQ(3U, response.lines.size()); | 93 ASSERT_EQ(3U, response.lines.size()); |
| 94 EXPECT_EQ("FirstLineContinued", response.lines[0]); | 94 EXPECT_EQ("FirstLineContinued", response.lines[0]); |
| 95 EXPECT_EQ("SecondLine215 Continued", response.lines[1]); | 95 EXPECT_EQ("SecondLine215 Continued", response.lines[1]); |
| 96 EXPECT_EQ("LastLine", response.lines[2]); | 96 EXPECT_EQ("LastLine", response.lines[2]); |
| 97 } | 97 } |
| 98 | 98 |
| 99 TEST_F(FtpCtrlResponseBufferTest, MultilineContinuationZeroLength) { |
| 100 // For the corner case from bug 29322. |
| 101 EXPECT_EQ(net::OK, PushDataToBuffer("230-\r\n")); |
| 102 EXPECT_FALSE(buffer_.ResponseAvailable()); |
| 103 |
| 104 EXPECT_EQ(net::OK, PushDataToBuffer("example.com\r\n")); |
| 105 EXPECT_FALSE(buffer_.ResponseAvailable()); |
| 106 |
| 107 EXPECT_EQ(net::OK, PushDataToBuffer("230 LastLine\r\n")); |
| 108 EXPECT_TRUE(buffer_.ResponseAvailable()); |
| 109 |
| 110 net::FtpCtrlResponse response = buffer_.PopResponse(); |
| 111 EXPECT_FALSE(buffer_.ResponseAvailable()); |
| 112 EXPECT_EQ(230, response.status_code); |
| 113 ASSERT_EQ(2U, response.lines.size()); |
| 114 EXPECT_EQ("example.com", response.lines[0]); |
| 115 EXPECT_EQ("LastLine", response.lines[1]); |
| 116 } |
| 117 |
| 99 TEST_F(FtpCtrlResponseBufferTest, SimilarContinuation) { | 118 TEST_F(FtpCtrlResponseBufferTest, SimilarContinuation) { |
| 100 EXPECT_EQ(net::OK, PushDataToBuffer("230-FirstLine\r\n")); | 119 EXPECT_EQ(net::OK, PushDataToBuffer("230-FirstLine\r\n")); |
| 101 EXPECT_FALSE(buffer_.ResponseAvailable()); | 120 EXPECT_FALSE(buffer_.ResponseAvailable()); |
| 102 | 121 |
| 103 // Notice the space at the start of the line. It should be recognized | 122 // Notice the space at the start of the line. It should be recognized |
| 104 // as a continuation, and not the last line. | 123 // as a continuation, and not the last line. |
| 105 EXPECT_EQ(net::OK, PushDataToBuffer(" 230 Continued\r\n")); | 124 EXPECT_EQ(net::OK, PushDataToBuffer(" 230 Continued\r\n")); |
| 106 EXPECT_FALSE(buffer_.ResponseAvailable()); | 125 EXPECT_FALSE(buffer_.ResponseAvailable()); |
| 107 | 126 |
| 108 EXPECT_EQ(net::OK, PushDataToBuffer("230 TrueLastLine\r\n")); | 127 EXPECT_EQ(net::OK, PushDataToBuffer("230 TrueLastLine\r\n")); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 EXPECT_EQ(net::ERR_INVALID_RESPONSE, PushDataToBuffer("Non-numeric\r\n")); | 162 EXPECT_EQ(net::ERR_INVALID_RESPONSE, PushDataToBuffer("Non-numeric\r\n")); |
| 144 EXPECT_FALSE(buffer_.ResponseAvailable()); | 163 EXPECT_FALSE(buffer_.ResponseAvailable()); |
| 145 } | 164 } |
| 146 | 165 |
| 147 TEST_F(FtpCtrlResponseBufferTest, OutOfRangeResponse) { | 166 TEST_F(FtpCtrlResponseBufferTest, OutOfRangeResponse) { |
| 148 EXPECT_EQ(net::ERR_INVALID_RESPONSE, PushDataToBuffer("777 OK?\r\n")); | 167 EXPECT_EQ(net::ERR_INVALID_RESPONSE, PushDataToBuffer("777 OK?\r\n")); |
| 149 EXPECT_FALSE(buffer_.ResponseAvailable()); | 168 EXPECT_FALSE(buffer_.ResponseAvailable()); |
| 150 } | 169 } |
| 151 | 170 |
| 152 } // namespace | 171 } // namespace |
| OLD | NEW |