OLD | NEW |
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 "base/command_line.h" | 5 #include "base/command_line.h" |
6 #include "base/file_path.h" | 6 #include "base/file_path.h" |
7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/lazy_instance.h" | 8 #include "base/lazy_instance.h" |
9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 base::LazyInstance<std::string> g_last_upload_bytes = LAZY_INSTANCE_INITIALIZER; | 48 base::LazyInstance<std::string> g_last_upload_bytes = LAZY_INSTANCE_INITIALIZER; |
49 | 49 |
50 net::URLRequestJob* URLRequestFakerForPostRequests( | 50 net::URLRequestJob* URLRequestFakerForPostRequests( |
51 net::URLRequest* request, | 51 net::URLRequest* request, |
52 net::NetworkDelegate* network_delegate, | 52 net::NetworkDelegate* network_delegate, |
53 const std::string& scheme) { | 53 const std::string& scheme) { |
54 // Read the uploaded data and store it to g_last_upload_bytes. | 54 // Read the uploaded data and store it to g_last_upload_bytes. |
55 const net::UploadData* upload_data = request->get_upload(); | 55 const net::UploadData* upload_data = request->get_upload(); |
56 g_last_upload_bytes.Get().clear(); | 56 g_last_upload_bytes.Get().clear(); |
57 if (upload_data) { | 57 if (upload_data) { |
58 const std::vector<net::UploadElement>* elements = upload_data->elements(); | 58 const ScopedVector<net::UploadElement>& elements = upload_data->elements(); |
59 for (size_t i = 0; elements && i < elements->size(); ++i) { | 59 for (size_t i = 0; i < elements.size(); ++i) { |
60 if ((*elements)[i].type() == net::UploadElement::TYPE_BYTES) { | 60 if (elements[i]->type() == net::UploadElement::TYPE_BYTES) { |
61 g_last_upload_bytes.Get() += | 61 g_last_upload_bytes.Get() += |
62 std::string((*elements)[i].bytes(), (*elements)[i].bytes_length()); | 62 std::string(elements[i]->bytes(), elements[i]->bytes_length()); |
63 } | 63 } |
64 } | 64 } |
65 } | 65 } |
66 return new net::URLRequestTestJob( | 66 return new net::URLRequestTestJob( |
67 request, network_delegate, net::URLRequestTestJob::test_headers(), | 67 request, network_delegate, net::URLRequestTestJob::test_headers(), |
68 "<html><head><title>PASS</title></head><body>Data posted</body></html>", | 68 "<html><head><title>PASS</title></head><body>Data posted</body></html>", |
69 true); | 69 true); |
70 } | 70 } |
71 | 71 |
72 } // namespace | 72 } // namespace |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
260 // For debugging why this test fails. | 260 // For debugging why this test fails. |
261 LOG(ERROR) << "Got uploaded bytes:"; | 261 LOG(ERROR) << "Got uploaded bytes:"; |
262 LOG(ERROR) << g_last_upload_bytes.Get(); | 262 LOG(ERROR) << g_last_upload_bytes.Get(); |
263 LOG(ERROR) << "Going to fail the test."; | 263 LOG(ERROR) << "Going to fail the test."; |
264 } | 264 } |
265 EXPECT_TRUE(g_last_upload_bytes.Get().find("posted-text") != | 265 EXPECT_TRUE(g_last_upload_bytes.Get().find("posted-text") != |
266 std::string::npos); | 266 std::string::npos); |
267 EXPECT_TRUE(g_last_upload_bytes.Get().find("text-entered") != | 267 EXPECT_TRUE(g_last_upload_bytes.Get().find("text-entered") != |
268 std::string::npos); | 268 std::string::npos); |
269 } | 269 } |
OLD | NEW |