Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(514)

Unified Diff: net/test/embedded_test_server/http_request_unittest.cc

Issue 935333002: Update from https://crrev.com/316786 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/test/embedded_test_server/http_request.cc ('k') | net/test/run_all_unittests.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/test/embedded_test_server/http_request_unittest.cc
diff --git a/net/test/embedded_test_server/http_request_unittest.cc b/net/test/embedded_test_server/http_request_unittest.cc
index 56121bbc8e60e5a626177b325f64ba0a02583ea8..ff2ae3cf968a3c224d98a6079f6010017a96a5f0 100644
--- a/net/test/embedded_test_server/http_request_unittest.cc
+++ b/net/test/embedded_test_server/http_request_unittest.cc
@@ -4,6 +4,7 @@
#include "net/test/embedded_test_server/http_request.h"
+#include "base/memory/scoped_ptr.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace net {
@@ -76,6 +77,48 @@ TEST(HttpRequestTest, ParseRequestWithEmptyBody) {
EXPECT_EQ("0", request->headers["Content-Length"]);
}
+TEST(HttpRequestTest, ParseRequestWithChunkedBody) {
+ HttpRequestParser parser;
+
+ parser.ProcessChunk("POST /foobar.html HTTP/1.1\r\n");
+ parser.ProcessChunk("Transfer-Encoding: chunked\r\n\r\n");
+ parser.ProcessChunk("5\r\nhello\r\n");
+ parser.ProcessChunk("1\r\n \r\n");
+ parser.ProcessChunk("5\r\nworld\r\n");
+ parser.ProcessChunk("0\r\n\r\n");
+ ASSERT_EQ(HttpRequestParser::ACCEPTED, parser.ParseRequest());
+
+ scoped_ptr<HttpRequest> request = parser.GetRequest();
+ EXPECT_EQ("hello world", request->content);
+ EXPECT_TRUE(request->has_content);
+ EXPECT_EQ(1u, request->headers.count("Transfer-Encoding"));
+ EXPECT_EQ("chunked", request->headers["Transfer-Encoding"]);
+}
+
+TEST(HttpRequestTest, ParseRequestWithChunkedBodySlow) {
+ HttpRequestParser parser;
+
+ parser.ProcessChunk("POST /foobar.html HTTP/1.1\r\n");
+ parser.ProcessChunk("Transfer-Encoding: chunked\r\n\r\n");
+ std::string chunked_body = "5\r\nhello\r\n0\r\n\r\n";
+
+ // Send one character at a time, and make the parser parse the request.
+ for (size_t i = 0; i < chunked_body.size(); i++) {
+ parser.ProcessChunk(chunked_body.substr(i, 1));
+ // Except for the last pass, ParseRequest() should give WAITING.
+ if (i != chunked_body.size() - 1) {
+ ASSERT_EQ(HttpRequestParser::WAITING, parser.ParseRequest());
+ }
+ }
+ // All chunked data has been sent, the last ParseRequest should give ACCEPTED.
+ ASSERT_EQ(HttpRequestParser::ACCEPTED, parser.ParseRequest());
+ scoped_ptr<HttpRequest> request = parser.GetRequest();
+ EXPECT_EQ("hello", request->content);
+ EXPECT_TRUE(request->has_content);
+ EXPECT_EQ(1u, request->headers.count("Transfer-Encoding"));
+ EXPECT_EQ("chunked", request->headers["Transfer-Encoding"]);
+}
+
TEST(HttpRequestTest, ParseRequestWithoutBody) {
HttpRequestParser parser;
« no previous file with comments | « net/test/embedded_test_server/http_request.cc ('k') | net/test/run_all_unittests.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698