Chromium Code Reviews| 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 "build/build_config.h" | 5 #include "build/build_config.h" |
| 6 | 6 |
| 7 #if defined(OS_WIN) | 7 #if defined(OS_WIN) |
| 8 #include <windows.h> | 8 #include <windows.h> |
| 9 #include <shlobj.h> | 9 #include <shlobj.h> |
| 10 #endif | 10 #endif |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 45 #include "net/ftp/ftp_network_layer.h" | 45 #include "net/ftp/ftp_network_layer.h" |
| 46 #include "net/http/http_cache.h" | 46 #include "net/http/http_cache.h" |
| 47 #include "net/http/http_network_layer.h" | 47 #include "net/http/http_network_layer.h" |
| 48 #include "net/http/http_network_session.h" | 48 #include "net/http/http_network_session.h" |
| 49 #include "net/http/http_request_headers.h" | 49 #include "net/http/http_request_headers.h" |
| 50 #include "net/http/http_response_headers.h" | 50 #include "net/http/http_response_headers.h" |
| 51 #include "net/ocsp/nss_ocsp.h" | 51 #include "net/ocsp/nss_ocsp.h" |
| 52 #include "net/proxy/proxy_service.h" | 52 #include "net/proxy/proxy_service.h" |
| 53 #include "net/socket/ssl_client_socket.h" | 53 #include "net/socket/ssl_client_socket.h" |
| 54 #include "net/test/test_server.h" | 54 #include "net/test/test_server.h" |
| 55 #include "net/url_request/data_protocol_handler.h" | |
| 56 #include "net/url_request/file_protocol_handler.h" | |
| 55 #include "net/url_request/ftp_protocol_handler.h" | 57 #include "net/url_request/ftp_protocol_handler.h" |
| 56 #include "net/url_request/url_request.h" | 58 #include "net/url_request/url_request.h" |
| 57 #include "net/url_request/url_request_file_dir_job.h" | 59 #include "net/url_request/url_request_file_dir_job.h" |
| 58 #include "net/url_request/url_request_http_job.h" | 60 #include "net/url_request/url_request_http_job.h" |
| 59 #include "net/url_request/url_request_job_factory.h" | 61 #include "net/url_request/url_request_job_factory.h" |
| 60 #include "net/url_request/url_request_redirect_job.h" | 62 #include "net/url_request/url_request_redirect_job.h" |
| 61 #include "net/url_request/url_request_test_job.h" | 63 #include "net/url_request/url_request_test_job.h" |
| 62 #include "net/url_request/url_request_test_util.h" | 64 #include "net/url_request/url_request_test_util.h" |
| 63 #include "testing/gtest/include/gtest/gtest.h" | 65 #include "testing/gtest/include/gtest/gtest.h" |
| 64 #include "testing/platform_test.h" | 66 #include "testing/platform_test.h" |
| (...skipping 2358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2423 | 2425 |
| 2424 EXPECT_TRUE(!r.is_pending()); | 2426 EXPECT_TRUE(!r.is_pending()); |
| 2425 EXPECT_FALSE(d.received_data_before_response()); | 2427 EXPECT_FALSE(d.received_data_before_response()); |
| 2426 EXPECT_EQ(d.bytes_received(), 0); | 2428 EXPECT_EQ(d.bytes_received(), 0); |
| 2427 EXPECT_EQ("", r.GetSocketAddress().host()); | 2429 EXPECT_EQ("", r.GetSocketAddress().host()); |
| 2428 EXPECT_EQ(0, r.GetSocketAddress().port()); | 2430 EXPECT_EQ(0, r.GetSocketAddress().port()); |
| 2429 } | 2431 } |
| 2430 } | 2432 } |
| 2431 | 2433 |
| 2432 TEST_F(URLRequestTest, DataURLImageTest) { | 2434 TEST_F(URLRequestTest, DataURLImageTest) { |
| 2435 URLRequestJobFactory job_factory; | |
| 2436 job_factory.SetProtocolHandler("data", new DataProtocolHandler()); | |
| 2437 default_context_.set_job_factory(&job_factory); | |
| 2438 | |
| 2433 TestDelegate d; | 2439 TestDelegate d; |
| 2434 { | 2440 { |
| 2435 // Use our nice little Chrome logo. | 2441 // Use our nice little Chrome logo. |
| 2436 URLRequest r(GURL( | 2442 URLRequest r(GURL( |
| 2437 "data:image/png;base64," | 2443 "data:image/png;base64," |
| 2438 "iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAADVklEQVQ4jX2TfUwUBBjG3" | 2444 "iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAADVklEQVQ4jX2TfUwUBBjG3" |
| 2439 "w1y+HGcd9dxhXR8T4awOccJGgOSWclHImznLkTlSw0DDQXkrmgYgbUYnlQTqQxIEVxitD" | 2445 "w1y+HGcd9dxhXR8T4awOccJGgOSWclHImznLkTlSw0DDQXkrmgYgbUYnlQTqQxIEVxitD" |
| 2440 "5UMCATRA1CEEg+Qjw3bWDxIauJv/5oumqs39/P827vnucRmYN0gyF01GI5MpCVdW0gO7t" | 2446 "5UMCATRA1CEEg+Qjw3bWDxIauJv/5oumqs39/P827vnucRmYN0gyF01GI5MpCVdW0gO7t" |
| 2441 "vNC+vqSEtbZefk5NuLv1jdJ46p/zw0HeH4+PHr3h7c1mjoV2t5rKzMx1+fg9bAgK6zHq9" | 2447 "vNC+vqSEtbZefk5NuLv1jdJ46p/zw0HeH4+PHr3h7c1mjoV2t5rKzMx1+fg9bAgK6zHq9" |
| 2442 "cU5z+LpA3xOtx34+vTeT21onRuzssC3zxbbSwC13d/pFuC7CkIMDxQpF7r/MWq12UctI1" | 2448 "cU5z+LpA3xOtx34+vTeT21onRuzssC3zxbbSwC13d/pFuC7CkIMDxQpF7r/MWq12UctI1" |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 2467 EXPECT_EQ("", r.GetSocketAddress().host()); | 2473 EXPECT_EQ("", r.GetSocketAddress().host()); |
| 2468 EXPECT_EQ(0, r.GetSocketAddress().port()); | 2474 EXPECT_EQ(0, r.GetSocketAddress().port()); |
| 2469 } | 2475 } |
| 2470 } | 2476 } |
| 2471 | 2477 |
| 2472 TEST_F(URLRequestTest, FileTest) { | 2478 TEST_F(URLRequestTest, FileTest) { |
| 2473 FilePath app_path; | 2479 FilePath app_path; |
| 2474 PathService::Get(base::FILE_EXE, &app_path); | 2480 PathService::Get(base::FILE_EXE, &app_path); |
| 2475 GURL app_url = FilePathToFileURL(app_path); | 2481 GURL app_url = FilePathToFileURL(app_path); |
| 2476 | 2482 |
| 2483 URLRequestJobFactory job_factory; | |
| 2484 job_factory.SetProtocolHandler( | |
| 2485 "file", | |
| 2486 new FileProtocolHandler(default_context_.network_delegate())); | |
| 2487 default_context_.set_job_factory(&job_factory); | |
| 2488 | |
| 2477 TestDelegate d; | 2489 TestDelegate d; |
| 2478 { | 2490 { |
| 2479 URLRequest r(app_url, &d, &default_context_); | 2491 URLRequest r(app_url, &d, &default_context_); |
| 2480 | 2492 |
| 2481 r.Start(); | 2493 r.Start(); |
| 2482 EXPECT_TRUE(r.is_pending()); | 2494 EXPECT_TRUE(r.is_pending()); |
| 2483 | 2495 |
| 2484 MessageLoop::current()->Run(); | 2496 MessageLoop::current()->Run(); |
| 2485 | 2497 |
| 2486 int64 file_size = -1; | 2498 int64 file_size = -1; |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 2507 | 2519 |
| 2508 int64 file_size; | 2520 int64 file_size; |
| 2509 EXPECT_TRUE(file_util::GetFileSize(temp_path, &file_size)); | 2521 EXPECT_TRUE(file_util::GetFileSize(temp_path, &file_size)); |
| 2510 | 2522 |
| 2511 const size_t first_byte_position = 500; | 2523 const size_t first_byte_position = 500; |
| 2512 const size_t last_byte_position = buffer_size - first_byte_position; | 2524 const size_t last_byte_position = buffer_size - first_byte_position; |
| 2513 const size_t content_length = last_byte_position - first_byte_position + 1; | 2525 const size_t content_length = last_byte_position - first_byte_position + 1; |
| 2514 std::string partial_buffer_string(buffer.get() + first_byte_position, | 2526 std::string partial_buffer_string(buffer.get() + first_byte_position, |
| 2515 buffer.get() + last_byte_position + 1); | 2527 buffer.get() + last_byte_position + 1); |
| 2516 | 2528 |
| 2529 URLRequestJobFactory job_factory; | |
| 2530 job_factory.SetProtocolHandler( | |
| 2531 "file", | |
| 2532 new FileProtocolHandler(default_context_.network_delegate())); | |
| 2533 default_context_.set_job_factory(&job_factory); | |
| 2534 | |
| 2517 TestDelegate d; | 2535 TestDelegate d; |
| 2518 { | 2536 { |
| 2519 URLRequest r(temp_url, &d, &default_context_); | 2537 URLRequest r(temp_url, &d, &default_context_); |
| 2520 | 2538 |
| 2521 HttpRequestHeaders headers; | 2539 HttpRequestHeaders headers; |
| 2522 headers.SetHeader(HttpRequestHeaders::kRange, | 2540 headers.SetHeader(HttpRequestHeaders::kRange, |
| 2523 base::StringPrintf( | 2541 base::StringPrintf( |
| 2524 "bytes=%" PRIuS "-%" PRIuS, | 2542 "bytes=%" PRIuS "-%" PRIuS, |
| 2525 first_byte_position, last_byte_position)); | 2543 first_byte_position, last_byte_position)); |
| 2526 r.SetExtraRequestHeaders(headers); | 2544 r.SetExtraRequestHeaders(headers); |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 2551 | 2569 |
| 2552 int64 file_size; | 2570 int64 file_size; |
| 2553 EXPECT_TRUE(file_util::GetFileSize(temp_path, &file_size)); | 2571 EXPECT_TRUE(file_util::GetFileSize(temp_path, &file_size)); |
| 2554 | 2572 |
| 2555 const size_t first_byte_position = 500; | 2573 const size_t first_byte_position = 500; |
| 2556 const size_t last_byte_position = buffer_size - 1; | 2574 const size_t last_byte_position = buffer_size - 1; |
| 2557 const size_t content_length = last_byte_position - first_byte_position + 1; | 2575 const size_t content_length = last_byte_position - first_byte_position + 1; |
| 2558 std::string partial_buffer_string(buffer.get() + first_byte_position, | 2576 std::string partial_buffer_string(buffer.get() + first_byte_position, |
| 2559 buffer.get() + last_byte_position + 1); | 2577 buffer.get() + last_byte_position + 1); |
| 2560 | 2578 |
| 2579 URLRequestJobFactory job_factory; | |
| 2580 job_factory.SetProtocolHandler( | |
| 2581 "file", | |
| 2582 new FileProtocolHandler(default_context_.network_delegate())); | |
| 2583 default_context_.set_job_factory(&job_factory); | |
| 2584 | |
| 2561 TestDelegate d; | 2585 TestDelegate d; |
| 2562 { | 2586 { |
| 2563 URLRequest r(temp_url, &d, &default_context_); | 2587 URLRequest r(temp_url, &d, &default_context_); |
| 2564 | 2588 |
| 2565 HttpRequestHeaders headers; | 2589 HttpRequestHeaders headers; |
| 2566 headers.SetHeader(HttpRequestHeaders::kRange, | 2590 headers.SetHeader(HttpRequestHeaders::kRange, |
| 2567 base::StringPrintf("bytes=%" PRIuS "-", | 2591 base::StringPrintf("bytes=%" PRIuS "-", |
| 2568 first_byte_position)); | 2592 first_byte_position)); |
| 2569 r.SetExtraRequestHeaders(headers); | 2593 r.SetExtraRequestHeaders(headers); |
| 2570 r.Start(); | 2594 r.Start(); |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2772 // There is an implicit redirect when loading a file path that matches a | 2796 // There is an implicit redirect when loading a file path that matches a |
| 2773 // directory and does not end with a slash. Ensure that following such | 2797 // directory and does not end with a slash. Ensure that following such |
| 2774 // redirects does not crash. See http://crbug.com/18686. | 2798 // redirects does not crash. See http://crbug.com/18686. |
| 2775 | 2799 |
| 2776 FilePath path; | 2800 FilePath path; |
| 2777 PathService::Get(base::DIR_SOURCE_ROOT, &path); | 2801 PathService::Get(base::DIR_SOURCE_ROOT, &path); |
| 2778 path = path.Append(FILE_PATH_LITERAL("net")); | 2802 path = path.Append(FILE_PATH_LITERAL("net")); |
| 2779 path = path.Append(FILE_PATH_LITERAL("data")); | 2803 path = path.Append(FILE_PATH_LITERAL("data")); |
| 2780 path = path.Append(FILE_PATH_LITERAL("url_request_unittest")); | 2804 path = path.Append(FILE_PATH_LITERAL("url_request_unittest")); |
| 2781 | 2805 |
| 2806 URLRequestJobFactory job_factory; | |
| 2807 job_factory.SetProtocolHandler( | |
| 2808 "file", | |
| 2809 new FileProtocolHandler(default_context_.network_delegate())); | |
| 2810 default_context_.set_job_factory(&job_factory); | |
| 2811 | |
| 2782 TestDelegate d; | 2812 TestDelegate d; |
| 2783 URLRequest req(FilePathToFileURL(path), &d, &default_context_); | 2813 URLRequest req(FilePathToFileURL(path), &d, &default_context_); |
| 2784 req.Start(); | 2814 req.Start(); |
| 2785 MessageLoop::current()->Run(); | 2815 MessageLoop::current()->Run(); |
| 2786 | 2816 |
| 2787 ASSERT_EQ(1, d.received_redirect_count()); | 2817 ASSERT_EQ(1, d.received_redirect_count()); |
| 2788 ASSERT_LT(0, d.bytes_received()); | 2818 ASSERT_LT(0, d.bytes_received()); |
| 2789 ASSERT_FALSE(d.request_failed()); | 2819 ASSERT_FALSE(d.request_failed()); |
| 2790 ASSERT_TRUE(req.status().is_success()); | 2820 ASSERT_TRUE(req.status().is_success()); |
| 2791 } | 2821 } |
| 2792 | 2822 |
| 2793 #if defined(OS_WIN) | 2823 #if defined(OS_WIN) |
| 2794 // Don't accept the url "file:///" on windows. See http://crbug.com/1474. | 2824 // Don't accept the url "file:///" on windows. See http://crbug.com/1474. |
| 2795 TEST_F(URLRequestTest, FileDirRedirectSingleSlash) { | 2825 TEST_F(URLRequestTest, FileDirRedirectSingleSlash) { |
| 2796 TestDelegate d; | 2826 TestDelegate d; |
| 2797 URLRequest req(GURL("file:///"), &d, &default_context_); | 2827 URLRequest req(GURL("file:///"), &d, &default_context_); |
|
mmenke
2012/08/24 14:23:45
This test should also have a file job factory. Yo
| |
| 2798 req.Start(); | 2828 req.Start(); |
| 2799 MessageLoop::current()->Run(); | 2829 MessageLoop::current()->Run(); |
| 2800 | 2830 |
| 2801 ASSERT_EQ(1, d.received_redirect_count()); | 2831 ASSERT_EQ(1, d.received_redirect_count()); |
| 2802 ASSERT_FALSE(req.status().is_success()); | 2832 ASSERT_FALSE(req.status().is_success()); |
| 2803 } | 2833 } |
| 2804 #endif | 2834 #endif |
| 2805 | 2835 |
| 2806 TEST_F(URLRequestTestHTTP, RestrictRedirects) { | 2836 TEST_F(URLRequestTestHTTP, RestrictRedirects) { |
| 2807 ASSERT_TRUE(test_server_.Start()); | 2837 ASSERT_TRUE(test_server_.Start()); |
| 2808 | 2838 |
| 2839 URLRequestJobFactory job_factory; | |
| 2840 job_factory.SetProtocolHandler( | |
| 2841 "file", | |
| 2842 new FileProtocolHandler(default_context_.network_delegate())); | |
| 2843 default_context_.set_job_factory(&job_factory); | |
| 2844 | |
| 2809 TestDelegate d; | 2845 TestDelegate d; |
| 2810 URLRequest req(test_server_.GetURL( | 2846 URLRequest req(test_server_.GetURL( |
| 2811 "files/redirect-to-file.html"), &d, &default_context_); | 2847 "files/redirect-to-file.html"), &d, &default_context_); |
| 2812 req.Start(); | 2848 req.Start(); |
| 2813 MessageLoop::current()->Run(); | 2849 MessageLoop::current()->Run(); |
| 2814 | 2850 |
| 2815 EXPECT_EQ(URLRequestStatus::FAILED, req.status().status()); | 2851 EXPECT_EQ(URLRequestStatus::FAILED, req.status().status()); |
| 2816 EXPECT_EQ(ERR_UNSAFE_REDIRECT, req.status().error()); | 2852 EXPECT_EQ(ERR_UNSAFE_REDIRECT, req.status().error()); |
| 2817 } | 2853 } |
| 2818 | 2854 |
| (...skipping 1334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4153 TestServer test_server_; | 4189 TestServer test_server_; |
| 4154 }; | 4190 }; |
| 4155 | 4191 |
| 4156 // Make sure an FTP request using an unsafe ports fails. | 4192 // Make sure an FTP request using an unsafe ports fails. |
| 4157 TEST_F(URLRequestTestFTP, UnsafePort) { | 4193 TEST_F(URLRequestTestFTP, UnsafePort) { |
| 4158 ASSERT_TRUE(test_server_.Start()); | 4194 ASSERT_TRUE(test_server_.Start()); |
| 4159 | 4195 |
| 4160 URLRequestJobFactory job_factory; | 4196 URLRequestJobFactory job_factory; |
| 4161 | 4197 |
| 4162 GURL url("ftp://127.0.0.1:7"); | 4198 GURL url("ftp://127.0.0.1:7"); |
| 4163 FtpProtocolHandler ftp_protocol_handler( | |
| 4164 default_context_.network_delegate(), | |
| 4165 default_context_.ftp_transaction_factory(), | |
| 4166 default_context_.ftp_auth_cache()); | |
| 4167 job_factory.SetProtocolHandler( | 4199 job_factory.SetProtocolHandler( |
| 4168 "ftp", | 4200 "ftp", |
| 4169 new FtpProtocolHandler(default_context_.network_delegate(), | 4201 new FtpProtocolHandler(default_context_.network_delegate(), |
| 4170 default_context_.ftp_transaction_factory(), | 4202 default_context_.ftp_transaction_factory(), |
| 4171 default_context_.ftp_auth_cache())); | 4203 default_context_.ftp_auth_cache())); |
| 4172 default_context_.set_job_factory(&job_factory); | 4204 default_context_.set_job_factory(&job_factory); |
| 4173 | 4205 |
| 4174 TestDelegate d; | 4206 TestDelegate d; |
| 4175 { | 4207 { |
| 4176 URLRequest r(url, &d, &default_context_); | 4208 URLRequest r(url, &d, &default_context_); |
| (...skipping 495 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4672 req.SetExtraRequestHeaders(headers); | 4704 req.SetExtraRequestHeaders(headers); |
| 4673 req.Start(); | 4705 req.Start(); |
| 4674 MessageLoop::current()->Run(); | 4706 MessageLoop::current()->Run(); |
| 4675 // If the net tests are being run with ChromeFrame then we need to allow for | 4707 // If the net tests are being run with ChromeFrame then we need to allow for |
| 4676 // the 'chromeframe' suffix which is added to the user agent before the | 4708 // the 'chromeframe' suffix which is added to the user agent before the |
| 4677 // closing parentheses. | 4709 // closing parentheses. |
| 4678 EXPECT_TRUE(StartsWithASCII(d.data_received(), "Lynx (textmode", true)); | 4710 EXPECT_TRUE(StartsWithASCII(d.data_received(), "Lynx (textmode", true)); |
| 4679 } | 4711 } |
| 4680 | 4712 |
| 4681 } // namespace net | 4713 } // namespace net |
| OLD | NEW |