OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 <vector> |
| 6 |
5 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
6 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
7 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
8 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
9 #include "base/strings/string_number_conversions.h" | 11 #include "base/strings/string_number_conversions.h" |
10 #include "net/base/elements_upload_data_stream.h" | 12 #include "net/base/elements_upload_data_stream.h" |
11 #include "net/base/test_completion_callback.h" | 13 #include "net/base/test_completion_callback.h" |
12 #include "net/base/test_data_directory.h" | 14 #include "net/base/test_data_directory.h" |
13 #include "net/base/upload_bytes_element_reader.h" | 15 #include "net/base/upload_bytes_element_reader.h" |
14 #include "net/base/upload_data_stream.h" | 16 #include "net/base/upload_data_stream.h" |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
189 request_body_.clear(); | 191 request_body_.clear(); |
190 request_body_.reserve(length); | 192 request_body_.reserve(length); |
191 for (size_t i = 0; i < length; ++i) { | 193 for (size_t i = 0; i < length; ++i) { |
192 request_body_.append(1, static_cast<char>(32 + i % (126 - 32))); | 194 request_body_.append(1, static_cast<char>(32 + i % (126 - 32))); |
193 } | 195 } |
194 } | 196 } |
195 | 197 |
196 // Initializes |request_| for a post of |length| bytes. | 198 // Initializes |request_| for a post of |length| bytes. |
197 void InitializePostRequest(size_t length) { | 199 void InitializePostRequest(size_t length) { |
198 GenerateBody(length); | 200 GenerateBody(length); |
199 ScopedVector<UploadElementReader> element_readers; | 201 std::vector<scoped_ptr<UploadElementReader>> element_readers; |
200 element_readers.push_back( | 202 element_readers.push_back(make_scoped_ptr(new UploadBytesElementReader( |
201 new UploadBytesElementReader(request_body_.data(), | 203 request_body_.data(), request_body_.length()))); |
202 request_body_.length())); | |
203 upload_data_stream_.reset( | 204 upload_data_stream_.reset( |
204 new ElementsUploadDataStream(element_readers.Pass(), 0)); | 205 new ElementsUploadDataStream(std::move(element_readers), 0)); |
205 request_.method = "POST"; | 206 request_.method = "POST"; |
206 request_.url = GURL("https://test.example.com/"); | 207 request_.url = GURL("https://test.example.com/"); |
207 request_.upload_data_stream = upload_data_stream_.get(); | 208 request_.upload_data_stream = upload_data_stream_.get(); |
208 ASSERT_EQ(OK, request_.upload_data_stream->Init(CompletionCallback())); | 209 ASSERT_EQ(OK, request_.upload_data_stream->Init(CompletionCallback())); |
209 } | 210 } |
210 | 211 |
211 // Checks that |consumer| completed and received |status_line| and |body|. | 212 // Checks that |consumer| completed and received |status_line| and |body|. |
212 void CheckResponse(const TestTransactionConsumer& consumer, | 213 void CheckResponse(const TestTransactionConsumer& consumer, |
213 const std::string& status_line, | 214 const std::string& status_line, |
214 const std::string& body) { | 215 const std::string& body) { |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
313 base::MessageLoop::current()->Run(); | 314 base::MessageLoop::current()->Run(); |
314 | 315 |
315 for (size_t i = 0; i < num_requests; ++i) { | 316 for (size_t i = 0; i < num_requests; ++i) { |
316 CheckResponse(*consumers[i], "HTTP/1.1 200 OK", kResponseBody); | 317 CheckResponse(*consumers[i], "HTTP/1.1 200 OK", kResponseBody); |
317 } | 318 } |
318 STLDeleteElements(&consumers); | 319 STLDeleteElements(&consumers); |
319 } | 320 } |
320 | 321 |
321 } // namespace test | 322 } // namespace test |
322 } // namespace net | 323 } // namespace net |
OLD | NEW |