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

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

Issue 99923002: Move temp file functions to base namespace. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years 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
« no previous file with comments | « net/url_request/url_fetcher_response_writer.cc ('k') | printing/backend/cups_helper.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 724 matching lines...) Expand 10 before | Expand all | Expand 10 after
735 // destroyed. 735 // destroyed.
736 base::RunLoop().RunUntilIdle(); 736 base::RunLoop().RunUntilIdle();
737 } 737 }
738 738
739 TEST_F(URLRequestTest, FileTestFullSpecifiedRange) { 739 TEST_F(URLRequestTest, FileTestFullSpecifiedRange) {
740 const size_t buffer_size = 4000; 740 const size_t buffer_size = 4000;
741 scoped_ptr<char[]> buffer(new char[buffer_size]); 741 scoped_ptr<char[]> buffer(new char[buffer_size]);
742 FillBuffer(buffer.get(), buffer_size); 742 FillBuffer(buffer.get(), buffer_size);
743 743
744 base::FilePath temp_path; 744 base::FilePath temp_path;
745 EXPECT_TRUE(file_util::CreateTemporaryFile(&temp_path)); 745 EXPECT_TRUE(base::CreateTemporaryFile(&temp_path));
746 GURL temp_url = FilePathToFileURL(temp_path); 746 GURL temp_url = FilePathToFileURL(temp_path);
747 EXPECT_TRUE(file_util::WriteFile(temp_path, buffer.get(), buffer_size)); 747 EXPECT_TRUE(file_util::WriteFile(temp_path, buffer.get(), buffer_size));
748 748
749 int64 file_size; 749 int64 file_size;
750 EXPECT_TRUE(file_util::GetFileSize(temp_path, &file_size)); 750 EXPECT_TRUE(file_util::GetFileSize(temp_path, &file_size));
751 751
752 const size_t first_byte_position = 500; 752 const size_t first_byte_position = 500;
753 const size_t last_byte_position = buffer_size - first_byte_position; 753 const size_t last_byte_position = buffer_size - first_byte_position;
754 const size_t content_length = last_byte_position - first_byte_position + 1; 754 const size_t content_length = last_byte_position - first_byte_position + 1;
755 std::string partial_buffer_string(buffer.get() + first_byte_position, 755 std::string partial_buffer_string(buffer.get() + first_byte_position,
(...skipping 23 matching lines...) Expand all
779 779
780 EXPECT_TRUE(base::DeleteFile(temp_path, false)); 780 EXPECT_TRUE(base::DeleteFile(temp_path, false));
781 } 781 }
782 782
783 TEST_F(URLRequestTest, FileTestHalfSpecifiedRange) { 783 TEST_F(URLRequestTest, FileTestHalfSpecifiedRange) {
784 const size_t buffer_size = 4000; 784 const size_t buffer_size = 4000;
785 scoped_ptr<char[]> buffer(new char[buffer_size]); 785 scoped_ptr<char[]> buffer(new char[buffer_size]);
786 FillBuffer(buffer.get(), buffer_size); 786 FillBuffer(buffer.get(), buffer_size);
787 787
788 base::FilePath temp_path; 788 base::FilePath temp_path;
789 EXPECT_TRUE(file_util::CreateTemporaryFile(&temp_path)); 789 EXPECT_TRUE(base::CreateTemporaryFile(&temp_path));
790 GURL temp_url = FilePathToFileURL(temp_path); 790 GURL temp_url = FilePathToFileURL(temp_path);
791 EXPECT_TRUE(file_util::WriteFile(temp_path, buffer.get(), buffer_size)); 791 EXPECT_TRUE(file_util::WriteFile(temp_path, buffer.get(), buffer_size));
792 792
793 int64 file_size; 793 int64 file_size;
794 EXPECT_TRUE(file_util::GetFileSize(temp_path, &file_size)); 794 EXPECT_TRUE(file_util::GetFileSize(temp_path, &file_size));
795 795
796 const size_t first_byte_position = 500; 796 const size_t first_byte_position = 500;
797 const size_t last_byte_position = buffer_size - 1; 797 const size_t last_byte_position = buffer_size - 1;
798 const size_t content_length = last_byte_position - first_byte_position + 1; 798 const size_t content_length = last_byte_position - first_byte_position + 1;
799 std::string partial_buffer_string(buffer.get() + first_byte_position, 799 std::string partial_buffer_string(buffer.get() + first_byte_position,
(...skipping 22 matching lines...) Expand all
822 822
823 EXPECT_TRUE(base::DeleteFile(temp_path, false)); 823 EXPECT_TRUE(base::DeleteFile(temp_path, false));
824 } 824 }
825 825
826 TEST_F(URLRequestTest, FileTestMultipleRanges) { 826 TEST_F(URLRequestTest, FileTestMultipleRanges) {
827 const size_t buffer_size = 400000; 827 const size_t buffer_size = 400000;
828 scoped_ptr<char[]> buffer(new char[buffer_size]); 828 scoped_ptr<char[]> buffer(new char[buffer_size]);
829 FillBuffer(buffer.get(), buffer_size); 829 FillBuffer(buffer.get(), buffer_size);
830 830
831 base::FilePath temp_path; 831 base::FilePath temp_path;
832 EXPECT_TRUE(file_util::CreateTemporaryFile(&temp_path)); 832 EXPECT_TRUE(base::CreateTemporaryFile(&temp_path));
833 GURL temp_url = FilePathToFileURL(temp_path); 833 GURL temp_url = FilePathToFileURL(temp_path);
834 EXPECT_TRUE(file_util::WriteFile(temp_path, buffer.get(), buffer_size)); 834 EXPECT_TRUE(file_util::WriteFile(temp_path, buffer.get(), buffer_size));
835 835
836 int64 file_size; 836 int64 file_size;
837 EXPECT_TRUE(file_util::GetFileSize(temp_path, &file_size)); 837 EXPECT_TRUE(file_util::GetFileSize(temp_path, &file_size));
838 838
839 TestDelegate d; 839 TestDelegate d;
840 { 840 {
841 URLRequest r(temp_url, DEFAULT_PRIORITY, &d, &default_context_); 841 URLRequest r(temp_url, DEFAULT_PRIORITY, &d, &default_context_);
842 842
843 HttpRequestHeaders headers; 843 HttpRequestHeaders headers;
844 headers.SetHeader(HttpRequestHeaders::kRange, "bytes=0-0,10-200,200-300"); 844 headers.SetHeader(HttpRequestHeaders::kRange, "bytes=0-0,10-200,200-300");
845 r.SetExtraRequestHeaders(headers); 845 r.SetExtraRequestHeaders(headers);
846 r.Start(); 846 r.Start();
847 EXPECT_TRUE(r.is_pending()); 847 EXPECT_TRUE(r.is_pending());
848 848
849 base::RunLoop().Run(); 849 base::RunLoop().Run();
850 EXPECT_TRUE(d.request_failed()); 850 EXPECT_TRUE(d.request_failed());
851 } 851 }
852 852
853 EXPECT_TRUE(base::DeleteFile(temp_path, false)); 853 EXPECT_TRUE(base::DeleteFile(temp_path, false));
854 } 854 }
855 855
856 TEST_F(URLRequestTest, AllowFileURLs) { 856 TEST_F(URLRequestTest, AllowFileURLs) {
857 base::ScopedTempDir temp_dir; 857 base::ScopedTempDir temp_dir;
858 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 858 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
859 base::FilePath test_file; 859 base::FilePath test_file;
860 ASSERT_TRUE(file_util::CreateTemporaryFileInDir(temp_dir.path(), &test_file)); 860 ASSERT_TRUE(base::CreateTemporaryFileInDir(temp_dir.path(), &test_file));
861 std::string test_data("monkey"); 861 std::string test_data("monkey");
862 file_util::WriteFile(test_file, test_data.data(), test_data.size()); 862 file_util::WriteFile(test_file, test_data.data(), test_data.size());
863 GURL test_file_url = net::FilePathToFileURL(test_file); 863 GURL test_file_url = net::FilePathToFileURL(test_file);
864 864
865 { 865 {
866 TestDelegate d; 866 TestDelegate d;
867 TestNetworkDelegate network_delegate; 867 TestNetworkDelegate network_delegate;
868 network_delegate.set_can_access_files(true); 868 network_delegate.set_can_access_files(true);
869 default_context_.set_network_delegate(&network_delegate); 869 default_context_.set_network_delegate(&network_delegate);
870 URLRequest r(test_file_url, DEFAULT_PRIORITY, &d, &default_context_); 870 URLRequest r(test_file_url, DEFAULT_PRIORITY, &d, &default_context_);
(...skipping 6473 matching lines...) Expand 10 before | Expand all | Expand 10 after
7344 7344
7345 EXPECT_FALSE(r.is_pending()); 7345 EXPECT_FALSE(r.is_pending());
7346 EXPECT_EQ(1, d->response_started_count()); 7346 EXPECT_EQ(1, d->response_started_count());
7347 EXPECT_FALSE(d->received_data_before_response()); 7347 EXPECT_FALSE(d->received_data_before_response());
7348 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size)); 7348 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size));
7349 } 7349 }
7350 } 7350 }
7351 #endif // !defined(DISABLE_FTP_SUPPORT) 7351 #endif // !defined(DISABLE_FTP_SUPPORT)
7352 7352
7353 } // namespace net 7353 } // namespace net
OLDNEW
« no previous file with comments | « net/url_request/url_fetcher_response_writer.cc ('k') | printing/backend/cups_helper.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698