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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 TEST_F(JumpListFileUtilTest, DeleteDirectoryContent) { | 45 TEST_F(JumpListFileUtilTest, DeleteDirectoryContent) { |
46 base::FilePath dir_path = temp_dir_path(); | 46 base::FilePath dir_path = temp_dir_path(); |
47 | 47 |
48 // Create a file. | 48 // Create a file. |
49 base::FilePath file_name = | 49 base::FilePath file_name = |
50 dir_path.Append(FILE_PATH_LITERAL("TestDeleteFile.txt")); | 50 dir_path.Append(FILE_PATH_LITERAL("TestDeleteFile.txt")); |
51 ASSERT_NO_FATAL_FAILURE(CreateTextFile(file_name, kFileContent)); | 51 ASSERT_NO_FATAL_FAILURE(CreateTextFile(file_name, kFileContent)); |
52 | 52 |
53 // Delete the directory content using DeleteDirectoryContent(). The file | 53 // Delete the directory content using DeleteDirectoryContent(). The file |
54 // should be deleted and the directory remains. | 54 // should be deleted and the directory remains. |
55 ASSERT_EQ(DeleteDirectoryContent(dir_path, kFileDeleteLimit), SUCCEED); | 55 DeleteDirectoryContent(dir_path, kFileDeleteLimit); |
56 EXPECT_FALSE(PathExists(file_name)); | 56 EXPECT_FALSE(PathExists(file_name)); |
57 EXPECT_TRUE(DirectoryExists(dir_path)); | 57 EXPECT_TRUE(DirectoryExists(dir_path)); |
58 } | 58 } |
59 | 59 |
60 TEST_F(JumpListFileUtilTest, DeleteSubDirectory) { | 60 TEST_F(JumpListFileUtilTest, DeleteSubDirectory) { |
61 base::FilePath dir_path = temp_dir_path(); | 61 base::FilePath dir_path = temp_dir_path(); |
62 | 62 |
63 // Create a subdirectory. | 63 // Create a subdirectory. |
64 base::FilePath test_subdir = | 64 base::FilePath test_subdir = |
65 dir_path.Append(FILE_PATH_LITERAL("TestSubDirectory")); | 65 dir_path.Append(FILE_PATH_LITERAL("TestSubDirectory")); |
66 ASSERT_NO_FATAL_FAILURE(CreateDirectory(test_subdir)); | 66 ASSERT_NO_FATAL_FAILURE(CreateDirectory(test_subdir)); |
67 | 67 |
68 // Delete the directory using DeleteDirectory(), which should fail because | 68 // Delete the directory using DeleteDirectory(), which should fail because |
69 // a subdirectory exists. | 69 // a subdirectory exists. Therefore, both root directory and sub-directory |
70 ASSERT_EQ(DeleteDirectory(dir_path, kFileDeleteLimit), | 70 // should still exist. |
71 FAIL_SUBDIRECTORY_EXISTS); | 71 DeleteDirectory(dir_path, kFileDeleteLimit); |
72 EXPECT_TRUE(DirectoryExists(dir_path)); | 72 EXPECT_TRUE(DirectoryExists(dir_path)); |
73 EXPECT_TRUE(DirectoryExists(test_subdir)); | 73 EXPECT_TRUE(DirectoryExists(test_subdir)); |
74 | 74 |
75 // Delete the subdirectory alone should be working. | 75 // Delete the subdirectory alone should be working. |
76 ASSERT_EQ(DeleteDirectory(test_subdir, kFileDeleteLimit), SUCCEED); | 76 DeleteDirectory(test_subdir, kFileDeleteLimit); |
77 EXPECT_TRUE(DirectoryExists(dir_path)); | 77 EXPECT_TRUE(DirectoryExists(dir_path)); |
78 EXPECT_FALSE(DirectoryExists(test_subdir)); | 78 EXPECT_FALSE(DirectoryExists(test_subdir)); |
79 } | 79 } |
80 | 80 |
81 TEST_F(JumpListFileUtilTest, DeleteMaxFilesAllowed) { | 81 TEST_F(JumpListFileUtilTest, DeleteMaxFilesAllowed) { |
82 base::FilePath dir_path = temp_dir_path(); | 82 base::FilePath dir_path = temp_dir_path(); |
83 | 83 |
84 // Create 2 files. | 84 // Create 2 files. |
85 base::FilePath file_name = | 85 base::FilePath file_name = |
86 dir_path.Append(FILE_PATH_LITERAL("TestDeleteFile1.txt")); | 86 dir_path.Append(FILE_PATH_LITERAL("TestDeleteFile1.txt")); |
87 ASSERT_NO_FATAL_FAILURE(CreateTextFile(file_name, kFileContent)); | 87 ASSERT_NO_FATAL_FAILURE(CreateTextFile(file_name, kFileContent)); |
88 | 88 |
89 file_name = dir_path.Append(FILE_PATH_LITERAL("TestDeleteFile2.txt")); | 89 file_name = dir_path.Append(FILE_PATH_LITERAL("TestDeleteFile2.txt")); |
90 ASSERT_NO_FATAL_FAILURE(CreateTextFile(file_name, kFileContent)); | 90 ASSERT_NO_FATAL_FAILURE(CreateTextFile(file_name, kFileContent)); |
91 | 91 |
92 // Delete the directory content using DeleteDirectoryContent(). | 92 // Delete the directory content using DeleteDirectoryContent(). |
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 ASSERT_EQ(DeleteDirectoryContent(dir_path, kFileDeleteLimitForTest), SUCCEED); | 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 ASSERT_EQ(DeleteDirectoryContent(dir_path, kFileDeleteLimitForTest), SUCCEED); | 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 } |
OLD | NEW |