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

Side by Side Diff: base/platform_file_unittest.cc

Issue 7233007: Add a flag to open files in share delete mode (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 6 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « base/platform_file.h ('k') | base/platform_file_win.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "base/file_util.h" 5 #include "base/file_util.h"
6 #include "base/platform_file.h" 6 #include "base/platform_file.h"
7 #include "base/scoped_temp_dir.h" 7 #include "base/scoped_temp_dir.h"
8 #include "base/time.h" 8 #include "base/time.h"
9 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
10 10
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 base::PLATFORM_FILE_READ, 120 base::PLATFORM_FILE_READ,
121 &created, &error_code); 121 &created, &error_code);
122 EXPECT_NE(base::kInvalidPlatformFileValue, file); 122 EXPECT_NE(base::kInvalidPlatformFileValue, file);
123 EXPECT_TRUE(created); 123 EXPECT_TRUE(created);
124 EXPECT_EQ(base::PLATFORM_FILE_OK, error_code); 124 EXPECT_EQ(base::PLATFORM_FILE_OK, error_code);
125 125
126 EXPECT_TRUE(base::ClosePlatformFile(file)); 126 EXPECT_TRUE(base::ClosePlatformFile(file));
127 EXPECT_FALSE(file_util::PathExists(file_path)); 127 EXPECT_FALSE(file_util::PathExists(file_path));
128 } 128 }
129 129
130 TEST(PlatformFile, DeleteOpenFile) {
131 ScopedTempDir temp_dir;
132 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
133 FilePath file_path = temp_dir.path().AppendASCII("create_file_1");
134
135 // Create a file.
136 bool created = false;
137 base::PlatformFileError error_code = base::PLATFORM_FILE_OK;
138 base::PlatformFile file = base::CreatePlatformFile(
139 file_path,
140 base::PLATFORM_FILE_OPEN_ALWAYS |
141 base::PLATFORM_FILE_READ |
142 base::PLATFORM_FILE_SHARE_DELETE,
143 &created, &error_code);
144 EXPECT_NE(base::kInvalidPlatformFileValue, file);
145 EXPECT_TRUE(created);
146 EXPECT_EQ(base::PLATFORM_FILE_OK, error_code);
147
148 // Open an existing file and mark it as delete on close.
149 created = false;
150 base::PlatformFile same_file = base::CreatePlatformFile(
151 file_path,
152 base::PLATFORM_FILE_OPEN |
153 base::PLATFORM_FILE_DELETE_ON_CLOSE |
154 base::PLATFORM_FILE_READ,
155 &created, &error_code);
156 EXPECT_NE(base::kInvalidPlatformFileValue, file);
157 EXPECT_FALSE(created);
158 EXPECT_EQ(base::PLATFORM_FILE_OK, error_code);
159
160 // Close both handles and check that the file is gone.
161 base::ClosePlatformFile(file);
162 base::ClosePlatformFile(same_file);
163 EXPECT_FALSE(file_util::PathExists(file_path));
164 }
165
130 TEST(PlatformFile, ReadWritePlatformFile) { 166 TEST(PlatformFile, ReadWritePlatformFile) {
131 ScopedTempDir temp_dir; 167 ScopedTempDir temp_dir;
132 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 168 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
133 FilePath file_path = temp_dir.path().AppendASCII("read_write_file"); 169 FilePath file_path = temp_dir.path().AppendASCII("read_write_file");
134 base::PlatformFile file = base::CreatePlatformFile( 170 base::PlatformFile file = base::CreatePlatformFile(
135 file_path, 171 file_path,
136 base::PLATFORM_FILE_CREATE | 172 base::PLATFORM_FILE_CREATE |
137 base::PLATFORM_FILE_READ | 173 base::PLATFORM_FILE_READ |
138 base::PLATFORM_FILE_WRITE, 174 base::PLATFORM_FILE_WRITE,
139 NULL, NULL); 175 NULL, NULL);
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
317 EXPECT_EQ(info.last_modified.ToInternalValue(), 353 EXPECT_EQ(info.last_modified.ToInternalValue(),
318 new_last_modified.ToInternalValue()); 354 new_last_modified.ToInternalValue());
319 #endif 355 #endif
320 356
321 EXPECT_EQ(info.creation_time.ToInternalValue(), 357 EXPECT_EQ(info.creation_time.ToInternalValue(),
322 creation_time.ToInternalValue()); 358 creation_time.ToInternalValue());
323 359
324 // Close the file handle to allow the temp directory to be deleted. 360 // Close the file handle to allow the temp directory to be deleted.
325 base::ClosePlatformFile(file); 361 base::ClosePlatformFile(file);
326 } 362 }
OLDNEW
« no previous file with comments | « base/platform_file.h ('k') | base/platform_file_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698