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

Unified Diff: net/http/http_stream_parser_unittest.cc

Issue 9270030: net: Don't merge HTTP headers and body if the body is not in memory. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix win build Created 8 years, 11 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
Index: net/http/http_stream_parser_unittest.cc
diff --git a/net/http/http_stream_parser_unittest.cc b/net/http/http_stream_parser_unittest.cc
index d40eac6267c73feb19f45ebea72065ddb0548f2a..1e96038c06493ea3ff9f4730c8ebd2434d7c46bf 100644
--- a/net/http/http_stream_parser_unittest.cc
+++ b/net/http/http_stream_parser_unittest.cc
@@ -4,9 +4,14 @@
#include "net/http/http_stream_parser.h"
+#include "base/file_path.h"
+#include "base/file_util.h"
+#include "base/scoped_temp_dir.h"
#include "base/string_piece.h"
#include "base/stringprintf.h"
#include "net/base/net_errors.h"
+#include "net/base/upload_data.h"
+#include "net/base/upload_data_stream.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace net {
@@ -74,4 +79,69 @@ TEST(HttpStreamParser, EncodeChunk_TooLargePayload) {
ASSERT_EQ(ERR_INVALID_ARGUMENT, num_bytes_written);
}
+TEST(HttpStreamParser, ShouldMerge_NoBody) {
+ // Shouldn't be merged if upload data is non-existent.
+ ASSERT_FALSE(HttpStreamParser::ShouldMerge("some header", NULL));
+}
+
+TEST(HttpStreamParser, ShouldMerge_EmptyBody) {
+ scoped_refptr<UploadData> upload_data = new UploadData;
+ scoped_ptr<UploadDataStream> body(
+ UploadDataStream::Create(upload_data.get(), NULL));
+ // Shouldn't be merged if upload data is empty.
+ ASSERT_FALSE(HttpStreamParser::ShouldMerge("some header", body.get()));
+}
+
+TEST(HttpStreamParser, ShouldMerge_ChunkedBody) {
+ scoped_refptr<UploadData> upload_data = new UploadData;
+ upload_data->set_is_chunked(true);
+ const std::string payload = "123";
+ upload_data->AppendChunk(payload.data(), payload.size(), true);
+
+ scoped_ptr<UploadDataStream> body(
+ UploadDataStream::Create(upload_data.get(), NULL));
+ // Shouldn't be merged if upload data carries chunked data.
+ ASSERT_FALSE(HttpStreamParser::ShouldMerge("some header", body.get()));
+}
+
+TEST(HttpStreamParser, ShouldMerge_FileBody) {
+ scoped_refptr<UploadData> upload_data = new UploadData;
+
+ // Create an empty temporary file.
+ ScopedTempDir temp_dir;
+ ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
+ FilePath temp_file_path;
+ ASSERT_TRUE(file_util::CreateTemporaryFileInDir(temp_dir.path(),
+ &temp_file_path));
+
+ upload_data->AppendFileRange(temp_file_path, 0, 0, base::Time());
+
+ scoped_ptr<UploadDataStream> body(
+ UploadDataStream::Create(upload_data.get(), NULL));
+ // Shouldn't be merged if upload data carries a file, as it's not in-memory.
+ ASSERT_FALSE(HttpStreamParser::ShouldMerge("some header", body.get()));
+}
+
+TEST(HttpStreamParser, ShouldMerge_SmallBodyInMemory) {
+ scoped_refptr<UploadData> upload_data = new UploadData;
+ const std::string payload = "123";
+ upload_data->AppendBytes(payload.data(), payload.size());
+
+ scoped_ptr<UploadDataStream> body(
+ UploadDataStream::Create(upload_data.get(), NULL));
+ // Yes, should be merged if the in-memory body is small here.
+ ASSERT_TRUE(HttpStreamParser::ShouldMerge("some header", body.get()));
+}
+
+TEST(HttpStreamParser, ShouldMerge_LargeBodyInMemory) {
+ scoped_refptr<UploadData> upload_data = new UploadData;
+ const std::string payload(10000, 'a'); // 'a' x 10000.
+ upload_data->AppendBytes(payload.data(), payload.size());
+
+ scoped_ptr<UploadDataStream> body(
+ UploadDataStream::Create(upload_data.get(), NULL));
+ // Shouldn't be merged if the in-memory body is large here.
+ ASSERT_FALSE(HttpStreamParser::ShouldMerge("some header", body.get()));
+}
+
} // namespace net

Powered by Google App Engine
This is Rietveld 408576698