Chromium Code Reviews| Index: net/http/http_chunked_decoder_unittest.cc |
| =================================================================== |
| --- net/http/http_chunked_decoder_unittest.cc (revision 28152) |
| +++ net/http/http_chunked_decoder_unittest.cc (working copy) |
| @@ -13,7 +13,8 @@ |
| void RunTest(const char* inputs[], size_t num_inputs, |
| const char* expected_output, |
| - bool expected_eof) { |
| + bool expected_eof, |
| + int bytes_after_eof) { |
| net::HttpChunkedDecoder decoder; |
| EXPECT_FALSE(decoder.reached_eof()); |
| @@ -27,8 +28,9 @@ |
| result.append(input.data(), n); |
| } |
| - EXPECT_TRUE(result == expected_output); |
| - EXPECT_TRUE(decoder.reached_eof() == expected_eof); |
| + EXPECT_EQ(result, expected_output); |
|
wtc
2009/10/12 18:48:19
Another nit: in these EXPECT_XX macros, the expect
|
| + EXPECT_EQ(decoder.reached_eof(), expected_eof); |
| + EXPECT_EQ(decoder.bytes_after_eof(), bytes_after_eof); |
| } |
| // Feed the inputs to the decoder, until it returns an error. |
| @@ -56,14 +58,14 @@ |
| const char* inputs[] = { |
| "5\r\nhello\r\n0\r\n\r\n" |
| }; |
| - RunTest(inputs, arraysize(inputs), "hello", true); |
| + RunTest(inputs, arraysize(inputs), "hello", true, 0); |
| } |
| TEST(HttpChunkedDecoderTest, OneChunk) { |
| const char* inputs[] = { |
| "5\r\nhello\r\n" |
| }; |
| - RunTest(inputs, arraysize(inputs), "hello", false); |
| + RunTest(inputs, arraysize(inputs), "hello", false, 0); |
| } |
| TEST(HttpChunkedDecoderTest, Typical) { |
| @@ -73,7 +75,7 @@ |
| "5\r\nworld\r\n", |
| "0\r\n\r\n" |
| }; |
| - RunTest(inputs, arraysize(inputs), "hello world", true); |
| + RunTest(inputs, arraysize(inputs), "hello world", true, 0); |
| } |
| TEST(HttpChunkedDecoderTest, Incremental) { |
| @@ -90,7 +92,7 @@ |
| "\r", |
| "\n" |
| }; |
| - RunTest(inputs, arraysize(inputs), "hello", true); |
| + RunTest(inputs, arraysize(inputs), "hello", true, 0); |
| } |
| TEST(HttpChunkedDecoderTest, LF_InsteadOf_CRLF) { |
| @@ -103,7 +105,7 @@ |
| "5\nworld\n", |
| "0\n\n" |
| }; |
| - RunTest(inputs, arraysize(inputs), "hello world", true); |
| + RunTest(inputs, arraysize(inputs), "hello world", true, 0); |
| } |
| TEST(HttpChunkedDecoderTest, Extensions) { |
| @@ -111,7 +113,7 @@ |
| "5;x=0\r\nhello\r\n", |
| "0;y=\"2 \"\r\n\r\n" |
| }; |
| - RunTest(inputs, arraysize(inputs), "hello", true); |
| + RunTest(inputs, arraysize(inputs), "hello", true, 0); |
| } |
| TEST(HttpChunkedDecoderTest, Trailers) { |
| @@ -122,7 +124,7 @@ |
| "Bar: 2\r\n", |
| "\r\n" |
| }; |
| - RunTest(inputs, arraysize(inputs), "hello", true); |
| + RunTest(inputs, arraysize(inputs), "hello", true, 0); |
| } |
| TEST(HttpChunkedDecoderTest, TrailersUnfinished) { |
| @@ -131,7 +133,7 @@ |
| "0\r\n", |
| "Foo: 1\r\n" |
| }; |
| - RunTest(inputs, arraysize(inputs), "hello", false); |
| + RunTest(inputs, arraysize(inputs), "hello", false, 0); |
| } |
| TEST(HttpChunkedDecoderTest, InvalidChunkSize_TooBig) { |
| @@ -165,7 +167,7 @@ |
| "5 \r\nhello\r\n", |
| "0\r\n\r\n" |
| }; |
| - RunTest(inputs, arraysize(inputs), "hello", true); |
| + RunTest(inputs, arraysize(inputs), "hello", true, 0); |
| } |
| TEST(HttpChunkedDecoderTest, InvalidChunkSize_TrailingTab) { |
| @@ -273,3 +275,35 @@ |
| }; |
| RunTestUntilFailure(inputs, arraysize(inputs), 0); |
| } |
| + |
| +TEST(HttpChunkedDecoderTest, BasicExtraData) { |
| + const char* inputs[] = { |
| + "5\r\nhello\r\n0\r\n\r\nextra bytes" |
| + }; |
| + RunTest(inputs, arraysize(inputs), "hello", true, 11); |
| +} |
| + |
| +TEST(HttpChunkedDecoderTest, IncrementalExtraData) { |
| + const char* inputs[] = { |
| + "5", |
| + "\r", |
| + "\n", |
| + "hello", |
| + "\r", |
| + "\n", |
| + "0", |
| + "\r", |
| + "\n", |
| + "\r", |
| + "\nextra bytes" |
| + }; |
| + RunTest(inputs, arraysize(inputs), "hello", true, 11); |
| +} |
| + |
| +TEST(HttpChunkedDecoderTest, MultipleExtraDataBlocks) { |
| + const char* inputs[] = { |
| + "5\r\nhello\r\n0\r\n\r\nextra", |
| + " bytes" |
| + }; |
| + RunTest(inputs, arraysize(inputs), "hello", true, 11); |
| +} |