Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4339)

Unified Diff: base/files/file_unittest.cc

Issue 2567383002: Add FLAG_CAN_DELETE_ON_CLOSE and DeleteOnClose for use on Windows. (Closed)
Patch Set: thakis comments Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: base/files/file_unittest.cc
diff --git a/base/files/file_unittest.cc b/base/files/file_unittest.cc
index d3a5cdfa9b7770d8cfad8f085e80a6ed4898768e..ce7c82c4f91df4fe257d6d633975a726d75527ec 100644
--- a/base/files/file_unittest.cc
+++ b/base/files/file_unittest.cc
@@ -517,4 +517,63 @@ 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.
Nico 2017/01/11 15:47:18 The Windows API flag is called DELETE, but maybe a
grt (UTC plus 2) 2017/01/12 13:58:20 CAN sounds good to me. Done.
+ 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, marking it for delete, then clearing delete on
+ // 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));
+}
+
+TEST(FileTest, DeleteWithoutPermission) {
+ base::ScopedTempDir temp_dir;
+ ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
+ FilePath file_path = temp_dir.GetPath().AppendASCII("file");
+
+ // It should not be possible to mark a file for deletion when it was not
+ // created/opened with DELETE.
+ File file(file_path, (base::File::FLAG_CREATE | base::File::FLAG_READ |
+ base::File::FLAG_WRITE));
+ ASSERT_TRUE(file.IsValid());
+ ASSERT_FALSE(file.DeleteOnClose(true));
+ file.Close();
+ ASSERT_TRUE(base::PathExists(file_path));
+}
#endif // defined(OS_WIN)
« base/files/file.h ('K') | « base/files/file.h ('k') | base/files/file_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698