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

Side by Side Diff: net/http/http_stream_parser_unittest.cc

Issue 9284033: net: Give more descriptive names for code around the request merging logic. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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 unified diff | Download patch | Annotate | Revision Log
« net/base/upload_data.cc ('K') | « net/http/http_stream_parser.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "net/http/http_stream_parser.h" 5 #include "net/http/http_stream_parser.h"
6 6
7 #include "base/file_path.h" 7 #include "base/file_path.h"
8 #include "base/file_util.h" 8 #include "base/file_util.h"
9 #include "base/scoped_temp_dir.h" 9 #include "base/scoped_temp_dir.h"
10 #include "base/string_piece.h" 10 #include "base/string_piece.h"
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 TEST(HttpStreamParser, EncodeChunk_TooLargePayload) { 72 TEST(HttpStreamParser, EncodeChunk_TooLargePayload) {
73 char output[kOutputSize]; 73 char output[kOutputSize];
74 74
75 // The payload is one byte larger the output buffer size. 75 // The payload is one byte larger the output buffer size.
76 const std::string kPayload(kMaxPayloadSize + 1, '\xff'); 76 const std::string kPayload(kMaxPayloadSize + 1, '\xff');
77 const int num_bytes_written = 77 const int num_bytes_written =
78 HttpStreamParser::EncodeChunk(kPayload, output, sizeof(output)); 78 HttpStreamParser::EncodeChunk(kPayload, output, sizeof(output));
79 ASSERT_EQ(ERR_INVALID_ARGUMENT, num_bytes_written); 79 ASSERT_EQ(ERR_INVALID_ARGUMENT, num_bytes_written);
80 } 80 }
81 81
82 TEST(HttpStreamParser, ShouldMerge_NoBody) { 82 TEST(HttpStreamParser, ShouldMergeRequestHeadersAndBody_NoBody) {
83 // Shouldn't be merged if upload data is non-existent. 83 // Shouldn't be merged if upload data is non-existent.
84 ASSERT_FALSE(HttpStreamParser::ShouldMerge("some header", NULL)); 84 ASSERT_FALSE(HttpStreamParser::ShouldMergeRequestHeadersAndBody(
85 "some header", NULL));
85 } 86 }
86 87
87 TEST(HttpStreamParser, ShouldMerge_EmptyBody) { 88 TEST(HttpStreamParser, ShouldMergeRequestHeadersAndBody_EmptyBody) {
88 scoped_refptr<UploadData> upload_data = new UploadData; 89 scoped_refptr<UploadData> upload_data = new UploadData;
89 scoped_ptr<UploadDataStream> body( 90 scoped_ptr<UploadDataStream> body(
90 UploadDataStream::Create(upload_data.get(), NULL)); 91 UploadDataStream::Create(upload_data.get(), NULL));
91 // Shouldn't be merged if upload data is empty. 92 // Shouldn't be merged if upload data is empty.
92 ASSERT_FALSE(HttpStreamParser::ShouldMerge("some header", body.get())); 93 ASSERT_FALSE(HttpStreamParser::ShouldMergeRequestHeadersAndBody(
94 "some header", body.get()));
93 } 95 }
94 96
95 TEST(HttpStreamParser, ShouldMerge_ChunkedBody) { 97 TEST(HttpStreamParser, ShouldMergeRequestHeadersAndBody_ChunkedBody) {
96 scoped_refptr<UploadData> upload_data = new UploadData; 98 scoped_refptr<UploadData> upload_data = new UploadData;
97 upload_data->set_is_chunked(true); 99 upload_data->set_is_chunked(true);
98 const std::string payload = "123"; 100 const std::string payload = "123";
99 upload_data->AppendChunk(payload.data(), payload.size(), true); 101 upload_data->AppendChunk(payload.data(), payload.size(), true);
100 102
101 scoped_ptr<UploadDataStream> body( 103 scoped_ptr<UploadDataStream> body(
102 UploadDataStream::Create(upload_data.get(), NULL)); 104 UploadDataStream::Create(upload_data.get(), NULL));
103 // Shouldn't be merged if upload data carries chunked data. 105 // Shouldn't be merged if upload data carries chunked data.
104 ASSERT_FALSE(HttpStreamParser::ShouldMerge("some header", body.get())); 106 ASSERT_FALSE(HttpStreamParser::ShouldMergeRequestHeadersAndBody(
107 "some header", body.get()));
105 } 108 }
106 109
107 TEST(HttpStreamParser, ShouldMerge_FileBody) { 110 TEST(HttpStreamParser, ShouldMergeRequestHeadersAndBody_FileBody) {
108 scoped_refptr<UploadData> upload_data = new UploadData; 111 scoped_refptr<UploadData> upload_data = new UploadData;
109 112
110 // Create an empty temporary file. 113 // Create an empty temporary file.
111 ScopedTempDir temp_dir; 114 ScopedTempDir temp_dir;
112 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 115 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
113 FilePath temp_file_path; 116 FilePath temp_file_path;
114 ASSERT_TRUE(file_util::CreateTemporaryFileInDir(temp_dir.path(), 117 ASSERT_TRUE(file_util::CreateTemporaryFileInDir(temp_dir.path(),
115 &temp_file_path)); 118 &temp_file_path));
116 119
117 upload_data->AppendFileRange(temp_file_path, 0, 0, base::Time()); 120 upload_data->AppendFileRange(temp_file_path, 0, 0, base::Time());
118 121
119 scoped_ptr<UploadDataStream> body( 122 scoped_ptr<UploadDataStream> body(
120 UploadDataStream::Create(upload_data.get(), NULL)); 123 UploadDataStream::Create(upload_data.get(), NULL));
121 // Shouldn't be merged if upload data carries a file, as it's not in-memory. 124 // Shouldn't be merged if upload data carries a file, as it's not in-memory.
122 ASSERT_FALSE(HttpStreamParser::ShouldMerge("some header", body.get())); 125 ASSERT_FALSE(HttpStreamParser::ShouldMergeRequestHeadersAndBody(
126 "some header", body.get()));
123 } 127 }
124 128
125 TEST(HttpStreamParser, ShouldMerge_SmallBodyInMemory) { 129 TEST(HttpStreamParser, ShouldMergeRequestHeadersAndBody_SmallBodyInMemory) {
126 scoped_refptr<UploadData> upload_data = new UploadData; 130 scoped_refptr<UploadData> upload_data = new UploadData;
127 const std::string payload = "123"; 131 const std::string payload = "123";
128 upload_data->AppendBytes(payload.data(), payload.size()); 132 upload_data->AppendBytes(payload.data(), payload.size());
129 133
130 scoped_ptr<UploadDataStream> body( 134 scoped_ptr<UploadDataStream> body(
131 UploadDataStream::Create(upload_data.get(), NULL)); 135 UploadDataStream::Create(upload_data.get(), NULL));
132 // Yes, should be merged if the in-memory body is small here. 136 // Yes, should be merged if the in-memory body is small here.
133 ASSERT_TRUE(HttpStreamParser::ShouldMerge("some header", body.get())); 137 ASSERT_TRUE(HttpStreamParser::ShouldMergeRequestHeadersAndBody(
138 "some header", body.get()));
134 } 139 }
135 140
136 TEST(HttpStreamParser, ShouldMerge_LargeBodyInMemory) { 141 TEST(HttpStreamParser, ShouldMergeRequestHeadersAndBody_LargeBodyInMemory) {
137 scoped_refptr<UploadData> upload_data = new UploadData; 142 scoped_refptr<UploadData> upload_data = new UploadData;
138 const std::string payload(10000, 'a'); // 'a' x 10000. 143 const std::string payload(10000, 'a'); // 'a' x 10000.
139 upload_data->AppendBytes(payload.data(), payload.size()); 144 upload_data->AppendBytes(payload.data(), payload.size());
140 145
141 scoped_ptr<UploadDataStream> body( 146 scoped_ptr<UploadDataStream> body(
142 UploadDataStream::Create(upload_data.get(), NULL)); 147 UploadDataStream::Create(upload_data.get(), NULL));
143 // Shouldn't be merged if the in-memory body is large here. 148 // Shouldn't be merged if the in-memory body is large here.
144 ASSERT_FALSE(HttpStreamParser::ShouldMerge("some header", body.get())); 149 ASSERT_FALSE(HttpStreamParser::ShouldMergeRequestHeadersAndBody(
150 "some header", body.get()));
145 } 151 }
146 152
147 } // namespace net 153 } // namespace net
OLDNEW
« net/base/upload_data.cc ('K') | « net/http/http_stream_parser.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698