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

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

Issue 11275088: Remove implicit scoped_refptr operator T* Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 8 years, 1 month 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
« no previous file with comments | « net/http/http_stream_factory_impl_request.cc ('k') | net/http/http_transaction_unittest.cc » ('j') | 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/memory/ref_counted.h" 9 #include "base/memory/ref_counted.h"
10 #include "base/scoped_temp_dir.h" 10 #include "base/scoped_temp_dir.h"
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 } 89 }
90 90
91 TEST(HttpStreamParser, ShouldMergeRequestHeadersAndBody_NoBody) { 91 TEST(HttpStreamParser, ShouldMergeRequestHeadersAndBody_NoBody) {
92 // Shouldn't be merged if upload data is non-existent. 92 // Shouldn't be merged if upload data is non-existent.
93 ASSERT_FALSE(HttpStreamParser::ShouldMergeRequestHeadersAndBody( 93 ASSERT_FALSE(HttpStreamParser::ShouldMergeRequestHeadersAndBody(
94 "some header", NULL)); 94 "some header", NULL));
95 } 95 }
96 96
97 TEST(HttpStreamParser, ShouldMergeRequestHeadersAndBody_EmptyBody) { 97 TEST(HttpStreamParser, ShouldMergeRequestHeadersAndBody_EmptyBody) {
98 scoped_refptr<UploadData> upload_data = new UploadData; 98 scoped_refptr<UploadData> upload_data = new UploadData;
99 scoped_ptr<UploadDataStream> body(new UploadDataStream(upload_data)); 99 scoped_ptr<UploadDataStream> body(new UploadDataStream(upload_data.get()));
100 ASSERT_EQ(OK, body->InitSync()); 100 ASSERT_EQ(OK, body->InitSync());
101 // Shouldn't be merged if upload data is empty. 101 // Shouldn't be merged if upload data is empty.
102 ASSERT_FALSE(HttpStreamParser::ShouldMergeRequestHeadersAndBody( 102 ASSERT_FALSE(HttpStreamParser::ShouldMergeRequestHeadersAndBody(
103 "some header", body.get())); 103 "some header", body.get()));
104 } 104 }
105 105
106 TEST(HttpStreamParser, ShouldMergeRequestHeadersAndBody_ChunkedBody) { 106 TEST(HttpStreamParser, ShouldMergeRequestHeadersAndBody_ChunkedBody) {
107 scoped_refptr<UploadData> upload_data = new UploadData; 107 scoped_refptr<UploadData> upload_data = new UploadData;
108 upload_data->set_is_chunked(true); 108 upload_data->set_is_chunked(true);
109 const std::string payload = "123"; 109 const std::string payload = "123";
110 upload_data->AppendChunk(payload.data(), payload.size(), true); 110 upload_data->AppendChunk(payload.data(), payload.size(), true);
111 111
112 scoped_ptr<UploadDataStream> body(new UploadDataStream(upload_data)); 112 scoped_ptr<UploadDataStream> body(new UploadDataStream(upload_data.get()));
113 ASSERT_EQ(OK, body->InitSync()); 113 ASSERT_EQ(OK, body->InitSync());
114 // Shouldn't be merged if upload data carries chunked data. 114 // Shouldn't be merged if upload data carries chunked data.
115 ASSERT_FALSE(HttpStreamParser::ShouldMergeRequestHeadersAndBody( 115 ASSERT_FALSE(HttpStreamParser::ShouldMergeRequestHeadersAndBody(
116 "some header", body.get())); 116 "some header", body.get()));
117 } 117 }
118 118
119 TEST(HttpStreamParser, ShouldMergeRequestHeadersAndBody_FileBody) { 119 TEST(HttpStreamParser, ShouldMergeRequestHeadersAndBody_FileBody) {
120 scoped_refptr<UploadData> upload_data = new UploadData; 120 scoped_refptr<UploadData> upload_data = new UploadData;
121 121
122 // Create an empty temporary file. 122 // Create an empty temporary file.
123 ScopedTempDir temp_dir; 123 ScopedTempDir temp_dir;
124 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 124 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
125 FilePath temp_file_path; 125 FilePath temp_file_path;
126 ASSERT_TRUE(file_util::CreateTemporaryFileInDir(temp_dir.path(), 126 ASSERT_TRUE(file_util::CreateTemporaryFileInDir(temp_dir.path(),
127 &temp_file_path)); 127 &temp_file_path));
128 128
129 upload_data->AppendFileRange(temp_file_path, 0, 0, base::Time()); 129 upload_data->AppendFileRange(temp_file_path, 0, 0, base::Time());
130 130
131 scoped_ptr<UploadDataStream> body(new UploadDataStream(upload_data)); 131 scoped_ptr<UploadDataStream> body(new UploadDataStream(upload_data.get()));
132 ASSERT_EQ(OK, body->InitSync()); 132 ASSERT_EQ(OK, body->InitSync());
133 // Shouldn't be merged if upload data carries a file, as it's not in-memory. 133 // Shouldn't be merged if upload data carries a file, as it's not in-memory.
134 ASSERT_FALSE(HttpStreamParser::ShouldMergeRequestHeadersAndBody( 134 ASSERT_FALSE(HttpStreamParser::ShouldMergeRequestHeadersAndBody(
135 "some header", body.get())); 135 "some header", body.get()));
136 } 136 }
137 137
138 TEST(HttpStreamParser, ShouldMergeRequestHeadersAndBody_SmallBodyInMemory) { 138 TEST(HttpStreamParser, ShouldMergeRequestHeadersAndBody_SmallBodyInMemory) {
139 scoped_refptr<UploadData> upload_data = new UploadData; 139 scoped_refptr<UploadData> upload_data = new UploadData;
140 const std::string payload = "123"; 140 const std::string payload = "123";
141 upload_data->AppendBytes(payload.data(), payload.size()); 141 upload_data->AppendBytes(payload.data(), payload.size());
142 142
143 scoped_ptr<UploadDataStream> body(new UploadDataStream(upload_data)); 143 scoped_ptr<UploadDataStream> body(new UploadDataStream(upload_data.get()));
144 ASSERT_EQ(OK, body->InitSync()); 144 ASSERT_EQ(OK, body->InitSync());
145 // Yes, should be merged if the in-memory body is small here. 145 // Yes, should be merged if the in-memory body is small here.
146 ASSERT_TRUE(HttpStreamParser::ShouldMergeRequestHeadersAndBody( 146 ASSERT_TRUE(HttpStreamParser::ShouldMergeRequestHeadersAndBody(
147 "some header", body.get())); 147 "some header", body.get()));
148 } 148 }
149 149
150 TEST(HttpStreamParser, ShouldMergeRequestHeadersAndBody_LargeBodyInMemory) { 150 TEST(HttpStreamParser, ShouldMergeRequestHeadersAndBody_LargeBodyInMemory) {
151 scoped_refptr<UploadData> upload_data = new UploadData; 151 scoped_refptr<UploadData> upload_data = new UploadData;
152 const std::string payload(10000, 'a'); // 'a' x 10000. 152 const std::string payload(10000, 'a'); // 'a' x 10000.
153 upload_data->AppendBytes(payload.data(), payload.size()); 153 upload_data->AppendBytes(payload.data(), payload.size());
154 154
155 scoped_ptr<UploadDataStream> body(new UploadDataStream(upload_data)); 155 scoped_ptr<UploadDataStream> body(new UploadDataStream(upload_data.get()));
156 ASSERT_EQ(OK, body->InitSync()); 156 ASSERT_EQ(OK, body->InitSync());
157 // Shouldn't be merged if the in-memory body is large here. 157 // Shouldn't be merged if the in-memory body is large here.
158 ASSERT_FALSE(HttpStreamParser::ShouldMergeRequestHeadersAndBody( 158 ASSERT_FALSE(HttpStreamParser::ShouldMergeRequestHeadersAndBody(
159 "some header", body.get())); 159 "some header", body.get()));
160 } 160 }
161 161
162 // Test to ensure the HttpStreamParser state machine does not get confused 162 // Test to ensure the HttpStreamParser state machine does not get confused
163 // when sending a request with a chunked body, where chunks become available 163 // when sending a request with a chunked body, where chunks become available
164 // asynchronously, over a socket where writes may also complete 164 // asynchronously, over a socket where writes may also complete
165 // asynchronously. 165 // asynchronously.
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 209
210 scoped_ptr<ClientSocketHandle> socket_handle(new ClientSocketHandle); 210 scoped_ptr<ClientSocketHandle> socket_handle(new ClientSocketHandle);
211 socket_handle->set_socket(transport.release()); 211 socket_handle->set_socket(transport.release());
212 212
213 HttpRequestInfo request_info; 213 HttpRequestInfo request_info;
214 request_info.method = "GET"; 214 request_info.method = "GET";
215 request_info.url = GURL("http://localhost"); 215 request_info.url = GURL("http://localhost");
216 request_info.load_flags = LOAD_NORMAL; 216 request_info.load_flags = LOAD_NORMAL;
217 217
218 scoped_refptr<GrowableIOBuffer> read_buffer(new GrowableIOBuffer); 218 scoped_refptr<GrowableIOBuffer> read_buffer(new GrowableIOBuffer);
219 HttpStreamParser parser(socket_handle.get(), &request_info, read_buffer, 219 HttpStreamParser parser(socket_handle.get(), &request_info, read_buffer.get(),
220 BoundNetLog()); 220 BoundNetLog());
221 221
222 scoped_refptr<UploadData> upload_data(new UploadData); 222 scoped_refptr<UploadData> upload_data(new UploadData);
223 upload_data->set_is_chunked(true); 223 upload_data->set_is_chunked(true);
224 224
225 upload_data->AppendChunk(kChunk1, arraysize(kChunk1) - 1, false); 225 upload_data->AppendChunk(kChunk1, arraysize(kChunk1) - 1, false);
226 226
227 scoped_ptr<UploadDataStream> upload_stream( 227 scoped_ptr<UploadDataStream> upload_stream(
228 new UploadDataStream(upload_data)); 228 new UploadDataStream(upload_data.get()));
229 ASSERT_EQ(OK, upload_stream->InitSync()); 229 ASSERT_EQ(OK, upload_stream->InitSync());
230 230
231 HttpRequestHeaders request_headers; 231 HttpRequestHeaders request_headers;
232 request_headers.SetHeader("Host", "localhost"); 232 request_headers.SetHeader("Host", "localhost");
233 request_headers.SetHeader("Transfer-Encoding", "chunked"); 233 request_headers.SetHeader("Transfer-Encoding", "chunked");
234 request_headers.SetHeader("Connection", "keep-alive"); 234 request_headers.SetHeader("Connection", "keep-alive");
235 235
236 HttpResponseInfo response_info; 236 HttpResponseInfo response_info;
237 // This will attempt to Write() the initial request and headers, which will 237 // This will attempt to Write() the initial request and headers, which will
238 // complete asynchronously. 238 // complete asynchronously.
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 rv = parser.ReadResponseHeaders(callback.callback()); 286 rv = parser.ReadResponseHeaders(callback.callback());
287 ASSERT_EQ(ERR_IO_PENDING, rv); 287 ASSERT_EQ(ERR_IO_PENDING, rv);
288 data.RunFor(2); 288 data.RunFor(2);
289 289
290 ASSERT_TRUE(callback.have_result()); 290 ASSERT_TRUE(callback.have_result());
291 rv = callback.WaitForResult(); 291 rv = callback.WaitForResult();
292 ASSERT_GT(rv, 0); 292 ASSERT_GT(rv, 0);
293 293
294 // Finally, attempt to read the response body. 294 // Finally, attempt to read the response body.
295 scoped_refptr<IOBuffer> body_buffer(new IOBuffer(kBodySize)); 295 scoped_refptr<IOBuffer> body_buffer(new IOBuffer(kBodySize));
296 rv = parser.ReadResponseBody(body_buffer, kBodySize, callback.callback()); 296 rv =
297 parser.ReadResponseBody(
298 body_buffer.get(), kBodySize, callback.callback());
297 ASSERT_EQ(ERR_IO_PENDING, rv); 299 ASSERT_EQ(ERR_IO_PENDING, rv);
298 data.RunFor(1); 300 data.RunFor(1);
299 301
300 ASSERT_TRUE(callback.have_result()); 302 ASSERT_TRUE(callback.have_result());
301 rv = callback.WaitForResult(); 303 rv = callback.WaitForResult();
302 ASSERT_EQ(kBodySize, rv); 304 ASSERT_EQ(kBodySize, rv);
303 } 305 }
304 306
305 } // namespace net 307 } // namespace net
OLDNEW
« no previous file with comments | « net/http/http_stream_factory_impl_request.cc ('k') | net/http/http_transaction_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698