Chromium Code Reviews| Index: base/files/file_unittest.cc |
| diff --git a/base/files/file_unittest.cc b/base/files/file_unittest.cc |
| index d3a5cdfa9b7770d8cfad8f085e80a6ed4898768e..90aba2fb3309d97b3ea00d6d96a37a9eaba7b2ba 100644 |
| --- a/base/files/file_unittest.cc |
| +++ b/base/files/file_unittest.cc |
| @@ -517,4 +517,48 @@ TEST(FileTest, GetInfoForDirectory) { |
| EXPECT_FALSE(info.is_symbolic_link); |
| EXPECT_EQ(0, info.size); |
| } |
| + |
| +TEST(FileTest, DeleteNoop) { |
| + base::ScopedTempDir temp_dir; |
| + ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
| + FilePath file_path = temp_dir.GetPath().AppendASCII("file"); |
| + |
| + // Creating and closing a file with DELETE perms should do nothing special. |
| + File file(file_path, (base::File::FLAG_CREATE | base::File::FLAG_READ | |
| + base::File::FLAG_WRITE | base::File::FLAG_DELETE)); |
| + ASSERT_TRUE(file.IsValid()); |
| + file.Close(); |
| + ASSERT_TRUE(base::PathExists(file_path)); |
| +} |
| + |
| +TEST(FileTest, Delete) { |
| + base::ScopedTempDir temp_dir; |
| + ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
| + FilePath file_path = temp_dir.GetPath().AppendASCII("file"); |
| + |
| + // Creating a file with DELETE and then marking for delete on close should |
| + // delete it. |
| + File file(file_path, (base::File::FLAG_CREATE | base::File::FLAG_READ | |
| + base::File::FLAG_WRITE | base::File::FLAG_DELETE)); |
| + ASSERT_TRUE(file.IsValid()); |
| + ASSERT_TRUE(file.DeleteOnClose(true)); |
| + file.Close(); |
| + ASSERT_FALSE(base::PathExists(file_path)); |
| +} |
| + |
| +TEST(FileTest, DeleteThenRevoke) { |
| + base::ScopedTempDir temp_dir; |
| + ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
| + FilePath file_path = temp_dir.GetPath().AppendASCII("file"); |
| + |
| + // Creating a file with DELETE, mraking it for delete, then clearing delete on |
|
Nico
2017/01/10 18:04:16
(typo mraking)
grt (UTC plus 2)
2017/01/11 13:52:17
Done.
|
| + // close should not delete it. |
| + File file(file_path, (base::File::FLAG_CREATE | base::File::FLAG_READ | |
| + base::File::FLAG_WRITE | base::File::FLAG_DELETE)); |
| + ASSERT_TRUE(file.IsValid()); |
| + ASSERT_TRUE(file.DeleteOnClose(true)); |
| + ASSERT_TRUE(file.DeleteOnClose(false)); |
| + file.Close(); |
| + ASSERT_TRUE(base::PathExists(file_path)); |
| +} |
|
Nico
2017/01/10 18:04:15
what happens if you file.DeleteOnClose(true) on a
grt (UTC plus 2)
2017/01/11 13:52:17
The call to set attributes fails and DOC returns f
|
| #endif // defined(OS_WIN) |