Index: chrome/browser/win/jumplist_file_util_unittest.cc |
diff --git a/chrome/browser/win/jumplist_file_util_unittest.cc b/chrome/browser/win/jumplist_file_util_unittest.cc |
index b4cfbfb29bc147e04da4d932231f3ed55bfc1dbe..ea7f4dbdcbcdaf54d28b247b13efd51cbe3bd0d6 100644 |
--- a/chrome/browser/win/jumplist_file_util_unittest.cc |
+++ b/chrome/browser/win/jumplist_file_util_unittest.cc |
@@ -100,3 +100,47 @@ TEST_F(JumpListFileUtilTest, DeleteMaxFilesAllowed) { |
EXPECT_TRUE(base::IsDirectoryEmpty(dir_path)); |
EXPECT_TRUE(DirectoryExists(dir_path)); |
} |
+ |
+TEST_F(JumpListFileUtilTest, FilesExceedLimitInDir) { |
+ base::FilePath dir_path = temp_dir_path(); |
+ |
+ // Create 2 files. |
+ base::FilePath file_name = |
+ dir_path.Append(FILE_PATH_LITERAL("TestFile1.txt")); |
+ ASSERT_NO_FATAL_FAILURE(CreateTextFile(file_name, kFileContent)); |
+ |
+ file_name = dir_path.Append(FILE_PATH_LITERAL("TestFile2.txt")); |
+ ASSERT_NO_FATAL_FAILURE(CreateTextFile(file_name, kFileContent)); |
+ |
+ EXPECT_TRUE(FilesExceedLimitInDir(dir_path, 1)); |
+ EXPECT_FALSE(FilesExceedLimitInDir(dir_path, 2)); |
+ |
+ DeleteDirectory(dir_path, kFileDeleteLimit); |
+} |
+ |
+TEST_F(JumpListFileUtilTest, DeleteNonCachedFiles) { |
+ base::FilePath dir_path = temp_dir_path(); |
+ |
+ std::set<base::FilePath> path_set; |
+ |
+ // Create 1 file and cache its filename. |
+ base::FilePath file_name = |
+ dir_path.Append(FILE_PATH_LITERAL("TestFile1.txt")); |
+ ASSERT_NO_FATAL_FAILURE(CreateTextFile(file_name, kFileContent)); |
+ |
+ path_set.insert(file_name); |
+ |
+ // Create another file but not cache its filename. |
+ file_name = dir_path.Append(FILE_PATH_LITERAL("TestFile2.txt")); |
+ ASSERT_NO_FATAL_FAILURE(CreateTextFile(file_name, kFileContent)); |
+ |
+ // The second file created will be deleted as its filename is not in the |
+ // cache, while the first file remains. |
+ DeleteNonCachedFiles(dir_path, path_set); |
+ EXPECT_FALSE(base::IsDirectoryEmpty(dir_path)); |
+ |
+ // Clear the set and delete again, and now the first file should be gone. |
+ path_set.clear(); |
+ DeleteNonCachedFiles(dir_path, path_set); |
+ EXPECT_TRUE(base::IsDirectoryEmpty(dir_path)); |
+} |