| 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_impl.h" | 61 #include "net/url_request/url_request_job_factory_impl.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 2361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2426 | 2428 |
| 2427 EXPECT_TRUE(!r.is_pending()); | 2429 EXPECT_TRUE(!r.is_pending()); |
| 2428 EXPECT_FALSE(d.received_data_before_response()); | 2430 EXPECT_FALSE(d.received_data_before_response()); |
| 2429 EXPECT_EQ(d.bytes_received(), 0); | 2431 EXPECT_EQ(d.bytes_received(), 0); |
| 2430 EXPECT_EQ("", r.GetSocketAddress().host()); | 2432 EXPECT_EQ("", r.GetSocketAddress().host()); |
| 2431 EXPECT_EQ(0, r.GetSocketAddress().port()); | 2433 EXPECT_EQ(0, r.GetSocketAddress().port()); |
| 2432 } | 2434 } |
| 2433 } | 2435 } |
| 2434 | 2436 |
| 2435 TEST_F(URLRequestTest, DataURLImageTest) { | 2437 TEST_F(URLRequestTest, DataURLImageTest) { |
| 2438 URLRequestJobFactory job_factory; |
| 2439 job_factory.SetProtocolHandler("data", new DataProtocolHandler()); |
| 2440 default_context_.set_job_factory(&job_factory); |
| 2441 |
| 2436 TestDelegate d; | 2442 TestDelegate d; |
| 2437 { | 2443 { |
| 2438 // Use our nice little Chrome logo. | 2444 // Use our nice little Chrome logo. |
| 2439 URLRequest r(GURL( | 2445 URLRequest r(GURL( |
| 2440 "data:image/png;base64," | 2446 "data:image/png;base64," |
| 2441 "iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAADVklEQVQ4jX2TfUwUBBjG3" | 2447 "iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAADVklEQVQ4jX2TfUwUBBjG3" |
| 2442 "w1y+HGcd9dxhXR8T4awOccJGgOSWclHImznLkTlSw0DDQXkrmgYgbUYnlQTqQxIEVxitD" | 2448 "w1y+HGcd9dxhXR8T4awOccJGgOSWclHImznLkTlSw0DDQXkrmgYgbUYnlQTqQxIEVxitD" |
| 2443 "5UMCATRA1CEEg+Qjw3bWDxIauJv/5oumqs39/P827vnucRmYN0gyF01GI5MpCVdW0gO7t" | 2449 "5UMCATRA1CEEg+Qjw3bWDxIauJv/5oumqs39/P827vnucRmYN0gyF01GI5MpCVdW0gO7t" |
| 2444 "vNC+vqSEtbZefk5NuLv1jdJ46p/zw0HeH4+PHr3h7c1mjoV2t5rKzMx1+fg9bAgK6zHq9" | 2450 "vNC+vqSEtbZefk5NuLv1jdJ46p/zw0HeH4+PHr3h7c1mjoV2t5rKzMx1+fg9bAgK6zHq9" |
| 2445 "cU5z+LpA3xOtx34+vTeT21onRuzssC3zxbbSwC13d/pFuC7CkIMDxQpF7r/MWq12UctI1" | 2451 "cU5z+LpA3xOtx34+vTeT21onRuzssC3zxbbSwC13d/pFuC7CkIMDxQpF7r/MWq12UctI1" |
| (...skipping 24 matching lines...) Expand all Loading... |
| 2470 EXPECT_EQ("", r.GetSocketAddress().host()); | 2476 EXPECT_EQ("", r.GetSocketAddress().host()); |
| 2471 EXPECT_EQ(0, r.GetSocketAddress().port()); | 2477 EXPECT_EQ(0, r.GetSocketAddress().port()); |
| 2472 } | 2478 } |
| 2473 } | 2479 } |
| 2474 | 2480 |
| 2475 TEST_F(URLRequestTest, FileTest) { | 2481 TEST_F(URLRequestTest, FileTest) { |
| 2476 FilePath app_path; | 2482 FilePath app_path; |
| 2477 PathService::Get(base::FILE_EXE, &app_path); | 2483 PathService::Get(base::FILE_EXE, &app_path); |
| 2478 GURL app_url = FilePathToFileURL(app_path); | 2484 GURL app_url = FilePathToFileURL(app_path); |
| 2479 | 2485 |
| 2486 URLRequestJobFactory job_factory; |
| 2487 job_factory.SetProtocolHandler("file", new FileProtocolHandler()); |
| 2488 default_context_.set_job_factory(&job_factory); |
| 2489 |
| 2480 TestDelegate d; | 2490 TestDelegate d; |
| 2481 { | 2491 { |
| 2482 URLRequest r(app_url, &d, &default_context_); | 2492 URLRequest r(app_url, &d, &default_context_); |
| 2483 | 2493 |
| 2484 r.Start(); | 2494 r.Start(); |
| 2485 EXPECT_TRUE(r.is_pending()); | 2495 EXPECT_TRUE(r.is_pending()); |
| 2486 | 2496 |
| 2487 MessageLoop::current()->Run(); | 2497 MessageLoop::current()->Run(); |
| 2488 | 2498 |
| 2489 int64 file_size = -1; | 2499 int64 file_size = -1; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 2510 | 2520 |
| 2511 int64 file_size; | 2521 int64 file_size; |
| 2512 EXPECT_TRUE(file_util::GetFileSize(temp_path, &file_size)); | 2522 EXPECT_TRUE(file_util::GetFileSize(temp_path, &file_size)); |
| 2513 | 2523 |
| 2514 const size_t first_byte_position = 500; | 2524 const size_t first_byte_position = 500; |
| 2515 const size_t last_byte_position = buffer_size - first_byte_position; | 2525 const size_t last_byte_position = buffer_size - first_byte_position; |
| 2516 const size_t content_length = last_byte_position - first_byte_position + 1; | 2526 const size_t content_length = last_byte_position - first_byte_position + 1; |
| 2517 std::string partial_buffer_string(buffer.get() + first_byte_position, | 2527 std::string partial_buffer_string(buffer.get() + first_byte_position, |
| 2518 buffer.get() + last_byte_position + 1); | 2528 buffer.get() + last_byte_position + 1); |
| 2519 | 2529 |
| 2530 URLRequestJobFactory job_factory; |
| 2531 job_factory.SetProtocolHandler("file", new FileProtocolHandler()); |
| 2532 default_context_.set_job_factory(&job_factory); |
| 2533 |
| 2520 TestDelegate d; | 2534 TestDelegate d; |
| 2521 { | 2535 { |
| 2522 URLRequest r(temp_url, &d, &default_context_); | 2536 URLRequest r(temp_url, &d, &default_context_); |
| 2523 | 2537 |
| 2524 HttpRequestHeaders headers; | 2538 HttpRequestHeaders headers; |
| 2525 headers.SetHeader(HttpRequestHeaders::kRange, | 2539 headers.SetHeader(HttpRequestHeaders::kRange, |
| 2526 base::StringPrintf( | 2540 base::StringPrintf( |
| 2527 "bytes=%" PRIuS "-%" PRIuS, | 2541 "bytes=%" PRIuS "-%" PRIuS, |
| 2528 first_byte_position, last_byte_position)); | 2542 first_byte_position, last_byte_position)); |
| 2529 r.SetExtraRequestHeaders(headers); | 2543 r.SetExtraRequestHeaders(headers); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 2554 | 2568 |
| 2555 int64 file_size; | 2569 int64 file_size; |
| 2556 EXPECT_TRUE(file_util::GetFileSize(temp_path, &file_size)); | 2570 EXPECT_TRUE(file_util::GetFileSize(temp_path, &file_size)); |
| 2557 | 2571 |
| 2558 const size_t first_byte_position = 500; | 2572 const size_t first_byte_position = 500; |
| 2559 const size_t last_byte_position = buffer_size - 1; | 2573 const size_t last_byte_position = buffer_size - 1; |
| 2560 const size_t content_length = last_byte_position - first_byte_position + 1; | 2574 const size_t content_length = last_byte_position - first_byte_position + 1; |
| 2561 std::string partial_buffer_string(buffer.get() + first_byte_position, | 2575 std::string partial_buffer_string(buffer.get() + first_byte_position, |
| 2562 buffer.get() + last_byte_position + 1); | 2576 buffer.get() + last_byte_position + 1); |
| 2563 | 2577 |
| 2578 URLRequestJobFactory job_factory; |
| 2579 job_factory.SetProtocolHandler("file", new FileProtocolHandler()); |
| 2580 default_context_.set_job_factory(&job_factory); |
| 2581 |
| 2564 TestDelegate d; | 2582 TestDelegate d; |
| 2565 { | 2583 { |
| 2566 URLRequest r(temp_url, &d, &default_context_); | 2584 URLRequest r(temp_url, &d, &default_context_); |
| 2567 | 2585 |
| 2568 HttpRequestHeaders headers; | 2586 HttpRequestHeaders headers; |
| 2569 headers.SetHeader(HttpRequestHeaders::kRange, | 2587 headers.SetHeader(HttpRequestHeaders::kRange, |
| 2570 base::StringPrintf("bytes=%" PRIuS "-", | 2588 base::StringPrintf("bytes=%" PRIuS "-", |
| 2571 first_byte_position)); | 2589 first_byte_position)); |
| 2572 r.SetExtraRequestHeaders(headers); | 2590 r.SetExtraRequestHeaders(headers); |
| 2573 r.Start(); | 2591 r.Start(); |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2775 // There is an implicit redirect when loading a file path that matches a | 2793 // There is an implicit redirect when loading a file path that matches a |
| 2776 // directory and does not end with a slash. Ensure that following such | 2794 // directory and does not end with a slash. Ensure that following such |
| 2777 // redirects does not crash. See http://crbug.com/18686. | 2795 // redirects does not crash. See http://crbug.com/18686. |
| 2778 | 2796 |
| 2779 FilePath path; | 2797 FilePath path; |
| 2780 PathService::Get(base::DIR_SOURCE_ROOT, &path); | 2798 PathService::Get(base::DIR_SOURCE_ROOT, &path); |
| 2781 path = path.Append(FILE_PATH_LITERAL("net")); | 2799 path = path.Append(FILE_PATH_LITERAL("net")); |
| 2782 path = path.Append(FILE_PATH_LITERAL("data")); | 2800 path = path.Append(FILE_PATH_LITERAL("data")); |
| 2783 path = path.Append(FILE_PATH_LITERAL("url_request_unittest")); | 2801 path = path.Append(FILE_PATH_LITERAL("url_request_unittest")); |
| 2784 | 2802 |
| 2803 URLRequestJobFactory job_factory; |
| 2804 job_factory.SetProtocolHandler("file", new FileProtocolHandler()); |
| 2805 default_context_.set_job_factory(&job_factory); |
| 2806 |
| 2785 TestDelegate d; | 2807 TestDelegate d; |
| 2786 URLRequest req(FilePathToFileURL(path), &d, &default_context_); | 2808 URLRequest req(FilePathToFileURL(path), &d, &default_context_); |
| 2787 req.Start(); | 2809 req.Start(); |
| 2788 MessageLoop::current()->Run(); | 2810 MessageLoop::current()->Run(); |
| 2789 | 2811 |
| 2790 ASSERT_EQ(1, d.received_redirect_count()); | 2812 ASSERT_EQ(1, d.received_redirect_count()); |
| 2791 ASSERT_LT(0, d.bytes_received()); | 2813 ASSERT_LT(0, d.bytes_received()); |
| 2792 ASSERT_FALSE(d.request_failed()); | 2814 ASSERT_FALSE(d.request_failed()); |
| 2793 ASSERT_TRUE(req.status().is_success()); | 2815 ASSERT_TRUE(req.status().is_success()); |
| 2794 } | 2816 } |
| 2795 | 2817 |
| 2796 #if defined(OS_WIN) | 2818 #if defined(OS_WIN) |
| 2797 // Don't accept the url "file:///" on windows. See http://crbug.com/1474. | 2819 // Don't accept the url "file:///" on windows. See http://crbug.com/1474. |
| 2798 TEST_F(URLRequestTest, FileDirRedirectSingleSlash) { | 2820 TEST_F(URLRequestTest, FileDirRedirectSingleSlash) { |
| 2799 TestDelegate d; | 2821 TestDelegate d; |
| 2800 URLRequest req(GURL("file:///"), &d, &default_context_); | 2822 URLRequest req(GURL("file:///"), &d, &default_context_); |
| 2801 req.Start(); | 2823 req.Start(); |
| 2802 MessageLoop::current()->Run(); | 2824 MessageLoop::current()->Run(); |
| 2803 | 2825 |
| 2804 ASSERT_EQ(1, d.received_redirect_count()); | 2826 ASSERT_EQ(1, d.received_redirect_count()); |
| 2805 ASSERT_FALSE(req.status().is_success()); | 2827 ASSERT_FALSE(req.status().is_success()); |
| 2806 } | 2828 } |
| 2807 #endif | 2829 #endif |
| 2808 | 2830 |
| 2809 TEST_F(URLRequestTestHTTP, RestrictRedirects) { | 2831 TEST_F(URLRequestTestHTTP, RestrictRedirects) { |
| 2810 ASSERT_TRUE(test_server_.Start()); | 2832 ASSERT_TRUE(test_server_.Start()); |
| 2811 | 2833 |
| 2834 URLRequestJobFactory job_factory; |
| 2835 job_factory.SetProtocolHandler("file", new FileProtocolHandler()); |
| 2836 default_context_.set_job_factory(&job_factory); |
| 2837 |
| 2812 TestDelegate d; | 2838 TestDelegate d; |
| 2813 URLRequest req(test_server_.GetURL( | 2839 URLRequest req(test_server_.GetURL( |
| 2814 "files/redirect-to-file.html"), &d, &default_context_); | 2840 "files/redirect-to-file.html"), &d, &default_context_); |
| 2815 req.Start(); | 2841 req.Start(); |
| 2816 MessageLoop::current()->Run(); | 2842 MessageLoop::current()->Run(); |
| 2817 | 2843 |
| 2818 EXPECT_EQ(URLRequestStatus::FAILED, req.status().status()); | 2844 EXPECT_EQ(URLRequestStatus::FAILED, req.status().status()); |
| 2819 EXPECT_EQ(ERR_UNSAFE_REDIRECT, req.status().error()); | 2845 EXPECT_EQ(ERR_UNSAFE_REDIRECT, req.status().error()); |
| 2820 } | 2846 } |
| 2821 | 2847 |
| (...skipping 1342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4164 TestServer test_server_; | 4190 TestServer test_server_; |
| 4165 }; | 4191 }; |
| 4166 | 4192 |
| 4167 // Make sure an FTP request using an unsafe ports fails. | 4193 // Make sure an FTP request using an unsafe ports fails. |
| 4168 TEST_F(URLRequestTestFTP, UnsafePort) { | 4194 TEST_F(URLRequestTestFTP, UnsafePort) { |
| 4169 ASSERT_TRUE(test_server_.Start()); | 4195 ASSERT_TRUE(test_server_.Start()); |
| 4170 | 4196 |
| 4171 URLRequestJobFactoryImpl job_factory; | 4197 URLRequestJobFactoryImpl job_factory; |
| 4172 | 4198 |
| 4173 GURL url("ftp://127.0.0.1:7"); | 4199 GURL url("ftp://127.0.0.1:7"); |
| 4174 FtpProtocolHandler ftp_protocol_handler( | |
| 4175 default_context_.ftp_transaction_factory(), | |
| 4176 default_context_.ftp_auth_cache()); | |
| 4177 job_factory.SetProtocolHandler( | 4200 job_factory.SetProtocolHandler( |
| 4178 "ftp", | 4201 "ftp", |
| 4179 new FtpProtocolHandler(default_context_.ftp_transaction_factory(), | 4202 new FtpProtocolHandler(default_context_.ftp_transaction_factory(), |
| 4180 default_context_.ftp_auth_cache())); | 4203 default_context_.ftp_auth_cache())); |
| 4181 default_context_.set_job_factory(&job_factory); | 4204 default_context_.set_job_factory(&job_factory); |
| 4182 | 4205 |
| 4183 TestDelegate d; | 4206 TestDelegate d; |
| 4184 { | 4207 { |
| 4185 URLRequest r(url, &d, &default_context_); | 4208 URLRequest r(url, &d, &default_context_); |
| 4186 r.Start(); | 4209 r.Start(); |
| (...skipping 494 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4681 req.SetExtraRequestHeaders(headers); | 4704 req.SetExtraRequestHeaders(headers); |
| 4682 req.Start(); | 4705 req.Start(); |
| 4683 MessageLoop::current()->Run(); | 4706 MessageLoop::current()->Run(); |
| 4684 // 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 |
| 4685 // 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 |
| 4686 // closing parentheses. | 4709 // closing parentheses. |
| 4687 EXPECT_TRUE(StartsWithASCII(d.data_received(), "Lynx (textmode", true)); | 4710 EXPECT_TRUE(StartsWithASCII(d.data_received(), "Lynx (textmode", true)); |
| 4688 } | 4711 } |
| 4689 | 4712 |
| 4690 } // namespace net | 4713 } // namespace net |
| OLD | NEW |