| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 <map> | 5 #include <map> |
| 6 #include <queue> | 6 #include <queue> |
| 7 | 7 |
| 8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
| (...skipping 701 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 712 } | 712 } |
| 713 } | 713 } |
| 714 } | 714 } |
| 715 } | 715 } |
| 716 | 716 |
| 717 TEST(LocalFileSystemCopyOrMoveOperationTest, StreamCopyHelper) { | 717 TEST(LocalFileSystemCopyOrMoveOperationTest, StreamCopyHelper) { |
| 718 base::ScopedTempDir temp_dir; | 718 base::ScopedTempDir temp_dir; |
| 719 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 719 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
| 720 base::FilePath source_path = temp_dir.path().AppendASCII("source"); | 720 base::FilePath source_path = temp_dir.path().AppendASCII("source"); |
| 721 const char kTestData[] = "abcdefghijklmnopqrstuvwxyz0123456789"; | 721 const char kTestData[] = "abcdefghijklmnopqrstuvwxyz0123456789"; |
| 722 file_util::WriteFile(source_path, kTestData, | 722 base::WriteFile(source_path, kTestData, |
| 723 arraysize(kTestData) - 1); // Exclude trailing '\0'. | 723 arraysize(kTestData) - 1); // Exclude trailing '\0'. |
| 724 | 724 |
| 725 base::FilePath dest_path = temp_dir.path().AppendASCII("dest"); | 725 base::FilePath dest_path = temp_dir.path().AppendASCII("dest"); |
| 726 // LocalFileWriter requires the file exists. So create an empty file here. | 726 // LocalFileWriter requires the file exists. So create an empty file here. |
| 727 file_util::WriteFile(dest_path, "", 0); | 727 base::WriteFile(dest_path, "", 0); |
| 728 | 728 |
| 729 base::MessageLoopForIO message_loop; | 729 base::MessageLoopForIO message_loop; |
| 730 base::Thread file_thread("file_thread"); | 730 base::Thread file_thread("file_thread"); |
| 731 ASSERT_TRUE(file_thread.Start()); | 731 ASSERT_TRUE(file_thread.Start()); |
| 732 ScopedThreadStopper thread_stopper(&file_thread); | 732 ScopedThreadStopper thread_stopper(&file_thread); |
| 733 ASSERT_TRUE(thread_stopper.is_valid()); | 733 ASSERT_TRUE(thread_stopper.is_valid()); |
| 734 | 734 |
| 735 scoped_refptr<base::MessageLoopProxy> task_runner = | 735 scoped_refptr<base::MessageLoopProxy> task_runner = |
| 736 file_thread.message_loop_proxy(); | 736 file_thread.message_loop_proxy(); |
| 737 | 737 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 770 | 770 |
| 771 TEST(LocalFileSystemCopyOrMoveOperationTest, StreamCopyHelperWithFlush) { | 771 TEST(LocalFileSystemCopyOrMoveOperationTest, StreamCopyHelperWithFlush) { |
| 772 // Testing the same configuration as StreamCopyHelper, but with |need_flush| | 772 // Testing the same configuration as StreamCopyHelper, but with |need_flush| |
| 773 // parameter set to true. Since it is hard to test that the flush is indeed | 773 // parameter set to true. Since it is hard to test that the flush is indeed |
| 774 // taking place, this test just only verifies that the file is correctly | 774 // taking place, this test just only verifies that the file is correctly |
| 775 // written with or without the flag. | 775 // written with or without the flag. |
| 776 base::ScopedTempDir temp_dir; | 776 base::ScopedTempDir temp_dir; |
| 777 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 777 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
| 778 base::FilePath source_path = temp_dir.path().AppendASCII("source"); | 778 base::FilePath source_path = temp_dir.path().AppendASCII("source"); |
| 779 const char kTestData[] = "abcdefghijklmnopqrstuvwxyz0123456789"; | 779 const char kTestData[] = "abcdefghijklmnopqrstuvwxyz0123456789"; |
| 780 file_util::WriteFile(source_path, kTestData, | 780 base::WriteFile(source_path, kTestData, |
| 781 arraysize(kTestData) - 1); // Exclude trailing '\0'. | 781 arraysize(kTestData) - 1); // Exclude trailing '\0'. |
| 782 | 782 |
| 783 base::FilePath dest_path = temp_dir.path().AppendASCII("dest"); | 783 base::FilePath dest_path = temp_dir.path().AppendASCII("dest"); |
| 784 // LocalFileWriter requires the file exists. So create an empty file here. | 784 // LocalFileWriter requires the file exists. So create an empty file here. |
| 785 file_util::WriteFile(dest_path, "", 0); | 785 base::WriteFile(dest_path, "", 0); |
| 786 | 786 |
| 787 base::MessageLoopForIO message_loop; | 787 base::MessageLoopForIO message_loop; |
| 788 base::Thread file_thread("file_thread"); | 788 base::Thread file_thread("file_thread"); |
| 789 ASSERT_TRUE(file_thread.Start()); | 789 ASSERT_TRUE(file_thread.Start()); |
| 790 ScopedThreadStopper thread_stopper(&file_thread); | 790 ScopedThreadStopper thread_stopper(&file_thread); |
| 791 ASSERT_TRUE(thread_stopper.is_valid()); | 791 ASSERT_TRUE(thread_stopper.is_valid()); |
| 792 | 792 |
| 793 scoped_refptr<base::MessageLoopProxy> task_runner = | 793 scoped_refptr<base::MessageLoopProxy> task_runner = |
| 794 file_thread.message_loop_proxy(); | 794 file_thread.message_loop_proxy(); |
| 795 | 795 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 824 std::string content; | 824 std::string content; |
| 825 ASSERT_TRUE(base::ReadFileToString(dest_path, &content)); | 825 ASSERT_TRUE(base::ReadFileToString(dest_path, &content)); |
| 826 EXPECT_EQ(kTestData, content); | 826 EXPECT_EQ(kTestData, content); |
| 827 } | 827 } |
| 828 | 828 |
| 829 TEST(LocalFileSystemCopyOrMoveOperationTest, StreamCopyHelper_Cancel) { | 829 TEST(LocalFileSystemCopyOrMoveOperationTest, StreamCopyHelper_Cancel) { |
| 830 base::ScopedTempDir temp_dir; | 830 base::ScopedTempDir temp_dir; |
| 831 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 831 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
| 832 base::FilePath source_path = temp_dir.path().AppendASCII("source"); | 832 base::FilePath source_path = temp_dir.path().AppendASCII("source"); |
| 833 const char kTestData[] = "abcdefghijklmnopqrstuvwxyz0123456789"; | 833 const char kTestData[] = "abcdefghijklmnopqrstuvwxyz0123456789"; |
| 834 file_util::WriteFile(source_path, kTestData, | 834 base::WriteFile(source_path, kTestData, |
| 835 arraysize(kTestData) - 1); // Exclude trailing '\0'. | 835 arraysize(kTestData) - 1); // Exclude trailing '\0'. |
| 836 | 836 |
| 837 base::FilePath dest_path = temp_dir.path().AppendASCII("dest"); | 837 base::FilePath dest_path = temp_dir.path().AppendASCII("dest"); |
| 838 // LocalFileWriter requires the file exists. So create an empty file here. | 838 // LocalFileWriter requires the file exists. So create an empty file here. |
| 839 file_util::WriteFile(dest_path, "", 0); | 839 base::WriteFile(dest_path, "", 0); |
| 840 | 840 |
| 841 base::MessageLoopForIO message_loop; | 841 base::MessageLoopForIO message_loop; |
| 842 base::Thread file_thread("file_thread"); | 842 base::Thread file_thread("file_thread"); |
| 843 ASSERT_TRUE(file_thread.Start()); | 843 ASSERT_TRUE(file_thread.Start()); |
| 844 ScopedThreadStopper thread_stopper(&file_thread); | 844 ScopedThreadStopper thread_stopper(&file_thread); |
| 845 ASSERT_TRUE(thread_stopper.is_valid()); | 845 ASSERT_TRUE(thread_stopper.is_valid()); |
| 846 | 846 |
| 847 scoped_refptr<base::MessageLoopProxy> task_runner = | 847 scoped_refptr<base::MessageLoopProxy> task_runner = |
| 848 file_thread.message_loop_proxy(); | 848 file_thread.message_loop_proxy(); |
| 849 | 849 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 870 | 870 |
| 871 base::File::Error error = base::File::FILE_ERROR_FAILED; | 871 base::File::Error error = base::File::FILE_ERROR_FAILED; |
| 872 base::RunLoop run_loop; | 872 base::RunLoop run_loop; |
| 873 helper.Run(base::Bind(&AssignAndQuit, &run_loop, &error)); | 873 helper.Run(base::Bind(&AssignAndQuit, &run_loop, &error)); |
| 874 run_loop.Run(); | 874 run_loop.Run(); |
| 875 | 875 |
| 876 EXPECT_EQ(base::File::FILE_ERROR_ABORT, error); | 876 EXPECT_EQ(base::File::FILE_ERROR_ABORT, error); |
| 877 } | 877 } |
| 878 | 878 |
| 879 } // namespace content | 879 } // namespace content |
| OLD | NEW |