diff options
author | jochen@chromium.org <jochen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-06-22 19:29:23 +0000 |
---|---|---|
committer | jochen@chromium.org <jochen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-06-22 19:29:23 +0000 |
commit | ad0f81dd10c2322df4bf4dcbbe4719ea6d097a6f (patch) | |
tree | e0e0e24b9da6997137639312630800ac76434707 /base/platform_file_unittest.cc | |
parent | e7da6aefa0e6219917d8e5d098212e965c7a28ce (diff) | |
download | chromium_src-ad0f81dd10c2322df4bf4dcbbe4719ea6d097a6f.zip chromium_src-ad0f81dd10c2322df4bf4dcbbe4719ea6d097a6f.tar.gz chromium_src-ad0f81dd10c2322df4bf4dcbbe4719ea6d097a6f.tar.bz2 |
Add a flag to open files in share delete mode
BUG=86928
TEST=base_unittests
Review URL: http://codereview.chromium.org/7233007
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@90071 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/platform_file_unittest.cc')
-rw-r--r-- | base/platform_file_unittest.cc | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/base/platform_file_unittest.cc b/base/platform_file_unittest.cc index 0bd4fb3..039c7ef 100644 --- a/base/platform_file_unittest.cc +++ b/base/platform_file_unittest.cc @@ -127,6 +127,42 @@ TEST(PlatformFile, CreatePlatformFile) { EXPECT_FALSE(file_util::PathExists(file_path)); } +TEST(PlatformFile, DeleteOpenFile) { + ScopedTempDir temp_dir; + ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); + FilePath file_path = temp_dir.path().AppendASCII("create_file_1"); + + // Create a file. + bool created = false; + base::PlatformFileError error_code = base::PLATFORM_FILE_OK; + base::PlatformFile file = base::CreatePlatformFile( + file_path, + base::PLATFORM_FILE_OPEN_ALWAYS | + base::PLATFORM_FILE_READ | + base::PLATFORM_FILE_SHARE_DELETE, + &created, &error_code); + EXPECT_NE(base::kInvalidPlatformFileValue, file); + EXPECT_TRUE(created); + EXPECT_EQ(base::PLATFORM_FILE_OK, error_code); + + // Open an existing file and mark it as delete on close. + created = false; + base::PlatformFile same_file = base::CreatePlatformFile( + file_path, + base::PLATFORM_FILE_OPEN | + base::PLATFORM_FILE_DELETE_ON_CLOSE | + base::PLATFORM_FILE_READ, + &created, &error_code); + EXPECT_NE(base::kInvalidPlatformFileValue, file); + EXPECT_FALSE(created); + EXPECT_EQ(base::PLATFORM_FILE_OK, error_code); + + // Close both handles and check that the file is gone. + base::ClosePlatformFile(file); + base::ClosePlatformFile(same_file); + EXPECT_FALSE(file_util::PathExists(file_path)); +} + TEST(PlatformFile, ReadWritePlatformFile) { ScopedTempDir temp_dir; ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |