| 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
|
|
|