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 720 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
731 | 731 |
732 // Infinite loop! | 732 // Infinite loop! |
733 EXPECT_FALSE(file_util::NormalizeFilePath(link_from, &normalized_path)); | 733 EXPECT_FALSE(file_util::NormalizeFilePath(link_from, &normalized_path)); |
734 } | 734 } |
735 #endif // defined(OS_POSIX) | 735 #endif // defined(OS_POSIX) |
736 | 736 |
737 TEST_F(FileUtilTest, DeleteNonExistent) { | 737 TEST_F(FileUtilTest, DeleteNonExistent) { |
738 FilePath non_existent = temp_dir_.path().AppendASCII("bogus_file_dne.foobar"); | 738 FilePath non_existent = temp_dir_.path().AppendASCII("bogus_file_dne.foobar"); |
739 ASSERT_FALSE(base::PathExists(non_existent)); | 739 ASSERT_FALSE(base::PathExists(non_existent)); |
740 | 740 |
741 EXPECT_TRUE(base::Delete(non_existent, false)); | 741 EXPECT_TRUE(base::DeleteFile(non_existent, false)); |
742 ASSERT_FALSE(base::PathExists(non_existent)); | 742 ASSERT_FALSE(base::PathExists(non_existent)); |
743 EXPECT_TRUE(base::Delete(non_existent, true)); | 743 EXPECT_TRUE(base::DeleteFile(non_existent, true)); |
744 ASSERT_FALSE(base::PathExists(non_existent)); | 744 ASSERT_FALSE(base::PathExists(non_existent)); |
745 } | 745 } |
746 | 746 |
747 TEST_F(FileUtilTest, DeleteFile) { | 747 TEST_F(FileUtilTest, DeleteFile) { |
748 // Create a file | 748 // Create a file |
749 FilePath file_name = temp_dir_.path().Append(FPL("Test DeleteFile 1.txt")); | 749 FilePath file_name = temp_dir_.path().Append(FPL("Test DeleteFile 1.txt")); |
750 CreateTextFile(file_name, bogus_content); | 750 CreateTextFile(file_name, bogus_content); |
751 ASSERT_TRUE(base::PathExists(file_name)); | 751 ASSERT_TRUE(base::PathExists(file_name)); |
752 | 752 |
753 // Make sure it's deleted | 753 // Make sure it's deleted |
754 EXPECT_TRUE(base::Delete(file_name, false)); | 754 EXPECT_TRUE(base::DeleteFile(file_name, false)); |
755 EXPECT_FALSE(base::PathExists(file_name)); | 755 EXPECT_FALSE(base::PathExists(file_name)); |
756 | 756 |
757 // Test recursive case, create a new file | 757 // Test recursive case, create a new file |
758 file_name = temp_dir_.path().Append(FPL("Test DeleteFile 2.txt")); | 758 file_name = temp_dir_.path().Append(FPL("Test DeleteFile 2.txt")); |
759 CreateTextFile(file_name, bogus_content); | 759 CreateTextFile(file_name, bogus_content); |
760 ASSERT_TRUE(base::PathExists(file_name)); | 760 ASSERT_TRUE(base::PathExists(file_name)); |
761 | 761 |
762 // Make sure it's deleted | 762 // Make sure it's deleted |
763 EXPECT_TRUE(base::Delete(file_name, true)); | 763 EXPECT_TRUE(base::DeleteFile(file_name, true)); |
764 EXPECT_FALSE(base::PathExists(file_name)); | 764 EXPECT_FALSE(base::PathExists(file_name)); |
765 } | 765 } |
766 | 766 |
767 #if defined(OS_POSIX) | 767 #if defined(OS_POSIX) |
768 TEST_F(FileUtilTest, DeleteSymlinkToExistentFile) { | 768 TEST_F(FileUtilTest, DeleteSymlinkToExistentFile) { |
769 // Create a file. | 769 // Create a file. |
770 FilePath file_name = temp_dir_.path().Append(FPL("Test DeleteFile 2.txt")); | 770 FilePath file_name = temp_dir_.path().Append(FPL("Test DeleteFile 2.txt")); |
771 CreateTextFile(file_name, bogus_content); | 771 CreateTextFile(file_name, bogus_content); |
772 ASSERT_TRUE(base::PathExists(file_name)); | 772 ASSERT_TRUE(base::PathExists(file_name)); |
773 | 773 |
774 // Create a symlink to the file. | 774 // Create a symlink to the file. |
775 FilePath file_link = temp_dir_.path().Append("file_link_2"); | 775 FilePath file_link = temp_dir_.path().Append("file_link_2"); |
776 ASSERT_TRUE(file_util::CreateSymbolicLink(file_name, file_link)) | 776 ASSERT_TRUE(file_util::CreateSymbolicLink(file_name, file_link)) |
777 << "Failed to create symlink."; | 777 << "Failed to create symlink."; |
778 | 778 |
779 // Delete the symbolic link. | 779 // Delete the symbolic link. |
780 EXPECT_TRUE(base::Delete(file_link, false)); | 780 EXPECT_TRUE(base::DeleteFile(file_link, false)); |
781 | 781 |
782 // Make sure original file is not deleted. | 782 // Make sure original file is not deleted. |
783 EXPECT_FALSE(base::PathExists(file_link)); | 783 EXPECT_FALSE(base::PathExists(file_link)); |
784 EXPECT_TRUE(base::PathExists(file_name)); | 784 EXPECT_TRUE(base::PathExists(file_name)); |
785 } | 785 } |
786 | 786 |
787 TEST_F(FileUtilTest, DeleteSymlinkToNonExistentFile) { | 787 TEST_F(FileUtilTest, DeleteSymlinkToNonExistentFile) { |
788 // Create a non-existent file path. | 788 // Create a non-existent file path. |
789 FilePath non_existent = temp_dir_.path().Append(FPL("Test DeleteFile 3.txt")); | 789 FilePath non_existent = temp_dir_.path().Append(FPL("Test DeleteFile 3.txt")); |
790 EXPECT_FALSE(base::PathExists(non_existent)); | 790 EXPECT_FALSE(base::PathExists(non_existent)); |
791 | 791 |
792 // Create a symlink to the non-existent file. | 792 // Create a symlink to the non-existent file. |
793 FilePath file_link = temp_dir_.path().Append("file_link_3"); | 793 FilePath file_link = temp_dir_.path().Append("file_link_3"); |
794 ASSERT_TRUE(file_util::CreateSymbolicLink(non_existent, file_link)) | 794 ASSERT_TRUE(file_util::CreateSymbolicLink(non_existent, file_link)) |
795 << "Failed to create symlink."; | 795 << "Failed to create symlink."; |
796 | 796 |
797 // Make sure the symbolic link is exist. | 797 // Make sure the symbolic link is exist. |
798 EXPECT_TRUE(file_util::IsLink(file_link)); | 798 EXPECT_TRUE(file_util::IsLink(file_link)); |
799 EXPECT_FALSE(base::PathExists(file_link)); | 799 EXPECT_FALSE(base::PathExists(file_link)); |
800 | 800 |
801 // Delete the symbolic link. | 801 // Delete the symbolic link. |
802 EXPECT_TRUE(base::Delete(file_link, false)); | 802 EXPECT_TRUE(base::DeleteFile(file_link, false)); |
803 | 803 |
804 // Make sure the symbolic link is deleted. | 804 // Make sure the symbolic link is deleted. |
805 EXPECT_FALSE(file_util::IsLink(file_link)); | 805 EXPECT_FALSE(file_util::IsLink(file_link)); |
806 } | 806 } |
807 | 807 |
808 TEST_F(FileUtilTest, ChangeFilePermissionsAndRead) { | 808 TEST_F(FileUtilTest, ChangeFilePermissionsAndRead) { |
809 // Create a file path. | 809 // Create a file path. |
810 FilePath file_name = temp_dir_.path().Append(FPL("Test Readable File.txt")); | 810 FilePath file_name = temp_dir_.path().Append(FPL("Test Readable File.txt")); |
811 EXPECT_FALSE(base::PathExists(file_name)); | 811 EXPECT_FALSE(base::PathExists(file_name)); |
812 | 812 |
(...skipping 23 matching lines...) Expand all Loading... |
836 EXPECT_TRUE(file_util::SetPosixFilePermissions( | 836 EXPECT_TRUE(file_util::SetPosixFilePermissions( |
837 file_name, | 837 file_name, |
838 file_util::FILE_PERMISSION_READ_BY_USER)); | 838 file_util::FILE_PERMISSION_READ_BY_USER)); |
839 EXPECT_TRUE(file_util::GetPosixFilePermissions(file_name, &mode)); | 839 EXPECT_TRUE(file_util::GetPosixFilePermissions(file_name, &mode)); |
840 EXPECT_TRUE(mode & file_util::FILE_PERMISSION_READ_BY_USER); | 840 EXPECT_TRUE(mode & file_util::FILE_PERMISSION_READ_BY_USER); |
841 // Make sure the file can be read. | 841 // Make sure the file can be read. |
842 EXPECT_EQ(static_cast<int>(kData.length()), | 842 EXPECT_EQ(static_cast<int>(kData.length()), |
843 file_util::ReadFile(file_name, buffer, buffer_size)); | 843 file_util::ReadFile(file_name, buffer, buffer_size)); |
844 | 844 |
845 // Delete the file. | 845 // Delete the file. |
846 EXPECT_TRUE(base::Delete(file_name, false)); | 846 EXPECT_TRUE(base::DeleteFile(file_name, false)); |
847 EXPECT_FALSE(base::PathExists(file_name)); | 847 EXPECT_FALSE(base::PathExists(file_name)); |
848 | 848 |
849 delete[] buffer; | 849 delete[] buffer; |
850 } | 850 } |
851 | 851 |
852 TEST_F(FileUtilTest, ChangeFilePermissionsAndWrite) { | 852 TEST_F(FileUtilTest, ChangeFilePermissionsAndWrite) { |
853 // Create a file path. | 853 // Create a file path. |
854 FilePath file_name = temp_dir_.path().Append(FPL("Test Readable File.txt")); | 854 FilePath file_name = temp_dir_.path().Append(FPL("Test Readable File.txt")); |
855 EXPECT_FALSE(base::PathExists(file_name)); | 855 EXPECT_FALSE(base::PathExists(file_name)); |
856 | 856 |
(...skipping 24 matching lines...) Expand all Loading... |
881 file_name, | 881 file_name, |
882 file_util::FILE_PERMISSION_WRITE_BY_USER)); | 882 file_util::FILE_PERMISSION_WRITE_BY_USER)); |
883 EXPECT_TRUE(file_util::GetPosixFilePermissions(file_name, &mode)); | 883 EXPECT_TRUE(file_util::GetPosixFilePermissions(file_name, &mode)); |
884 EXPECT_TRUE(mode & file_util::FILE_PERMISSION_WRITE_BY_USER); | 884 EXPECT_TRUE(mode & file_util::FILE_PERMISSION_WRITE_BY_USER); |
885 // Make sure the file can be write. | 885 // Make sure the file can be write. |
886 EXPECT_EQ(static_cast<int>(kData.length()), | 886 EXPECT_EQ(static_cast<int>(kData.length()), |
887 file_util::WriteFile(file_name, kData.data(), kData.length())); | 887 file_util::WriteFile(file_name, kData.data(), kData.length())); |
888 EXPECT_TRUE(PathIsWritable(file_name)); | 888 EXPECT_TRUE(PathIsWritable(file_name)); |
889 | 889 |
890 // Delete the file. | 890 // Delete the file. |
891 EXPECT_TRUE(base::Delete(file_name, false)); | 891 EXPECT_TRUE(base::DeleteFile(file_name, false)); |
892 EXPECT_FALSE(base::PathExists(file_name)); | 892 EXPECT_FALSE(base::PathExists(file_name)); |
893 } | 893 } |
894 | 894 |
895 TEST_F(FileUtilTest, ChangeDirectoryPermissionsAndEnumerate) { | 895 TEST_F(FileUtilTest, ChangeDirectoryPermissionsAndEnumerate) { |
896 // Create a directory path. | 896 // Create a directory path. |
897 FilePath subdir_path = | 897 FilePath subdir_path = |
898 temp_dir_.path().Append(FPL("PermissionTest1")); | 898 temp_dir_.path().Append(FPL("PermissionTest1")); |
899 file_util::CreateDirectory(subdir_path); | 899 file_util::CreateDirectory(subdir_path); |
900 ASSERT_TRUE(base::PathExists(subdir_path)); | 900 ASSERT_TRUE(base::PathExists(subdir_path)); |
901 | 901 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
933 EXPECT_EQ(file_util::FILE_PERMISSION_USER_MASK, | 933 EXPECT_EQ(file_util::FILE_PERMISSION_USER_MASK, |
934 mode & file_util::FILE_PERMISSION_USER_MASK); | 934 mode & file_util::FILE_PERMISSION_USER_MASK); |
935 | 935 |
936 // Make sure the file in the directory can be enumerated. | 936 // Make sure the file in the directory can be enumerated. |
937 FileEnumerator f2(subdir_path, true, FileEnumerator::FILES); | 937 FileEnumerator f2(subdir_path, true, FileEnumerator::FILES); |
938 FindResultCollector c2(f2); | 938 FindResultCollector c2(f2); |
939 EXPECT_TRUE(c2.HasFile(file_name)); | 939 EXPECT_TRUE(c2.HasFile(file_name)); |
940 EXPECT_EQ(c2.size(), 1); | 940 EXPECT_EQ(c2.size(), 1); |
941 | 941 |
942 // Delete the file. | 942 // Delete the file. |
943 EXPECT_TRUE(base::Delete(subdir_path, true)); | 943 EXPECT_TRUE(base::DeleteFile(subdir_path, true)); |
944 EXPECT_FALSE(base::PathExists(subdir_path)); | 944 EXPECT_FALSE(base::PathExists(subdir_path)); |
945 } | 945 } |
946 | 946 |
947 #endif // defined(OS_POSIX) | 947 #endif // defined(OS_POSIX) |
948 | 948 |
949 #if defined(OS_WIN) | 949 #if defined(OS_WIN) |
950 // Tests that the Delete function works for wild cards, especially | 950 // Tests that the Delete function works for wild cards, especially |
951 // with the recursion flag. Also coincidentally tests PathExists. | 951 // with the recursion flag. Also coincidentally tests PathExists. |
952 // TODO(erikkay): see if anyone's actually using this feature of the API | 952 // TODO(erikkay): see if anyone's actually using this feature of the API |
953 TEST_F(FileUtilTest, DeleteWildCard) { | 953 TEST_F(FileUtilTest, DeleteWildCard) { |
954 // Create a file and a directory | 954 // Create a file and a directory |
955 FilePath file_name = temp_dir_.path().Append(FPL("Test DeleteWildCard.txt")); | 955 FilePath file_name = temp_dir_.path().Append(FPL("Test DeleteWildCard.txt")); |
956 CreateTextFile(file_name, bogus_content); | 956 CreateTextFile(file_name, bogus_content); |
957 ASSERT_TRUE(base::PathExists(file_name)); | 957 ASSERT_TRUE(base::PathExists(file_name)); |
958 | 958 |
959 FilePath subdir_path = temp_dir_.path().Append(FPL("DeleteWildCardDir")); | 959 FilePath subdir_path = temp_dir_.path().Append(FPL("DeleteWildCardDir")); |
960 file_util::CreateDirectory(subdir_path); | 960 file_util::CreateDirectory(subdir_path); |
961 ASSERT_TRUE(base::PathExists(subdir_path)); | 961 ASSERT_TRUE(base::PathExists(subdir_path)); |
962 | 962 |
963 // Create the wildcard path | 963 // Create the wildcard path |
964 FilePath directory_contents = temp_dir_.path(); | 964 FilePath directory_contents = temp_dir_.path(); |
965 directory_contents = directory_contents.Append(FPL("*")); | 965 directory_contents = directory_contents.Append(FPL("*")); |
966 | 966 |
967 // Delete non-recursively and check that only the file is deleted | 967 // Delete non-recursively and check that only the file is deleted |
968 EXPECT_TRUE(base::Delete(directory_contents, false)); | 968 EXPECT_TRUE(base::DeleteFile(directory_contents, false)); |
969 EXPECT_FALSE(base::PathExists(file_name)); | 969 EXPECT_FALSE(base::PathExists(file_name)); |
970 EXPECT_TRUE(base::PathExists(subdir_path)); | 970 EXPECT_TRUE(base::PathExists(subdir_path)); |
971 | 971 |
972 // Delete recursively and make sure all contents are deleted | 972 // Delete recursively and make sure all contents are deleted |
973 EXPECT_TRUE(base::Delete(directory_contents, true)); | 973 EXPECT_TRUE(base::DeleteFile(directory_contents, true)); |
974 EXPECT_FALSE(base::PathExists(file_name)); | 974 EXPECT_FALSE(base::PathExists(file_name)); |
975 EXPECT_FALSE(base::PathExists(subdir_path)); | 975 EXPECT_FALSE(base::PathExists(subdir_path)); |
976 } | 976 } |
977 | 977 |
978 // TODO(erikkay): see if anyone's actually using this feature of the API | 978 // TODO(erikkay): see if anyone's actually using this feature of the API |
979 TEST_F(FileUtilTest, DeleteNonExistantWildCard) { | 979 TEST_F(FileUtilTest, DeleteNonExistantWildCard) { |
980 // Create a file and a directory | 980 // Create a file and a directory |
981 FilePath subdir_path = | 981 FilePath subdir_path = |
982 temp_dir_.path().Append(FPL("DeleteNonExistantWildCard")); | 982 temp_dir_.path().Append(FPL("DeleteNonExistantWildCard")); |
983 file_util::CreateDirectory(subdir_path); | 983 file_util::CreateDirectory(subdir_path); |
984 ASSERT_TRUE(base::PathExists(subdir_path)); | 984 ASSERT_TRUE(base::PathExists(subdir_path)); |
985 | 985 |
986 // Create the wildcard path | 986 // Create the wildcard path |
987 FilePath directory_contents = subdir_path; | 987 FilePath directory_contents = subdir_path; |
988 directory_contents = directory_contents.Append(FPL("*")); | 988 directory_contents = directory_contents.Append(FPL("*")); |
989 | 989 |
990 // Delete non-recursively and check nothing got deleted | 990 // Delete non-recursively and check nothing got deleted |
991 EXPECT_TRUE(base::Delete(directory_contents, false)); | 991 EXPECT_TRUE(base::DeleteFile(directory_contents, false)); |
992 EXPECT_TRUE(base::PathExists(subdir_path)); | 992 EXPECT_TRUE(base::PathExists(subdir_path)); |
993 | 993 |
994 // Delete recursively and check nothing got deleted | 994 // Delete recursively and check nothing got deleted |
995 EXPECT_TRUE(base::Delete(directory_contents, true)); | 995 EXPECT_TRUE(base::DeleteFile(directory_contents, true)); |
996 EXPECT_TRUE(base::PathExists(subdir_path)); | 996 EXPECT_TRUE(base::PathExists(subdir_path)); |
997 } | 997 } |
998 #endif | 998 #endif |
999 | 999 |
1000 // Tests non-recursive Delete() for a directory. | 1000 // Tests non-recursive Delete() for a directory. |
1001 TEST_F(FileUtilTest, DeleteDirNonRecursive) { | 1001 TEST_F(FileUtilTest, DeleteDirNonRecursive) { |
1002 // Create a subdirectory and put a file and two directories inside. | 1002 // Create a subdirectory and put a file and two directories inside. |
1003 FilePath test_subdir = temp_dir_.path().Append(FPL("DeleteDirNonRecursive")); | 1003 FilePath test_subdir = temp_dir_.path().Append(FPL("DeleteDirNonRecursive")); |
1004 file_util::CreateDirectory(test_subdir); | 1004 file_util::CreateDirectory(test_subdir); |
1005 ASSERT_TRUE(base::PathExists(test_subdir)); | 1005 ASSERT_TRUE(base::PathExists(test_subdir)); |
1006 | 1006 |
1007 FilePath file_name = test_subdir.Append(FPL("Test DeleteDir.txt")); | 1007 FilePath file_name = test_subdir.Append(FPL("Test DeleteDir.txt")); |
1008 CreateTextFile(file_name, bogus_content); | 1008 CreateTextFile(file_name, bogus_content); |
1009 ASSERT_TRUE(base::PathExists(file_name)); | 1009 ASSERT_TRUE(base::PathExists(file_name)); |
1010 | 1010 |
1011 FilePath subdir_path1 = test_subdir.Append(FPL("TestSubDir1")); | 1011 FilePath subdir_path1 = test_subdir.Append(FPL("TestSubDir1")); |
1012 file_util::CreateDirectory(subdir_path1); | 1012 file_util::CreateDirectory(subdir_path1); |
1013 ASSERT_TRUE(base::PathExists(subdir_path1)); | 1013 ASSERT_TRUE(base::PathExists(subdir_path1)); |
1014 | 1014 |
1015 FilePath subdir_path2 = test_subdir.Append(FPL("TestSubDir2")); | 1015 FilePath subdir_path2 = test_subdir.Append(FPL("TestSubDir2")); |
1016 file_util::CreateDirectory(subdir_path2); | 1016 file_util::CreateDirectory(subdir_path2); |
1017 ASSERT_TRUE(base::PathExists(subdir_path2)); | 1017 ASSERT_TRUE(base::PathExists(subdir_path2)); |
1018 | 1018 |
1019 // Delete non-recursively and check that the empty dir got deleted | 1019 // Delete non-recursively and check that the empty dir got deleted |
1020 EXPECT_TRUE(base::Delete(subdir_path2, false)); | 1020 EXPECT_TRUE(base::DeleteFile(subdir_path2, false)); |
1021 EXPECT_FALSE(base::PathExists(subdir_path2)); | 1021 EXPECT_FALSE(base::PathExists(subdir_path2)); |
1022 | 1022 |
1023 // Delete non-recursively and check that nothing got deleted | 1023 // Delete non-recursively and check that nothing got deleted |
1024 EXPECT_FALSE(base::Delete(test_subdir, false)); | 1024 EXPECT_FALSE(base::DeleteFile(test_subdir, false)); |
1025 EXPECT_TRUE(base::PathExists(test_subdir)); | 1025 EXPECT_TRUE(base::PathExists(test_subdir)); |
1026 EXPECT_TRUE(base::PathExists(file_name)); | 1026 EXPECT_TRUE(base::PathExists(file_name)); |
1027 EXPECT_TRUE(base::PathExists(subdir_path1)); | 1027 EXPECT_TRUE(base::PathExists(subdir_path1)); |
1028 } | 1028 } |
1029 | 1029 |
1030 // Tests recursive Delete() for a directory. | 1030 // Tests recursive Delete() for a directory. |
1031 TEST_F(FileUtilTest, DeleteDirRecursive) { | 1031 TEST_F(FileUtilTest, DeleteDirRecursive) { |
1032 // Create a subdirectory and put a file and two directories inside. | 1032 // Create a subdirectory and put a file and two directories inside. |
1033 FilePath test_subdir = temp_dir_.path().Append(FPL("DeleteDirRecursive")); | 1033 FilePath test_subdir = temp_dir_.path().Append(FPL("DeleteDirRecursive")); |
1034 file_util::CreateDirectory(test_subdir); | 1034 file_util::CreateDirectory(test_subdir); |
1035 ASSERT_TRUE(base::PathExists(test_subdir)); | 1035 ASSERT_TRUE(base::PathExists(test_subdir)); |
1036 | 1036 |
1037 FilePath file_name = test_subdir.Append(FPL("Test DeleteDirRecursive.txt")); | 1037 FilePath file_name = test_subdir.Append(FPL("Test DeleteDirRecursive.txt")); |
1038 CreateTextFile(file_name, bogus_content); | 1038 CreateTextFile(file_name, bogus_content); |
1039 ASSERT_TRUE(base::PathExists(file_name)); | 1039 ASSERT_TRUE(base::PathExists(file_name)); |
1040 | 1040 |
1041 FilePath subdir_path1 = test_subdir.Append(FPL("TestSubDir1")); | 1041 FilePath subdir_path1 = test_subdir.Append(FPL("TestSubDir1")); |
1042 file_util::CreateDirectory(subdir_path1); | 1042 file_util::CreateDirectory(subdir_path1); |
1043 ASSERT_TRUE(base::PathExists(subdir_path1)); | 1043 ASSERT_TRUE(base::PathExists(subdir_path1)); |
1044 | 1044 |
1045 FilePath subdir_path2 = test_subdir.Append(FPL("TestSubDir2")); | 1045 FilePath subdir_path2 = test_subdir.Append(FPL("TestSubDir2")); |
1046 file_util::CreateDirectory(subdir_path2); | 1046 file_util::CreateDirectory(subdir_path2); |
1047 ASSERT_TRUE(base::PathExists(subdir_path2)); | 1047 ASSERT_TRUE(base::PathExists(subdir_path2)); |
1048 | 1048 |
1049 // Delete recursively and check that the empty dir got deleted | 1049 // Delete recursively and check that the empty dir got deleted |
1050 EXPECT_TRUE(base::Delete(subdir_path2, true)); | 1050 EXPECT_TRUE(base::DeleteFile(subdir_path2, true)); |
1051 EXPECT_FALSE(base::PathExists(subdir_path2)); | 1051 EXPECT_FALSE(base::PathExists(subdir_path2)); |
1052 | 1052 |
1053 // Delete recursively and check that everything got deleted | 1053 // Delete recursively and check that everything got deleted |
1054 EXPECT_TRUE(base::Delete(test_subdir, true)); | 1054 EXPECT_TRUE(base::DeleteFile(test_subdir, true)); |
1055 EXPECT_FALSE(base::PathExists(file_name)); | 1055 EXPECT_FALSE(base::PathExists(file_name)); |
1056 EXPECT_FALSE(base::PathExists(subdir_path1)); | 1056 EXPECT_FALSE(base::PathExists(subdir_path1)); |
1057 EXPECT_FALSE(base::PathExists(test_subdir)); | 1057 EXPECT_FALSE(base::PathExists(test_subdir)); |
1058 } | 1058 } |
1059 | 1059 |
1060 TEST_F(FileUtilTest, MoveFileNew) { | 1060 TEST_F(FileUtilTest, MoveFileNew) { |
1061 // Create a file | 1061 // Create a file |
1062 FilePath file_name_from = | 1062 FilePath file_name_from = |
1063 temp_dir_.path().Append(FILE_PATH_LITERAL("Move_Test_File.txt")); | 1063 temp_dir_.path().Append(FILE_PATH_LITERAL("Move_Test_File.txt")); |
1064 CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle"); | 1064 CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle"); |
(...skipping 620 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1685 TEST_F(FileUtilTest, CreateTemporaryFileTest) { | 1685 TEST_F(FileUtilTest, CreateTemporaryFileTest) { |
1686 FilePath temp_files[3]; | 1686 FilePath temp_files[3]; |
1687 for (int i = 0; i < 3; i++) { | 1687 for (int i = 0; i < 3; i++) { |
1688 ASSERT_TRUE(file_util::CreateTemporaryFile(&(temp_files[i]))); | 1688 ASSERT_TRUE(file_util::CreateTemporaryFile(&(temp_files[i]))); |
1689 EXPECT_TRUE(base::PathExists(temp_files[i])); | 1689 EXPECT_TRUE(base::PathExists(temp_files[i])); |
1690 EXPECT_FALSE(DirectoryExists(temp_files[i])); | 1690 EXPECT_FALSE(DirectoryExists(temp_files[i])); |
1691 } | 1691 } |
1692 for (int i = 0; i < 3; i++) | 1692 for (int i = 0; i < 3; i++) |
1693 EXPECT_FALSE(temp_files[i] == temp_files[(i+1)%3]); | 1693 EXPECT_FALSE(temp_files[i] == temp_files[(i+1)%3]); |
1694 for (int i = 0; i < 3; i++) | 1694 for (int i = 0; i < 3; i++) |
1695 EXPECT_TRUE(base::Delete(temp_files[i], false)); | 1695 EXPECT_TRUE(base::DeleteFile(temp_files[i], false)); |
1696 } | 1696 } |
1697 | 1697 |
1698 TEST_F(FileUtilTest, CreateAndOpenTemporaryFileTest) { | 1698 TEST_F(FileUtilTest, CreateAndOpenTemporaryFileTest) { |
1699 FilePath names[3]; | 1699 FilePath names[3]; |
1700 FILE* fps[3]; | 1700 FILE* fps[3]; |
1701 int i; | 1701 int i; |
1702 | 1702 |
1703 // Create; make sure they are open and exist. | 1703 // Create; make sure they are open and exist. |
1704 for (i = 0; i < 3; ++i) { | 1704 for (i = 0; i < 3; ++i) { |
1705 fps[i] = file_util::CreateAndOpenTemporaryFile(&(names[i])); | 1705 fps[i] = file_util::CreateAndOpenTemporaryFile(&(names[i])); |
1706 ASSERT_TRUE(fps[i]); | 1706 ASSERT_TRUE(fps[i]); |
1707 EXPECT_TRUE(base::PathExists(names[i])); | 1707 EXPECT_TRUE(base::PathExists(names[i])); |
1708 } | 1708 } |
1709 | 1709 |
1710 // Make sure all names are unique. | 1710 // Make sure all names are unique. |
1711 for (i = 0; i < 3; ++i) { | 1711 for (i = 0; i < 3; ++i) { |
1712 EXPECT_FALSE(names[i] == names[(i+1)%3]); | 1712 EXPECT_FALSE(names[i] == names[(i+1)%3]); |
1713 } | 1713 } |
1714 | 1714 |
1715 // Close and delete. | 1715 // Close and delete. |
1716 for (i = 0; i < 3; ++i) { | 1716 for (i = 0; i < 3; ++i) { |
1717 EXPECT_TRUE(file_util::CloseFile(fps[i])); | 1717 EXPECT_TRUE(file_util::CloseFile(fps[i])); |
1718 EXPECT_TRUE(base::Delete(names[i], false)); | 1718 EXPECT_TRUE(base::DeleteFile(names[i], false)); |
1719 } | 1719 } |
1720 } | 1720 } |
1721 | 1721 |
1722 TEST_F(FileUtilTest, CreateNewTempDirectoryTest) { | 1722 TEST_F(FileUtilTest, CreateNewTempDirectoryTest) { |
1723 FilePath temp_dir; | 1723 FilePath temp_dir; |
1724 ASSERT_TRUE(file_util::CreateNewTempDirectory(FilePath::StringType(), | 1724 ASSERT_TRUE(file_util::CreateNewTempDirectory(FilePath::StringType(), |
1725 &temp_dir)); | 1725 &temp_dir)); |
1726 EXPECT_TRUE(base::PathExists(temp_dir)); | 1726 EXPECT_TRUE(base::PathExists(temp_dir)); |
1727 EXPECT_TRUE(base::Delete(temp_dir, false)); | 1727 EXPECT_TRUE(base::DeleteFile(temp_dir, false)); |
1728 } | 1728 } |
1729 | 1729 |
1730 TEST_F(FileUtilTest, CreateNewTemporaryDirInDirTest) { | 1730 TEST_F(FileUtilTest, CreateNewTemporaryDirInDirTest) { |
1731 FilePath new_dir; | 1731 FilePath new_dir; |
1732 ASSERT_TRUE(file_util::CreateTemporaryDirInDir( | 1732 ASSERT_TRUE(file_util::CreateTemporaryDirInDir( |
1733 temp_dir_.path(), | 1733 temp_dir_.path(), |
1734 FILE_PATH_LITERAL("CreateNewTemporaryDirInDirTest"), | 1734 FILE_PATH_LITERAL("CreateNewTemporaryDirInDirTest"), |
1735 &new_dir)); | 1735 &new_dir)); |
1736 EXPECT_TRUE(base::PathExists(new_dir)); | 1736 EXPECT_TRUE(base::PathExists(new_dir)); |
1737 EXPECT_TRUE(temp_dir_.path().IsParent(new_dir)); | 1737 EXPECT_TRUE(temp_dir_.path().IsParent(new_dir)); |
1738 EXPECT_TRUE(base::Delete(new_dir, false)); | 1738 EXPECT_TRUE(base::DeleteFile(new_dir, false)); |
1739 } | 1739 } |
1740 | 1740 |
1741 TEST_F(FileUtilTest, GetShmemTempDirTest) { | 1741 TEST_F(FileUtilTest, GetShmemTempDirTest) { |
1742 FilePath dir; | 1742 FilePath dir; |
1743 EXPECT_TRUE(file_util::GetShmemTempDir(&dir, false)); | 1743 EXPECT_TRUE(file_util::GetShmemTempDir(&dir, false)); |
1744 EXPECT_TRUE(DirectoryExists(dir)); | 1744 EXPECT_TRUE(DirectoryExists(dir)); |
1745 } | 1745 } |
1746 | 1746 |
1747 TEST_F(FileUtilTest, CreateDirectoryTest) { | 1747 TEST_F(FileUtilTest, CreateDirectoryTest) { |
1748 FilePath test_root = | 1748 FilePath test_root = |
(...skipping 12 matching lines...) Expand all Loading... |
1761 // CreateDirectory returns true if the DirectoryExists returns true. | 1761 // CreateDirectory returns true if the DirectoryExists returns true. |
1762 EXPECT_TRUE(file_util::CreateDirectory(test_path)); | 1762 EXPECT_TRUE(file_util::CreateDirectory(test_path)); |
1763 | 1763 |
1764 // Doesn't work to create it on top of a non-dir | 1764 // Doesn't work to create it on top of a non-dir |
1765 test_path = test_path.Append(FILE_PATH_LITERAL("foobar.txt")); | 1765 test_path = test_path.Append(FILE_PATH_LITERAL("foobar.txt")); |
1766 EXPECT_FALSE(base::PathExists(test_path)); | 1766 EXPECT_FALSE(base::PathExists(test_path)); |
1767 CreateTextFile(test_path, L"test file"); | 1767 CreateTextFile(test_path, L"test file"); |
1768 EXPECT_TRUE(base::PathExists(test_path)); | 1768 EXPECT_TRUE(base::PathExists(test_path)); |
1769 EXPECT_FALSE(file_util::CreateDirectory(test_path)); | 1769 EXPECT_FALSE(file_util::CreateDirectory(test_path)); |
1770 | 1770 |
1771 EXPECT_TRUE(base::Delete(test_root, true)); | 1771 EXPECT_TRUE(base::DeleteFile(test_root, true)); |
1772 EXPECT_FALSE(base::PathExists(test_root)); | 1772 EXPECT_FALSE(base::PathExists(test_root)); |
1773 EXPECT_FALSE(base::PathExists(test_path)); | 1773 EXPECT_FALSE(base::PathExists(test_path)); |
1774 | 1774 |
1775 // Verify assumptions made by the Windows implementation: | 1775 // Verify assumptions made by the Windows implementation: |
1776 // 1. The current directory always exists. | 1776 // 1. The current directory always exists. |
1777 // 2. The root directory always exists. | 1777 // 2. The root directory always exists. |
1778 ASSERT_TRUE(DirectoryExists(FilePath(FilePath::kCurrentDirectory))); | 1778 ASSERT_TRUE(DirectoryExists(FilePath(FilePath::kCurrentDirectory))); |
1779 FilePath top_level = test_root; | 1779 FilePath top_level = test_root; |
1780 while (top_level != top_level.DirName()) { | 1780 while (top_level != top_level.DirName()) { |
1781 top_level = top_level.DirName(); | 1781 top_level = top_level.DirName(); |
(...skipping 24 matching lines...) Expand all Loading... |
1806 EXPECT_TRUE(file_util::CreateDirectory(test_root)); | 1806 EXPECT_TRUE(file_util::CreateDirectory(test_root)); |
1807 EXPECT_TRUE(base::PathExists(test_root)); | 1807 EXPECT_TRUE(base::PathExists(test_root)); |
1808 EXPECT_TRUE(DirectoryExists(test_root)); | 1808 EXPECT_TRUE(DirectoryExists(test_root)); |
1809 // Check a file | 1809 // Check a file |
1810 FilePath test_path = | 1810 FilePath test_path = |
1811 test_root.Append(FILE_PATH_LITERAL("foobar.txt")); | 1811 test_root.Append(FILE_PATH_LITERAL("foobar.txt")); |
1812 EXPECT_FALSE(base::PathExists(test_path)); | 1812 EXPECT_FALSE(base::PathExists(test_path)); |
1813 CreateTextFile(test_path, L"test file"); | 1813 CreateTextFile(test_path, L"test file"); |
1814 EXPECT_TRUE(base::PathExists(test_path)); | 1814 EXPECT_TRUE(base::PathExists(test_path)); |
1815 EXPECT_FALSE(DirectoryExists(test_path)); | 1815 EXPECT_FALSE(DirectoryExists(test_path)); |
1816 EXPECT_TRUE(base::Delete(test_path, false)); | 1816 EXPECT_TRUE(base::DeleteFile(test_path, false)); |
1817 | 1817 |
1818 EXPECT_TRUE(base::Delete(test_root, true)); | 1818 EXPECT_TRUE(base::DeleteFile(test_root, true)); |
1819 } | 1819 } |
1820 | 1820 |
1821 TEST_F(FileUtilTest, FileEnumeratorTest) { | 1821 TEST_F(FileUtilTest, FileEnumeratorTest) { |
1822 // Test an empty directory. | 1822 // Test an empty directory. |
1823 FileEnumerator f0(temp_dir_.path(), true, FILES_AND_DIRECTORIES); | 1823 FileEnumerator f0(temp_dir_.path(), true, FILES_AND_DIRECTORIES); |
1824 EXPECT_EQ(f0.Next().value(), FILE_PATH_LITERAL("")); | 1824 EXPECT_EQ(f0.Next().value(), FILE_PATH_LITERAL("")); |
1825 EXPECT_EQ(f0.Next().value(), FILE_PATH_LITERAL("")); | 1825 EXPECT_EQ(f0.Next().value(), FILE_PATH_LITERAL("")); |
1826 | 1826 |
1827 // Test an empty directory, non-recursively, including "..". | 1827 // Test an empty directory, non-recursively, including "..". |
1828 FileEnumerator f0_dotdot(temp_dir_.path(), false, | 1828 FileEnumerator f0_dotdot(temp_dir_.path(), false, |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1926 EXPECT_FALSE(f6.Next().value().empty()); // Should have found something | 1926 EXPECT_FALSE(f6.Next().value().empty()); // Should have found something |
1927 // (we don't care what). | 1927 // (we don't care what). |
1928 } | 1928 } |
1929 | 1929 |
1930 TEST_F(FileUtilTest, AppendToFile) { | 1930 TEST_F(FileUtilTest, AppendToFile) { |
1931 FilePath data_dir = | 1931 FilePath data_dir = |
1932 temp_dir_.path().Append(FILE_PATH_LITERAL("FilePathTest")); | 1932 temp_dir_.path().Append(FILE_PATH_LITERAL("FilePathTest")); |
1933 | 1933 |
1934 // Create a fresh, empty copy of this directory. | 1934 // Create a fresh, empty copy of this directory. |
1935 if (base::PathExists(data_dir)) { | 1935 if (base::PathExists(data_dir)) { |
1936 ASSERT_TRUE(base::Delete(data_dir, true)); | 1936 ASSERT_TRUE(base::DeleteFile(data_dir, true)); |
1937 } | 1937 } |
1938 ASSERT_TRUE(file_util::CreateDirectory(data_dir)); | 1938 ASSERT_TRUE(file_util::CreateDirectory(data_dir)); |
1939 | 1939 |
1940 // Create a fresh, empty copy of this directory. | 1940 // Create a fresh, empty copy of this directory. |
1941 if (base::PathExists(data_dir)) { | 1941 if (base::PathExists(data_dir)) { |
1942 ASSERT_TRUE(base::Delete(data_dir, true)); | 1942 ASSERT_TRUE(base::DeleteFile(data_dir, true)); |
1943 } | 1943 } |
1944 ASSERT_TRUE(file_util::CreateDirectory(data_dir)); | 1944 ASSERT_TRUE(file_util::CreateDirectory(data_dir)); |
1945 FilePath foobar(data_dir.Append(FILE_PATH_LITERAL("foobar.txt"))); | 1945 FilePath foobar(data_dir.Append(FILE_PATH_LITERAL("foobar.txt"))); |
1946 | 1946 |
1947 std::string data("hello"); | 1947 std::string data("hello"); |
1948 EXPECT_EQ(-1, file_util::AppendToFile(foobar, data.c_str(), data.length())); | 1948 EXPECT_EQ(-1, file_util::AppendToFile(foobar, data.c_str(), data.length())); |
1949 EXPECT_EQ(static_cast<int>(data.length()), | 1949 EXPECT_EQ(static_cast<int>(data.length()), |
1950 file_util::WriteFile(foobar, data.c_str(), data.length())); | 1950 file_util::WriteFile(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::AppendToFile(foobar, data.c_str(), data.length())); | 1952 file_util::AppendToFile(foobar, data.c_str(), data.length())); |
1953 | 1953 |
1954 const std::wstring read_content = ReadTextFile(foobar); | 1954 const std::wstring read_content = ReadTextFile(foobar); |
1955 EXPECT_EQ(L"hellohello", read_content); | 1955 EXPECT_EQ(L"hellohello", read_content); |
1956 } | 1956 } |
1957 | 1957 |
1958 TEST_F(FileUtilTest, TouchFile) { | 1958 TEST_F(FileUtilTest, TouchFile) { |
1959 FilePath data_dir = | 1959 FilePath data_dir = |
1960 temp_dir_.path().Append(FILE_PATH_LITERAL("FilePathTest")); | 1960 temp_dir_.path().Append(FILE_PATH_LITERAL("FilePathTest")); |
1961 | 1961 |
1962 // Create a fresh, empty copy of this directory. | 1962 // Create a fresh, empty copy of this directory. |
1963 if (base::PathExists(data_dir)) { | 1963 if (base::PathExists(data_dir)) { |
1964 ASSERT_TRUE(base::Delete(data_dir, true)); | 1964 ASSERT_TRUE(base::DeleteFile(data_dir, true)); |
1965 } | 1965 } |
1966 ASSERT_TRUE(file_util::CreateDirectory(data_dir)); | 1966 ASSERT_TRUE(file_util::CreateDirectory(data_dir)); |
1967 | 1967 |
1968 FilePath foobar(data_dir.Append(FILE_PATH_LITERAL("foobar.txt"))); | 1968 FilePath foobar(data_dir.Append(FILE_PATH_LITERAL("foobar.txt"))); |
1969 std::string data("hello"); | 1969 std::string data("hello"); |
1970 ASSERT_TRUE(file_util::WriteFile(foobar, data.c_str(), data.length())); | 1970 ASSERT_TRUE(file_util::WriteFile(foobar, data.c_str(), data.length())); |
1971 | 1971 |
1972 base::Time access_time; | 1972 base::Time access_time; |
1973 // This timestamp is divisible by one day (in local timezone), | 1973 // This timestamp is divisible by one day (in local timezone), |
1974 // to make it work on FAT too. | 1974 // to make it work on FAT too. |
(...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2372 file_util::VerifyPathControlledByUser( | 2372 file_util::VerifyPathControlledByUser( |
2373 base_dir_, text_file_, uid_, ok_gids_)); | 2373 base_dir_, text_file_, uid_, ok_gids_)); |
2374 EXPECT_TRUE( | 2374 EXPECT_TRUE( |
2375 file_util::VerifyPathControlledByUser( | 2375 file_util::VerifyPathControlledByUser( |
2376 sub_dir_, text_file_, uid_, ok_gids_)); | 2376 sub_dir_, text_file_, uid_, ok_gids_)); |
2377 } | 2377 } |
2378 | 2378 |
2379 #endif // defined(OS_POSIX) | 2379 #endif // defined(OS_POSIX) |
2380 | 2380 |
2381 } // namespace | 2381 } // namespace |
OLD | NEW |