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

Side by Side Diff: chrome/browser/sessions/better_session_restore_browsertest.cc

Issue 11419034: net: Move ownership of UploadDataStream from URLRequestHttpJob to URLRequest (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Fix ASAN 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
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 "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"
11 #include "chrome/browser/content_settings/cookie_settings.h" 11 #include "chrome/browser/content_settings/cookie_settings.h"
12 #include "chrome/browser/prefs/session_startup_pref.h" 12 #include "chrome/browser/prefs/session_startup_pref.h"
13 #include "chrome/browser/ui/browser.h" 13 #include "chrome/browser/ui/browser.h"
14 #include "chrome/browser/ui/browser_tabstrip.h" 14 #include "chrome/browser/ui/browser_tabstrip.h"
15 #include "chrome/common/chrome_switches.h" 15 #include "chrome/common/chrome_switches.h"
16 #include "chrome/common/content_settings.h" 16 #include "chrome/common/content_settings.h"
17 #include "chrome/test/base/in_process_browser_test.h" 17 #include "chrome/test/base/in_process_browser_test.h"
18 #include "chrome/test/base/ui_test_utils.h" 18 #include "chrome/test/base/ui_test_utils.h"
19 #include "content/public/browser/web_contents.h" 19 #include "content/public/browser/web_contents.h"
20 #include "content/public/test/browser_test_utils.h" 20 #include "content/public/test/browser_test_utils.h"
21 #include "net/base/net_util.h" 21 #include "net/base/net_util.h"
22 #include "net/base/upload_data.h" 22 #include "net/base/upload_bytes_element_reader.h"
23 #include "net/base/upload_element.h" 23 #include "net/base/upload_data_stream.h"
24 #include "net/url_request/url_request.h" 24 #include "net/url_request/url_request.h"
25 #include "net/url_request/url_request_filter.h" 25 #include "net/url_request/url_request_filter.h"
26 #include "net/url_request/url_request_test_job.h" 26 #include "net/url_request/url_request_test_job.h"
27 27
28 namespace { 28 namespace {
29 29
30 // We need to serve the test files so that PRE_Test and Test can access the same 30 // We need to serve the test files so that PRE_Test and Test can access the same
31 // page using the same URL. In addition, perceived security origin of the page 31 // page using the same URL. In addition, perceived security origin of the page
32 // needs to stay the same, so e.g., redirecting the URL requests doesn't 32 // needs to stay the same, so e.g., redirecting the URL requests doesn't
33 // work. (If we used a test server, the PRE_Test and Test would have separate 33 // work. (If we used a test server, the PRE_Test and Test would have separate
(...skipping 11 matching lines...) Expand all
45 g_file_contents.Get()[request->url().path()], true); 45 g_file_contents.Get()[request->url().path()], true);
46 } 46 }
47 47
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::UploadDataStream* 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 ScopedVector<net::UploadElement>& elements = upload_data->elements(); 58 const ScopedVector<net::UploadElementReader>& readers =
59 for (size_t i = 0; i < elements.size(); ++i) { 59 upload_data->element_readers();
60 if (elements[i]->type() == net::UploadElement::TYPE_BYTES) { 60 for (size_t i = 0; i < readers.size(); ++i) {
61 const net::UploadBytesElementReader* bytes_reader =
62 readers[i]->AsBytesReader();
63 if (bytes_reader) {
61 g_last_upload_bytes.Get() += 64 g_last_upload_bytes.Get() +=
62 std::string(elements[i]->bytes(), elements[i]->bytes_length()); 65 std::string(bytes_reader->bytes(), bytes_reader->length());
63 } 66 }
64 } 67 }
65 } 68 }
66 return new net::URLRequestTestJob( 69 return new net::URLRequestTestJob(
67 request, network_delegate, net::URLRequestTestJob::test_headers(), 70 request, network_delegate, net::URLRequestTestJob::test_headers(),
68 "<html><head><title>PASS</title></head><body>Data posted</body></html>", 71 "<html><head><title>PASS</title></head><body>Data posted</body></html>",
69 true); 72 true);
70 } 73 }
71 74
72 } // namespace 75 } // namespace
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 // The form data contained passwords, so it's removed completely. 285 // The form data contained passwords, so it's removed completely.
283 EXPECT_TRUE(g_last_upload_bytes.Get().find("posted-text") == 286 EXPECT_TRUE(g_last_upload_bytes.Get().find("posted-text") ==
284 std::string::npos); 287 std::string::npos);
285 EXPECT_TRUE(g_last_upload_bytes.Get().find("text-entered") == 288 EXPECT_TRUE(g_last_upload_bytes.Get().find("text-entered") ==
286 std::string::npos); 289 std::string::npos);
287 EXPECT_TRUE(g_last_upload_bytes.Get().find("posted-password") == 290 EXPECT_TRUE(g_last_upload_bytes.Get().find("posted-password") ==
288 std::string::npos); 291 std::string::npos);
289 EXPECT_TRUE(g_last_upload_bytes.Get().find("password-entered") == 292 EXPECT_TRUE(g_last_upload_bytes.Get().find("password-entered") ==
290 std::string::npos); 293 std::string::npos);
291 } 294 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698