OLD | NEW |
1 // Copyright (c) 2017 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2017 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 "chrome/browser/win/jumplist_file_util.h" | 5 #include "chrome/browser/win/jumplist_file_util.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/files/file_util.h" | 9 #include "base/files/file_util.h" |
10 #include "base/files/scoped_temp_dir.h" | 10 #include "base/files/scoped_temp_dir.h" |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 // Sine the maximum files allowed to delete is 1, only 1 out of the 2 | 93 // Sine the maximum files allowed to delete is 1, only 1 out of the 2 |
94 // files is deleted. Therefore, the directory is not empty yet. | 94 // files is deleted. Therefore, the directory is not empty yet. |
95 DeleteDirectoryContent(dir_path, kFileDeleteLimitForTest); | 95 DeleteDirectoryContent(dir_path, kFileDeleteLimitForTest); |
96 EXPECT_FALSE(base::IsDirectoryEmpty(dir_path)); | 96 EXPECT_FALSE(base::IsDirectoryEmpty(dir_path)); |
97 | 97 |
98 // Delete another file, and now the directory is empty. | 98 // Delete another file, and now the directory is empty. |
99 DeleteDirectoryContent(dir_path, kFileDeleteLimitForTest); | 99 DeleteDirectoryContent(dir_path, kFileDeleteLimitForTest); |
100 EXPECT_TRUE(base::IsDirectoryEmpty(dir_path)); | 100 EXPECT_TRUE(base::IsDirectoryEmpty(dir_path)); |
101 EXPECT_TRUE(DirectoryExists(dir_path)); | 101 EXPECT_TRUE(DirectoryExists(dir_path)); |
102 } | 102 } |
| 103 |
| 104 TEST_F(JumpListFileUtilTest, FilesExceedLimitInDir) { |
| 105 base::FilePath dir_path = temp_dir_path(); |
| 106 |
| 107 // Create 2 files. |
| 108 base::FilePath file_name = |
| 109 dir_path.Append(FILE_PATH_LITERAL("TestFile1.txt")); |
| 110 ASSERT_NO_FATAL_FAILURE(CreateTextFile(file_name, kFileContent)); |
| 111 |
| 112 file_name = dir_path.Append(FILE_PATH_LITERAL("TestFile2.txt")); |
| 113 ASSERT_NO_FATAL_FAILURE(CreateTextFile(file_name, kFileContent)); |
| 114 |
| 115 EXPECT_TRUE(FilesExceedLimitInDir(dir_path, 1)); |
| 116 EXPECT_FALSE(FilesExceedLimitInDir(dir_path, 2)); |
| 117 |
| 118 DeleteDirectory(dir_path, kFileDeleteLimit); |
| 119 } |
| 120 |
| 121 TEST_F(JumpListFileUtilTest, DeleteNonCachedFiles) { |
| 122 base::FilePath dir_path = temp_dir_path(); |
| 123 |
| 124 base::flat_set<base::FilePath> cached_files; |
| 125 |
| 126 // Create 1 file and cache its filename. |
| 127 base::FilePath file_name = |
| 128 dir_path.Append(FILE_PATH_LITERAL("TestFile1.txt")); |
| 129 ASSERT_NO_FATAL_FAILURE(CreateTextFile(file_name, kFileContent)); |
| 130 |
| 131 cached_files.insert(file_name); |
| 132 |
| 133 // Create another file but not cache its filename. |
| 134 file_name = dir_path.Append(FILE_PATH_LITERAL("TestFile2.txt")); |
| 135 ASSERT_NO_FATAL_FAILURE(CreateTextFile(file_name, kFileContent)); |
| 136 |
| 137 // The second file created will be deleted as its filename is not in the |
| 138 // cache, while the first file remains. |
| 139 DeleteNonCachedFiles(dir_path, cached_files); |
| 140 EXPECT_FALSE(base::IsDirectoryEmpty(dir_path)); |
| 141 |
| 142 // Clear the set and delete again, and now the first file should be gone. |
| 143 cached_files.clear(); |
| 144 DeleteNonCachedFiles(dir_path, cached_files); |
| 145 EXPECT_TRUE(base::IsDirectoryEmpty(dir_path)); |
| 146 } |
OLD | NEW |