| OLD | NEW |
| 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 Loading... |
| 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().host(), |
| 271 r.GetSocketAddress().host()); |
| 272 EXPECT_EQ(test_server_.host_port_pair().port(), |
| 273 r.GetSocketAddress().port()); |
| 270 | 274 |
| 271 // TODO(eroman): Add back the NetLog tests... | 275 // TODO(eroman): Add back the NetLog tests... |
| 272 } | 276 } |
| 273 } | 277 } |
| 274 | 278 |
| 275 TEST_F(URLRequestTestHTTP, GetTest) { | 279 TEST_F(URLRequestTestHTTP, GetTest) { |
| 276 ASSERT_TRUE(test_server_.Start()); | 280 ASSERT_TRUE(test_server_.Start()); |
| 277 | 281 |
| 278 TestDelegate d; | 282 TestDelegate d; |
| 279 { | 283 { |
| 280 TestURLRequest r(test_server_.GetURL(""), &d); | 284 TestURLRequest r(test_server_.GetURL(""), &d); |
| 281 | 285 |
| 282 r.Start(); | 286 r.Start(); |
| 283 EXPECT_TRUE(r.is_pending()); | 287 EXPECT_TRUE(r.is_pending()); |
| 284 | 288 |
| 285 MessageLoop::current()->Run(); | 289 MessageLoop::current()->Run(); |
| 286 | 290 |
| 287 EXPECT_EQ(1, d.response_started_count()); | 291 EXPECT_EQ(1, d.response_started_count()); |
| 288 EXPECT_FALSE(d.received_data_before_response()); | 292 EXPECT_FALSE(d.received_data_before_response()); |
| 289 EXPECT_NE(0, d.bytes_received()); | 293 EXPECT_NE(0, d.bytes_received()); |
| 294 EXPECT_EQ(test_server_.host_port_pair().host(), |
| 295 r.GetSocketAddress().host()); |
| 296 EXPECT_EQ(test_server_.host_port_pair().port(), |
| 297 r.GetSocketAddress().port()); |
| 290 } | 298 } |
| 291 } | 299 } |
| 292 | 300 |
| 293 TEST_F(URLRequestTestHTTP, HTTPSToHTTPRedirectNoRefererTest) { | 301 TEST_F(URLRequestTestHTTP, HTTPSToHTTPRedirectNoRefererTest) { |
| 294 ASSERT_TRUE(test_server_.Start()); | 302 ASSERT_TRUE(test_server_.Start()); |
| 295 | 303 |
| 296 net::TestServer https_test_server( | 304 net::TestServer https_test_server( |
| 297 net::TestServer::TYPE_HTTPS, FilePath(FILE_PATH_LITERAL("net/data/ssl"))); | 305 net::TestServer::TYPE_HTTPS, FilePath(FILE_PATH_LITERAL("net/data/ssl"))); |
| 298 ASSERT_TRUE(https_test_server.Start()); | 306 ASSERT_TRUE(https_test_server.Start()); |
| 299 | 307 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 328 | 336 |
| 329 r.Start(); | 337 r.Start(); |
| 330 EXPECT_TRUE(r.is_pending()); | 338 EXPECT_TRUE(r.is_pending()); |
| 331 | 339 |
| 332 MessageLoop::current()->Run(); | 340 MessageLoop::current()->Run(); |
| 333 | 341 |
| 334 EXPECT_EQ(1, d.response_started_count()); | 342 EXPECT_EQ(1, d.response_started_count()); |
| 335 EXPECT_FALSE(d.received_data_before_response()); | 343 EXPECT_FALSE(d.received_data_before_response()); |
| 336 EXPECT_NE(0, d.bytes_received()); | 344 EXPECT_NE(0, d.bytes_received()); |
| 337 CheckSSLInfo(r.ssl_info()); | 345 CheckSSLInfo(r.ssl_info()); |
| 346 EXPECT_EQ(test_server.host_port_pair().host(), |
| 347 r.GetSocketAddress().host()); |
| 348 EXPECT_EQ(test_server.host_port_pair().port(), |
| 349 r.GetSocketAddress().port()); |
| 338 } | 350 } |
| 339 } | 351 } |
| 340 | 352 |
| 341 TEST_F(HTTPSRequestTest, HTTPSMismatchedTest) { | 353 TEST_F(HTTPSRequestTest, HTTPSMismatchedTest) { |
| 342 net::TestServer::HTTPSOptions https_options( | 354 net::TestServer::HTTPSOptions https_options( |
| 343 net::TestServer::HTTPSOptions::CERT_MISMATCHED_NAME); | 355 net::TestServer::HTTPSOptions::CERT_MISMATCHED_NAME); |
| 344 net::TestServer test_server(https_options, | 356 net::TestServer test_server(https_options, |
| 345 FilePath(FILE_PATH_LITERAL("net/data/ssl"))); | 357 FilePath(FILE_PATH_LITERAL("net/data/ssl"))); |
| 346 ASSERT_TRUE(test_server.Start()); | 358 ASSERT_TRUE(test_server.Start()); |
| 347 | 359 |
| (...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 706 TestURLRequest r(GURL("about:blank"), &d); | 718 TestURLRequest r(GURL("about:blank"), &d); |
| 707 | 719 |
| 708 r.Start(); | 720 r.Start(); |
| 709 EXPECT_TRUE(r.is_pending()); | 721 EXPECT_TRUE(r.is_pending()); |
| 710 | 722 |
| 711 MessageLoop::current()->Run(); | 723 MessageLoop::current()->Run(); |
| 712 | 724 |
| 713 EXPECT_TRUE(!r.is_pending()); | 725 EXPECT_TRUE(!r.is_pending()); |
| 714 EXPECT_FALSE(d.received_data_before_response()); | 726 EXPECT_FALSE(d.received_data_before_response()); |
| 715 EXPECT_EQ(d.bytes_received(), 0); | 727 EXPECT_EQ(d.bytes_received(), 0); |
| 728 EXPECT_EQ("", r.GetSocketAddress().host()); |
| 729 EXPECT_EQ(0, r.GetSocketAddress().port()); |
| 716 } | 730 } |
| 717 } | 731 } |
| 718 | 732 |
| 719 TEST_F(URLRequestTest, DataURLImageTest) { | 733 TEST_F(URLRequestTest, DataURLImageTest) { |
| 720 TestDelegate d; | 734 TestDelegate d; |
| 721 { | 735 { |
| 722 // Use our nice little Chrome logo. | 736 // Use our nice little Chrome logo. |
| 723 TestURLRequest r(GURL( | 737 TestURLRequest r(GURL( |
| 724 "data:image/png;base64," | 738 "data:image/png;base64," |
| 725 "iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAADVklEQVQ4jX2TfUwUBBjG3" | 739 "iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAADVklEQVQ4jX2TfUwUBBjG3" |
| (...skipping 17 matching lines...) Expand all Loading... |
| 743 &d); | 757 &d); |
| 744 | 758 |
| 745 r.Start(); | 759 r.Start(); |
| 746 EXPECT_TRUE(r.is_pending()); | 760 EXPECT_TRUE(r.is_pending()); |
| 747 | 761 |
| 748 MessageLoop::current()->Run(); | 762 MessageLoop::current()->Run(); |
| 749 | 763 |
| 750 EXPECT_TRUE(!r.is_pending()); | 764 EXPECT_TRUE(!r.is_pending()); |
| 751 EXPECT_FALSE(d.received_data_before_response()); | 765 EXPECT_FALSE(d.received_data_before_response()); |
| 752 EXPECT_EQ(d.bytes_received(), 911); | 766 EXPECT_EQ(d.bytes_received(), 911); |
| 767 EXPECT_EQ("", r.GetSocketAddress().host()); |
| 768 EXPECT_EQ(0, r.GetSocketAddress().port()); |
| 753 } | 769 } |
| 754 } | 770 } |
| 755 | 771 |
| 756 TEST_F(URLRequestTest, FileTest) { | 772 TEST_F(URLRequestTest, FileTest) { |
| 757 FilePath app_path; | 773 FilePath app_path; |
| 758 PathService::Get(base::FILE_EXE, &app_path); | 774 PathService::Get(base::FILE_EXE, &app_path); |
| 759 GURL app_url = net::FilePathToFileURL(app_path); | 775 GURL app_url = net::FilePathToFileURL(app_path); |
| 760 | 776 |
| 761 TestDelegate d; | 777 TestDelegate d; |
| 762 { | 778 { |
| 763 TestURLRequest r(app_url, &d); | 779 TestURLRequest r(app_url, &d); |
| 764 | 780 |
| 765 r.Start(); | 781 r.Start(); |
| 766 EXPECT_TRUE(r.is_pending()); | 782 EXPECT_TRUE(r.is_pending()); |
| 767 | 783 |
| 768 MessageLoop::current()->Run(); | 784 MessageLoop::current()->Run(); |
| 769 | 785 |
| 770 int64 file_size = -1; | 786 int64 file_size = -1; |
| 771 EXPECT_TRUE(file_util::GetFileSize(app_path, &file_size)); | 787 EXPECT_TRUE(file_util::GetFileSize(app_path, &file_size)); |
| 772 | 788 |
| 773 EXPECT_TRUE(!r.is_pending()); | 789 EXPECT_TRUE(!r.is_pending()); |
| 774 EXPECT_EQ(1, d.response_started_count()); | 790 EXPECT_EQ(1, d.response_started_count()); |
| 775 EXPECT_FALSE(d.received_data_before_response()); | 791 EXPECT_FALSE(d.received_data_before_response()); |
| 776 EXPECT_EQ(d.bytes_received(), static_cast<int>(file_size)); | 792 EXPECT_EQ(d.bytes_received(), static_cast<int>(file_size)); |
| 793 EXPECT_EQ("", r.GetSocketAddress().host()); |
| 794 EXPECT_EQ(0, r.GetSocketAddress().port()); |
| 777 } | 795 } |
| 778 } | 796 } |
| 779 | 797 |
| 780 TEST_F(URLRequestTest, FileTestFullSpecifiedRange) { | 798 TEST_F(URLRequestTest, FileTestFullSpecifiedRange) { |
| 781 const size_t buffer_size = 4000; | 799 const size_t buffer_size = 4000; |
| 782 scoped_array<char> buffer(new char[buffer_size]); | 800 scoped_array<char> buffer(new char[buffer_size]); |
| 783 FillBuffer(buffer.get(), buffer_size); | 801 FillBuffer(buffer.get(), buffer_size); |
| 784 | 802 |
| 785 FilePath temp_path; | 803 FilePath temp_path; |
| 786 EXPECT_TRUE(file_util::CreateTemporaryFile(&temp_path)); | 804 EXPECT_TRUE(file_util::CreateTemporaryFile(&temp_path)); |
| (...skipping 1579 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2366 TestURLRequest r(test_server_.GetURL("/"), &d); | 2384 TestURLRequest r(test_server_.GetURL("/"), &d); |
| 2367 r.Start(); | 2385 r.Start(); |
| 2368 EXPECT_TRUE(r.is_pending()); | 2386 EXPECT_TRUE(r.is_pending()); |
| 2369 | 2387 |
| 2370 MessageLoop::current()->Run(); | 2388 MessageLoop::current()->Run(); |
| 2371 | 2389 |
| 2372 EXPECT_FALSE(r.is_pending()); | 2390 EXPECT_FALSE(r.is_pending()); |
| 2373 EXPECT_EQ(1, d.response_started_count()); | 2391 EXPECT_EQ(1, d.response_started_count()); |
| 2374 EXPECT_FALSE(d.received_data_before_response()); | 2392 EXPECT_FALSE(d.received_data_before_response()); |
| 2375 EXPECT_LT(0, d.bytes_received()); | 2393 EXPECT_LT(0, d.bytes_received()); |
| 2394 EXPECT_EQ(test_server_.host_port_pair().host(), |
| 2395 r.GetSocketAddress().host()); |
| 2396 EXPECT_EQ(test_server_.host_port_pair().port(), |
| 2397 r.GetSocketAddress().port()); |
| 2376 } | 2398 } |
| 2377 } | 2399 } |
| 2378 | 2400 |
| 2379 // Flaky, see http://crbug.com/25045. | 2401 // Flaky, see http://crbug.com/25045. |
| 2380 TEST_F(URLRequestTestFTP, FLAKY_FTPGetTestAnonymous) { | 2402 TEST_F(URLRequestTestFTP, FLAKY_FTPGetTestAnonymous) { |
| 2381 ASSERT_TRUE(test_server_.Start()); | 2403 ASSERT_TRUE(test_server_.Start()); |
| 2382 | 2404 |
| 2383 FilePath app_path; | 2405 FilePath app_path; |
| 2384 PathService::Get(base::DIR_SOURCE_ROOT, &app_path); | 2406 PathService::Get(base::DIR_SOURCE_ROOT, &app_path); |
| 2385 app_path = app_path.AppendASCII("LICENSE"); | 2407 app_path = app_path.AppendASCII("LICENSE"); |
| 2386 TestDelegate d; | 2408 TestDelegate d; |
| 2387 { | 2409 { |
| 2388 TestURLRequest r(test_server_.GetURL("/LICENSE"), &d); | 2410 TestURLRequest r(test_server_.GetURL("/LICENSE"), &d); |
| 2389 r.Start(); | 2411 r.Start(); |
| 2390 EXPECT_TRUE(r.is_pending()); | 2412 EXPECT_TRUE(r.is_pending()); |
| 2391 | 2413 |
| 2392 MessageLoop::current()->Run(); | 2414 MessageLoop::current()->Run(); |
| 2393 | 2415 |
| 2394 int64 file_size = 0; | 2416 int64 file_size = 0; |
| 2395 file_util::GetFileSize(app_path, &file_size); | 2417 file_util::GetFileSize(app_path, &file_size); |
| 2396 | 2418 |
| 2397 EXPECT_FALSE(r.is_pending()); | 2419 EXPECT_FALSE(r.is_pending()); |
| 2398 EXPECT_EQ(1, d.response_started_count()); | 2420 EXPECT_EQ(1, d.response_started_count()); |
| 2399 EXPECT_FALSE(d.received_data_before_response()); | 2421 EXPECT_FALSE(d.received_data_before_response()); |
| 2400 EXPECT_EQ(d.bytes_received(), static_cast<int>(file_size)); | 2422 EXPECT_EQ(d.bytes_received(), static_cast<int>(file_size)); |
| 2423 EXPECT_EQ(test_server_.host_port_pair().host(), |
| 2424 r.GetSocketAddress().host()); |
| 2425 EXPECT_EQ(test_server_.host_port_pair().port(), |
| 2426 r.GetSocketAddress().port()); |
| 2401 } | 2427 } |
| 2402 } | 2428 } |
| 2403 | 2429 |
| 2404 // Flaky, see http://crbug.com/25045. | 2430 // Flaky, see http://crbug.com/25045. |
| 2405 TEST_F(URLRequestTestFTP, FLAKY_FTPGetTest) { | 2431 TEST_F(URLRequestTestFTP, FLAKY_FTPGetTest) { |
| 2406 ASSERT_TRUE(test_server_.Start()); | 2432 ASSERT_TRUE(test_server_.Start()); |
| 2407 | 2433 |
| 2408 FilePath app_path; | 2434 FilePath app_path; |
| 2409 PathService::Get(base::DIR_SOURCE_ROOT, &app_path); | 2435 PathService::Get(base::DIR_SOURCE_ROOT, &app_path); |
| 2410 app_path = app_path.AppendASCII("LICENSE"); | 2436 app_path = app_path.AppendASCII("LICENSE"); |
| 2411 TestDelegate d; | 2437 TestDelegate d; |
| 2412 { | 2438 { |
| 2413 TestURLRequest r( | 2439 TestURLRequest r( |
| 2414 test_server_.GetURLWithUserAndPassword("/LICENSE", "chrome", "chrome"), | 2440 test_server_.GetURLWithUserAndPassword("/LICENSE", "chrome", "chrome"), |
| 2415 &d); | 2441 &d); |
| 2416 r.Start(); | 2442 r.Start(); |
| 2417 EXPECT_TRUE(r.is_pending()); | 2443 EXPECT_TRUE(r.is_pending()); |
| 2418 | 2444 |
| 2419 MessageLoop::current()->Run(); | 2445 MessageLoop::current()->Run(); |
| 2420 | 2446 |
| 2421 int64 file_size = 0; | 2447 int64 file_size = 0; |
| 2422 file_util::GetFileSize(app_path, &file_size); | 2448 file_util::GetFileSize(app_path, &file_size); |
| 2423 | 2449 |
| 2424 EXPECT_FALSE(r.is_pending()); | 2450 EXPECT_FALSE(r.is_pending()); |
| 2451 EXPECT_EQ(test_server_.host_port_pair().host(), |
| 2452 r.GetSocketAddress().host()); |
| 2453 EXPECT_EQ(test_server_.host_port_pair().port(), |
| 2454 r.GetSocketAddress().port()); |
| 2425 EXPECT_EQ(1, d.response_started_count()); | 2455 EXPECT_EQ(1, d.response_started_count()); |
| 2426 EXPECT_FALSE(d.received_data_before_response()); | 2456 EXPECT_FALSE(d.received_data_before_response()); |
| 2427 EXPECT_EQ(d.bytes_received(), static_cast<int>(file_size)); | 2457 EXPECT_EQ(d.bytes_received(), static_cast<int>(file_size)); |
| 2428 } | 2458 } |
| 2429 } | 2459 } |
| 2430 | 2460 |
| 2431 // Flaky, see http://crbug.com/25045. | 2461 // Flaky, see http://crbug.com/25045. |
| 2432 TEST_F(URLRequestTestFTP, FLAKY_FTPCheckWrongPassword) { | 2462 TEST_F(URLRequestTestFTP, FLAKY_FTPCheckWrongPassword) { |
| 2433 ASSERT_TRUE(test_server_.Start()); | 2463 ASSERT_TRUE(test_server_.Start()); |
| 2434 | 2464 |
| (...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2738 net::HttpRequestHeaders headers; | 2768 net::HttpRequestHeaders headers; |
| 2739 headers.SetHeader(net::HttpRequestHeaders::kUserAgent, "Lynx (textmode)"); | 2769 headers.SetHeader(net::HttpRequestHeaders::kUserAgent, "Lynx (textmode)"); |
| 2740 req.SetExtraRequestHeaders(headers); | 2770 req.SetExtraRequestHeaders(headers); |
| 2741 req.Start(); | 2771 req.Start(); |
| 2742 MessageLoop::current()->Run(); | 2772 MessageLoop::current()->Run(); |
| 2743 // If the net tests are being run with ChromeFrame then we need to allow for | 2773 // If the net tests are being run with ChromeFrame then we need to allow for |
| 2744 // the 'chromeframe' suffix which is added to the user agent before the | 2774 // the 'chromeframe' suffix which is added to the user agent before the |
| 2745 // closing parentheses. | 2775 // closing parentheses. |
| 2746 EXPECT_TRUE(StartsWithASCII(d.data_received(), "Lynx (textmode", true)); | 2776 EXPECT_TRUE(StartsWithASCII(d.data_received(), "Lynx (textmode", true)); |
| 2747 } | 2777 } |
| OLD | NEW |