Chromium Code Reviews| 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 726 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 737 // Test recursive case, create a new file | 737 // Test recursive case, create a new file |
| 738 file_name = temp_dir_.path().Append(FPL("Test DeleteFile 2.txt")); | 738 file_name = temp_dir_.path().Append(FPL("Test DeleteFile 2.txt")); |
| 739 CreateTextFile(file_name, bogus_content); | 739 CreateTextFile(file_name, bogus_content); |
| 740 ASSERT_TRUE(file_util::PathExists(file_name)); | 740 ASSERT_TRUE(file_util::PathExists(file_name)); |
| 741 | 741 |
| 742 // Make sure it's deleted | 742 // Make sure it's deleted |
| 743 EXPECT_TRUE(file_util::Delete(file_name, true)); | 743 EXPECT_TRUE(file_util::Delete(file_name, true)); |
| 744 EXPECT_FALSE(file_util::PathExists(file_name)); | 744 EXPECT_FALSE(file_util::PathExists(file_name)); |
| 745 } | 745 } |
| 746 | 746 |
| 747 #if defined(OS_POSIX) | |
| 748 TEST_F(FileUtilTest, DeleteSymlinkOfExistentFile) { | |
|
satorux1
2012/06/29 18:25:20
DeleteSymlinkToExistentFile
yoshiki
2012/06/29 19:12:27
Done.
| |
| 749 // Create a file | |
| 750 FilePath file_name = temp_dir_.path().Append(FPL("Test DeleteFile 2.txt")); | |
| 751 CreateTextFile(file_name, bogus_content); | |
| 752 ASSERT_TRUE(file_util::PathExists(file_name)); | |
| 753 | |
| 754 // Create a symlink to the file. | |
| 755 FilePath file_link = temp_dir_.path().Append("file_link_2"); | |
| 756 ASSERT_TRUE(file_util::CreateSymbolicLink(file_name, file_link)) | |
| 757 << "Failed to create symlink."; | |
| 758 | |
| 759 // Delete the symbolic link. | |
| 760 EXPECT_TRUE(file_util::Delete(file_link, false)); | |
| 761 | |
| 762 // Make sure original file is not deleted | |
| 763 EXPECT_FALSE(file_util::PathExists(file_link)); | |
| 764 EXPECT_TRUE(file_util::PathExists(file_name)); | |
| 765 } | |
| 766 | |
| 767 TEST_F(FileUtilTest, DeleteSymlinkOfNonExistentFile) { | |
|
satorux1
2012/06/29 18:25:20
DeleteSymlinkToNonExistentFile
satorux1
2012/06/29 18:25:20
DeleteSymlinkToNonExistentFile
yoshiki
2012/06/29 19:12:27
Done.
| |
| 768 // Create a dummy file to be deleted. | |
| 769 FilePath non_existent = temp_dir_.path().Append(FPL("Test DeleteFile 3.txt")); | |
| 770 CreateTextFile(non_existent, bogus_content); | |
| 771 EXPECT_TRUE(file_util::PathExists(non_existent)); | |
|
satorux1
2012/06/29 18:25:20
You don't need a dummy file to create a dangling s
yoshiki
2012/06/29 19:12:27
Done.
| |
| 772 | |
| 773 // Create a symlink to the dummy file. | |
| 774 FilePath file_link = temp_dir_.path().Append("file_link_3"); | |
| 775 ASSERT_TRUE(file_util::CreateSymbolicLink(non_existent, file_link)) | |
| 776 << "Failed to create symlink."; | |
| 777 EXPECT_TRUE(file_util::PathExists(non_existent)); | |
| 778 EXPECT_TRUE(file_util::PathExists(file_link)); | |
| 779 | |
| 780 // Delete the dummy file, keeping the symbolic link. | |
| 781 EXPECT_TRUE(file_util::Delete(non_existent, false)); | |
| 782 EXPECT_FALSE(file_util::PathExists(non_existent)); | |
| 783 EXPECT_FALSE(file_util::PathExists(file_link)); | |
|
satorux1
2012/06/29 18:25:20
I'd suggest to remove this part too.
yoshiki
2012/06/29 19:12:27
Done.
| |
| 784 | |
| 785 // Make sure the symbolic link is not deleted | |
| 786 EXPECT_TRUE(file_util::IsLink(file_link)); | |
| 787 | |
| 788 // Delete the symbolic link. | |
| 789 EXPECT_TRUE(file_util::Delete(file_link, false)); | |
| 790 | |
| 791 // Make sure the symbolic link is deleted | |
| 792 EXPECT_FALSE(file_util::IsLink(file_link)); | |
| 793 } | |
| 794 #endif // defined(OS_POSIX) | |
| 795 | |
| 747 #if defined(OS_WIN) | 796 #if defined(OS_WIN) |
| 748 // Tests that the Delete function works for wild cards, especially | 797 // Tests that the Delete function works for wild cards, especially |
| 749 // with the recursion flag. Also coincidentally tests PathExists. | 798 // with the recursion flag. Also coincidentally tests PathExists. |
| 750 // TODO(erikkay): see if anyone's actually using this feature of the API | 799 // TODO(erikkay): see if anyone's actually using this feature of the API |
| 751 TEST_F(FileUtilTest, DeleteWildCard) { | 800 TEST_F(FileUtilTest, DeleteWildCard) { |
| 752 // Create a file and a directory | 801 // Create a file and a directory |
| 753 FilePath file_name = temp_dir_.path().Append(FPL("Test DeleteWildCard.txt")); | 802 FilePath file_name = temp_dir_.path().Append(FPL("Test DeleteWildCard.txt")); |
| 754 CreateTextFile(file_name, bogus_content); | 803 CreateTextFile(file_name, bogus_content); |
| 755 ASSERT_TRUE(file_util::PathExists(file_name)); | 804 ASSERT_TRUE(file_util::PathExists(file_name)); |
| 756 | 805 |
| (...skipping 1519 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2276 file_util::VerifyPathControlledByUser( | 2325 file_util::VerifyPathControlledByUser( |
| 2277 base_dir_, text_file_, uid_, ok_gids_)); | 2326 base_dir_, text_file_, uid_, ok_gids_)); |
| 2278 EXPECT_TRUE( | 2327 EXPECT_TRUE( |
| 2279 file_util::VerifyPathControlledByUser( | 2328 file_util::VerifyPathControlledByUser( |
| 2280 sub_dir_, text_file_, uid_, ok_gids_)); | 2329 sub_dir_, text_file_, uid_, ok_gids_)); |
| 2281 } | 2330 } |
| 2282 | 2331 |
| 2283 #endif // defined(OS_POSIX) | 2332 #endif // defined(OS_POSIX) |
| 2284 | 2333 |
| 2285 } // namespace | 2334 } // namespace |
| OLD | NEW |