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

Side by Side Diff: net/url_request/url_request_unittest.cc

Issue 6488010: Propagate the remote socket address to URLRequest and to ViewHostMsg_FrameNavigate. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 10 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
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "build/build_config.h" 5 #include "build/build_config.h"
6 6
7 #if defined(OS_WIN) 7 #if defined(OS_WIN)
8 #include <shlobj.h> 8 #include <shlobj.h>
9 #include <windows.h> 9 #include <windows.h>
10 #elif defined(USE_NSS) 10 #elif defined(USE_NSS)
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 TestURLRequest r(test_server_.GetURL(""), &d); 260 TestURLRequest r(test_server_.GetURL(""), &d);
261 261
262 r.Start(); 262 r.Start();
263 EXPECT_TRUE(r.is_pending()); 263 EXPECT_TRUE(r.is_pending());
264 264
265 MessageLoop::current()->Run(); 265 MessageLoop::current()->Run();
266 266
267 EXPECT_EQ(1, d.response_started_count()); 267 EXPECT_EQ(1, d.response_started_count());
268 EXPECT_FALSE(d.received_data_before_response()); 268 EXPECT_FALSE(d.received_data_before_response());
269 EXPECT_NE(0, d.bytes_received()); 269 EXPECT_NE(0, d.bytes_received());
270 EXPECT_EQ(test_server_.host_port_pair().ToString(), r.GetSocketAddress());
270 271
271 // TODO(eroman): Add back the NetLog tests... 272 // TODO(eroman): Add back the NetLog tests...
272 } 273 }
273 } 274 }
274 275
275 TEST_F(URLRequestTestHTTP, GetTest) { 276 TEST_F(URLRequestTestHTTP, GetTest) {
276 ASSERT_TRUE(test_server_.Start()); 277 ASSERT_TRUE(test_server_.Start());
277 278
278 TestDelegate d; 279 TestDelegate d;
279 { 280 {
280 TestURLRequest r(test_server_.GetURL(""), &d); 281 TestURLRequest r(test_server_.GetURL(""), &d);
281 282
282 r.Start(); 283 r.Start();
283 EXPECT_TRUE(r.is_pending()); 284 EXPECT_TRUE(r.is_pending());
284 285
285 MessageLoop::current()->Run(); 286 MessageLoop::current()->Run();
286 287
287 EXPECT_EQ(1, d.response_started_count()); 288 EXPECT_EQ(1, d.response_started_count());
288 EXPECT_FALSE(d.received_data_before_response()); 289 EXPECT_FALSE(d.received_data_before_response());
289 EXPECT_NE(0, d.bytes_received()); 290 EXPECT_NE(0, d.bytes_received());
291 EXPECT_EQ(test_server_.host_port_pair().ToString(), r.GetSocketAddress());
290 } 292 }
291 } 293 }
292 294
293 TEST_F(URLRequestTestHTTP, HTTPSToHTTPRedirectNoRefererTest) { 295 TEST_F(URLRequestTestHTTP, HTTPSToHTTPRedirectNoRefererTest) {
294 ASSERT_TRUE(test_server_.Start()); 296 ASSERT_TRUE(test_server_.Start());
295 297
296 net::TestServer https_test_server( 298 net::TestServer https_test_server(
297 net::TestServer::TYPE_HTTPS, FilePath(FILE_PATH_LITERAL("net/data/ssl"))); 299 net::TestServer::TYPE_HTTPS, FilePath(FILE_PATH_LITERAL("net/data/ssl")));
298 ASSERT_TRUE(https_test_server.Start()); 300 ASSERT_TRUE(https_test_server.Start());
299 301
(...skipping 28 matching lines...) Expand all
328 330
329 r.Start(); 331 r.Start();
330 EXPECT_TRUE(r.is_pending()); 332 EXPECT_TRUE(r.is_pending());
331 333
332 MessageLoop::current()->Run(); 334 MessageLoop::current()->Run();
333 335
334 EXPECT_EQ(1, d.response_started_count()); 336 EXPECT_EQ(1, d.response_started_count());
335 EXPECT_FALSE(d.received_data_before_response()); 337 EXPECT_FALSE(d.received_data_before_response());
336 EXPECT_NE(0, d.bytes_received()); 338 EXPECT_NE(0, d.bytes_received());
337 CheckSSLInfo(r.ssl_info()); 339 CheckSSLInfo(r.ssl_info());
340 EXPECT_EQ(test_server.host_port_pair().ToString(), r.GetSocketAddress());
338 } 341 }
339 } 342 }
340 343
341 TEST_F(HTTPSRequestTest, HTTPSMismatchedTest) { 344 TEST_F(HTTPSRequestTest, HTTPSMismatchedTest) {
342 net::TestServer::HTTPSOptions https_options( 345 net::TestServer::HTTPSOptions https_options(
343 net::TestServer::HTTPSOptions::CERT_MISMATCHED_NAME); 346 net::TestServer::HTTPSOptions::CERT_MISMATCHED_NAME);
344 net::TestServer test_server(https_options, 347 net::TestServer test_server(https_options,
345 FilePath(FILE_PATH_LITERAL("net/data/ssl"))); 348 FilePath(FILE_PATH_LITERAL("net/data/ssl")));
346 ASSERT_TRUE(test_server.Start()); 349 ASSERT_TRUE(test_server.Start());
347 350
(...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after
706 TestURLRequest r(GURL("about:blank"), &d); 709 TestURLRequest r(GURL("about:blank"), &d);
707 710
708 r.Start(); 711 r.Start();
709 EXPECT_TRUE(r.is_pending()); 712 EXPECT_TRUE(r.is_pending());
710 713
711 MessageLoop::current()->Run(); 714 MessageLoop::current()->Run();
712 715
713 EXPECT_TRUE(!r.is_pending()); 716 EXPECT_TRUE(!r.is_pending());
714 EXPECT_FALSE(d.received_data_before_response()); 717 EXPECT_FALSE(d.received_data_before_response());
715 EXPECT_EQ(d.bytes_received(), 0); 718 EXPECT_EQ(d.bytes_received(), 0);
719 EXPECT_EQ("", r.GetSocketAddress());
716 } 720 }
717 } 721 }
718 722
719 TEST_F(URLRequestTest, DataURLImageTest) { 723 TEST_F(URLRequestTest, DataURLImageTest) {
720 TestDelegate d; 724 TestDelegate d;
721 { 725 {
722 // Use our nice little Chrome logo. 726 // Use our nice little Chrome logo.
723 TestURLRequest r(GURL( 727 TestURLRequest r(GURL(
724 "data:image/png;base64," 728 "data:image/png;base64,"
725 "iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAADVklEQVQ4jX2TfUwUBBjG3" 729 "iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAADVklEQVQ4jX2TfUwUBBjG3"
(...skipping 17 matching lines...) Expand all
743 &d); 747 &d);
744 748
745 r.Start(); 749 r.Start();
746 EXPECT_TRUE(r.is_pending()); 750 EXPECT_TRUE(r.is_pending());
747 751
748 MessageLoop::current()->Run(); 752 MessageLoop::current()->Run();
749 753
750 EXPECT_TRUE(!r.is_pending()); 754 EXPECT_TRUE(!r.is_pending());
751 EXPECT_FALSE(d.received_data_before_response()); 755 EXPECT_FALSE(d.received_data_before_response());
752 EXPECT_EQ(d.bytes_received(), 911); 756 EXPECT_EQ(d.bytes_received(), 911);
757 EXPECT_EQ("", r.GetSocketAddress());
753 } 758 }
754 } 759 }
755 760
756 TEST_F(URLRequestTest, FileTest) { 761 TEST_F(URLRequestTest, FileTest) {
757 FilePath app_path; 762 FilePath app_path;
758 PathService::Get(base::FILE_EXE, &app_path); 763 PathService::Get(base::FILE_EXE, &app_path);
759 GURL app_url = net::FilePathToFileURL(app_path); 764 GURL app_url = net::FilePathToFileURL(app_path);
760 765
761 TestDelegate d; 766 TestDelegate d;
762 { 767 {
763 TestURLRequest r(app_url, &d); 768 TestURLRequest r(app_url, &d);
764 769
765 r.Start(); 770 r.Start();
766 EXPECT_TRUE(r.is_pending()); 771 EXPECT_TRUE(r.is_pending());
767 772
768 MessageLoop::current()->Run(); 773 MessageLoop::current()->Run();
769 774
770 int64 file_size = -1; 775 int64 file_size = -1;
771 EXPECT_TRUE(file_util::GetFileSize(app_path, &file_size)); 776 EXPECT_TRUE(file_util::GetFileSize(app_path, &file_size));
772 777
773 EXPECT_TRUE(!r.is_pending()); 778 EXPECT_TRUE(!r.is_pending());
774 EXPECT_EQ(1, d.response_started_count()); 779 EXPECT_EQ(1, d.response_started_count());
775 EXPECT_FALSE(d.received_data_before_response()); 780 EXPECT_FALSE(d.received_data_before_response());
776 EXPECT_EQ(d.bytes_received(), static_cast<int>(file_size)); 781 EXPECT_EQ(d.bytes_received(), static_cast<int>(file_size));
782 EXPECT_EQ("", r.GetSocketAddress());
777 } 783 }
778 } 784 }
779 785
780 TEST_F(URLRequestTest, FileTestFullSpecifiedRange) { 786 TEST_F(URLRequestTest, FileTestFullSpecifiedRange) {
781 const size_t buffer_size = 4000; 787 const size_t buffer_size = 4000;
782 scoped_array<char> buffer(new char[buffer_size]); 788 scoped_array<char> buffer(new char[buffer_size]);
783 FillBuffer(buffer.get(), buffer_size); 789 FillBuffer(buffer.get(), buffer_size);
784 790
785 FilePath temp_path; 791 FilePath temp_path;
786 EXPECT_TRUE(file_util::CreateTemporaryFile(&temp_path)); 792 EXPECT_TRUE(file_util::CreateTemporaryFile(&temp_path));
(...skipping 1570 matching lines...) Expand 10 before | Expand all | Expand 10 after
2357 TestURLRequest r(test_server_.GetURL("/"), &d); 2363 TestURLRequest r(test_server_.GetURL("/"), &d);
2358 r.Start(); 2364 r.Start();
2359 EXPECT_TRUE(r.is_pending()); 2365 EXPECT_TRUE(r.is_pending());
2360 2366
2361 MessageLoop::current()->Run(); 2367 MessageLoop::current()->Run();
2362 2368
2363 EXPECT_FALSE(r.is_pending()); 2369 EXPECT_FALSE(r.is_pending());
2364 EXPECT_EQ(1, d.response_started_count()); 2370 EXPECT_EQ(1, d.response_started_count());
2365 EXPECT_FALSE(d.received_data_before_response()); 2371 EXPECT_FALSE(d.received_data_before_response());
2366 EXPECT_LT(0, d.bytes_received()); 2372 EXPECT_LT(0, d.bytes_received());
2373 EXPECT_EQ(test_server_.host_port_pair().ToString(), r.GetSocketAddress());
2367 } 2374 }
2368 } 2375 }
2369 2376
2370 // Flaky, see http://crbug.com/25045. 2377 // Flaky, see http://crbug.com/25045.
2371 TEST_F(URLRequestTestFTP, FLAKY_FTPGetTestAnonymous) { 2378 TEST_F(URLRequestTestFTP, FLAKY_FTPGetTestAnonymous) {
2372 ASSERT_TRUE(test_server_.Start()); 2379 ASSERT_TRUE(test_server_.Start());
2373 2380
2374 FilePath app_path; 2381 FilePath app_path;
2375 PathService::Get(base::DIR_SOURCE_ROOT, &app_path); 2382 PathService::Get(base::DIR_SOURCE_ROOT, &app_path);
2376 app_path = app_path.AppendASCII("LICENSE"); 2383 app_path = app_path.AppendASCII("LICENSE");
2377 TestDelegate d; 2384 TestDelegate d;
2378 { 2385 {
2379 TestURLRequest r(test_server_.GetURL("/LICENSE"), &d); 2386 TestURLRequest r(test_server_.GetURL("/LICENSE"), &d);
2380 r.Start(); 2387 r.Start();
2381 EXPECT_TRUE(r.is_pending()); 2388 EXPECT_TRUE(r.is_pending());
2382 2389
2383 MessageLoop::current()->Run(); 2390 MessageLoop::current()->Run();
2384 2391
2385 int64 file_size = 0; 2392 int64 file_size = 0;
2386 file_util::GetFileSize(app_path, &file_size); 2393 file_util::GetFileSize(app_path, &file_size);
2387 2394
2388 EXPECT_FALSE(r.is_pending()); 2395 EXPECT_FALSE(r.is_pending());
2389 EXPECT_EQ(1, d.response_started_count()); 2396 EXPECT_EQ(1, d.response_started_count());
2390 EXPECT_FALSE(d.received_data_before_response()); 2397 EXPECT_FALSE(d.received_data_before_response());
2391 EXPECT_EQ(d.bytes_received(), static_cast<int>(file_size)); 2398 EXPECT_EQ(d.bytes_received(), static_cast<int>(file_size));
2399 EXPECT_EQ(test_server_.host_port_pair().ToString(), r.GetSocketAddress());
2392 } 2400 }
2393 } 2401 }
2394 2402
2395 // Flaky, see http://crbug.com/25045. 2403 // Flaky, see http://crbug.com/25045.
2396 TEST_F(URLRequestTestFTP, FLAKY_FTPGetTest) { 2404 TEST_F(URLRequestTestFTP, FLAKY_FTPGetTest) {
2397 ASSERT_TRUE(test_server_.Start()); 2405 ASSERT_TRUE(test_server_.Start());
2398 2406
2399 FilePath app_path; 2407 FilePath app_path;
2400 PathService::Get(base::DIR_SOURCE_ROOT, &app_path); 2408 PathService::Get(base::DIR_SOURCE_ROOT, &app_path);
2401 app_path = app_path.AppendASCII("LICENSE"); 2409 app_path = app_path.AppendASCII("LICENSE");
2402 TestDelegate d; 2410 TestDelegate d;
2403 { 2411 {
2404 TestURLRequest r( 2412 TestURLRequest r(
2405 test_server_.GetURLWithUserAndPassword("/LICENSE", "chrome", "chrome"), 2413 test_server_.GetURLWithUserAndPassword("/LICENSE", "chrome", "chrome"),
2406 &d); 2414 &d);
2407 r.Start(); 2415 r.Start();
2408 EXPECT_TRUE(r.is_pending()); 2416 EXPECT_TRUE(r.is_pending());
2409 2417
2410 MessageLoop::current()->Run(); 2418 MessageLoop::current()->Run();
2411 2419
2412 int64 file_size = 0; 2420 int64 file_size = 0;
2413 file_util::GetFileSize(app_path, &file_size); 2421 file_util::GetFileSize(app_path, &file_size);
2414 2422
2415 EXPECT_FALSE(r.is_pending()); 2423 EXPECT_FALSE(r.is_pending());
2424 EXPECT_EQ(test_server_.host_port_pair().ToString(), r.GetSocketAddress());
2416 EXPECT_EQ(1, d.response_started_count()); 2425 EXPECT_EQ(1, d.response_started_count());
2417 EXPECT_FALSE(d.received_data_before_response()); 2426 EXPECT_FALSE(d.received_data_before_response());
2418 EXPECT_EQ(d.bytes_received(), static_cast<int>(file_size)); 2427 EXPECT_EQ(d.bytes_received(), static_cast<int>(file_size));
2419 } 2428 }
2420 } 2429 }
2421 2430
2422 // Flaky, see http://crbug.com/25045. 2431 // Flaky, see http://crbug.com/25045.
2423 TEST_F(URLRequestTestFTP, FLAKY_FTPCheckWrongPassword) { 2432 TEST_F(URLRequestTestFTP, FLAKY_FTPCheckWrongPassword) {
2424 ASSERT_TRUE(test_server_.Start()); 2433 ASSERT_TRUE(test_server_.Start());
2425 2434
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after
2729 net::HttpRequestHeaders headers; 2738 net::HttpRequestHeaders headers;
2730 headers.SetHeader(net::HttpRequestHeaders::kUserAgent, "Lynx (textmode)"); 2739 headers.SetHeader(net::HttpRequestHeaders::kUserAgent, "Lynx (textmode)");
2731 req.SetExtraRequestHeaders(headers); 2740 req.SetExtraRequestHeaders(headers);
2732 req.Start(); 2741 req.Start();
2733 MessageLoop::current()->Run(); 2742 MessageLoop::current()->Run();
2734 // If the net tests are being run with ChromeFrame then we need to allow for 2743 // If the net tests are being run with ChromeFrame then we need to allow for
2735 // the 'chromeframe' suffix which is added to the user agent before the 2744 // the 'chromeframe' suffix which is added to the user agent before the
2736 // closing parentheses. 2745 // closing parentheses.
2737 EXPECT_TRUE(StartsWithASCII(d.data_received(), "Lynx (textmode", true)); 2746 EXPECT_TRUE(StartsWithASCII(d.data_received(), "Lynx (textmode", true));
2738 } 2747 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698