| 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 720 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 731 } | 731 } |
| 732 | 732 |
| 733 TEST_F(URLRequestTest, FileTestFullSpecifiedRange) { | 733 TEST_F(URLRequestTest, FileTestFullSpecifiedRange) { |
| 734 const size_t buffer_size = 4000; | 734 const size_t buffer_size = 4000; |
| 735 scoped_ptr<char[]> buffer(new char[buffer_size]); | 735 scoped_ptr<char[]> buffer(new char[buffer_size]); |
| 736 FillBuffer(buffer.get(), buffer_size); | 736 FillBuffer(buffer.get(), buffer_size); |
| 737 | 737 |
| 738 base::FilePath temp_path; | 738 base::FilePath temp_path; |
| 739 EXPECT_TRUE(base::CreateTemporaryFile(&temp_path)); | 739 EXPECT_TRUE(base::CreateTemporaryFile(&temp_path)); |
| 740 GURL temp_url = FilePathToFileURL(temp_path); | 740 GURL temp_url = FilePathToFileURL(temp_path); |
| 741 EXPECT_TRUE(file_util::WriteFile(temp_path, buffer.get(), buffer_size)); | 741 EXPECT_TRUE(base::WriteFile(temp_path, buffer.get(), buffer_size)); |
| 742 | 742 |
| 743 int64 file_size; | 743 int64 file_size; |
| 744 EXPECT_TRUE(base::GetFileSize(temp_path, &file_size)); | 744 EXPECT_TRUE(base::GetFileSize(temp_path, &file_size)); |
| 745 | 745 |
| 746 const size_t first_byte_position = 500; | 746 const size_t first_byte_position = 500; |
| 747 const size_t last_byte_position = buffer_size - first_byte_position; | 747 const size_t last_byte_position = buffer_size - first_byte_position; |
| 748 const size_t content_length = last_byte_position - first_byte_position + 1; | 748 const size_t content_length = last_byte_position - first_byte_position + 1; |
| 749 std::string partial_buffer_string(buffer.get() + first_byte_position, | 749 std::string partial_buffer_string(buffer.get() + first_byte_position, |
| 750 buffer.get() + last_byte_position + 1); | 750 buffer.get() + last_byte_position + 1); |
| 751 | 751 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 775 } | 775 } |
| 776 | 776 |
| 777 TEST_F(URLRequestTest, FileTestHalfSpecifiedRange) { | 777 TEST_F(URLRequestTest, FileTestHalfSpecifiedRange) { |
| 778 const size_t buffer_size = 4000; | 778 const size_t buffer_size = 4000; |
| 779 scoped_ptr<char[]> buffer(new char[buffer_size]); | 779 scoped_ptr<char[]> buffer(new char[buffer_size]); |
| 780 FillBuffer(buffer.get(), buffer_size); | 780 FillBuffer(buffer.get(), buffer_size); |
| 781 | 781 |
| 782 base::FilePath temp_path; | 782 base::FilePath temp_path; |
| 783 EXPECT_TRUE(base::CreateTemporaryFile(&temp_path)); | 783 EXPECT_TRUE(base::CreateTemporaryFile(&temp_path)); |
| 784 GURL temp_url = FilePathToFileURL(temp_path); | 784 GURL temp_url = FilePathToFileURL(temp_path); |
| 785 EXPECT_TRUE(file_util::WriteFile(temp_path, buffer.get(), buffer_size)); | 785 EXPECT_TRUE(base::WriteFile(temp_path, buffer.get(), buffer_size)); |
| 786 | 786 |
| 787 int64 file_size; | 787 int64 file_size; |
| 788 EXPECT_TRUE(base::GetFileSize(temp_path, &file_size)); | 788 EXPECT_TRUE(base::GetFileSize(temp_path, &file_size)); |
| 789 | 789 |
| 790 const size_t first_byte_position = 500; | 790 const size_t first_byte_position = 500; |
| 791 const size_t last_byte_position = buffer_size - 1; | 791 const size_t last_byte_position = buffer_size - 1; |
| 792 const size_t content_length = last_byte_position - first_byte_position + 1; | 792 const size_t content_length = last_byte_position - first_byte_position + 1; |
| 793 std::string partial_buffer_string(buffer.get() + first_byte_position, | 793 std::string partial_buffer_string(buffer.get() + first_byte_position, |
| 794 buffer.get() + last_byte_position + 1); | 794 buffer.get() + last_byte_position + 1); |
| 795 | 795 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 818 } | 818 } |
| 819 | 819 |
| 820 TEST_F(URLRequestTest, FileTestMultipleRanges) { | 820 TEST_F(URLRequestTest, FileTestMultipleRanges) { |
| 821 const size_t buffer_size = 400000; | 821 const size_t buffer_size = 400000; |
| 822 scoped_ptr<char[]> buffer(new char[buffer_size]); | 822 scoped_ptr<char[]> buffer(new char[buffer_size]); |
| 823 FillBuffer(buffer.get(), buffer_size); | 823 FillBuffer(buffer.get(), buffer_size); |
| 824 | 824 |
| 825 base::FilePath temp_path; | 825 base::FilePath temp_path; |
| 826 EXPECT_TRUE(base::CreateTemporaryFile(&temp_path)); | 826 EXPECT_TRUE(base::CreateTemporaryFile(&temp_path)); |
| 827 GURL temp_url = FilePathToFileURL(temp_path); | 827 GURL temp_url = FilePathToFileURL(temp_path); |
| 828 EXPECT_TRUE(file_util::WriteFile(temp_path, buffer.get(), buffer_size)); | 828 EXPECT_TRUE(base::WriteFile(temp_path, buffer.get(), buffer_size)); |
| 829 | 829 |
| 830 int64 file_size; | 830 int64 file_size; |
| 831 EXPECT_TRUE(base::GetFileSize(temp_path, &file_size)); | 831 EXPECT_TRUE(base::GetFileSize(temp_path, &file_size)); |
| 832 | 832 |
| 833 TestDelegate d; | 833 TestDelegate d; |
| 834 { | 834 { |
| 835 URLRequest r(temp_url, DEFAULT_PRIORITY, &d, &default_context_); | 835 URLRequest r(temp_url, DEFAULT_PRIORITY, &d, &default_context_); |
| 836 | 836 |
| 837 HttpRequestHeaders headers; | 837 HttpRequestHeaders headers; |
| 838 headers.SetHeader(HttpRequestHeaders::kRange, "bytes=0-0,10-200,200-300"); | 838 headers.SetHeader(HttpRequestHeaders::kRange, "bytes=0-0,10-200,200-300"); |
| 839 r.SetExtraRequestHeaders(headers); | 839 r.SetExtraRequestHeaders(headers); |
| 840 r.Start(); | 840 r.Start(); |
| 841 EXPECT_TRUE(r.is_pending()); | 841 EXPECT_TRUE(r.is_pending()); |
| 842 | 842 |
| 843 base::RunLoop().Run(); | 843 base::RunLoop().Run(); |
| 844 EXPECT_TRUE(d.request_failed()); | 844 EXPECT_TRUE(d.request_failed()); |
| 845 } | 845 } |
| 846 | 846 |
| 847 EXPECT_TRUE(base::DeleteFile(temp_path, false)); | 847 EXPECT_TRUE(base::DeleteFile(temp_path, false)); |
| 848 } | 848 } |
| 849 | 849 |
| 850 TEST_F(URLRequestTest, AllowFileURLs) { | 850 TEST_F(URLRequestTest, AllowFileURLs) { |
| 851 base::ScopedTempDir temp_dir; | 851 base::ScopedTempDir temp_dir; |
| 852 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 852 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
| 853 base::FilePath test_file; | 853 base::FilePath test_file; |
| 854 ASSERT_TRUE(base::CreateTemporaryFileInDir(temp_dir.path(), &test_file)); | 854 ASSERT_TRUE(base::CreateTemporaryFileInDir(temp_dir.path(), &test_file)); |
| 855 std::string test_data("monkey"); | 855 std::string test_data("monkey"); |
| 856 file_util::WriteFile(test_file, test_data.data(), test_data.size()); | 856 base::WriteFile(test_file, test_data.data(), test_data.size()); |
| 857 GURL test_file_url = net::FilePathToFileURL(test_file); | 857 GURL test_file_url = net::FilePathToFileURL(test_file); |
| 858 | 858 |
| 859 { | 859 { |
| 860 TestDelegate d; | 860 TestDelegate d; |
| 861 TestNetworkDelegate network_delegate; | 861 TestNetworkDelegate network_delegate; |
| 862 network_delegate.set_can_access_files(true); | 862 network_delegate.set_can_access_files(true); |
| 863 default_context_.set_network_delegate(&network_delegate); | 863 default_context_.set_network_delegate(&network_delegate); |
| 864 URLRequest r(test_file_url, DEFAULT_PRIORITY, &d, &default_context_); | 864 URLRequest r(test_file_url, DEFAULT_PRIORITY, &d, &default_context_); |
| 865 r.Start(); | 865 r.Start(); |
| 866 base::RunLoop().Run(); | 866 base::RunLoop().Run(); |
| (...skipping 6726 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7593 | 7593 |
| 7594 EXPECT_FALSE(r.is_pending()); | 7594 EXPECT_FALSE(r.is_pending()); |
| 7595 EXPECT_EQ(1, d->response_started_count()); | 7595 EXPECT_EQ(1, d->response_started_count()); |
| 7596 EXPECT_FALSE(d->received_data_before_response()); | 7596 EXPECT_FALSE(d->received_data_before_response()); |
| 7597 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size)); | 7597 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size)); |
| 7598 } | 7598 } |
| 7599 } | 7599 } |
| 7600 #endif // !defined(DISABLE_FTP_SUPPORT) | 7600 #endif // !defined(DISABLE_FTP_SUPPORT) |
| 7601 | 7601 |
| 7602 } // namespace net | 7602 } // namespace net |
| OLD | NEW |