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 <shellapi.h> | 9 #include <shellapi.h> |
10 #include <shlobj.h> | 10 #include <shlobj.h> |
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
342 | 342 |
343 TEST_F(FileUtilTest, NormalizeFilePathBasic) { | 343 TEST_F(FileUtilTest, NormalizeFilePathBasic) { |
344 // Create a directory under the test dir. Because we create it, | 344 // Create a directory under the test dir. Because we create it, |
345 // we know it is not a link. | 345 // we know it is not a link. |
346 FilePath file_a_path = temp_dir_.path().Append(FPL("file_a")); | 346 FilePath file_a_path = temp_dir_.path().Append(FPL("file_a")); |
347 FilePath dir_path = temp_dir_.path().Append(FPL("dir")); | 347 FilePath dir_path = temp_dir_.path().Append(FPL("dir")); |
348 FilePath file_b_path = dir_path.Append(FPL("file_b")); | 348 FilePath file_b_path = dir_path.Append(FPL("file_b")); |
349 file_util::CreateDirectory(dir_path); | 349 file_util::CreateDirectory(dir_path); |
350 | 350 |
351 FilePath normalized_file_a_path, normalized_file_b_path; | 351 FilePath normalized_file_a_path, normalized_file_b_path; |
352 ASSERT_FALSE(file_util::PathExists(file_a_path)); | 352 ASSERT_FALSE(base::PathExists(file_a_path)); |
353 ASSERT_FALSE(file_util::NormalizeFilePath(file_a_path, | 353 ASSERT_FALSE(file_util::NormalizeFilePath(file_a_path, |
354 &normalized_file_a_path)) | 354 &normalized_file_a_path)) |
355 << "NormalizeFilePath() should fail on nonexistent paths."; | 355 << "NormalizeFilePath() should fail on nonexistent paths."; |
356 | 356 |
357 CreateTextFile(file_a_path, bogus_content); | 357 CreateTextFile(file_a_path, bogus_content); |
358 ASSERT_TRUE(file_util::PathExists(file_a_path)); | 358 ASSERT_TRUE(base::PathExists(file_a_path)); |
359 ASSERT_TRUE(file_util::NormalizeFilePath(file_a_path, | 359 ASSERT_TRUE(file_util::NormalizeFilePath(file_a_path, |
360 &normalized_file_a_path)); | 360 &normalized_file_a_path)); |
361 | 361 |
362 CreateTextFile(file_b_path, bogus_content); | 362 CreateTextFile(file_b_path, bogus_content); |
363 ASSERT_TRUE(file_util::PathExists(file_b_path)); | 363 ASSERT_TRUE(base::PathExists(file_b_path)); |
364 ASSERT_TRUE(file_util::NormalizeFilePath(file_b_path, | 364 ASSERT_TRUE(file_util::NormalizeFilePath(file_b_path, |
365 &normalized_file_b_path)); | 365 &normalized_file_b_path)); |
366 | 366 |
367 // Beacuse this test created |dir_path|, we know it is not a link | 367 // Beacuse this test created |dir_path|, we know it is not a link |
368 // or junction. So, the real path of the directory holding file a | 368 // or junction. So, the real path of the directory holding file a |
369 // must be the parent of the path holding file b. | 369 // must be the parent of the path holding file b. |
370 ASSERT_TRUE(normalized_file_a_path.DirName() | 370 ASSERT_TRUE(normalized_file_a_path.DirName() |
371 .IsParent(normalized_file_b_path.DirName())); | 371 .IsParent(normalized_file_b_path.DirName())); |
372 } | 372 } |
373 | 373 |
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
619 DWORD path_buffer_length = GetShortPathName(long_test_dir.value().c_str(), | 619 DWORD path_buffer_length = GetShortPathName(long_test_dir.value().c_str(), |
620 path_buffer, MAX_PATH); | 620 path_buffer, MAX_PATH); |
621 ASSERT_LT(path_buffer_length, DWORD(MAX_PATH)); | 621 ASSERT_LT(path_buffer_length, DWORD(MAX_PATH)); |
622 ASSERT_NE(DWORD(0), path_buffer_length); | 622 ASSERT_NE(DWORD(0), path_buffer_length); |
623 FilePath short_test_dir(path_buffer); | 623 FilePath short_test_dir(path_buffer); |
624 ASSERT_STRNE(kLongDirName, short_test_dir.BaseName().value().c_str()); | 624 ASSERT_STRNE(kLongDirName, short_test_dir.BaseName().value().c_str()); |
625 | 625 |
626 FilePath temp_file; | 626 FilePath temp_file; |
627 ASSERT_TRUE(file_util::CreateTemporaryFileInDir(short_test_dir, &temp_file)); | 627 ASSERT_TRUE(file_util::CreateTemporaryFileInDir(short_test_dir, &temp_file)); |
628 EXPECT_STREQ(kLongDirName, temp_file.DirName().BaseName().value().c_str()); | 628 EXPECT_STREQ(kLongDirName, temp_file.DirName().BaseName().value().c_str()); |
629 EXPECT_TRUE(file_util::PathExists(temp_file)); | 629 EXPECT_TRUE(base::PathExists(temp_file)); |
630 | 630 |
631 // Create a subdirectory of |long_test_dir| and make |long_test_dir| | 631 // Create a subdirectory of |long_test_dir| and make |long_test_dir| |
632 // unreadable. We should still be able to create a temp file in the | 632 // unreadable. We should still be able to create a temp file in the |
633 // subdirectory, but we won't be able to determine the long path for it. This | 633 // subdirectory, but we won't be able to determine the long path for it. This |
634 // mimics the environment that some users run where their user profiles reside | 634 // mimics the environment that some users run where their user profiles reside |
635 // in a location where the don't have full access to the higher level | 635 // in a location where the don't have full access to the higher level |
636 // directories. (Note that this assumption is true for NTFS, but not for some | 636 // directories. (Note that this assumption is true for NTFS, but not for some |
637 // network file systems. E.g. AFS). | 637 // network file systems. E.g. AFS). |
638 FilePath access_test_dir = long_test_dir.Append(kTestSubDirName); | 638 FilePath access_test_dir = long_test_dir.Append(kTestSubDirName); |
639 ASSERT_TRUE(file_util::CreateDirectory(access_test_dir)); | 639 ASSERT_TRUE(file_util::CreateDirectory(access_test_dir)); |
640 file_util::PermissionRestorer long_test_dir_restorer(long_test_dir); | 640 file_util::PermissionRestorer long_test_dir_restorer(long_test_dir); |
641 ASSERT_TRUE(file_util::MakeFileUnreadable(long_test_dir)); | 641 ASSERT_TRUE(file_util::MakeFileUnreadable(long_test_dir)); |
642 | 642 |
643 // Use the short form of the directory to create a temporary filename. | 643 // Use the short form of the directory to create a temporary filename. |
644 ASSERT_TRUE(file_util::CreateTemporaryFileInDir( | 644 ASSERT_TRUE(file_util::CreateTemporaryFileInDir( |
645 short_test_dir.Append(kTestSubDirName), &temp_file)); | 645 short_test_dir.Append(kTestSubDirName), &temp_file)); |
646 EXPECT_TRUE(file_util::PathExists(temp_file)); | 646 EXPECT_TRUE(base::PathExists(temp_file)); |
647 EXPECT_TRUE(short_test_dir.IsParent(temp_file.DirName())); | 647 EXPECT_TRUE(short_test_dir.IsParent(temp_file.DirName())); |
648 | 648 |
649 // Check that the long path can't be determined for |temp_file|. | 649 // Check that the long path can't be determined for |temp_file|. |
650 path_buffer_length = GetLongPathName(temp_file.value().c_str(), | 650 path_buffer_length = GetLongPathName(temp_file.value().c_str(), |
651 path_buffer, MAX_PATH); | 651 path_buffer, MAX_PATH); |
652 EXPECT_EQ(DWORD(0), path_buffer_length); | 652 EXPECT_EQ(DWORD(0), path_buffer_length); |
653 } | 653 } |
654 | 654 |
655 #endif // defined(OS_WIN) | 655 #endif // defined(OS_WIN) |
656 | 656 |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
726 ASSERT_TRUE(file_util::CreateSymbolicLink(link_from, link_to)) | 726 ASSERT_TRUE(file_util::CreateSymbolicLink(link_from, link_to)) |
727 << "Failed to create loop symlink b."; | 727 << "Failed to create loop symlink b."; |
728 | 728 |
729 // Infinite loop! | 729 // Infinite loop! |
730 EXPECT_FALSE(file_util::NormalizeFilePath(link_from, &normalized_path)); | 730 EXPECT_FALSE(file_util::NormalizeFilePath(link_from, &normalized_path)); |
731 } | 731 } |
732 #endif // defined(OS_POSIX) | 732 #endif // defined(OS_POSIX) |
733 | 733 |
734 TEST_F(FileUtilTest, DeleteNonExistent) { | 734 TEST_F(FileUtilTest, DeleteNonExistent) { |
735 FilePath non_existent = temp_dir_.path().AppendASCII("bogus_file_dne.foobar"); | 735 FilePath non_existent = temp_dir_.path().AppendASCII("bogus_file_dne.foobar"); |
736 ASSERT_FALSE(file_util::PathExists(non_existent)); | 736 ASSERT_FALSE(base::PathExists(non_existent)); |
737 | 737 |
738 EXPECT_TRUE(base::Delete(non_existent, false)); | 738 EXPECT_TRUE(base::Delete(non_existent, false)); |
739 ASSERT_FALSE(file_util::PathExists(non_existent)); | 739 ASSERT_FALSE(base::PathExists(non_existent)); |
740 EXPECT_TRUE(base::Delete(non_existent, true)); | 740 EXPECT_TRUE(base::Delete(non_existent, true)); |
741 ASSERT_FALSE(file_util::PathExists(non_existent)); | 741 ASSERT_FALSE(base::PathExists(non_existent)); |
742 } | 742 } |
743 | 743 |
744 TEST_F(FileUtilTest, DeleteFile) { | 744 TEST_F(FileUtilTest, DeleteFile) { |
745 // Create a file | 745 // Create a file |
746 FilePath file_name = temp_dir_.path().Append(FPL("Test DeleteFile 1.txt")); | 746 FilePath file_name = temp_dir_.path().Append(FPL("Test DeleteFile 1.txt")); |
747 CreateTextFile(file_name, bogus_content); | 747 CreateTextFile(file_name, bogus_content); |
748 ASSERT_TRUE(file_util::PathExists(file_name)); | 748 ASSERT_TRUE(base::PathExists(file_name)); |
749 | 749 |
750 // Make sure it's deleted | 750 // Make sure it's deleted |
751 EXPECT_TRUE(base::Delete(file_name, false)); | 751 EXPECT_TRUE(base::Delete(file_name, false)); |
752 EXPECT_FALSE(file_util::PathExists(file_name)); | 752 EXPECT_FALSE(base::PathExists(file_name)); |
753 | 753 |
754 // Test recursive case, create a new file | 754 // Test recursive case, create a new file |
755 file_name = temp_dir_.path().Append(FPL("Test DeleteFile 2.txt")); | 755 file_name = temp_dir_.path().Append(FPL("Test DeleteFile 2.txt")); |
756 CreateTextFile(file_name, bogus_content); | 756 CreateTextFile(file_name, bogus_content); |
757 ASSERT_TRUE(file_util::PathExists(file_name)); | 757 ASSERT_TRUE(base::PathExists(file_name)); |
758 | 758 |
759 // Make sure it's deleted | 759 // Make sure it's deleted |
760 EXPECT_TRUE(base::Delete(file_name, true)); | 760 EXPECT_TRUE(base::Delete(file_name, true)); |
761 EXPECT_FALSE(file_util::PathExists(file_name)); | 761 EXPECT_FALSE(base::PathExists(file_name)); |
762 } | 762 } |
763 | 763 |
764 #if defined(OS_POSIX) | 764 #if defined(OS_POSIX) |
765 TEST_F(FileUtilTest, DeleteSymlinkToExistentFile) { | 765 TEST_F(FileUtilTest, DeleteSymlinkToExistentFile) { |
766 // Create a file. | 766 // Create a file. |
767 FilePath file_name = temp_dir_.path().Append(FPL("Test DeleteFile 2.txt")); | 767 FilePath file_name = temp_dir_.path().Append(FPL("Test DeleteFile 2.txt")); |
768 CreateTextFile(file_name, bogus_content); | 768 CreateTextFile(file_name, bogus_content); |
769 ASSERT_TRUE(file_util::PathExists(file_name)); | 769 ASSERT_TRUE(base::PathExists(file_name)); |
770 | 770 |
771 // Create a symlink to the file. | 771 // Create a symlink to the file. |
772 FilePath file_link = temp_dir_.path().Append("file_link_2"); | 772 FilePath file_link = temp_dir_.path().Append("file_link_2"); |
773 ASSERT_TRUE(file_util::CreateSymbolicLink(file_name, file_link)) | 773 ASSERT_TRUE(file_util::CreateSymbolicLink(file_name, file_link)) |
774 << "Failed to create symlink."; | 774 << "Failed to create symlink."; |
775 | 775 |
776 // Delete the symbolic link. | 776 // Delete the symbolic link. |
777 EXPECT_TRUE(base::Delete(file_link, false)); | 777 EXPECT_TRUE(base::Delete(file_link, false)); |
778 | 778 |
779 // Make sure original file is not deleted. | 779 // Make sure original file is not deleted. |
780 EXPECT_FALSE(file_util::PathExists(file_link)); | 780 EXPECT_FALSE(base::PathExists(file_link)); |
781 EXPECT_TRUE(file_util::PathExists(file_name)); | 781 EXPECT_TRUE(base::PathExists(file_name)); |
782 } | 782 } |
783 | 783 |
784 TEST_F(FileUtilTest, DeleteSymlinkToNonExistentFile) { | 784 TEST_F(FileUtilTest, DeleteSymlinkToNonExistentFile) { |
785 // Create a non-existent file path. | 785 // Create a non-existent file path. |
786 FilePath non_existent = temp_dir_.path().Append(FPL("Test DeleteFile 3.txt")); | 786 FilePath non_existent = temp_dir_.path().Append(FPL("Test DeleteFile 3.txt")); |
787 EXPECT_FALSE(file_util::PathExists(non_existent)); | 787 EXPECT_FALSE(base::PathExists(non_existent)); |
788 | 788 |
789 // Create a symlink to the non-existent file. | 789 // Create a symlink to the non-existent file. |
790 FilePath file_link = temp_dir_.path().Append("file_link_3"); | 790 FilePath file_link = temp_dir_.path().Append("file_link_3"); |
791 ASSERT_TRUE(file_util::CreateSymbolicLink(non_existent, file_link)) | 791 ASSERT_TRUE(file_util::CreateSymbolicLink(non_existent, file_link)) |
792 << "Failed to create symlink."; | 792 << "Failed to create symlink."; |
793 | 793 |
794 // Make sure the symbolic link is exist. | 794 // Make sure the symbolic link is exist. |
795 EXPECT_TRUE(file_util::IsLink(file_link)); | 795 EXPECT_TRUE(file_util::IsLink(file_link)); |
796 EXPECT_FALSE(file_util::PathExists(file_link)); | 796 EXPECT_FALSE(base::PathExists(file_link)); |
797 | 797 |
798 // Delete the symbolic link. | 798 // Delete the symbolic link. |
799 EXPECT_TRUE(base::Delete(file_link, false)); | 799 EXPECT_TRUE(base::Delete(file_link, false)); |
800 | 800 |
801 // Make sure the symbolic link is deleted. | 801 // Make sure the symbolic link is deleted. |
802 EXPECT_FALSE(file_util::IsLink(file_link)); | 802 EXPECT_FALSE(file_util::IsLink(file_link)); |
803 } | 803 } |
804 | 804 |
805 TEST_F(FileUtilTest, ChangeFilePermissionsAndRead) { | 805 TEST_F(FileUtilTest, ChangeFilePermissionsAndRead) { |
806 // Create a file path. | 806 // Create a file path. |
807 FilePath file_name = temp_dir_.path().Append(FPL("Test Readable File.txt")); | 807 FilePath file_name = temp_dir_.path().Append(FPL("Test Readable File.txt")); |
808 EXPECT_FALSE(file_util::PathExists(file_name)); | 808 EXPECT_FALSE(base::PathExists(file_name)); |
809 | 809 |
810 const std::string kData("hello"); | 810 const std::string kData("hello"); |
811 | 811 |
812 int buffer_size = kData.length(); | 812 int buffer_size = kData.length(); |
813 char* buffer = new char[buffer_size]; | 813 char* buffer = new char[buffer_size]; |
814 | 814 |
815 // Write file. | 815 // Write file. |
816 EXPECT_EQ(static_cast<int>(kData.length()), | 816 EXPECT_EQ(static_cast<int>(kData.length()), |
817 file_util::WriteFile(file_name, kData.data(), kData.length())); | 817 file_util::WriteFile(file_name, kData.data(), kData.length())); |
818 EXPECT_TRUE(file_util::PathExists(file_name)); | 818 EXPECT_TRUE(base::PathExists(file_name)); |
819 | 819 |
820 // Make sure the file is readable. | 820 // Make sure the file is readable. |
821 int32 mode = 0; | 821 int32 mode = 0; |
822 EXPECT_TRUE(file_util::GetPosixFilePermissions(file_name, &mode)); | 822 EXPECT_TRUE(file_util::GetPosixFilePermissions(file_name, &mode)); |
823 EXPECT_TRUE(mode & file_util::FILE_PERMISSION_READ_BY_USER); | 823 EXPECT_TRUE(mode & file_util::FILE_PERMISSION_READ_BY_USER); |
824 | 824 |
825 // Get rid of the read permission. | 825 // Get rid of the read permission. |
826 EXPECT_TRUE(file_util::SetPosixFilePermissions(file_name, 0u)); | 826 EXPECT_TRUE(file_util::SetPosixFilePermissions(file_name, 0u)); |
827 EXPECT_TRUE(file_util::GetPosixFilePermissions(file_name, &mode)); | 827 EXPECT_TRUE(file_util::GetPosixFilePermissions(file_name, &mode)); |
828 EXPECT_FALSE(mode & file_util::FILE_PERMISSION_READ_BY_USER); | 828 EXPECT_FALSE(mode & file_util::FILE_PERMISSION_READ_BY_USER); |
829 // Make sure the file can't be read. | 829 // Make sure the file can't be read. |
830 EXPECT_EQ(-1, file_util::ReadFile(file_name, buffer, buffer_size)); | 830 EXPECT_EQ(-1, file_util::ReadFile(file_name, buffer, buffer_size)); |
831 | 831 |
832 // Give the read permission. | 832 // Give the read permission. |
833 EXPECT_TRUE(file_util::SetPosixFilePermissions( | 833 EXPECT_TRUE(file_util::SetPosixFilePermissions( |
834 file_name, | 834 file_name, |
835 file_util::FILE_PERMISSION_READ_BY_USER)); | 835 file_util::FILE_PERMISSION_READ_BY_USER)); |
836 EXPECT_TRUE(file_util::GetPosixFilePermissions(file_name, &mode)); | 836 EXPECT_TRUE(file_util::GetPosixFilePermissions(file_name, &mode)); |
837 EXPECT_TRUE(mode & file_util::FILE_PERMISSION_READ_BY_USER); | 837 EXPECT_TRUE(mode & file_util::FILE_PERMISSION_READ_BY_USER); |
838 // Make sure the file can be read. | 838 // Make sure the file can be read. |
839 EXPECT_EQ(static_cast<int>(kData.length()), | 839 EXPECT_EQ(static_cast<int>(kData.length()), |
840 file_util::ReadFile(file_name, buffer, buffer_size)); | 840 file_util::ReadFile(file_name, buffer, buffer_size)); |
841 | 841 |
842 // Delete the file. | 842 // Delete the file. |
843 EXPECT_TRUE(base::Delete(file_name, false)); | 843 EXPECT_TRUE(base::Delete(file_name, false)); |
844 EXPECT_FALSE(file_util::PathExists(file_name)); | 844 EXPECT_FALSE(base::PathExists(file_name)); |
845 | 845 |
846 delete[] buffer; | 846 delete[] buffer; |
847 } | 847 } |
848 | 848 |
849 TEST_F(FileUtilTest, ChangeFilePermissionsAndWrite) { | 849 TEST_F(FileUtilTest, ChangeFilePermissionsAndWrite) { |
850 // Create a file path. | 850 // Create a file path. |
851 FilePath file_name = temp_dir_.path().Append(FPL("Test Readable File.txt")); | 851 FilePath file_name = temp_dir_.path().Append(FPL("Test Readable File.txt")); |
852 EXPECT_FALSE(file_util::PathExists(file_name)); | 852 EXPECT_FALSE(base::PathExists(file_name)); |
853 | 853 |
854 const std::string kData("hello"); | 854 const std::string kData("hello"); |
855 | 855 |
856 // Write file. | 856 // Write file. |
857 EXPECT_EQ(static_cast<int>(kData.length()), | 857 EXPECT_EQ(static_cast<int>(kData.length()), |
858 file_util::WriteFile(file_name, kData.data(), kData.length())); | 858 file_util::WriteFile(file_name, kData.data(), kData.length())); |
859 EXPECT_TRUE(file_util::PathExists(file_name)); | 859 EXPECT_TRUE(base::PathExists(file_name)); |
860 | 860 |
861 // Make sure the file is writable. | 861 // Make sure the file is writable. |
862 int mode = 0; | 862 int mode = 0; |
863 EXPECT_TRUE(file_util::GetPosixFilePermissions(file_name, &mode)); | 863 EXPECT_TRUE(file_util::GetPosixFilePermissions(file_name, &mode)); |
864 EXPECT_TRUE(mode & file_util::FILE_PERMISSION_WRITE_BY_USER); | 864 EXPECT_TRUE(mode & file_util::FILE_PERMISSION_WRITE_BY_USER); |
865 EXPECT_TRUE(file_util::PathIsWritable(file_name)); | 865 EXPECT_TRUE(file_util::PathIsWritable(file_name)); |
866 | 866 |
867 // Get rid of the write permission. | 867 // Get rid of the write permission. |
868 EXPECT_TRUE(file_util::SetPosixFilePermissions(file_name, 0u)); | 868 EXPECT_TRUE(file_util::SetPosixFilePermissions(file_name, 0u)); |
869 EXPECT_TRUE(file_util::GetPosixFilePermissions(file_name, &mode)); | 869 EXPECT_TRUE(file_util::GetPosixFilePermissions(file_name, &mode)); |
870 EXPECT_FALSE(mode & file_util::FILE_PERMISSION_WRITE_BY_USER); | 870 EXPECT_FALSE(mode & file_util::FILE_PERMISSION_WRITE_BY_USER); |
871 // Make sure the file can't be write. | 871 // Make sure the file can't be write. |
872 EXPECT_EQ(-1, | 872 EXPECT_EQ(-1, |
873 file_util::WriteFile(file_name, kData.data(), kData.length())); | 873 file_util::WriteFile(file_name, kData.data(), kData.length())); |
874 EXPECT_FALSE(file_util::PathIsWritable(file_name)); | 874 EXPECT_FALSE(file_util::PathIsWritable(file_name)); |
875 | 875 |
876 // Give read permission. | 876 // Give read permission. |
877 EXPECT_TRUE(file_util::SetPosixFilePermissions( | 877 EXPECT_TRUE(file_util::SetPosixFilePermissions( |
878 file_name, | 878 file_name, |
879 file_util::FILE_PERMISSION_WRITE_BY_USER)); | 879 file_util::FILE_PERMISSION_WRITE_BY_USER)); |
880 EXPECT_TRUE(file_util::GetPosixFilePermissions(file_name, &mode)); | 880 EXPECT_TRUE(file_util::GetPosixFilePermissions(file_name, &mode)); |
881 EXPECT_TRUE(mode & file_util::FILE_PERMISSION_WRITE_BY_USER); | 881 EXPECT_TRUE(mode & file_util::FILE_PERMISSION_WRITE_BY_USER); |
882 // Make sure the file can be write. | 882 // Make sure the file can be write. |
883 EXPECT_EQ(static_cast<int>(kData.length()), | 883 EXPECT_EQ(static_cast<int>(kData.length()), |
884 file_util::WriteFile(file_name, kData.data(), kData.length())); | 884 file_util::WriteFile(file_name, kData.data(), kData.length())); |
885 EXPECT_TRUE(file_util::PathIsWritable(file_name)); | 885 EXPECT_TRUE(file_util::PathIsWritable(file_name)); |
886 | 886 |
887 // Delete the file. | 887 // Delete the file. |
888 EXPECT_TRUE(base::Delete(file_name, false)); | 888 EXPECT_TRUE(base::Delete(file_name, false)); |
889 EXPECT_FALSE(file_util::PathExists(file_name)); | 889 EXPECT_FALSE(base::PathExists(file_name)); |
890 } | 890 } |
891 | 891 |
892 TEST_F(FileUtilTest, ChangeDirectoryPermissionsAndEnumerate) { | 892 TEST_F(FileUtilTest, ChangeDirectoryPermissionsAndEnumerate) { |
893 // Create a directory path. | 893 // Create a directory path. |
894 FilePath subdir_path = | 894 FilePath subdir_path = |
895 temp_dir_.path().Append(FPL("PermissionTest1")); | 895 temp_dir_.path().Append(FPL("PermissionTest1")); |
896 file_util::CreateDirectory(subdir_path); | 896 file_util::CreateDirectory(subdir_path); |
897 ASSERT_TRUE(file_util::PathExists(subdir_path)); | 897 ASSERT_TRUE(base::PathExists(subdir_path)); |
898 | 898 |
899 // Create a dummy file to enumerate. | 899 // Create a dummy file to enumerate. |
900 FilePath file_name = subdir_path.Append(FPL("Test Readable File.txt")); | 900 FilePath file_name = subdir_path.Append(FPL("Test Readable File.txt")); |
901 EXPECT_FALSE(file_util::PathExists(file_name)); | 901 EXPECT_FALSE(base::PathExists(file_name)); |
902 const std::string kData("hello"); | 902 const std::string kData("hello"); |
903 EXPECT_EQ(static_cast<int>(kData.length()), | 903 EXPECT_EQ(static_cast<int>(kData.length()), |
904 file_util::WriteFile(file_name, kData.data(), kData.length())); | 904 file_util::WriteFile(file_name, kData.data(), kData.length())); |
905 EXPECT_TRUE(file_util::PathExists(file_name)); | 905 EXPECT_TRUE(base::PathExists(file_name)); |
906 | 906 |
907 // Make sure the directory has the all permissions. | 907 // Make sure the directory has the all permissions. |
908 int mode = 0; | 908 int mode = 0; |
909 EXPECT_TRUE(file_util::GetPosixFilePermissions(subdir_path, &mode)); | 909 EXPECT_TRUE(file_util::GetPosixFilePermissions(subdir_path, &mode)); |
910 EXPECT_EQ(file_util::FILE_PERMISSION_USER_MASK, | 910 EXPECT_EQ(file_util::FILE_PERMISSION_USER_MASK, |
911 mode & file_util::FILE_PERMISSION_USER_MASK); | 911 mode & file_util::FILE_PERMISSION_USER_MASK); |
912 | 912 |
913 // Get rid of the permissions from the directory. | 913 // Get rid of the permissions from the directory. |
914 EXPECT_TRUE(file_util::SetPosixFilePermissions(subdir_path, 0u)); | 914 EXPECT_TRUE(file_util::SetPosixFilePermissions(subdir_path, 0u)); |
915 EXPECT_TRUE(file_util::GetPosixFilePermissions(subdir_path, &mode)); | 915 EXPECT_TRUE(file_util::GetPosixFilePermissions(subdir_path, &mode)); |
916 EXPECT_FALSE(mode & file_util::FILE_PERMISSION_USER_MASK); | 916 EXPECT_FALSE(mode & file_util::FILE_PERMISSION_USER_MASK); |
917 | 917 |
918 // Make sure the file in the directory can't be enumerated. | 918 // Make sure the file in the directory can't be enumerated. |
919 FileEnumerator f1(subdir_path, true, FileEnumerator::FILES); | 919 FileEnumerator f1(subdir_path, true, FileEnumerator::FILES); |
920 EXPECT_TRUE(file_util::PathExists(subdir_path)); | 920 EXPECT_TRUE(base::PathExists(subdir_path)); |
921 FindResultCollector c1(f1); | 921 FindResultCollector c1(f1); |
922 EXPECT_EQ(c1.size(), 0); | 922 EXPECT_EQ(c1.size(), 0); |
923 EXPECT_FALSE(file_util::GetPosixFilePermissions(file_name, &mode)); | 923 EXPECT_FALSE(file_util::GetPosixFilePermissions(file_name, &mode)); |
924 | 924 |
925 // Give the permissions to the directory. | 925 // Give the permissions to the directory. |
926 EXPECT_TRUE(file_util::SetPosixFilePermissions( | 926 EXPECT_TRUE(file_util::SetPosixFilePermissions( |
927 subdir_path, | 927 subdir_path, |
928 file_util::FILE_PERMISSION_USER_MASK)); | 928 file_util::FILE_PERMISSION_USER_MASK)); |
929 EXPECT_TRUE(file_util::GetPosixFilePermissions(subdir_path, &mode)); | 929 EXPECT_TRUE(file_util::GetPosixFilePermissions(subdir_path, &mode)); |
930 EXPECT_EQ(file_util::FILE_PERMISSION_USER_MASK, | 930 EXPECT_EQ(file_util::FILE_PERMISSION_USER_MASK, |
931 mode & file_util::FILE_PERMISSION_USER_MASK); | 931 mode & file_util::FILE_PERMISSION_USER_MASK); |
932 | 932 |
933 // Make sure the file in the directory can be enumerated. | 933 // Make sure the file in the directory can be enumerated. |
934 FileEnumerator f2(subdir_path, true, FileEnumerator::FILES); | 934 FileEnumerator f2(subdir_path, true, FileEnumerator::FILES); |
935 FindResultCollector c2(f2); | 935 FindResultCollector c2(f2); |
936 EXPECT_TRUE(c2.HasFile(file_name)); | 936 EXPECT_TRUE(c2.HasFile(file_name)); |
937 EXPECT_EQ(c2.size(), 1); | 937 EXPECT_EQ(c2.size(), 1); |
938 | 938 |
939 // Delete the file. | 939 // Delete the file. |
940 EXPECT_TRUE(base::Delete(subdir_path, true)); | 940 EXPECT_TRUE(base::Delete(subdir_path, true)); |
941 EXPECT_FALSE(file_util::PathExists(subdir_path)); | 941 EXPECT_FALSE(base::PathExists(subdir_path)); |
942 } | 942 } |
943 | 943 |
944 #endif // defined(OS_POSIX) | 944 #endif // defined(OS_POSIX) |
945 | 945 |
946 #if defined(OS_WIN) | 946 #if defined(OS_WIN) |
947 // Tests that the Delete function works for wild cards, especially | 947 // Tests that the Delete function works for wild cards, especially |
948 // with the recursion flag. Also coincidentally tests PathExists. | 948 // with the recursion flag. Also coincidentally tests PathExists. |
949 // TODO(erikkay): see if anyone's actually using this feature of the API | 949 // TODO(erikkay): see if anyone's actually using this feature of the API |
950 TEST_F(FileUtilTest, DeleteWildCard) { | 950 TEST_F(FileUtilTest, DeleteWildCard) { |
951 // Create a file and a directory | 951 // Create a file and a directory |
952 FilePath file_name = temp_dir_.path().Append(FPL("Test DeleteWildCard.txt")); | 952 FilePath file_name = temp_dir_.path().Append(FPL("Test DeleteWildCard.txt")); |
953 CreateTextFile(file_name, bogus_content); | 953 CreateTextFile(file_name, bogus_content); |
954 ASSERT_TRUE(file_util::PathExists(file_name)); | 954 ASSERT_TRUE(base::PathExists(file_name)); |
955 | 955 |
956 FilePath subdir_path = temp_dir_.path().Append(FPL("DeleteWildCardDir")); | 956 FilePath subdir_path = temp_dir_.path().Append(FPL("DeleteWildCardDir")); |
957 file_util::CreateDirectory(subdir_path); | 957 file_util::CreateDirectory(subdir_path); |
958 ASSERT_TRUE(file_util::PathExists(subdir_path)); | 958 ASSERT_TRUE(base::PathExists(subdir_path)); |
959 | 959 |
960 // Create the wildcard path | 960 // Create the wildcard path |
961 FilePath directory_contents = temp_dir_.path(); | 961 FilePath directory_contents = temp_dir_.path(); |
962 directory_contents = directory_contents.Append(FPL("*")); | 962 directory_contents = directory_contents.Append(FPL("*")); |
963 | 963 |
964 // Delete non-recursively and check that only the file is deleted | 964 // Delete non-recursively and check that only the file is deleted |
965 EXPECT_TRUE(base::Delete(directory_contents, false)); | 965 EXPECT_TRUE(base::Delete(directory_contents, false)); |
966 EXPECT_FALSE(file_util::PathExists(file_name)); | 966 EXPECT_FALSE(base::PathExists(file_name)); |
967 EXPECT_TRUE(file_util::PathExists(subdir_path)); | 967 EXPECT_TRUE(base::PathExists(subdir_path)); |
968 | 968 |
969 // Delete recursively and make sure all contents are deleted | 969 // Delete recursively and make sure all contents are deleted |
970 EXPECT_TRUE(base::Delete(directory_contents, true)); | 970 EXPECT_TRUE(base::Delete(directory_contents, true)); |
971 EXPECT_FALSE(file_util::PathExists(file_name)); | 971 EXPECT_FALSE(base::PathExists(file_name)); |
972 EXPECT_FALSE(file_util::PathExists(subdir_path)); | 972 EXPECT_FALSE(base::PathExists(subdir_path)); |
973 } | 973 } |
974 | 974 |
975 // TODO(erikkay): see if anyone's actually using this feature of the API | 975 // TODO(erikkay): see if anyone's actually using this feature of the API |
976 TEST_F(FileUtilTest, DeleteNonExistantWildCard) { | 976 TEST_F(FileUtilTest, DeleteNonExistantWildCard) { |
977 // Create a file and a directory | 977 // Create a file and a directory |
978 FilePath subdir_path = | 978 FilePath subdir_path = |
979 temp_dir_.path().Append(FPL("DeleteNonExistantWildCard")); | 979 temp_dir_.path().Append(FPL("DeleteNonExistantWildCard")); |
980 file_util::CreateDirectory(subdir_path); | 980 file_util::CreateDirectory(subdir_path); |
981 ASSERT_TRUE(file_util::PathExists(subdir_path)); | 981 ASSERT_TRUE(base::PathExists(subdir_path)); |
982 | 982 |
983 // Create the wildcard path | 983 // Create the wildcard path |
984 FilePath directory_contents = subdir_path; | 984 FilePath directory_contents = subdir_path; |
985 directory_contents = directory_contents.Append(FPL("*")); | 985 directory_contents = directory_contents.Append(FPL("*")); |
986 | 986 |
987 // Delete non-recursively and check nothing got deleted | 987 // Delete non-recursively and check nothing got deleted |
988 EXPECT_TRUE(base::Delete(directory_contents, false)); | 988 EXPECT_TRUE(base::Delete(directory_contents, false)); |
989 EXPECT_TRUE(file_util::PathExists(subdir_path)); | 989 EXPECT_TRUE(base::PathExists(subdir_path)); |
990 | 990 |
991 // Delete recursively and check nothing got deleted | 991 // Delete recursively and check nothing got deleted |
992 EXPECT_TRUE(base::Delete(directory_contents, true)); | 992 EXPECT_TRUE(base::Delete(directory_contents, true)); |
993 EXPECT_TRUE(file_util::PathExists(subdir_path)); | 993 EXPECT_TRUE(base::PathExists(subdir_path)); |
994 } | 994 } |
995 #endif | 995 #endif |
996 | 996 |
997 // Tests non-recursive Delete() for a directory. | 997 // Tests non-recursive Delete() for a directory. |
998 TEST_F(FileUtilTest, DeleteDirNonRecursive) { | 998 TEST_F(FileUtilTest, DeleteDirNonRecursive) { |
999 // Create a subdirectory and put a file and two directories inside. | 999 // Create a subdirectory and put a file and two directories inside. |
1000 FilePath test_subdir = temp_dir_.path().Append(FPL("DeleteDirNonRecursive")); | 1000 FilePath test_subdir = temp_dir_.path().Append(FPL("DeleteDirNonRecursive")); |
1001 file_util::CreateDirectory(test_subdir); | 1001 file_util::CreateDirectory(test_subdir); |
1002 ASSERT_TRUE(file_util::PathExists(test_subdir)); | 1002 ASSERT_TRUE(base::PathExists(test_subdir)); |
1003 | 1003 |
1004 FilePath file_name = test_subdir.Append(FPL("Test DeleteDir.txt")); | 1004 FilePath file_name = test_subdir.Append(FPL("Test DeleteDir.txt")); |
1005 CreateTextFile(file_name, bogus_content); | 1005 CreateTextFile(file_name, bogus_content); |
1006 ASSERT_TRUE(file_util::PathExists(file_name)); | 1006 ASSERT_TRUE(base::PathExists(file_name)); |
1007 | 1007 |
1008 FilePath subdir_path1 = test_subdir.Append(FPL("TestSubDir1")); | 1008 FilePath subdir_path1 = test_subdir.Append(FPL("TestSubDir1")); |
1009 file_util::CreateDirectory(subdir_path1); | 1009 file_util::CreateDirectory(subdir_path1); |
1010 ASSERT_TRUE(file_util::PathExists(subdir_path1)); | 1010 ASSERT_TRUE(base::PathExists(subdir_path1)); |
1011 | 1011 |
1012 FilePath subdir_path2 = test_subdir.Append(FPL("TestSubDir2")); | 1012 FilePath subdir_path2 = test_subdir.Append(FPL("TestSubDir2")); |
1013 file_util::CreateDirectory(subdir_path2); | 1013 file_util::CreateDirectory(subdir_path2); |
1014 ASSERT_TRUE(file_util::PathExists(subdir_path2)); | 1014 ASSERT_TRUE(base::PathExists(subdir_path2)); |
1015 | 1015 |
1016 // Delete non-recursively and check that the empty dir got deleted | 1016 // Delete non-recursively and check that the empty dir got deleted |
1017 EXPECT_TRUE(base::Delete(subdir_path2, false)); | 1017 EXPECT_TRUE(base::Delete(subdir_path2, false)); |
1018 EXPECT_FALSE(file_util::PathExists(subdir_path2)); | 1018 EXPECT_FALSE(base::PathExists(subdir_path2)); |
1019 | 1019 |
1020 // Delete non-recursively and check that nothing got deleted | 1020 // Delete non-recursively and check that nothing got deleted |
1021 EXPECT_FALSE(base::Delete(test_subdir, false)); | 1021 EXPECT_FALSE(base::Delete(test_subdir, false)); |
1022 EXPECT_TRUE(file_util::PathExists(test_subdir)); | 1022 EXPECT_TRUE(base::PathExists(test_subdir)); |
1023 EXPECT_TRUE(file_util::PathExists(file_name)); | 1023 EXPECT_TRUE(base::PathExists(file_name)); |
1024 EXPECT_TRUE(file_util::PathExists(subdir_path1)); | 1024 EXPECT_TRUE(base::PathExists(subdir_path1)); |
1025 } | 1025 } |
1026 | 1026 |
1027 // Tests recursive Delete() for a directory. | 1027 // Tests recursive Delete() for a directory. |
1028 TEST_F(FileUtilTest, DeleteDirRecursive) { | 1028 TEST_F(FileUtilTest, DeleteDirRecursive) { |
1029 // Create a subdirectory and put a file and two directories inside. | 1029 // Create a subdirectory and put a file and two directories inside. |
1030 FilePath test_subdir = temp_dir_.path().Append(FPL("DeleteDirRecursive")); | 1030 FilePath test_subdir = temp_dir_.path().Append(FPL("DeleteDirRecursive")); |
1031 file_util::CreateDirectory(test_subdir); | 1031 file_util::CreateDirectory(test_subdir); |
1032 ASSERT_TRUE(file_util::PathExists(test_subdir)); | 1032 ASSERT_TRUE(base::PathExists(test_subdir)); |
1033 | 1033 |
1034 FilePath file_name = test_subdir.Append(FPL("Test DeleteDirRecursive.txt")); | 1034 FilePath file_name = test_subdir.Append(FPL("Test DeleteDirRecursive.txt")); |
1035 CreateTextFile(file_name, bogus_content); | 1035 CreateTextFile(file_name, bogus_content); |
1036 ASSERT_TRUE(file_util::PathExists(file_name)); | 1036 ASSERT_TRUE(base::PathExists(file_name)); |
1037 | 1037 |
1038 FilePath subdir_path1 = test_subdir.Append(FPL("TestSubDir1")); | 1038 FilePath subdir_path1 = test_subdir.Append(FPL("TestSubDir1")); |
1039 file_util::CreateDirectory(subdir_path1); | 1039 file_util::CreateDirectory(subdir_path1); |
1040 ASSERT_TRUE(file_util::PathExists(subdir_path1)); | 1040 ASSERT_TRUE(base::PathExists(subdir_path1)); |
1041 | 1041 |
1042 FilePath subdir_path2 = test_subdir.Append(FPL("TestSubDir2")); | 1042 FilePath subdir_path2 = test_subdir.Append(FPL("TestSubDir2")); |
1043 file_util::CreateDirectory(subdir_path2); | 1043 file_util::CreateDirectory(subdir_path2); |
1044 ASSERT_TRUE(file_util::PathExists(subdir_path2)); | 1044 ASSERT_TRUE(base::PathExists(subdir_path2)); |
1045 | 1045 |
1046 // Delete recursively and check that the empty dir got deleted | 1046 // Delete recursively and check that the empty dir got deleted |
1047 EXPECT_TRUE(base::Delete(subdir_path2, true)); | 1047 EXPECT_TRUE(base::Delete(subdir_path2, true)); |
1048 EXPECT_FALSE(file_util::PathExists(subdir_path2)); | 1048 EXPECT_FALSE(base::PathExists(subdir_path2)); |
1049 | 1049 |
1050 // Delete recursively and check that everything got deleted | 1050 // Delete recursively and check that everything got deleted |
1051 EXPECT_TRUE(base::Delete(test_subdir, true)); | 1051 EXPECT_TRUE(base::Delete(test_subdir, true)); |
1052 EXPECT_FALSE(file_util::PathExists(file_name)); | 1052 EXPECT_FALSE(base::PathExists(file_name)); |
1053 EXPECT_FALSE(file_util::PathExists(subdir_path1)); | 1053 EXPECT_FALSE(base::PathExists(subdir_path1)); |
1054 EXPECT_FALSE(file_util::PathExists(test_subdir)); | 1054 EXPECT_FALSE(base::PathExists(test_subdir)); |
1055 } | 1055 } |
1056 | 1056 |
1057 TEST_F(FileUtilTest, MoveFileNew) { | 1057 TEST_F(FileUtilTest, MoveFileNew) { |
1058 // Create a file | 1058 // Create a file |
1059 FilePath file_name_from = | 1059 FilePath file_name_from = |
1060 temp_dir_.path().Append(FILE_PATH_LITERAL("Move_Test_File.txt")); | 1060 temp_dir_.path().Append(FILE_PATH_LITERAL("Move_Test_File.txt")); |
1061 CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle"); | 1061 CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle"); |
1062 ASSERT_TRUE(file_util::PathExists(file_name_from)); | 1062 ASSERT_TRUE(base::PathExists(file_name_from)); |
1063 | 1063 |
1064 // The destination. | 1064 // The destination. |
1065 FilePath file_name_to = temp_dir_.path().Append( | 1065 FilePath file_name_to = temp_dir_.path().Append( |
1066 FILE_PATH_LITERAL("Move_Test_File_Destination.txt")); | 1066 FILE_PATH_LITERAL("Move_Test_File_Destination.txt")); |
1067 ASSERT_FALSE(file_util::PathExists(file_name_to)); | 1067 ASSERT_FALSE(base::PathExists(file_name_to)); |
1068 | 1068 |
1069 EXPECT_TRUE(base::Move(file_name_from, file_name_to)); | 1069 EXPECT_TRUE(base::Move(file_name_from, file_name_to)); |
1070 | 1070 |
1071 // Check everything has been moved. | 1071 // Check everything has been moved. |
1072 EXPECT_FALSE(file_util::PathExists(file_name_from)); | 1072 EXPECT_FALSE(base::PathExists(file_name_from)); |
1073 EXPECT_TRUE(file_util::PathExists(file_name_to)); | 1073 EXPECT_TRUE(base::PathExists(file_name_to)); |
1074 } | 1074 } |
1075 | 1075 |
1076 TEST_F(FileUtilTest, MoveFileExists) { | 1076 TEST_F(FileUtilTest, MoveFileExists) { |
1077 // Create a file | 1077 // Create a file |
1078 FilePath file_name_from = | 1078 FilePath file_name_from = |
1079 temp_dir_.path().Append(FILE_PATH_LITERAL("Move_Test_File.txt")); | 1079 temp_dir_.path().Append(FILE_PATH_LITERAL("Move_Test_File.txt")); |
1080 CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle"); | 1080 CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle"); |
1081 ASSERT_TRUE(file_util::PathExists(file_name_from)); | 1081 ASSERT_TRUE(base::PathExists(file_name_from)); |
1082 | 1082 |
1083 // The destination name. | 1083 // The destination name. |
1084 FilePath file_name_to = temp_dir_.path().Append( | 1084 FilePath file_name_to = temp_dir_.path().Append( |
1085 FILE_PATH_LITERAL("Move_Test_File_Destination.txt")); | 1085 FILE_PATH_LITERAL("Move_Test_File_Destination.txt")); |
1086 CreateTextFile(file_name_to, L"Old file content"); | 1086 CreateTextFile(file_name_to, L"Old file content"); |
1087 ASSERT_TRUE(file_util::PathExists(file_name_to)); | 1087 ASSERT_TRUE(base::PathExists(file_name_to)); |
1088 | 1088 |
1089 EXPECT_TRUE(base::Move(file_name_from, file_name_to)); | 1089 EXPECT_TRUE(base::Move(file_name_from, file_name_to)); |
1090 | 1090 |
1091 // Check everything has been moved. | 1091 // Check everything has been moved. |
1092 EXPECT_FALSE(file_util::PathExists(file_name_from)); | 1092 EXPECT_FALSE(base::PathExists(file_name_from)); |
1093 EXPECT_TRUE(file_util::PathExists(file_name_to)); | 1093 EXPECT_TRUE(base::PathExists(file_name_to)); |
1094 EXPECT_TRUE(L"Gooooooooooooooooooooogle" == ReadTextFile(file_name_to)); | 1094 EXPECT_TRUE(L"Gooooooooooooooooooooogle" == ReadTextFile(file_name_to)); |
1095 } | 1095 } |
1096 | 1096 |
1097 TEST_F(FileUtilTest, MoveFileDirExists) { | 1097 TEST_F(FileUtilTest, MoveFileDirExists) { |
1098 // Create a file | 1098 // Create a file |
1099 FilePath file_name_from = | 1099 FilePath file_name_from = |
1100 temp_dir_.path().Append(FILE_PATH_LITERAL("Move_Test_File.txt")); | 1100 temp_dir_.path().Append(FILE_PATH_LITERAL("Move_Test_File.txt")); |
1101 CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle"); | 1101 CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle"); |
1102 ASSERT_TRUE(file_util::PathExists(file_name_from)); | 1102 ASSERT_TRUE(base::PathExists(file_name_from)); |
1103 | 1103 |
1104 // The destination directory | 1104 // The destination directory |
1105 FilePath dir_name_to = | 1105 FilePath dir_name_to = |
1106 temp_dir_.path().Append(FILE_PATH_LITERAL("Destination")); | 1106 temp_dir_.path().Append(FILE_PATH_LITERAL("Destination")); |
1107 file_util::CreateDirectory(dir_name_to); | 1107 file_util::CreateDirectory(dir_name_to); |
1108 ASSERT_TRUE(file_util::PathExists(dir_name_to)); | 1108 ASSERT_TRUE(base::PathExists(dir_name_to)); |
1109 | 1109 |
1110 EXPECT_FALSE(base::Move(file_name_from, dir_name_to)); | 1110 EXPECT_FALSE(base::Move(file_name_from, dir_name_to)); |
1111 } | 1111 } |
1112 | 1112 |
1113 | 1113 |
1114 TEST_F(FileUtilTest, MoveNew) { | 1114 TEST_F(FileUtilTest, MoveNew) { |
1115 // Create a directory | 1115 // Create a directory |
1116 FilePath dir_name_from = | 1116 FilePath dir_name_from = |
1117 temp_dir_.path().Append(FILE_PATH_LITERAL("Move_From_Subdir")); | 1117 temp_dir_.path().Append(FILE_PATH_LITERAL("Move_From_Subdir")); |
1118 file_util::CreateDirectory(dir_name_from); | 1118 file_util::CreateDirectory(dir_name_from); |
1119 ASSERT_TRUE(file_util::PathExists(dir_name_from)); | 1119 ASSERT_TRUE(base::PathExists(dir_name_from)); |
1120 | 1120 |
1121 // Create a file under the directory | 1121 // Create a file under the directory |
1122 FilePath txt_file_name(FILE_PATH_LITERAL("Move_Test_File.txt")); | 1122 FilePath txt_file_name(FILE_PATH_LITERAL("Move_Test_File.txt")); |
1123 FilePath file_name_from = dir_name_from.Append(txt_file_name); | 1123 FilePath file_name_from = dir_name_from.Append(txt_file_name); |
1124 CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle"); | 1124 CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle"); |
1125 ASSERT_TRUE(file_util::PathExists(file_name_from)); | 1125 ASSERT_TRUE(base::PathExists(file_name_from)); |
1126 | 1126 |
1127 // Move the directory. | 1127 // Move the directory. |
1128 FilePath dir_name_to = | 1128 FilePath dir_name_to = |
1129 temp_dir_.path().Append(FILE_PATH_LITERAL("Move_To_Subdir")); | 1129 temp_dir_.path().Append(FILE_PATH_LITERAL("Move_To_Subdir")); |
1130 FilePath file_name_to = | 1130 FilePath file_name_to = |
1131 dir_name_to.Append(FILE_PATH_LITERAL("Move_Test_File.txt")); | 1131 dir_name_to.Append(FILE_PATH_LITERAL("Move_Test_File.txt")); |
1132 | 1132 |
1133 ASSERT_FALSE(file_util::PathExists(dir_name_to)); | 1133 ASSERT_FALSE(base::PathExists(dir_name_to)); |
1134 | 1134 |
1135 EXPECT_TRUE(base::Move(dir_name_from, dir_name_to)); | 1135 EXPECT_TRUE(base::Move(dir_name_from, dir_name_to)); |
1136 | 1136 |
1137 // Check everything has been moved. | 1137 // Check everything has been moved. |
1138 EXPECT_FALSE(file_util::PathExists(dir_name_from)); | 1138 EXPECT_FALSE(base::PathExists(dir_name_from)); |
1139 EXPECT_FALSE(file_util::PathExists(file_name_from)); | 1139 EXPECT_FALSE(base::PathExists(file_name_from)); |
1140 EXPECT_TRUE(file_util::PathExists(dir_name_to)); | 1140 EXPECT_TRUE(base::PathExists(dir_name_to)); |
1141 EXPECT_TRUE(file_util::PathExists(file_name_to)); | 1141 EXPECT_TRUE(base::PathExists(file_name_to)); |
1142 | 1142 |
1143 // Test path traversal. | 1143 // Test path traversal. |
1144 file_name_from = dir_name_to.Append(txt_file_name); | 1144 file_name_from = dir_name_to.Append(txt_file_name); |
1145 file_name_to = dir_name_to.Append(FILE_PATH_LITERAL("..")); | 1145 file_name_to = dir_name_to.Append(FILE_PATH_LITERAL("..")); |
1146 file_name_to = file_name_to.Append(txt_file_name); | 1146 file_name_to = file_name_to.Append(txt_file_name); |
1147 EXPECT_FALSE(base::Move(file_name_from, file_name_to)); | 1147 EXPECT_FALSE(base::Move(file_name_from, file_name_to)); |
1148 EXPECT_TRUE(file_util::PathExists(file_name_from)); | 1148 EXPECT_TRUE(base::PathExists(file_name_from)); |
1149 EXPECT_FALSE(file_util::PathExists(file_name_to)); | 1149 EXPECT_FALSE(base::PathExists(file_name_to)); |
1150 EXPECT_TRUE(base::internal::MoveUnsafe(file_name_from, file_name_to)); | 1150 EXPECT_TRUE(base::internal::MoveUnsafe(file_name_from, file_name_to)); |
1151 EXPECT_FALSE(file_util::PathExists(file_name_from)); | 1151 EXPECT_FALSE(base::PathExists(file_name_from)); |
1152 EXPECT_TRUE(file_util::PathExists(file_name_to)); | 1152 EXPECT_TRUE(base::PathExists(file_name_to)); |
1153 } | 1153 } |
1154 | 1154 |
1155 TEST_F(FileUtilTest, MoveExist) { | 1155 TEST_F(FileUtilTest, MoveExist) { |
1156 // Create a directory | 1156 // Create a directory |
1157 FilePath dir_name_from = | 1157 FilePath dir_name_from = |
1158 temp_dir_.path().Append(FILE_PATH_LITERAL("Move_From_Subdir")); | 1158 temp_dir_.path().Append(FILE_PATH_LITERAL("Move_From_Subdir")); |
1159 file_util::CreateDirectory(dir_name_from); | 1159 file_util::CreateDirectory(dir_name_from); |
1160 ASSERT_TRUE(file_util::PathExists(dir_name_from)); | 1160 ASSERT_TRUE(base::PathExists(dir_name_from)); |
1161 | 1161 |
1162 // Create a file under the directory | 1162 // Create a file under the directory |
1163 FilePath file_name_from = | 1163 FilePath file_name_from = |
1164 dir_name_from.Append(FILE_PATH_LITERAL("Move_Test_File.txt")); | 1164 dir_name_from.Append(FILE_PATH_LITERAL("Move_Test_File.txt")); |
1165 CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle"); | 1165 CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle"); |
1166 ASSERT_TRUE(file_util::PathExists(file_name_from)); | 1166 ASSERT_TRUE(base::PathExists(file_name_from)); |
1167 | 1167 |
1168 // Move the directory | 1168 // Move the directory |
1169 FilePath dir_name_exists = | 1169 FilePath dir_name_exists = |
1170 temp_dir_.path().Append(FILE_PATH_LITERAL("Destination")); | 1170 temp_dir_.path().Append(FILE_PATH_LITERAL("Destination")); |
1171 | 1171 |
1172 FilePath dir_name_to = | 1172 FilePath dir_name_to = |
1173 dir_name_exists.Append(FILE_PATH_LITERAL("Move_To_Subdir")); | 1173 dir_name_exists.Append(FILE_PATH_LITERAL("Move_To_Subdir")); |
1174 FilePath file_name_to = | 1174 FilePath file_name_to = |
1175 dir_name_to.Append(FILE_PATH_LITERAL("Move_Test_File.txt")); | 1175 dir_name_to.Append(FILE_PATH_LITERAL("Move_Test_File.txt")); |
1176 | 1176 |
1177 // Create the destination directory. | 1177 // Create the destination directory. |
1178 file_util::CreateDirectory(dir_name_exists); | 1178 file_util::CreateDirectory(dir_name_exists); |
1179 ASSERT_TRUE(file_util::PathExists(dir_name_exists)); | 1179 ASSERT_TRUE(base::PathExists(dir_name_exists)); |
1180 | 1180 |
1181 EXPECT_TRUE(base::Move(dir_name_from, dir_name_to)); | 1181 EXPECT_TRUE(base::Move(dir_name_from, dir_name_to)); |
1182 | 1182 |
1183 // Check everything has been moved. | 1183 // Check everything has been moved. |
1184 EXPECT_FALSE(file_util::PathExists(dir_name_from)); | 1184 EXPECT_FALSE(base::PathExists(dir_name_from)); |
1185 EXPECT_FALSE(file_util::PathExists(file_name_from)); | 1185 EXPECT_FALSE(base::PathExists(file_name_from)); |
1186 EXPECT_TRUE(file_util::PathExists(dir_name_to)); | 1186 EXPECT_TRUE(base::PathExists(dir_name_to)); |
1187 EXPECT_TRUE(file_util::PathExists(file_name_to)); | 1187 EXPECT_TRUE(base::PathExists(file_name_to)); |
1188 } | 1188 } |
1189 | 1189 |
1190 TEST_F(FileUtilTest, CopyDirectoryRecursivelyNew) { | 1190 TEST_F(FileUtilTest, CopyDirectoryRecursivelyNew) { |
1191 // Create a directory. | 1191 // Create a directory. |
1192 FilePath dir_name_from = | 1192 FilePath dir_name_from = |
1193 temp_dir_.path().Append(FILE_PATH_LITERAL("Copy_From_Subdir")); | 1193 temp_dir_.path().Append(FILE_PATH_LITERAL("Copy_From_Subdir")); |
1194 file_util::CreateDirectory(dir_name_from); | 1194 file_util::CreateDirectory(dir_name_from); |
1195 ASSERT_TRUE(file_util::PathExists(dir_name_from)); | 1195 ASSERT_TRUE(base::PathExists(dir_name_from)); |
1196 | 1196 |
1197 // Create a file under the directory. | 1197 // Create a file under the directory. |
1198 FilePath file_name_from = | 1198 FilePath file_name_from = |
1199 dir_name_from.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); | 1199 dir_name_from.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); |
1200 CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle"); | 1200 CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle"); |
1201 ASSERT_TRUE(file_util::PathExists(file_name_from)); | 1201 ASSERT_TRUE(base::PathExists(file_name_from)); |
1202 | 1202 |
1203 // Create a subdirectory. | 1203 // Create a subdirectory. |
1204 FilePath subdir_name_from = | 1204 FilePath subdir_name_from = |
1205 dir_name_from.Append(FILE_PATH_LITERAL("Subdir")); | 1205 dir_name_from.Append(FILE_PATH_LITERAL("Subdir")); |
1206 file_util::CreateDirectory(subdir_name_from); | 1206 file_util::CreateDirectory(subdir_name_from); |
1207 ASSERT_TRUE(file_util::PathExists(subdir_name_from)); | 1207 ASSERT_TRUE(base::PathExists(subdir_name_from)); |
1208 | 1208 |
1209 // Create a file under the subdirectory. | 1209 // Create a file under the subdirectory. |
1210 FilePath file_name2_from = | 1210 FilePath file_name2_from = |
1211 subdir_name_from.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); | 1211 subdir_name_from.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); |
1212 CreateTextFile(file_name2_from, L"Gooooooooooooooooooooogle"); | 1212 CreateTextFile(file_name2_from, L"Gooooooooooooooooooooogle"); |
1213 ASSERT_TRUE(file_util::PathExists(file_name2_from)); | 1213 ASSERT_TRUE(base::PathExists(file_name2_from)); |
1214 | 1214 |
1215 // Copy the directory recursively. | 1215 // Copy the directory recursively. |
1216 FilePath dir_name_to = | 1216 FilePath dir_name_to = |
1217 temp_dir_.path().Append(FILE_PATH_LITERAL("Copy_To_Subdir")); | 1217 temp_dir_.path().Append(FILE_PATH_LITERAL("Copy_To_Subdir")); |
1218 FilePath file_name_to = | 1218 FilePath file_name_to = |
1219 dir_name_to.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); | 1219 dir_name_to.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); |
1220 FilePath subdir_name_to = | 1220 FilePath subdir_name_to = |
1221 dir_name_to.Append(FILE_PATH_LITERAL("Subdir")); | 1221 dir_name_to.Append(FILE_PATH_LITERAL("Subdir")); |
1222 FilePath file_name2_to = | 1222 FilePath file_name2_to = |
1223 subdir_name_to.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); | 1223 subdir_name_to.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); |
1224 | 1224 |
1225 ASSERT_FALSE(file_util::PathExists(dir_name_to)); | 1225 ASSERT_FALSE(base::PathExists(dir_name_to)); |
1226 | 1226 |
1227 EXPECT_TRUE(base::CopyDirectory(dir_name_from, dir_name_to, true)); | 1227 EXPECT_TRUE(base::CopyDirectory(dir_name_from, dir_name_to, true)); |
1228 | 1228 |
1229 // Check everything has been copied. | 1229 // Check everything has been copied. |
1230 EXPECT_TRUE(file_util::PathExists(dir_name_from)); | 1230 EXPECT_TRUE(base::PathExists(dir_name_from)); |
1231 EXPECT_TRUE(file_util::PathExists(file_name_from)); | 1231 EXPECT_TRUE(base::PathExists(file_name_from)); |
1232 EXPECT_TRUE(file_util::PathExists(subdir_name_from)); | 1232 EXPECT_TRUE(base::PathExists(subdir_name_from)); |
1233 EXPECT_TRUE(file_util::PathExists(file_name2_from)); | 1233 EXPECT_TRUE(base::PathExists(file_name2_from)); |
1234 EXPECT_TRUE(file_util::PathExists(dir_name_to)); | 1234 EXPECT_TRUE(base::PathExists(dir_name_to)); |
1235 EXPECT_TRUE(file_util::PathExists(file_name_to)); | 1235 EXPECT_TRUE(base::PathExists(file_name_to)); |
1236 EXPECT_TRUE(file_util::PathExists(subdir_name_to)); | 1236 EXPECT_TRUE(base::PathExists(subdir_name_to)); |
1237 EXPECT_TRUE(file_util::PathExists(file_name2_to)); | 1237 EXPECT_TRUE(base::PathExists(file_name2_to)); |
1238 } | 1238 } |
1239 | 1239 |
1240 TEST_F(FileUtilTest, CopyDirectoryRecursivelyExists) { | 1240 TEST_F(FileUtilTest, CopyDirectoryRecursivelyExists) { |
1241 // Create a directory. | 1241 // Create a directory. |
1242 FilePath dir_name_from = | 1242 FilePath dir_name_from = |
1243 temp_dir_.path().Append(FILE_PATH_LITERAL("Copy_From_Subdir")); | 1243 temp_dir_.path().Append(FILE_PATH_LITERAL("Copy_From_Subdir")); |
1244 file_util::CreateDirectory(dir_name_from); | 1244 file_util::CreateDirectory(dir_name_from); |
1245 ASSERT_TRUE(file_util::PathExists(dir_name_from)); | 1245 ASSERT_TRUE(base::PathExists(dir_name_from)); |
1246 | 1246 |
1247 // Create a file under the directory. | 1247 // Create a file under the directory. |
1248 FilePath file_name_from = | 1248 FilePath file_name_from = |
1249 dir_name_from.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); | 1249 dir_name_from.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); |
1250 CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle"); | 1250 CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle"); |
1251 ASSERT_TRUE(file_util::PathExists(file_name_from)); | 1251 ASSERT_TRUE(base::PathExists(file_name_from)); |
1252 | 1252 |
1253 // Create a subdirectory. | 1253 // Create a subdirectory. |
1254 FilePath subdir_name_from = | 1254 FilePath subdir_name_from = |
1255 dir_name_from.Append(FILE_PATH_LITERAL("Subdir")); | 1255 dir_name_from.Append(FILE_PATH_LITERAL("Subdir")); |
1256 file_util::CreateDirectory(subdir_name_from); | 1256 file_util::CreateDirectory(subdir_name_from); |
1257 ASSERT_TRUE(file_util::PathExists(subdir_name_from)); | 1257 ASSERT_TRUE(base::PathExists(subdir_name_from)); |
1258 | 1258 |
1259 // Create a file under the subdirectory. | 1259 // Create a file under the subdirectory. |
1260 FilePath file_name2_from = | 1260 FilePath file_name2_from = |
1261 subdir_name_from.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); | 1261 subdir_name_from.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); |
1262 CreateTextFile(file_name2_from, L"Gooooooooooooooooooooogle"); | 1262 CreateTextFile(file_name2_from, L"Gooooooooooooooooooooogle"); |
1263 ASSERT_TRUE(file_util::PathExists(file_name2_from)); | 1263 ASSERT_TRUE(base::PathExists(file_name2_from)); |
1264 | 1264 |
1265 // Copy the directory recursively. | 1265 // Copy the directory recursively. |
1266 FilePath dir_name_exists = | 1266 FilePath dir_name_exists = |
1267 temp_dir_.path().Append(FILE_PATH_LITERAL("Destination")); | 1267 temp_dir_.path().Append(FILE_PATH_LITERAL("Destination")); |
1268 | 1268 |
1269 FilePath dir_name_to = | 1269 FilePath dir_name_to = |
1270 dir_name_exists.Append(FILE_PATH_LITERAL("Copy_From_Subdir")); | 1270 dir_name_exists.Append(FILE_PATH_LITERAL("Copy_From_Subdir")); |
1271 FilePath file_name_to = | 1271 FilePath file_name_to = |
1272 dir_name_to.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); | 1272 dir_name_to.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); |
1273 FilePath subdir_name_to = | 1273 FilePath subdir_name_to = |
1274 dir_name_to.Append(FILE_PATH_LITERAL("Subdir")); | 1274 dir_name_to.Append(FILE_PATH_LITERAL("Subdir")); |
1275 FilePath file_name2_to = | 1275 FilePath file_name2_to = |
1276 subdir_name_to.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); | 1276 subdir_name_to.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); |
1277 | 1277 |
1278 // Create the destination directory. | 1278 // Create the destination directory. |
1279 file_util::CreateDirectory(dir_name_exists); | 1279 file_util::CreateDirectory(dir_name_exists); |
1280 ASSERT_TRUE(file_util::PathExists(dir_name_exists)); | 1280 ASSERT_TRUE(base::PathExists(dir_name_exists)); |
1281 | 1281 |
1282 EXPECT_TRUE(base::CopyDirectory(dir_name_from, dir_name_exists, true)); | 1282 EXPECT_TRUE(base::CopyDirectory(dir_name_from, dir_name_exists, true)); |
1283 | 1283 |
1284 // Check everything has been copied. | 1284 // Check everything has been copied. |
1285 EXPECT_TRUE(file_util::PathExists(dir_name_from)); | 1285 EXPECT_TRUE(base::PathExists(dir_name_from)); |
1286 EXPECT_TRUE(file_util::PathExists(file_name_from)); | 1286 EXPECT_TRUE(base::PathExists(file_name_from)); |
1287 EXPECT_TRUE(file_util::PathExists(subdir_name_from)); | 1287 EXPECT_TRUE(base::PathExists(subdir_name_from)); |
1288 EXPECT_TRUE(file_util::PathExists(file_name2_from)); | 1288 EXPECT_TRUE(base::PathExists(file_name2_from)); |
1289 EXPECT_TRUE(file_util::PathExists(dir_name_to)); | 1289 EXPECT_TRUE(base::PathExists(dir_name_to)); |
1290 EXPECT_TRUE(file_util::PathExists(file_name_to)); | 1290 EXPECT_TRUE(base::PathExists(file_name_to)); |
1291 EXPECT_TRUE(file_util::PathExists(subdir_name_to)); | 1291 EXPECT_TRUE(base::PathExists(subdir_name_to)); |
1292 EXPECT_TRUE(file_util::PathExists(file_name2_to)); | 1292 EXPECT_TRUE(base::PathExists(file_name2_to)); |
1293 } | 1293 } |
1294 | 1294 |
1295 TEST_F(FileUtilTest, CopyDirectoryNew) { | 1295 TEST_F(FileUtilTest, CopyDirectoryNew) { |
1296 // Create a directory. | 1296 // Create a directory. |
1297 FilePath dir_name_from = | 1297 FilePath dir_name_from = |
1298 temp_dir_.path().Append(FILE_PATH_LITERAL("Copy_From_Subdir")); | 1298 temp_dir_.path().Append(FILE_PATH_LITERAL("Copy_From_Subdir")); |
1299 file_util::CreateDirectory(dir_name_from); | 1299 file_util::CreateDirectory(dir_name_from); |
1300 ASSERT_TRUE(file_util::PathExists(dir_name_from)); | 1300 ASSERT_TRUE(base::PathExists(dir_name_from)); |
1301 | 1301 |
1302 // Create a file under the directory. | 1302 // Create a file under the directory. |
1303 FilePath file_name_from = | 1303 FilePath file_name_from = |
1304 dir_name_from.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); | 1304 dir_name_from.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); |
1305 CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle"); | 1305 CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle"); |
1306 ASSERT_TRUE(file_util::PathExists(file_name_from)); | 1306 ASSERT_TRUE(base::PathExists(file_name_from)); |
1307 | 1307 |
1308 // Create a subdirectory. | 1308 // Create a subdirectory. |
1309 FilePath subdir_name_from = | 1309 FilePath subdir_name_from = |
1310 dir_name_from.Append(FILE_PATH_LITERAL("Subdir")); | 1310 dir_name_from.Append(FILE_PATH_LITERAL("Subdir")); |
1311 file_util::CreateDirectory(subdir_name_from); | 1311 file_util::CreateDirectory(subdir_name_from); |
1312 ASSERT_TRUE(file_util::PathExists(subdir_name_from)); | 1312 ASSERT_TRUE(base::PathExists(subdir_name_from)); |
1313 | 1313 |
1314 // Create a file under the subdirectory. | 1314 // Create a file under the subdirectory. |
1315 FilePath file_name2_from = | 1315 FilePath file_name2_from = |
1316 subdir_name_from.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); | 1316 subdir_name_from.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); |
1317 CreateTextFile(file_name2_from, L"Gooooooooooooooooooooogle"); | 1317 CreateTextFile(file_name2_from, L"Gooooooooooooooooooooogle"); |
1318 ASSERT_TRUE(file_util::PathExists(file_name2_from)); | 1318 ASSERT_TRUE(base::PathExists(file_name2_from)); |
1319 | 1319 |
1320 // Copy the directory not recursively. | 1320 // Copy the directory not recursively. |
1321 FilePath dir_name_to = | 1321 FilePath dir_name_to = |
1322 temp_dir_.path().Append(FILE_PATH_LITERAL("Copy_To_Subdir")); | 1322 temp_dir_.path().Append(FILE_PATH_LITERAL("Copy_To_Subdir")); |
1323 FilePath file_name_to = | 1323 FilePath file_name_to = |
1324 dir_name_to.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); | 1324 dir_name_to.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); |
1325 FilePath subdir_name_to = | 1325 FilePath subdir_name_to = |
1326 dir_name_to.Append(FILE_PATH_LITERAL("Subdir")); | 1326 dir_name_to.Append(FILE_PATH_LITERAL("Subdir")); |
1327 | 1327 |
1328 ASSERT_FALSE(file_util::PathExists(dir_name_to)); | 1328 ASSERT_FALSE(base::PathExists(dir_name_to)); |
1329 | 1329 |
1330 EXPECT_TRUE(base::CopyDirectory(dir_name_from, dir_name_to, false)); | 1330 EXPECT_TRUE(base::CopyDirectory(dir_name_from, dir_name_to, false)); |
1331 | 1331 |
1332 // Check everything has been copied. | 1332 // Check everything has been copied. |
1333 EXPECT_TRUE(file_util::PathExists(dir_name_from)); | 1333 EXPECT_TRUE(base::PathExists(dir_name_from)); |
1334 EXPECT_TRUE(file_util::PathExists(file_name_from)); | 1334 EXPECT_TRUE(base::PathExists(file_name_from)); |
1335 EXPECT_TRUE(file_util::PathExists(subdir_name_from)); | 1335 EXPECT_TRUE(base::PathExists(subdir_name_from)); |
1336 EXPECT_TRUE(file_util::PathExists(file_name2_from)); | 1336 EXPECT_TRUE(base::PathExists(file_name2_from)); |
1337 EXPECT_TRUE(file_util::PathExists(dir_name_to)); | 1337 EXPECT_TRUE(base::PathExists(dir_name_to)); |
1338 EXPECT_TRUE(file_util::PathExists(file_name_to)); | 1338 EXPECT_TRUE(base::PathExists(file_name_to)); |
1339 EXPECT_FALSE(file_util::PathExists(subdir_name_to)); | 1339 EXPECT_FALSE(base::PathExists(subdir_name_to)); |
1340 } | 1340 } |
1341 | 1341 |
1342 TEST_F(FileUtilTest, CopyDirectoryExists) { | 1342 TEST_F(FileUtilTest, CopyDirectoryExists) { |
1343 // Create a directory. | 1343 // Create a directory. |
1344 FilePath dir_name_from = | 1344 FilePath dir_name_from = |
1345 temp_dir_.path().Append(FILE_PATH_LITERAL("Copy_From_Subdir")); | 1345 temp_dir_.path().Append(FILE_PATH_LITERAL("Copy_From_Subdir")); |
1346 file_util::CreateDirectory(dir_name_from); | 1346 file_util::CreateDirectory(dir_name_from); |
1347 ASSERT_TRUE(file_util::PathExists(dir_name_from)); | 1347 ASSERT_TRUE(base::PathExists(dir_name_from)); |
1348 | 1348 |
1349 // Create a file under the directory. | 1349 // Create a file under the directory. |
1350 FilePath file_name_from = | 1350 FilePath file_name_from = |
1351 dir_name_from.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); | 1351 dir_name_from.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); |
1352 CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle"); | 1352 CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle"); |
1353 ASSERT_TRUE(file_util::PathExists(file_name_from)); | 1353 ASSERT_TRUE(base::PathExists(file_name_from)); |
1354 | 1354 |
1355 // Create a subdirectory. | 1355 // Create a subdirectory. |
1356 FilePath subdir_name_from = | 1356 FilePath subdir_name_from = |
1357 dir_name_from.Append(FILE_PATH_LITERAL("Subdir")); | 1357 dir_name_from.Append(FILE_PATH_LITERAL("Subdir")); |
1358 file_util::CreateDirectory(subdir_name_from); | 1358 file_util::CreateDirectory(subdir_name_from); |
1359 ASSERT_TRUE(file_util::PathExists(subdir_name_from)); | 1359 ASSERT_TRUE(base::PathExists(subdir_name_from)); |
1360 | 1360 |
1361 // Create a file under the subdirectory. | 1361 // Create a file under the subdirectory. |
1362 FilePath file_name2_from = | 1362 FilePath file_name2_from = |
1363 subdir_name_from.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); | 1363 subdir_name_from.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); |
1364 CreateTextFile(file_name2_from, L"Gooooooooooooooooooooogle"); | 1364 CreateTextFile(file_name2_from, L"Gooooooooooooooooooooogle"); |
1365 ASSERT_TRUE(file_util::PathExists(file_name2_from)); | 1365 ASSERT_TRUE(base::PathExists(file_name2_from)); |
1366 | 1366 |
1367 // Copy the directory not recursively. | 1367 // Copy the directory not recursively. |
1368 FilePath dir_name_to = | 1368 FilePath dir_name_to = |
1369 temp_dir_.path().Append(FILE_PATH_LITERAL("Copy_To_Subdir")); | 1369 temp_dir_.path().Append(FILE_PATH_LITERAL("Copy_To_Subdir")); |
1370 FilePath file_name_to = | 1370 FilePath file_name_to = |
1371 dir_name_to.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); | 1371 dir_name_to.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); |
1372 FilePath subdir_name_to = | 1372 FilePath subdir_name_to = |
1373 dir_name_to.Append(FILE_PATH_LITERAL("Subdir")); | 1373 dir_name_to.Append(FILE_PATH_LITERAL("Subdir")); |
1374 | 1374 |
1375 // Create the destination directory. | 1375 // Create the destination directory. |
1376 file_util::CreateDirectory(dir_name_to); | 1376 file_util::CreateDirectory(dir_name_to); |
1377 ASSERT_TRUE(file_util::PathExists(dir_name_to)); | 1377 ASSERT_TRUE(base::PathExists(dir_name_to)); |
1378 | 1378 |
1379 EXPECT_TRUE(base::CopyDirectory(dir_name_from, dir_name_to, false)); | 1379 EXPECT_TRUE(base::CopyDirectory(dir_name_from, dir_name_to, false)); |
1380 | 1380 |
1381 // Check everything has been copied. | 1381 // Check everything has been copied. |
1382 EXPECT_TRUE(file_util::PathExists(dir_name_from)); | 1382 EXPECT_TRUE(base::PathExists(dir_name_from)); |
1383 EXPECT_TRUE(file_util::PathExists(file_name_from)); | 1383 EXPECT_TRUE(base::PathExists(file_name_from)); |
1384 EXPECT_TRUE(file_util::PathExists(subdir_name_from)); | 1384 EXPECT_TRUE(base::PathExists(subdir_name_from)); |
1385 EXPECT_TRUE(file_util::PathExists(file_name2_from)); | 1385 EXPECT_TRUE(base::PathExists(file_name2_from)); |
1386 EXPECT_TRUE(file_util::PathExists(dir_name_to)); | 1386 EXPECT_TRUE(base::PathExists(dir_name_to)); |
1387 EXPECT_TRUE(file_util::PathExists(file_name_to)); | 1387 EXPECT_TRUE(base::PathExists(file_name_to)); |
1388 EXPECT_FALSE(file_util::PathExists(subdir_name_to)); | 1388 EXPECT_FALSE(base::PathExists(subdir_name_to)); |
1389 } | 1389 } |
1390 | 1390 |
1391 TEST_F(FileUtilTest, CopyFileWithCopyDirectoryRecursiveToNew) { | 1391 TEST_F(FileUtilTest, CopyFileWithCopyDirectoryRecursiveToNew) { |
1392 // Create a file | 1392 // Create a file |
1393 FilePath file_name_from = | 1393 FilePath file_name_from = |
1394 temp_dir_.path().Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); | 1394 temp_dir_.path().Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); |
1395 CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle"); | 1395 CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle"); |
1396 ASSERT_TRUE(file_util::PathExists(file_name_from)); | 1396 ASSERT_TRUE(base::PathExists(file_name_from)); |
1397 | 1397 |
1398 // The destination name | 1398 // The destination name |
1399 FilePath file_name_to = temp_dir_.path().Append( | 1399 FilePath file_name_to = temp_dir_.path().Append( |
1400 FILE_PATH_LITERAL("Copy_Test_File_Destination.txt")); | 1400 FILE_PATH_LITERAL("Copy_Test_File_Destination.txt")); |
1401 ASSERT_FALSE(file_util::PathExists(file_name_to)); | 1401 ASSERT_FALSE(base::PathExists(file_name_to)); |
1402 | 1402 |
1403 EXPECT_TRUE(base::CopyDirectory(file_name_from, file_name_to, true)); | 1403 EXPECT_TRUE(base::CopyDirectory(file_name_from, file_name_to, true)); |
1404 | 1404 |
1405 // Check the has been copied | 1405 // Check the has been copied |
1406 EXPECT_TRUE(file_util::PathExists(file_name_to)); | 1406 EXPECT_TRUE(base::PathExists(file_name_to)); |
1407 } | 1407 } |
1408 | 1408 |
1409 TEST_F(FileUtilTest, CopyFileWithCopyDirectoryRecursiveToExisting) { | 1409 TEST_F(FileUtilTest, CopyFileWithCopyDirectoryRecursiveToExisting) { |
1410 // Create a file | 1410 // Create a file |
1411 FilePath file_name_from = | 1411 FilePath file_name_from = |
1412 temp_dir_.path().Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); | 1412 temp_dir_.path().Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); |
1413 CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle"); | 1413 CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle"); |
1414 ASSERT_TRUE(file_util::PathExists(file_name_from)); | 1414 ASSERT_TRUE(base::PathExists(file_name_from)); |
1415 | 1415 |
1416 // The destination name | 1416 // The destination name |
1417 FilePath file_name_to = temp_dir_.path().Append( | 1417 FilePath file_name_to = temp_dir_.path().Append( |
1418 FILE_PATH_LITERAL("Copy_Test_File_Destination.txt")); | 1418 FILE_PATH_LITERAL("Copy_Test_File_Destination.txt")); |
1419 CreateTextFile(file_name_to, L"Old file content"); | 1419 CreateTextFile(file_name_to, L"Old file content"); |
1420 ASSERT_TRUE(file_util::PathExists(file_name_to)); | 1420 ASSERT_TRUE(base::PathExists(file_name_to)); |
1421 | 1421 |
1422 EXPECT_TRUE(base::CopyDirectory(file_name_from, file_name_to, true)); | 1422 EXPECT_TRUE(base::CopyDirectory(file_name_from, file_name_to, true)); |
1423 | 1423 |
1424 // Check the has been copied | 1424 // Check the has been copied |
1425 EXPECT_TRUE(file_util::PathExists(file_name_to)); | 1425 EXPECT_TRUE(base::PathExists(file_name_to)); |
1426 EXPECT_TRUE(L"Gooooooooooooooooooooogle" == ReadTextFile(file_name_to)); | 1426 EXPECT_TRUE(L"Gooooooooooooooooooooogle" == ReadTextFile(file_name_to)); |
1427 } | 1427 } |
1428 | 1428 |
1429 TEST_F(FileUtilTest, CopyFileWithCopyDirectoryRecursiveToExistingDirectory) { | 1429 TEST_F(FileUtilTest, CopyFileWithCopyDirectoryRecursiveToExistingDirectory) { |
1430 // Create a file | 1430 // Create a file |
1431 FilePath file_name_from = | 1431 FilePath file_name_from = |
1432 temp_dir_.path().Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); | 1432 temp_dir_.path().Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); |
1433 CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle"); | 1433 CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle"); |
1434 ASSERT_TRUE(file_util::PathExists(file_name_from)); | 1434 ASSERT_TRUE(base::PathExists(file_name_from)); |
1435 | 1435 |
1436 // The destination | 1436 // The destination |
1437 FilePath dir_name_to = | 1437 FilePath dir_name_to = |
1438 temp_dir_.path().Append(FILE_PATH_LITERAL("Destination")); | 1438 temp_dir_.path().Append(FILE_PATH_LITERAL("Destination")); |
1439 file_util::CreateDirectory(dir_name_to); | 1439 file_util::CreateDirectory(dir_name_to); |
1440 ASSERT_TRUE(file_util::PathExists(dir_name_to)); | 1440 ASSERT_TRUE(base::PathExists(dir_name_to)); |
1441 FilePath file_name_to = | 1441 FilePath file_name_to = |
1442 dir_name_to.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); | 1442 dir_name_to.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); |
1443 | 1443 |
1444 EXPECT_TRUE(base::CopyDirectory(file_name_from, dir_name_to, true)); | 1444 EXPECT_TRUE(base::CopyDirectory(file_name_from, dir_name_to, true)); |
1445 | 1445 |
1446 // Check the has been copied | 1446 // Check the has been copied |
1447 EXPECT_TRUE(file_util::PathExists(file_name_to)); | 1447 EXPECT_TRUE(base::PathExists(file_name_to)); |
1448 } | 1448 } |
1449 | 1449 |
1450 TEST_F(FileUtilTest, CopyDirectoryWithTrailingSeparators) { | 1450 TEST_F(FileUtilTest, CopyDirectoryWithTrailingSeparators) { |
1451 // Create a directory. | 1451 // Create a directory. |
1452 FilePath dir_name_from = | 1452 FilePath dir_name_from = |
1453 temp_dir_.path().Append(FILE_PATH_LITERAL("Copy_From_Subdir")); | 1453 temp_dir_.path().Append(FILE_PATH_LITERAL("Copy_From_Subdir")); |
1454 file_util::CreateDirectory(dir_name_from); | 1454 file_util::CreateDirectory(dir_name_from); |
1455 ASSERT_TRUE(file_util::PathExists(dir_name_from)); | 1455 ASSERT_TRUE(base::PathExists(dir_name_from)); |
1456 | 1456 |
1457 // Create a file under the directory. | 1457 // Create a file under the directory. |
1458 FilePath file_name_from = | 1458 FilePath file_name_from = |
1459 dir_name_from.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); | 1459 dir_name_from.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); |
1460 CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle"); | 1460 CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle"); |
1461 ASSERT_TRUE(file_util::PathExists(file_name_from)); | 1461 ASSERT_TRUE(base::PathExists(file_name_from)); |
1462 | 1462 |
1463 // Copy the directory recursively. | 1463 // Copy the directory recursively. |
1464 FilePath dir_name_to = | 1464 FilePath dir_name_to = |
1465 temp_dir_.path().Append(FILE_PATH_LITERAL("Copy_To_Subdir")); | 1465 temp_dir_.path().Append(FILE_PATH_LITERAL("Copy_To_Subdir")); |
1466 FilePath file_name_to = | 1466 FilePath file_name_to = |
1467 dir_name_to.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); | 1467 dir_name_to.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); |
1468 | 1468 |
1469 // Create from path with trailing separators. | 1469 // Create from path with trailing separators. |
1470 #if defined(OS_WIN) | 1470 #if defined(OS_WIN) |
1471 FilePath from_path = | 1471 FilePath from_path = |
1472 temp_dir_.path().Append(FILE_PATH_LITERAL("Copy_From_Subdir\\\\\\")); | 1472 temp_dir_.path().Append(FILE_PATH_LITERAL("Copy_From_Subdir\\\\\\")); |
1473 #elif defined (OS_POSIX) | 1473 #elif defined (OS_POSIX) |
1474 FilePath from_path = | 1474 FilePath from_path = |
1475 temp_dir_.path().Append(FILE_PATH_LITERAL("Copy_From_Subdir///")); | 1475 temp_dir_.path().Append(FILE_PATH_LITERAL("Copy_From_Subdir///")); |
1476 #endif | 1476 #endif |
1477 | 1477 |
1478 EXPECT_TRUE(base::CopyDirectory(from_path, dir_name_to, true)); | 1478 EXPECT_TRUE(base::CopyDirectory(from_path, dir_name_to, true)); |
1479 | 1479 |
1480 // Check everything has been copied. | 1480 // Check everything has been copied. |
1481 EXPECT_TRUE(file_util::PathExists(dir_name_from)); | 1481 EXPECT_TRUE(base::PathExists(dir_name_from)); |
1482 EXPECT_TRUE(file_util::PathExists(file_name_from)); | 1482 EXPECT_TRUE(base::PathExists(file_name_from)); |
1483 EXPECT_TRUE(file_util::PathExists(dir_name_to)); | 1483 EXPECT_TRUE(base::PathExists(dir_name_to)); |
1484 EXPECT_TRUE(file_util::PathExists(file_name_to)); | 1484 EXPECT_TRUE(base::PathExists(file_name_to)); |
1485 } | 1485 } |
1486 | 1486 |
1487 TEST_F(FileUtilTest, CopyFile) { | 1487 TEST_F(FileUtilTest, CopyFile) { |
1488 // Create a directory | 1488 // Create a directory |
1489 FilePath dir_name_from = | 1489 FilePath dir_name_from = |
1490 temp_dir_.path().Append(FILE_PATH_LITERAL("Copy_From_Subdir")); | 1490 temp_dir_.path().Append(FILE_PATH_LITERAL("Copy_From_Subdir")); |
1491 file_util::CreateDirectory(dir_name_from); | 1491 file_util::CreateDirectory(dir_name_from); |
1492 ASSERT_TRUE(file_util::PathExists(dir_name_from)); | 1492 ASSERT_TRUE(base::PathExists(dir_name_from)); |
1493 | 1493 |
1494 // Create a file under the directory | 1494 // Create a file under the directory |
1495 FilePath file_name_from = | 1495 FilePath file_name_from = |
1496 dir_name_from.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); | 1496 dir_name_from.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); |
1497 const std::wstring file_contents(L"Gooooooooooooooooooooogle"); | 1497 const std::wstring file_contents(L"Gooooooooooooooooooooogle"); |
1498 CreateTextFile(file_name_from, file_contents); | 1498 CreateTextFile(file_name_from, file_contents); |
1499 ASSERT_TRUE(file_util::PathExists(file_name_from)); | 1499 ASSERT_TRUE(base::PathExists(file_name_from)); |
1500 | 1500 |
1501 // Copy the file. | 1501 // Copy the file. |
1502 FilePath dest_file = dir_name_from.Append(FILE_PATH_LITERAL("DestFile.txt")); | 1502 FilePath dest_file = dir_name_from.Append(FILE_PATH_LITERAL("DestFile.txt")); |
1503 ASSERT_TRUE(base::CopyFile(file_name_from, dest_file)); | 1503 ASSERT_TRUE(base::CopyFile(file_name_from, dest_file)); |
1504 | 1504 |
1505 // Copy the file to another location using '..' in the path. | 1505 // Copy the file to another location using '..' in the path. |
1506 FilePath dest_file2(dir_name_from); | 1506 FilePath dest_file2(dir_name_from); |
1507 dest_file2 = dest_file2.AppendASCII(".."); | 1507 dest_file2 = dest_file2.AppendASCII(".."); |
1508 dest_file2 = dest_file2.AppendASCII("DestFile.txt"); | 1508 dest_file2 = dest_file2.AppendASCII("DestFile.txt"); |
1509 ASSERT_FALSE(base::CopyFile(file_name_from, dest_file2)); | 1509 ASSERT_FALSE(base::CopyFile(file_name_from, dest_file2)); |
1510 ASSERT_TRUE(base::internal::CopyFileUnsafe(file_name_from, dest_file2)); | 1510 ASSERT_TRUE(base::internal::CopyFileUnsafe(file_name_from, dest_file2)); |
1511 | 1511 |
1512 FilePath dest_file2_test(dir_name_from); | 1512 FilePath dest_file2_test(dir_name_from); |
1513 dest_file2_test = dest_file2_test.DirName(); | 1513 dest_file2_test = dest_file2_test.DirName(); |
1514 dest_file2_test = dest_file2_test.AppendASCII("DestFile.txt"); | 1514 dest_file2_test = dest_file2_test.AppendASCII("DestFile.txt"); |
1515 | 1515 |
1516 // Check everything has been copied. | 1516 // Check everything has been copied. |
1517 EXPECT_TRUE(file_util::PathExists(file_name_from)); | 1517 EXPECT_TRUE(base::PathExists(file_name_from)); |
1518 EXPECT_TRUE(file_util::PathExists(dest_file)); | 1518 EXPECT_TRUE(base::PathExists(dest_file)); |
1519 const std::wstring read_contents = ReadTextFile(dest_file); | 1519 const std::wstring read_contents = ReadTextFile(dest_file); |
1520 EXPECT_EQ(file_contents, read_contents); | 1520 EXPECT_EQ(file_contents, read_contents); |
1521 EXPECT_TRUE(file_util::PathExists(dest_file2_test)); | 1521 EXPECT_TRUE(base::PathExists(dest_file2_test)); |
1522 EXPECT_TRUE(file_util::PathExists(dest_file2)); | 1522 EXPECT_TRUE(base::PathExists(dest_file2)); |
1523 } | 1523 } |
1524 | 1524 |
1525 // file_util winds up using autoreleased objects on the Mac, so this needs | 1525 // file_util winds up using autoreleased objects on the Mac, so this needs |
1526 // to be a PlatformTest. | 1526 // to be a PlatformTest. |
1527 typedef PlatformTest ReadOnlyFileUtilTest; | 1527 typedef PlatformTest ReadOnlyFileUtilTest; |
1528 | 1528 |
1529 TEST_F(ReadOnlyFileUtilTest, ContentsEqual) { | 1529 TEST_F(ReadOnlyFileUtilTest, ContentsEqual) { |
1530 FilePath data_dir; | 1530 FilePath data_dir; |
1531 ASSERT_TRUE(PathService::Get(base::DIR_TEST_DATA, &data_dir)); | 1531 ASSERT_TRUE(PathService::Get(base::DIR_TEST_DATA, &data_dir)); |
1532 data_dir = data_dir.AppendASCII("file_util"); | 1532 data_dir = data_dir.AppendASCII("file_util"); |
1533 ASSERT_TRUE(file_util::PathExists(data_dir)); | 1533 ASSERT_TRUE(base::PathExists(data_dir)); |
1534 | 1534 |
1535 FilePath original_file = | 1535 FilePath original_file = |
1536 data_dir.Append(FILE_PATH_LITERAL("original.txt")); | 1536 data_dir.Append(FILE_PATH_LITERAL("original.txt")); |
1537 FilePath same_file = | 1537 FilePath same_file = |
1538 data_dir.Append(FILE_PATH_LITERAL("same.txt")); | 1538 data_dir.Append(FILE_PATH_LITERAL("same.txt")); |
1539 FilePath same_length_file = | 1539 FilePath same_length_file = |
1540 data_dir.Append(FILE_PATH_LITERAL("same_length.txt")); | 1540 data_dir.Append(FILE_PATH_LITERAL("same_length.txt")); |
1541 FilePath different_file = | 1541 FilePath different_file = |
1542 data_dir.Append(FILE_PATH_LITERAL("different.txt")); | 1542 data_dir.Append(FILE_PATH_LITERAL("different.txt")); |
1543 FilePath different_first_file = | 1543 FilePath different_first_file = |
(...skipping 26 matching lines...) Expand all Loading... |
1570 EXPECT_FALSE(file_util::ContentsEqual(original_file, shortened_file)); | 1570 EXPECT_FALSE(file_util::ContentsEqual(original_file, shortened_file)); |
1571 EXPECT_FALSE(file_util::ContentsEqual(shortened_file, original_file)); | 1571 EXPECT_FALSE(file_util::ContentsEqual(shortened_file, original_file)); |
1572 EXPECT_TRUE(file_util::ContentsEqual(binary_file, binary_file_same)); | 1572 EXPECT_TRUE(file_util::ContentsEqual(binary_file, binary_file_same)); |
1573 EXPECT_FALSE(file_util::ContentsEqual(binary_file, binary_file_diff)); | 1573 EXPECT_FALSE(file_util::ContentsEqual(binary_file, binary_file_diff)); |
1574 } | 1574 } |
1575 | 1575 |
1576 TEST_F(ReadOnlyFileUtilTest, TextContentsEqual) { | 1576 TEST_F(ReadOnlyFileUtilTest, TextContentsEqual) { |
1577 FilePath data_dir; | 1577 FilePath data_dir; |
1578 ASSERT_TRUE(PathService::Get(base::DIR_TEST_DATA, &data_dir)); | 1578 ASSERT_TRUE(PathService::Get(base::DIR_TEST_DATA, &data_dir)); |
1579 data_dir = data_dir.AppendASCII("file_util"); | 1579 data_dir = data_dir.AppendASCII("file_util"); |
1580 ASSERT_TRUE(file_util::PathExists(data_dir)); | 1580 ASSERT_TRUE(base::PathExists(data_dir)); |
1581 | 1581 |
1582 FilePath original_file = | 1582 FilePath original_file = |
1583 data_dir.Append(FILE_PATH_LITERAL("original.txt")); | 1583 data_dir.Append(FILE_PATH_LITERAL("original.txt")); |
1584 FilePath same_file = | 1584 FilePath same_file = |
1585 data_dir.Append(FILE_PATH_LITERAL("same.txt")); | 1585 data_dir.Append(FILE_PATH_LITERAL("same.txt")); |
1586 FilePath crlf_file = | 1586 FilePath crlf_file = |
1587 data_dir.Append(FILE_PATH_LITERAL("crlf.txt")); | 1587 data_dir.Append(FILE_PATH_LITERAL("crlf.txt")); |
1588 FilePath shortened_file = | 1588 FilePath shortened_file = |
1589 data_dir.Append(FILE_PATH_LITERAL("shortened.txt")); | 1589 data_dir.Append(FILE_PATH_LITERAL("shortened.txt")); |
1590 FilePath different_file = | 1590 FilePath different_file = |
(...skipping 30 matching lines...) Expand all Loading... |
1621 blank_line_crlf_file)); | 1621 blank_line_crlf_file)); |
1622 } | 1622 } |
1623 | 1623 |
1624 // We don't need equivalent functionality outside of Windows. | 1624 // We don't need equivalent functionality outside of Windows. |
1625 #if defined(OS_WIN) | 1625 #if defined(OS_WIN) |
1626 TEST_F(FileUtilTest, CopyAndDeleteDirectoryTest) { | 1626 TEST_F(FileUtilTest, CopyAndDeleteDirectoryTest) { |
1627 // Create a directory | 1627 // Create a directory |
1628 FilePath dir_name_from = | 1628 FilePath dir_name_from = |
1629 temp_dir_.path().Append(FILE_PATH_LITERAL("CopyAndDelete_From_Subdir")); | 1629 temp_dir_.path().Append(FILE_PATH_LITERAL("CopyAndDelete_From_Subdir")); |
1630 file_util::CreateDirectory(dir_name_from); | 1630 file_util::CreateDirectory(dir_name_from); |
1631 ASSERT_TRUE(file_util::PathExists(dir_name_from)); | 1631 ASSERT_TRUE(base::PathExists(dir_name_from)); |
1632 | 1632 |
1633 // Create a file under the directory | 1633 // Create a file under the directory |
1634 FilePath file_name_from = | 1634 FilePath file_name_from = |
1635 dir_name_from.Append(FILE_PATH_LITERAL("CopyAndDelete_Test_File.txt")); | 1635 dir_name_from.Append(FILE_PATH_LITERAL("CopyAndDelete_Test_File.txt")); |
1636 CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle"); | 1636 CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle"); |
1637 ASSERT_TRUE(file_util::PathExists(file_name_from)); | 1637 ASSERT_TRUE(base::PathExists(file_name_from)); |
1638 | 1638 |
1639 // Move the directory by using CopyAndDeleteDirectory | 1639 // Move the directory by using CopyAndDeleteDirectory |
1640 FilePath dir_name_to = temp_dir_.path().Append( | 1640 FilePath dir_name_to = temp_dir_.path().Append( |
1641 FILE_PATH_LITERAL("CopyAndDelete_To_Subdir")); | 1641 FILE_PATH_LITERAL("CopyAndDelete_To_Subdir")); |
1642 FilePath file_name_to = | 1642 FilePath file_name_to = |
1643 dir_name_to.Append(FILE_PATH_LITERAL("CopyAndDelete_Test_File.txt")); | 1643 dir_name_to.Append(FILE_PATH_LITERAL("CopyAndDelete_Test_File.txt")); |
1644 | 1644 |
1645 ASSERT_FALSE(file_util::PathExists(dir_name_to)); | 1645 ASSERT_FALSE(base::PathExists(dir_name_to)); |
1646 | 1646 |
1647 EXPECT_TRUE(base::internal::CopyAndDeleteDirectory(dir_name_from, | 1647 EXPECT_TRUE(base::internal::CopyAndDeleteDirectory(dir_name_from, |
1648 dir_name_to)); | 1648 dir_name_to)); |
1649 | 1649 |
1650 // Check everything has been moved. | 1650 // Check everything has been moved. |
1651 EXPECT_FALSE(file_util::PathExists(dir_name_from)); | 1651 EXPECT_FALSE(base::PathExists(dir_name_from)); |
1652 EXPECT_FALSE(file_util::PathExists(file_name_from)); | 1652 EXPECT_FALSE(base::PathExists(file_name_from)); |
1653 EXPECT_TRUE(file_util::PathExists(dir_name_to)); | 1653 EXPECT_TRUE(base::PathExists(dir_name_to)); |
1654 EXPECT_TRUE(file_util::PathExists(file_name_to)); | 1654 EXPECT_TRUE(base::PathExists(file_name_to)); |
1655 } | 1655 } |
1656 | 1656 |
1657 TEST_F(FileUtilTest, GetTempDirTest) { | 1657 TEST_F(FileUtilTest, GetTempDirTest) { |
1658 static const TCHAR* kTmpKey = _T("TMP"); | 1658 static const TCHAR* kTmpKey = _T("TMP"); |
1659 static const TCHAR* kTmpValues[] = { | 1659 static const TCHAR* kTmpValues[] = { |
1660 _T(""), _T("C:"), _T("C:\\"), _T("C:\\tmp"), _T("C:\\tmp\\") | 1660 _T(""), _T("C:"), _T("C:\\"), _T("C:\\tmp"), _T("C:\\tmp\\") |
1661 }; | 1661 }; |
1662 // Save the original $TMP. | 1662 // Save the original $TMP. |
1663 size_t original_tmp_size; | 1663 size_t original_tmp_size; |
1664 TCHAR* original_tmp; | 1664 TCHAR* original_tmp; |
(...skipping 15 matching lines...) Expand all Loading... |
1680 } else { | 1680 } else { |
1681 ::_tputenv_s(kTmpKey, _T("")); | 1681 ::_tputenv_s(kTmpKey, _T("")); |
1682 } | 1682 } |
1683 } | 1683 } |
1684 #endif // OS_WIN | 1684 #endif // OS_WIN |
1685 | 1685 |
1686 TEST_F(FileUtilTest, CreateTemporaryFileTest) { | 1686 TEST_F(FileUtilTest, CreateTemporaryFileTest) { |
1687 FilePath temp_files[3]; | 1687 FilePath temp_files[3]; |
1688 for (int i = 0; i < 3; i++) { | 1688 for (int i = 0; i < 3; i++) { |
1689 ASSERT_TRUE(file_util::CreateTemporaryFile(&(temp_files[i]))); | 1689 ASSERT_TRUE(file_util::CreateTemporaryFile(&(temp_files[i]))); |
1690 EXPECT_TRUE(file_util::PathExists(temp_files[i])); | 1690 EXPECT_TRUE(base::PathExists(temp_files[i])); |
1691 EXPECT_FALSE(file_util::DirectoryExists(temp_files[i])); | 1691 EXPECT_FALSE(file_util::DirectoryExists(temp_files[i])); |
1692 } | 1692 } |
1693 for (int i = 0; i < 3; i++) | 1693 for (int i = 0; i < 3; i++) |
1694 EXPECT_FALSE(temp_files[i] == temp_files[(i+1)%3]); | 1694 EXPECT_FALSE(temp_files[i] == temp_files[(i+1)%3]); |
1695 for (int i = 0; i < 3; i++) | 1695 for (int i = 0; i < 3; i++) |
1696 EXPECT_TRUE(base::Delete(temp_files[i], false)); | 1696 EXPECT_TRUE(base::Delete(temp_files[i], false)); |
1697 } | 1697 } |
1698 | 1698 |
1699 TEST_F(FileUtilTest, CreateAndOpenTemporaryFileTest) { | 1699 TEST_F(FileUtilTest, CreateAndOpenTemporaryFileTest) { |
1700 FilePath names[3]; | 1700 FilePath names[3]; |
1701 FILE* fps[3]; | 1701 FILE* fps[3]; |
1702 int i; | 1702 int i; |
1703 | 1703 |
1704 // Create; make sure they are open and exist. | 1704 // Create; make sure they are open and exist. |
1705 for (i = 0; i < 3; ++i) { | 1705 for (i = 0; i < 3; ++i) { |
1706 fps[i] = file_util::CreateAndOpenTemporaryFile(&(names[i])); | 1706 fps[i] = file_util::CreateAndOpenTemporaryFile(&(names[i])); |
1707 ASSERT_TRUE(fps[i]); | 1707 ASSERT_TRUE(fps[i]); |
1708 EXPECT_TRUE(file_util::PathExists(names[i])); | 1708 EXPECT_TRUE(base::PathExists(names[i])); |
1709 } | 1709 } |
1710 | 1710 |
1711 // Make sure all names are unique. | 1711 // Make sure all names are unique. |
1712 for (i = 0; i < 3; ++i) { | 1712 for (i = 0; i < 3; ++i) { |
1713 EXPECT_FALSE(names[i] == names[(i+1)%3]); | 1713 EXPECT_FALSE(names[i] == names[(i+1)%3]); |
1714 } | 1714 } |
1715 | 1715 |
1716 // Close and delete. | 1716 // Close and delete. |
1717 for (i = 0; i < 3; ++i) { | 1717 for (i = 0; i < 3; ++i) { |
1718 EXPECT_TRUE(file_util::CloseFile(fps[i])); | 1718 EXPECT_TRUE(file_util::CloseFile(fps[i])); |
1719 EXPECT_TRUE(base::Delete(names[i], false)); | 1719 EXPECT_TRUE(base::Delete(names[i], false)); |
1720 } | 1720 } |
1721 } | 1721 } |
1722 | 1722 |
1723 TEST_F(FileUtilTest, CreateNewTempDirectoryTest) { | 1723 TEST_F(FileUtilTest, CreateNewTempDirectoryTest) { |
1724 FilePath temp_dir; | 1724 FilePath temp_dir; |
1725 ASSERT_TRUE(file_util::CreateNewTempDirectory(FilePath::StringType(), | 1725 ASSERT_TRUE(file_util::CreateNewTempDirectory(FilePath::StringType(), |
1726 &temp_dir)); | 1726 &temp_dir)); |
1727 EXPECT_TRUE(file_util::PathExists(temp_dir)); | 1727 EXPECT_TRUE(base::PathExists(temp_dir)); |
1728 EXPECT_TRUE(base::Delete(temp_dir, false)); | 1728 EXPECT_TRUE(base::Delete(temp_dir, false)); |
1729 } | 1729 } |
1730 | 1730 |
1731 TEST_F(FileUtilTest, CreateNewTemporaryDirInDirTest) { | 1731 TEST_F(FileUtilTest, CreateNewTemporaryDirInDirTest) { |
1732 FilePath new_dir; | 1732 FilePath new_dir; |
1733 ASSERT_TRUE(file_util::CreateTemporaryDirInDir( | 1733 ASSERT_TRUE(file_util::CreateTemporaryDirInDir( |
1734 temp_dir_.path(), | 1734 temp_dir_.path(), |
1735 FILE_PATH_LITERAL("CreateNewTemporaryDirInDirTest"), | 1735 FILE_PATH_LITERAL("CreateNewTemporaryDirInDirTest"), |
1736 &new_dir)); | 1736 &new_dir)); |
1737 EXPECT_TRUE(file_util::PathExists(new_dir)); | 1737 EXPECT_TRUE(base::PathExists(new_dir)); |
1738 EXPECT_TRUE(temp_dir_.path().IsParent(new_dir)); | 1738 EXPECT_TRUE(temp_dir_.path().IsParent(new_dir)); |
1739 EXPECT_TRUE(base::Delete(new_dir, false)); | 1739 EXPECT_TRUE(base::Delete(new_dir, false)); |
1740 } | 1740 } |
1741 | 1741 |
1742 TEST_F(FileUtilTest, GetShmemTempDirTest) { | 1742 TEST_F(FileUtilTest, GetShmemTempDirTest) { |
1743 FilePath dir; | 1743 FilePath dir; |
1744 EXPECT_TRUE(file_util::GetShmemTempDir(&dir, false)); | 1744 EXPECT_TRUE(file_util::GetShmemTempDir(&dir, false)); |
1745 EXPECT_TRUE(file_util::DirectoryExists(dir)); | 1745 EXPECT_TRUE(file_util::DirectoryExists(dir)); |
1746 } | 1746 } |
1747 | 1747 |
1748 TEST_F(FileUtilTest, CreateDirectoryTest) { | 1748 TEST_F(FileUtilTest, CreateDirectoryTest) { |
1749 FilePath test_root = | 1749 FilePath test_root = |
1750 temp_dir_.path().Append(FILE_PATH_LITERAL("create_directory_test")); | 1750 temp_dir_.path().Append(FILE_PATH_LITERAL("create_directory_test")); |
1751 #if defined(OS_WIN) | 1751 #if defined(OS_WIN) |
1752 FilePath test_path = | 1752 FilePath test_path = |
1753 test_root.Append(FILE_PATH_LITERAL("dir\\tree\\likely\\doesnt\\exist\\")); | 1753 test_root.Append(FILE_PATH_LITERAL("dir\\tree\\likely\\doesnt\\exist\\")); |
1754 #elif defined(OS_POSIX) | 1754 #elif defined(OS_POSIX) |
1755 FilePath test_path = | 1755 FilePath test_path = |
1756 test_root.Append(FILE_PATH_LITERAL("dir/tree/likely/doesnt/exist/")); | 1756 test_root.Append(FILE_PATH_LITERAL("dir/tree/likely/doesnt/exist/")); |
1757 #endif | 1757 #endif |
1758 | 1758 |
1759 EXPECT_FALSE(file_util::PathExists(test_path)); | 1759 EXPECT_FALSE(base::PathExists(test_path)); |
1760 EXPECT_TRUE(file_util::CreateDirectory(test_path)); | 1760 EXPECT_TRUE(file_util::CreateDirectory(test_path)); |
1761 EXPECT_TRUE(file_util::PathExists(test_path)); | 1761 EXPECT_TRUE(base::PathExists(test_path)); |
1762 // CreateDirectory returns true if the DirectoryExists returns true. | 1762 // CreateDirectory returns true if the DirectoryExists returns true. |
1763 EXPECT_TRUE(file_util::CreateDirectory(test_path)); | 1763 EXPECT_TRUE(file_util::CreateDirectory(test_path)); |
1764 | 1764 |
1765 // Doesn't work to create it on top of a non-dir | 1765 // Doesn't work to create it on top of a non-dir |
1766 test_path = test_path.Append(FILE_PATH_LITERAL("foobar.txt")); | 1766 test_path = test_path.Append(FILE_PATH_LITERAL("foobar.txt")); |
1767 EXPECT_FALSE(file_util::PathExists(test_path)); | 1767 EXPECT_FALSE(base::PathExists(test_path)); |
1768 CreateTextFile(test_path, L"test file"); | 1768 CreateTextFile(test_path, L"test file"); |
1769 EXPECT_TRUE(file_util::PathExists(test_path)); | 1769 EXPECT_TRUE(base::PathExists(test_path)); |
1770 EXPECT_FALSE(file_util::CreateDirectory(test_path)); | 1770 EXPECT_FALSE(file_util::CreateDirectory(test_path)); |
1771 | 1771 |
1772 EXPECT_TRUE(base::Delete(test_root, true)); | 1772 EXPECT_TRUE(base::Delete(test_root, true)); |
1773 EXPECT_FALSE(file_util::PathExists(test_root)); | 1773 EXPECT_FALSE(base::PathExists(test_root)); |
1774 EXPECT_FALSE(file_util::PathExists(test_path)); | 1774 EXPECT_FALSE(base::PathExists(test_path)); |
1775 | 1775 |
1776 // Verify assumptions made by the Windows implementation: | 1776 // Verify assumptions made by the Windows implementation: |
1777 // 1. The current directory always exists. | 1777 // 1. The current directory always exists. |
1778 // 2. The root directory always exists. | 1778 // 2. The root directory always exists. |
1779 ASSERT_TRUE(file_util::DirectoryExists( | 1779 ASSERT_TRUE(file_util::DirectoryExists( |
1780 FilePath(FilePath::kCurrentDirectory))); | 1780 FilePath(FilePath::kCurrentDirectory))); |
1781 FilePath top_level = test_root; | 1781 FilePath top_level = test_root; |
1782 while (top_level != top_level.DirName()) { | 1782 while (top_level != top_level.DirName()) { |
1783 top_level = top_level.DirName(); | 1783 top_level = top_level.DirName(); |
1784 } | 1784 } |
1785 ASSERT_TRUE(file_util::DirectoryExists(top_level)); | 1785 ASSERT_TRUE(file_util::DirectoryExists(top_level)); |
1786 | 1786 |
1787 // Given these assumptions hold, it should be safe to | 1787 // Given these assumptions hold, it should be safe to |
1788 // test that "creating" these directories succeeds. | 1788 // test that "creating" these directories succeeds. |
1789 EXPECT_TRUE(file_util::CreateDirectory( | 1789 EXPECT_TRUE(file_util::CreateDirectory( |
1790 FilePath(FilePath::kCurrentDirectory))); | 1790 FilePath(FilePath::kCurrentDirectory))); |
1791 EXPECT_TRUE(file_util::CreateDirectory(top_level)); | 1791 EXPECT_TRUE(file_util::CreateDirectory(top_level)); |
1792 | 1792 |
1793 #if defined(OS_WIN) | 1793 #if defined(OS_WIN) |
1794 FilePath invalid_drive(FILE_PATH_LITERAL("o:\\")); | 1794 FilePath invalid_drive(FILE_PATH_LITERAL("o:\\")); |
1795 FilePath invalid_path = | 1795 FilePath invalid_path = |
1796 invalid_drive.Append(FILE_PATH_LITERAL("some\\inaccessible\\dir")); | 1796 invalid_drive.Append(FILE_PATH_LITERAL("some\\inaccessible\\dir")); |
1797 if (!file_util::PathExists(invalid_drive)) { | 1797 if (!base::PathExists(invalid_drive)) { |
1798 EXPECT_FALSE(file_util::CreateDirectory(invalid_path)); | 1798 EXPECT_FALSE(file_util::CreateDirectory(invalid_path)); |
1799 } | 1799 } |
1800 #endif | 1800 #endif |
1801 } | 1801 } |
1802 | 1802 |
1803 TEST_F(FileUtilTest, DetectDirectoryTest) { | 1803 TEST_F(FileUtilTest, DetectDirectoryTest) { |
1804 // Check a directory | 1804 // Check a directory |
1805 FilePath test_root = | 1805 FilePath test_root = |
1806 temp_dir_.path().Append(FILE_PATH_LITERAL("detect_directory_test")); | 1806 temp_dir_.path().Append(FILE_PATH_LITERAL("detect_directory_test")); |
1807 EXPECT_FALSE(file_util::PathExists(test_root)); | 1807 EXPECT_FALSE(base::PathExists(test_root)); |
1808 EXPECT_TRUE(file_util::CreateDirectory(test_root)); | 1808 EXPECT_TRUE(file_util::CreateDirectory(test_root)); |
1809 EXPECT_TRUE(file_util::PathExists(test_root)); | 1809 EXPECT_TRUE(base::PathExists(test_root)); |
1810 EXPECT_TRUE(file_util::DirectoryExists(test_root)); | 1810 EXPECT_TRUE(file_util::DirectoryExists(test_root)); |
1811 // Check a file | 1811 // Check a file |
1812 FilePath test_path = | 1812 FilePath test_path = |
1813 test_root.Append(FILE_PATH_LITERAL("foobar.txt")); | 1813 test_root.Append(FILE_PATH_LITERAL("foobar.txt")); |
1814 EXPECT_FALSE(file_util::PathExists(test_path)); | 1814 EXPECT_FALSE(base::PathExists(test_path)); |
1815 CreateTextFile(test_path, L"test file"); | 1815 CreateTextFile(test_path, L"test file"); |
1816 EXPECT_TRUE(file_util::PathExists(test_path)); | 1816 EXPECT_TRUE(base::PathExists(test_path)); |
1817 EXPECT_FALSE(file_util::DirectoryExists(test_path)); | 1817 EXPECT_FALSE(file_util::DirectoryExists(test_path)); |
1818 EXPECT_TRUE(base::Delete(test_path, false)); | 1818 EXPECT_TRUE(base::Delete(test_path, false)); |
1819 | 1819 |
1820 EXPECT_TRUE(base::Delete(test_root, true)); | 1820 EXPECT_TRUE(base::Delete(test_root, true)); |
1821 } | 1821 } |
1822 | 1822 |
1823 TEST_F(FileUtilTest, FileEnumeratorTest) { | 1823 TEST_F(FileUtilTest, FileEnumeratorTest) { |
1824 // Test an empty directory. | 1824 // Test an empty directory. |
1825 FileEnumerator f0(temp_dir_.path(), true, FILES_AND_DIRECTORIES); | 1825 FileEnumerator f0(temp_dir_.path(), true, FILES_AND_DIRECTORIES); |
1826 EXPECT_EQ(f0.Next().value(), FILE_PATH_LITERAL("")); | 1826 EXPECT_EQ(f0.Next().value(), FILE_PATH_LITERAL("")); |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1927 FileEnumerator f6(temp_dir_.path(), true, FILES_AND_DIRECTORIES); | 1927 FileEnumerator f6(temp_dir_.path(), true, FILES_AND_DIRECTORIES); |
1928 EXPECT_FALSE(f6.Next().value().empty()); // Should have found something | 1928 EXPECT_FALSE(f6.Next().value().empty()); // Should have found something |
1929 // (we don't care what). | 1929 // (we don't care what). |
1930 } | 1930 } |
1931 | 1931 |
1932 TEST_F(FileUtilTest, AppendToFile) { | 1932 TEST_F(FileUtilTest, AppendToFile) { |
1933 FilePath data_dir = | 1933 FilePath data_dir = |
1934 temp_dir_.path().Append(FILE_PATH_LITERAL("FilePathTest")); | 1934 temp_dir_.path().Append(FILE_PATH_LITERAL("FilePathTest")); |
1935 | 1935 |
1936 // Create a fresh, empty copy of this directory. | 1936 // Create a fresh, empty copy of this directory. |
1937 if (file_util::PathExists(data_dir)) { | 1937 if (base::PathExists(data_dir)) { |
1938 ASSERT_TRUE(base::Delete(data_dir, true)); | 1938 ASSERT_TRUE(base::Delete(data_dir, true)); |
1939 } | 1939 } |
1940 ASSERT_TRUE(file_util::CreateDirectory(data_dir)); | 1940 ASSERT_TRUE(file_util::CreateDirectory(data_dir)); |
1941 | 1941 |
1942 // Create a fresh, empty copy of this directory. | 1942 // Create a fresh, empty copy of this directory. |
1943 if (file_util::PathExists(data_dir)) { | 1943 if (base::PathExists(data_dir)) { |
1944 ASSERT_TRUE(base::Delete(data_dir, true)); | 1944 ASSERT_TRUE(base::Delete(data_dir, true)); |
1945 } | 1945 } |
1946 ASSERT_TRUE(file_util::CreateDirectory(data_dir)); | 1946 ASSERT_TRUE(file_util::CreateDirectory(data_dir)); |
1947 FilePath foobar(data_dir.Append(FILE_PATH_LITERAL("foobar.txt"))); | 1947 FilePath foobar(data_dir.Append(FILE_PATH_LITERAL("foobar.txt"))); |
1948 | 1948 |
1949 std::string data("hello"); | 1949 std::string data("hello"); |
1950 EXPECT_EQ(-1, file_util::AppendToFile(foobar, data.c_str(), data.length())); | 1950 EXPECT_EQ(-1, file_util::AppendToFile(foobar, data.c_str(), data.length())); |
1951 EXPECT_EQ(static_cast<int>(data.length()), | 1951 EXPECT_EQ(static_cast<int>(data.length()), |
1952 file_util::WriteFile(foobar, data.c_str(), data.length())); | 1952 file_util::WriteFile(foobar, data.c_str(), data.length())); |
1953 EXPECT_EQ(static_cast<int>(data.length()), | 1953 EXPECT_EQ(static_cast<int>(data.length()), |
1954 file_util::AppendToFile(foobar, data.c_str(), data.length())); | 1954 file_util::AppendToFile(foobar, data.c_str(), data.length())); |
1955 | 1955 |
1956 const std::wstring read_content = ReadTextFile(foobar); | 1956 const std::wstring read_content = ReadTextFile(foobar); |
1957 EXPECT_EQ(L"hellohello", read_content); | 1957 EXPECT_EQ(L"hellohello", read_content); |
1958 } | 1958 } |
1959 | 1959 |
1960 TEST_F(FileUtilTest, TouchFile) { | 1960 TEST_F(FileUtilTest, TouchFile) { |
1961 FilePath data_dir = | 1961 FilePath data_dir = |
1962 temp_dir_.path().Append(FILE_PATH_LITERAL("FilePathTest")); | 1962 temp_dir_.path().Append(FILE_PATH_LITERAL("FilePathTest")); |
1963 | 1963 |
1964 // Create a fresh, empty copy of this directory. | 1964 // Create a fresh, empty copy of this directory. |
1965 if (file_util::PathExists(data_dir)) { | 1965 if (base::PathExists(data_dir)) { |
1966 ASSERT_TRUE(base::Delete(data_dir, true)); | 1966 ASSERT_TRUE(base::Delete(data_dir, true)); |
1967 } | 1967 } |
1968 ASSERT_TRUE(file_util::CreateDirectory(data_dir)); | 1968 ASSERT_TRUE(file_util::CreateDirectory(data_dir)); |
1969 | 1969 |
1970 FilePath foobar(data_dir.Append(FILE_PATH_LITERAL("foobar.txt"))); | 1970 FilePath foobar(data_dir.Append(FILE_PATH_LITERAL("foobar.txt"))); |
1971 std::string data("hello"); | 1971 std::string data("hello"); |
1972 ASSERT_TRUE(file_util::WriteFile(foobar, data.c_str(), data.length())); | 1972 ASSERT_TRUE(file_util::WriteFile(foobar, data.c_str(), data.length())); |
1973 | 1973 |
1974 base::Time access_time; | 1974 base::Time access_time; |
1975 // This timestamp is divisible by one day (in local timezone), | 1975 // This timestamp is divisible by one day (in local timezone), |
(...skipping 12 matching lines...) Expand all Loading... |
1988 ASSERT_TRUE(file_util::GetFileInfo(foobar, &file_info)); | 1988 ASSERT_TRUE(file_util::GetFileInfo(foobar, &file_info)); |
1989 EXPECT_EQ(file_info.last_accessed.ToInternalValue(), | 1989 EXPECT_EQ(file_info.last_accessed.ToInternalValue(), |
1990 access_time.ToInternalValue()); | 1990 access_time.ToInternalValue()); |
1991 EXPECT_EQ(file_info.last_modified.ToInternalValue(), | 1991 EXPECT_EQ(file_info.last_modified.ToInternalValue(), |
1992 modification_time.ToInternalValue()); | 1992 modification_time.ToInternalValue()); |
1993 } | 1993 } |
1994 | 1994 |
1995 TEST_F(FileUtilTest, IsDirectoryEmpty) { | 1995 TEST_F(FileUtilTest, IsDirectoryEmpty) { |
1996 FilePath empty_dir = temp_dir_.path().Append(FILE_PATH_LITERAL("EmptyDir")); | 1996 FilePath empty_dir = temp_dir_.path().Append(FILE_PATH_LITERAL("EmptyDir")); |
1997 | 1997 |
1998 ASSERT_FALSE(file_util::PathExists(empty_dir)); | 1998 ASSERT_FALSE(base::PathExists(empty_dir)); |
1999 | 1999 |
2000 ASSERT_TRUE(file_util::CreateDirectory(empty_dir)); | 2000 ASSERT_TRUE(file_util::CreateDirectory(empty_dir)); |
2001 | 2001 |
2002 EXPECT_TRUE(file_util::IsDirectoryEmpty(empty_dir)); | 2002 EXPECT_TRUE(file_util::IsDirectoryEmpty(empty_dir)); |
2003 | 2003 |
2004 FilePath foo(empty_dir.Append(FILE_PATH_LITERAL("foo.txt"))); | 2004 FilePath foo(empty_dir.Append(FILE_PATH_LITERAL("foo.txt"))); |
2005 std::string bar("baz"); | 2005 std::string bar("baz"); |
2006 ASSERT_TRUE(file_util::WriteFile(foo, bar.c_str(), bar.length())); | 2006 ASSERT_TRUE(file_util::WriteFile(foo, bar.c_str(), bar.length())); |
2007 | 2007 |
2008 EXPECT_FALSE(file_util::IsDirectoryEmpty(empty_dir)); | 2008 EXPECT_FALSE(file_util::IsDirectoryEmpty(empty_dir)); |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2116 EXPECT_FALSE( | 2116 EXPECT_FALSE( |
2117 file_util::VerifyPathControlledByUser( | 2117 file_util::VerifyPathControlledByUser( |
2118 file_link, file_link, uid_, ok_gids_)); | 2118 file_link, file_link, uid_, ok_gids_)); |
2119 | 2119 |
2120 // Symlink from one directory to another within the path. | 2120 // Symlink from one directory to another within the path. |
2121 FilePath link_to_sub_dir = base_dir_.AppendASCII("link_to_sub_dir"); | 2121 FilePath link_to_sub_dir = base_dir_.AppendASCII("link_to_sub_dir"); |
2122 ASSERT_TRUE(file_util::CreateSymbolicLink(sub_dir_, link_to_sub_dir)) | 2122 ASSERT_TRUE(file_util::CreateSymbolicLink(sub_dir_, link_to_sub_dir)) |
2123 << "Failed to create symlink."; | 2123 << "Failed to create symlink."; |
2124 | 2124 |
2125 FilePath file_path_with_link = link_to_sub_dir.AppendASCII("file.txt"); | 2125 FilePath file_path_with_link = link_to_sub_dir.AppendASCII("file.txt"); |
2126 ASSERT_TRUE(file_util::PathExists(file_path_with_link)); | 2126 ASSERT_TRUE(base::PathExists(file_path_with_link)); |
2127 | 2127 |
2128 EXPECT_FALSE( | 2128 EXPECT_FALSE( |
2129 file_util::VerifyPathControlledByUser( | 2129 file_util::VerifyPathControlledByUser( |
2130 base_dir_, file_path_with_link, uid_, ok_gids_)); | 2130 base_dir_, file_path_with_link, uid_, ok_gids_)); |
2131 | 2131 |
2132 EXPECT_FALSE( | 2132 EXPECT_FALSE( |
2133 file_util::VerifyPathControlledByUser( | 2133 file_util::VerifyPathControlledByUser( |
2134 link_to_sub_dir, file_path_with_link, uid_, ok_gids_)); | 2134 link_to_sub_dir, file_path_with_link, uid_, ok_gids_)); |
2135 | 2135 |
2136 // Symlinks in parents of base path are allowed. | 2136 // Symlinks in parents of base path are allowed. |
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2374 file_util::VerifyPathControlledByUser( | 2374 file_util::VerifyPathControlledByUser( |
2375 base_dir_, text_file_, uid_, ok_gids_)); | 2375 base_dir_, text_file_, uid_, ok_gids_)); |
2376 EXPECT_TRUE( | 2376 EXPECT_TRUE( |
2377 file_util::VerifyPathControlledByUser( | 2377 file_util::VerifyPathControlledByUser( |
2378 sub_dir_, text_file_, uid_, ok_gids_)); | 2378 sub_dir_, text_file_, uid_, ok_gids_)); |
2379 } | 2379 } |
2380 | 2380 |
2381 #endif // defined(OS_POSIX) | 2381 #endif // defined(OS_POSIX) |
2382 | 2382 |
2383 } // namespace | 2383 } // namespace |
OLD | NEW |