summaryrefslogtreecommitdiffstats
path: root/net/http/http_chunked_decoder_unittest.cc
diff options
context:
space:
mode:
authorvandebo@chromium.org <vandebo@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-13 17:33:09 +0000
committervandebo@chromium.org <vandebo@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-13 17:33:09 +0000
commite1a96026a9403bfaa3c6efe120391261e5e795f4 (patch)
treebd97e3470f8d481e4464dcf5024ad311d2db707d /net/http/http_chunked_decoder_unittest.cc
parent8133c680452262815566bd8ba6c9b80ca8428780 (diff)
downloadchromium_src-e1a96026a9403bfaa3c6efe120391261e5e795f4.zip
chromium_src-e1a96026a9403bfaa3c6efe120391261e5e795f4.tar.gz
chromium_src-e1a96026a9403bfaa3c6efe120391261e5e795f4.tar.bz2
Add an interface to report the amount of data after a chunked encoding. This will be needed for pipelining. Separated out of http://codereview.chromium.org/249031.
BUG=13289 TEST=existing and added unittests Review URL: http://codereview.chromium.org/267042 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@28833 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/http/http_chunked_decoder_unittest.cc')
-rw-r--r--net/http/http_chunked_decoder_unittest.cc58
1 files changed, 46 insertions, 12 deletions
diff --git a/net/http/http_chunked_decoder_unittest.cc b/net/http/http_chunked_decoder_unittest.cc
index f335f0a..881ae0b 100644
--- a/net/http/http_chunked_decoder_unittest.cc
+++ b/net/http/http_chunked_decoder_unittest.cc
@@ -13,7 +13,8 @@ typedef testing::Test HttpChunkedDecoderTest;
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 @@ void RunTest(const char* inputs[], size_t num_inputs,
result.append(input.data(), n);
}
- EXPECT_TRUE(result == expected_output);
- EXPECT_TRUE(decoder.reached_eof() == expected_eof);
+ EXPECT_EQ(expected_output, result);
+ EXPECT_EQ(expected_eof, decoder.reached_eof());
+ EXPECT_EQ(bytes_after_eof, decoder.bytes_after_eof());
}
// Feed the inputs to the decoder, until it returns an error.
@@ -56,14 +58,14 @@ TEST(HttpChunkedDecoderTest, Basic) {
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 @@ TEST(HttpChunkedDecoderTest, Typical) {
"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 @@ TEST(HttpChunkedDecoderTest, Incremental) {
"\r",
"\n"
};
- RunTest(inputs, arraysize(inputs), "hello", true);
+ RunTest(inputs, arraysize(inputs), "hello", true, 0);
}
TEST(HttpChunkedDecoderTest, LF_InsteadOf_CRLF) {
@@ -103,7 +105,7 @@ TEST(HttpChunkedDecoderTest, LF_InsteadOf_CRLF) {
"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 @@ TEST(HttpChunkedDecoderTest, Extensions) {
"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 @@ TEST(HttpChunkedDecoderTest, Trailers) {
"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 @@ TEST(HttpChunkedDecoderTest, TrailersUnfinished) {
"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 @@ TEST(HttpChunkedDecoderTest, ChunkSize_TrailingSpace) {
"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 @@ TEST(HttpChunkedDecoderTest, ExcessiveChunkLen) {
};
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);
+}