OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 "base/basictypes.h" | 5 #include "base/basictypes.h" |
6 #include "net/base/net_errors.h" | 6 #include "net/base/net_errors.h" |
7 #include "net/http/http_chunked_decoder.h" | 7 #include "net/http/http_chunked_decoder.h" |
8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
9 | 9 |
10 namespace { | 10 namespace { |
(...skipping 14 matching lines...) Expand all Loading... |
25 EXPECT_GE(n, 0); | 25 EXPECT_GE(n, 0); |
26 if (n > 0) | 26 if (n > 0) |
27 result.append(input.data(), n); | 27 result.append(input.data(), n); |
28 } | 28 } |
29 | 29 |
30 EXPECT_TRUE(result == expected_output); | 30 EXPECT_TRUE(result == expected_output); |
31 EXPECT_TRUE(decoder.reached_eof() == expected_eof); | 31 EXPECT_TRUE(decoder.reached_eof() == expected_eof); |
32 } | 32 } |
33 | 33 |
34 // Feed the inputs to the decoder, until it returns an error. | 34 // Feed the inputs to the decoder, until it returns an error. |
35 void RunTestUntilFailure(const char* inputs[], size_t num_inputs, size_t fail_in
dex) { | 35 void RunTestUntilFailure(const char* inputs[], |
| 36 size_t num_inputs, |
| 37 size_t fail_index) { |
36 net::HttpChunkedDecoder decoder; | 38 net::HttpChunkedDecoder decoder; |
37 EXPECT_FALSE(decoder.reached_eof()); | 39 EXPECT_FALSE(decoder.reached_eof()); |
38 | 40 |
39 for (size_t i = 0; i < num_inputs; ++i) { | 41 for (size_t i = 0; i < num_inputs; ++i) { |
40 std::string input = inputs[i]; | 42 std::string input = inputs[i]; |
41 int n = decoder.FilterBuf(&input[0], static_cast<int>(input.size())); | 43 int n = decoder.FilterBuf(&input[0], static_cast<int>(input.size())); |
42 if (n < 0) { | 44 if (n < 0) { |
43 EXPECT_EQ(net::ERR_INVALID_CHUNKED_ENCODING, n); | 45 EXPECT_EQ(net::ERR_INVALID_CHUNKED_ENCODING, n); |
44 EXPECT_EQ(fail_index, i); | 46 EXPECT_EQ(fail_index, i); |
45 return; | 47 return; |
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
258 | 260 |
259 TEST(HttpChunkedDecoderTest, InvalidConsecutiveCRLFs) { | 261 TEST(HttpChunkedDecoderTest, InvalidConsecutiveCRLFs) { |
260 const char* inputs[] = { | 262 const char* inputs[] = { |
261 "5\r\nhello\r\n", | 263 "5\r\nhello\r\n", |
262 "\r\n\r\n\r\n\r\n", | 264 "\r\n\r\n\r\n\r\n", |
263 "0\r\n\r\n" | 265 "0\r\n\r\n" |
264 }; | 266 }; |
265 RunTestUntilFailure(inputs, arraysize(inputs), 1); | 267 RunTestUntilFailure(inputs, arraysize(inputs), 1); |
266 } | 268 } |
267 | 269 |
OLD | NEW |