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

Side by Side Diff: webkit/browser/fileapi/native_file_util_unittest.cc

Issue 145303002: Convert Media Galleries to use base::File (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 6 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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 <set> 5 #include <set>
6 6
7 #include "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/files/file_path.h" 8 #include "base/files/file_path.h"
9 #include "base/files/scoped_temp_dir.h" 9 #include "base/files/scoped_temp_dir.h"
10 #include "base/platform_file.h" 10 #include "base/platform_file.h"
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 base::ScopedTempDir data_dir_; 45 base::ScopedTempDir data_dir_;
46 46
47 DISALLOW_COPY_AND_ASSIGN(NativeFileUtilTest); 47 DISALLOW_COPY_AND_ASSIGN(NativeFileUtilTest);
48 }; 48 };
49 49
50 TEST_F(NativeFileUtilTest, CreateCloseAndDeleteFile) { 50 TEST_F(NativeFileUtilTest, CreateCloseAndDeleteFile) {
51 base::FilePath file_name = Path("test_file"); 51 base::FilePath file_name = Path("test_file");
52 base::PlatformFile file_handle; 52 base::PlatformFile file_handle;
53 bool created = false; 53 bool created = false;
54 int flags = base::PLATFORM_FILE_WRITE | base::PLATFORM_FILE_ASYNC; 54 int flags = base::PLATFORM_FILE_WRITE | base::PLATFORM_FILE_ASYNC;
55 ASSERT_EQ(base::PLATFORM_FILE_OK, 55 ASSERT_EQ(base::File::FILE_OK,
56 NativeFileUtil::CreateOrOpen(file_name, 56 NativeFileUtil::CreateOrOpen(file_name,
57 base::PLATFORM_FILE_CREATE | flags, 57 base::PLATFORM_FILE_CREATE | flags,
58 &file_handle, &created)); 58 &file_handle, &created));
59 ASSERT_TRUE(created); 59 ASSERT_TRUE(created);
60 60
61 EXPECT_TRUE(base::PathExists(file_name)); 61 EXPECT_TRUE(base::PathExists(file_name));
62 EXPECT_TRUE(NativeFileUtil::PathExists(file_name)); 62 EXPECT_TRUE(NativeFileUtil::PathExists(file_name));
63 EXPECT_EQ(0, GetSize(file_name)); 63 EXPECT_EQ(0, GetSize(file_name));
64 EXPECT_NE(base::kInvalidPlatformFileValue, file_handle); 64 EXPECT_NE(base::kInvalidPlatformFileValue, file_handle);
65 65
66 ASSERT_EQ(base::PLATFORM_FILE_OK, NativeFileUtil::Close(file_handle)); 66 ASSERT_EQ(base::File::FILE_OK, NativeFileUtil::Close(file_handle));
67 67
68 ASSERT_EQ(base::PLATFORM_FILE_OK, 68 ASSERT_EQ(base::File::FILE_OK,
69 NativeFileUtil::CreateOrOpen(file_name, 69 NativeFileUtil::CreateOrOpen(file_name,
70 base::PLATFORM_FILE_OPEN | flags, 70 base::PLATFORM_FILE_OPEN | flags,
71 &file_handle, &created)); 71 &file_handle, &created));
72 ASSERT_FALSE(created); 72 ASSERT_FALSE(created);
73 ASSERT_EQ(base::PLATFORM_FILE_OK, NativeFileUtil::Close(file_handle)); 73 ASSERT_EQ(base::File::FILE_OK, NativeFileUtil::Close(file_handle));
74 74
75 ASSERT_EQ(base::PLATFORM_FILE_OK, 75 ASSERT_EQ(base::File::FILE_OK,
76 NativeFileUtil::DeleteFile(file_name)); 76 NativeFileUtil::DeleteFile(file_name));
77 EXPECT_FALSE(base::PathExists(file_name)); 77 EXPECT_FALSE(base::PathExists(file_name));
78 EXPECT_FALSE(NativeFileUtil::PathExists(file_name)); 78 EXPECT_FALSE(NativeFileUtil::PathExists(file_name));
79 } 79 }
80 80
81 TEST_F(NativeFileUtilTest, EnsureFileExists) { 81 TEST_F(NativeFileUtilTest, EnsureFileExists) {
82 base::FilePath file_name = Path("foobar"); 82 base::FilePath file_name = Path("foobar");
83 bool created = false; 83 bool created = false;
84 ASSERT_EQ(base::PLATFORM_FILE_OK, 84 ASSERT_EQ(base::File::FILE_OK,
85 NativeFileUtil::EnsureFileExists(file_name, &created)); 85 NativeFileUtil::EnsureFileExists(file_name, &created));
86 ASSERT_TRUE(created); 86 ASSERT_TRUE(created);
87 87
88 EXPECT_TRUE(FileExists(file_name)); 88 EXPECT_TRUE(FileExists(file_name));
89 EXPECT_EQ(0, GetSize(file_name)); 89 EXPECT_EQ(0, GetSize(file_name));
90 90
91 ASSERT_EQ(base::PLATFORM_FILE_OK, 91 ASSERT_EQ(base::File::FILE_OK,
92 NativeFileUtil::EnsureFileExists(file_name, &created)); 92 NativeFileUtil::EnsureFileExists(file_name, &created));
93 EXPECT_FALSE(created); 93 EXPECT_FALSE(created);
94 } 94 }
95 95
96 TEST_F(NativeFileUtilTest, CreateAndDeleteDirectory) { 96 TEST_F(NativeFileUtilTest, CreateAndDeleteDirectory) {
97 base::FilePath dir_name = Path("test_dir"); 97 base::FilePath dir_name = Path("test_dir");
98 ASSERT_EQ(base::PLATFORM_FILE_OK, 98 ASSERT_EQ(base::File::FILE_OK,
99 NativeFileUtil::CreateDirectory(dir_name, 99 NativeFileUtil::CreateDirectory(dir_name,
100 false /* exclusive */, 100 false /* exclusive */,
101 false /* recursive */)); 101 false /* recursive */));
102 102
103 EXPECT_TRUE(NativeFileUtil::DirectoryExists(dir_name)); 103 EXPECT_TRUE(NativeFileUtil::DirectoryExists(dir_name));
104 EXPECT_TRUE(base::DirectoryExists(dir_name)); 104 EXPECT_TRUE(base::DirectoryExists(dir_name));
105 105
106 ASSERT_EQ(base::PLATFORM_FILE_ERROR_EXISTS, 106 ASSERT_EQ(base::File::FILE_ERROR_EXISTS,
107 NativeFileUtil::CreateDirectory(dir_name, 107 NativeFileUtil::CreateDirectory(dir_name,
108 true /* exclusive */, 108 true /* exclusive */,
109 false /* recursive */)); 109 false /* recursive */));
110 110
111 ASSERT_EQ(base::PLATFORM_FILE_OK, 111 ASSERT_EQ(base::File::FILE_OK,
112 NativeFileUtil::DeleteDirectory(dir_name)); 112 NativeFileUtil::DeleteDirectory(dir_name));
113 EXPECT_FALSE(base::DirectoryExists(dir_name)); 113 EXPECT_FALSE(base::DirectoryExists(dir_name));
114 EXPECT_FALSE(NativeFileUtil::DirectoryExists(dir_name)); 114 EXPECT_FALSE(NativeFileUtil::DirectoryExists(dir_name));
115 } 115 }
116 116
117 TEST_F(NativeFileUtilTest, TouchFileAndGetFileInfo) { 117 TEST_F(NativeFileUtilTest, TouchFileAndGetFileInfo) {
118 base::FilePath file_name = Path("test_file"); 118 base::FilePath file_name = Path("test_file");
119 base::PlatformFileInfo native_info; 119 base::File::Info native_info;
120 ASSERT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, 120 ASSERT_EQ(base::File::FILE_ERROR_NOT_FOUND,
121 NativeFileUtil::GetFileInfo(file_name, &native_info)); 121 NativeFileUtil::GetFileInfo(file_name, &native_info));
122 122
123 bool created = false; 123 bool created = false;
124 ASSERT_EQ(base::PLATFORM_FILE_OK, 124 ASSERT_EQ(base::File::FILE_OK,
125 NativeFileUtil::EnsureFileExists(file_name, &created)); 125 NativeFileUtil::EnsureFileExists(file_name, &created));
126 ASSERT_TRUE(created); 126 ASSERT_TRUE(created);
127 127
128 base::File::Info info; 128 base::File::Info info;
129 ASSERT_TRUE(base::GetFileInfo(file_name, &info)); 129 ASSERT_TRUE(base::GetFileInfo(file_name, &info));
130 ASSERT_EQ(base::PLATFORM_FILE_OK, 130 ASSERT_EQ(base::File::FILE_OK,
131 NativeFileUtil::GetFileInfo(file_name, &native_info)); 131 NativeFileUtil::GetFileInfo(file_name, &native_info));
132 ASSERT_EQ(info.size, native_info.size); 132 ASSERT_EQ(info.size, native_info.size);
133 ASSERT_EQ(info.is_directory, native_info.is_directory); 133 ASSERT_EQ(info.is_directory, native_info.is_directory);
134 ASSERT_EQ(info.is_symbolic_link, native_info.is_symbolic_link); 134 ASSERT_EQ(info.is_symbolic_link, native_info.is_symbolic_link);
135 ASSERT_EQ(info.last_modified, native_info.last_modified); 135 ASSERT_EQ(info.last_modified, native_info.last_modified);
136 ASSERT_EQ(info.last_accessed, native_info.last_accessed); 136 ASSERT_EQ(info.last_accessed, native_info.last_accessed);
137 ASSERT_EQ(info.creation_time, native_info.creation_time); 137 ASSERT_EQ(info.creation_time, native_info.creation_time);
138 138
139 const base::Time new_accessed = 139 const base::Time new_accessed =
140 info.last_accessed + base::TimeDelta::FromHours(10); 140 info.last_accessed + base::TimeDelta::FromHours(10);
141 const base::Time new_modified = 141 const base::Time new_modified =
142 info.last_modified + base::TimeDelta::FromHours(5); 142 info.last_modified + base::TimeDelta::FromHours(5);
143 143
144 EXPECT_EQ(base::PLATFORM_FILE_OK, 144 EXPECT_EQ(base::File::FILE_OK,
145 NativeFileUtil::Touch(file_name, 145 NativeFileUtil::Touch(file_name,
146 new_accessed, new_modified)); 146 new_accessed, new_modified));
147 147
148 ASSERT_TRUE(base::GetFileInfo(file_name, &info)); 148 ASSERT_TRUE(base::GetFileInfo(file_name, &info));
149 EXPECT_EQ(new_accessed, info.last_accessed); 149 EXPECT_EQ(new_accessed, info.last_accessed);
150 EXPECT_EQ(new_modified, info.last_modified); 150 EXPECT_EQ(new_modified, info.last_modified);
151 } 151 }
152 152
153 TEST_F(NativeFileUtilTest, CreateFileEnumerator) { 153 TEST_F(NativeFileUtilTest, CreateFileEnumerator) {
154 base::FilePath path_1 = Path("dir1"); 154 base::FilePath path_1 = Path("dir1");
155 base::FilePath path_2 = Path("file1"); 155 base::FilePath path_2 = Path("file1");
156 base::FilePath path_11 = Path("dir1").AppendASCII("file11"); 156 base::FilePath path_11 = Path("dir1").AppendASCII("file11");
157 base::FilePath path_12 = Path("dir1").AppendASCII("dir12"); 157 base::FilePath path_12 = Path("dir1").AppendASCII("dir12");
158 base::FilePath path_121 = 158 base::FilePath path_121 =
159 Path("dir1").AppendASCII("dir12").AppendASCII("file121"); 159 Path("dir1").AppendASCII("dir12").AppendASCII("file121");
160 ASSERT_EQ(base::PLATFORM_FILE_OK, 160 ASSERT_EQ(base::File::FILE_OK,
161 NativeFileUtil::CreateDirectory(path_1, false, false)); 161 NativeFileUtil::CreateDirectory(path_1, false, false));
162 bool created = false; 162 bool created = false;
163 ASSERT_EQ(base::PLATFORM_FILE_OK, 163 ASSERT_EQ(base::File::FILE_OK,
164 NativeFileUtil::EnsureFileExists(path_2, &created)); 164 NativeFileUtil::EnsureFileExists(path_2, &created));
165 ASSERT_EQ(base::PLATFORM_FILE_OK, 165 ASSERT_EQ(base::File::FILE_OK,
166 NativeFileUtil::EnsureFileExists(path_11, &created)); 166 NativeFileUtil::EnsureFileExists(path_11, &created));
167 ASSERT_EQ(base::PLATFORM_FILE_OK, 167 ASSERT_EQ(base::File::FILE_OK,
168 NativeFileUtil::CreateDirectory(path_12, false, false)); 168 NativeFileUtil::CreateDirectory(path_12, false, false));
169 ASSERT_EQ(base::PLATFORM_FILE_OK, 169 ASSERT_EQ(base::File::FILE_OK,
170 NativeFileUtil::EnsureFileExists(path_121, &created)); 170 NativeFileUtil::EnsureFileExists(path_121, &created));
171 171
172 { 172 {
173 scoped_ptr<FileSystemFileUtil::AbstractFileEnumerator> enumerator = 173 scoped_ptr<FileSystemFileUtil::AbstractFileEnumerator> enumerator =
174 NativeFileUtil::CreateFileEnumerator(Path(), false); 174 NativeFileUtil::CreateFileEnumerator(Path(), false);
175 std::set<base::FilePath> set; 175 std::set<base::FilePath> set;
176 set.insert(path_1); 176 set.insert(path_1);
177 set.insert(path_2); 177 set.insert(path_2);
178 for (base::FilePath path = enumerator->Next(); !path.empty(); 178 for (base::FilePath path = enumerator->Next(); !path.empty();
179 path = enumerator->Next()) 179 path = enumerator->Next())
(...skipping 13 matching lines...) Expand all
193 for (base::FilePath path = enumerator->Next(); !path.empty(); 193 for (base::FilePath path = enumerator->Next(); !path.empty();
194 path = enumerator->Next()) 194 path = enumerator->Next())
195 EXPECT_EQ(1U, set.erase(path)); 195 EXPECT_EQ(1U, set.erase(path));
196 EXPECT_TRUE(set.empty()); 196 EXPECT_TRUE(set.empty());
197 } 197 }
198 } 198 }
199 199
200 TEST_F(NativeFileUtilTest, Truncate) { 200 TEST_F(NativeFileUtilTest, Truncate) {
201 base::FilePath file_name = Path("truncated"); 201 base::FilePath file_name = Path("truncated");
202 bool created = false; 202 bool created = false;
203 ASSERT_EQ(base::PLATFORM_FILE_OK, 203 ASSERT_EQ(base::File::FILE_OK,
204 NativeFileUtil::EnsureFileExists(file_name, &created)); 204 NativeFileUtil::EnsureFileExists(file_name, &created));
205 ASSERT_TRUE(created); 205 ASSERT_TRUE(created);
206 206
207 ASSERT_EQ(base::PLATFORM_FILE_OK, 207 ASSERT_EQ(base::File::FILE_OK,
208 NativeFileUtil::Truncate(file_name, 1020)); 208 NativeFileUtil::Truncate(file_name, 1020));
209 209
210 EXPECT_TRUE(FileExists(file_name)); 210 EXPECT_TRUE(FileExists(file_name));
211 EXPECT_EQ(1020, GetSize(file_name)); 211 EXPECT_EQ(1020, GetSize(file_name));
212 } 212 }
213 213
214 TEST_F(NativeFileUtilTest, CopyFile) { 214 TEST_F(NativeFileUtilTest, CopyFile) {
215 base::FilePath from_file = Path("fromfile"); 215 base::FilePath from_file = Path("fromfile");
216 base::FilePath to_file1 = Path("tofile1"); 216 base::FilePath to_file1 = Path("tofile1");
217 base::FilePath to_file2 = Path("tofile2"); 217 base::FilePath to_file2 = Path("tofile2");
218 const NativeFileUtil::CopyOrMoveMode nosync = NativeFileUtil::COPY_NOSYNC; 218 const NativeFileUtil::CopyOrMoveMode nosync = NativeFileUtil::COPY_NOSYNC;
219 const NativeFileUtil::CopyOrMoveMode sync = NativeFileUtil::COPY_SYNC; 219 const NativeFileUtil::CopyOrMoveMode sync = NativeFileUtil::COPY_SYNC;
220 bool created = false; 220 bool created = false;
221 ASSERT_EQ(base::PLATFORM_FILE_OK, 221 ASSERT_EQ(base::File::FILE_OK,
222 NativeFileUtil::EnsureFileExists(from_file, &created)); 222 NativeFileUtil::EnsureFileExists(from_file, &created));
223 ASSERT_TRUE(created); 223 ASSERT_TRUE(created);
224 224
225 ASSERT_EQ(base::PLATFORM_FILE_OK, 225 ASSERT_EQ(base::File::FILE_OK,
226 NativeFileUtil::Truncate(from_file, 1020)); 226 NativeFileUtil::Truncate(from_file, 1020));
227 227
228 EXPECT_TRUE(FileExists(from_file)); 228 EXPECT_TRUE(FileExists(from_file));
229 EXPECT_EQ(1020, GetSize(from_file)); 229 EXPECT_EQ(1020, GetSize(from_file));
230 230
231 ASSERT_EQ(base::PLATFORM_FILE_OK, 231 ASSERT_EQ(base::File::FILE_OK,
232 NativeFileUtil::CopyOrMoveFile( 232 NativeFileUtil::CopyOrMoveFile(
233 from_file, to_file1, FileSystemOperation::OPTION_NONE, nosync)); 233 from_file, to_file1, FileSystemOperation::OPTION_NONE, nosync));
234 234
235 ASSERT_EQ(base::PLATFORM_FILE_OK, 235 ASSERT_EQ(base::File::FILE_OK,
236 NativeFileUtil::CopyOrMoveFile( 236 NativeFileUtil::CopyOrMoveFile(
237 from_file, to_file2, FileSystemOperation::OPTION_NONE, sync)); 237 from_file, to_file2, FileSystemOperation::OPTION_NONE, sync));
238 238
239 EXPECT_TRUE(FileExists(from_file)); 239 EXPECT_TRUE(FileExists(from_file));
240 EXPECT_EQ(1020, GetSize(from_file)); 240 EXPECT_EQ(1020, GetSize(from_file));
241 EXPECT_TRUE(FileExists(to_file1)); 241 EXPECT_TRUE(FileExists(to_file1));
242 EXPECT_EQ(1020, GetSize(to_file1)); 242 EXPECT_EQ(1020, GetSize(to_file1));
243 EXPECT_TRUE(FileExists(to_file2)); 243 EXPECT_TRUE(FileExists(to_file2));
244 EXPECT_EQ(1020, GetSize(to_file2)); 244 EXPECT_EQ(1020, GetSize(to_file2));
245 245
246 base::FilePath dir = Path("dir"); 246 base::FilePath dir = Path("dir");
247 ASSERT_EQ(base::PLATFORM_FILE_OK, 247 ASSERT_EQ(base::File::FILE_OK,
248 NativeFileUtil::CreateDirectory(dir, false, false)); 248 NativeFileUtil::CreateDirectory(dir, false, false));
249 ASSERT_TRUE(base::DirectoryExists(dir)); 249 ASSERT_TRUE(base::DirectoryExists(dir));
250 base::FilePath to_dir_file = dir.AppendASCII("file"); 250 base::FilePath to_dir_file = dir.AppendASCII("file");
251 ASSERT_EQ(base::PLATFORM_FILE_OK, 251 ASSERT_EQ(base::File::FILE_OK,
252 NativeFileUtil::CopyOrMoveFile( 252 NativeFileUtil::CopyOrMoveFile(
253 from_file, to_dir_file, 253 from_file, to_dir_file,
254 FileSystemOperation::OPTION_NONE, nosync)); 254 FileSystemOperation::OPTION_NONE, nosync));
255 EXPECT_TRUE(FileExists(to_dir_file)); 255 EXPECT_TRUE(FileExists(to_dir_file));
256 EXPECT_EQ(1020, GetSize(to_dir_file)); 256 EXPECT_EQ(1020, GetSize(to_dir_file));
257 257
258 // Following tests are error checking. 258 // Following tests are error checking.
259 // Source doesn't exist. 259 // Source doesn't exist.
260 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, 260 EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND,
261 NativeFileUtil::CopyOrMoveFile( 261 NativeFileUtil::CopyOrMoveFile(
262 Path("nonexists"), Path("file"), 262 Path("nonexists"), Path("file"),
263 FileSystemOperation::OPTION_NONE, nosync)); 263 FileSystemOperation::OPTION_NONE, nosync));
264 264
265 // Source is not a file. 265 // Source is not a file.
266 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_A_FILE, 266 EXPECT_EQ(base::File::FILE_ERROR_NOT_A_FILE,
267 NativeFileUtil::CopyOrMoveFile( 267 NativeFileUtil::CopyOrMoveFile(
268 dir, Path("file"), FileSystemOperation::OPTION_NONE, nosync)); 268 dir, Path("file"), FileSystemOperation::OPTION_NONE, nosync));
269 // Destination is not a file. 269 // Destination is not a file.
270 EXPECT_EQ(base::PLATFORM_FILE_ERROR_INVALID_OPERATION, 270 EXPECT_EQ(base::File::FILE_ERROR_INVALID_OPERATION,
271 NativeFileUtil::CopyOrMoveFile( 271 NativeFileUtil::CopyOrMoveFile(
272 from_file, dir, FileSystemOperation::OPTION_NONE, nosync)); 272 from_file, dir, FileSystemOperation::OPTION_NONE, nosync));
273 // Destination's parent doesn't exist. 273 // Destination's parent doesn't exist.
274 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, 274 EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND,
275 NativeFileUtil::CopyOrMoveFile( 275 NativeFileUtil::CopyOrMoveFile(
276 from_file, Path("nodir").AppendASCII("file"), 276 from_file, Path("nodir").AppendASCII("file"),
277 FileSystemOperation::OPTION_NONE, nosync)); 277 FileSystemOperation::OPTION_NONE, nosync));
278 // Destination's parent is a file. 278 // Destination's parent is a file.
279 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, 279 EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND,
280 NativeFileUtil::CopyOrMoveFile( 280 NativeFileUtil::CopyOrMoveFile(
281 from_file, Path("tofile1").AppendASCII("file"), 281 from_file, Path("tofile1").AppendASCII("file"),
282 FileSystemOperation::OPTION_NONE, nosync)); 282 FileSystemOperation::OPTION_NONE, nosync));
283 } 283 }
284 284
285 TEST_F(NativeFileUtilTest, MoveFile) { 285 TEST_F(NativeFileUtilTest, MoveFile) {
286 base::FilePath from_file = Path("fromfile"); 286 base::FilePath from_file = Path("fromfile");
287 base::FilePath to_file = Path("tofile"); 287 base::FilePath to_file = Path("tofile");
288 const NativeFileUtil::CopyOrMoveMode move = NativeFileUtil::MOVE; 288 const NativeFileUtil::CopyOrMoveMode move = NativeFileUtil::MOVE;
289 bool created = false; 289 bool created = false;
290 ASSERT_EQ(base::PLATFORM_FILE_OK, 290 ASSERT_EQ(base::File::FILE_OK,
291 NativeFileUtil::EnsureFileExists(from_file, &created)); 291 NativeFileUtil::EnsureFileExists(from_file, &created));
292 ASSERT_TRUE(created); 292 ASSERT_TRUE(created);
293 293
294 ASSERT_EQ(base::PLATFORM_FILE_OK, NativeFileUtil::Truncate(from_file, 1020)); 294 ASSERT_EQ(base::File::FILE_OK, NativeFileUtil::Truncate(from_file, 1020));
295 295
296 EXPECT_TRUE(FileExists(from_file)); 296 EXPECT_TRUE(FileExists(from_file));
297 EXPECT_EQ(1020, GetSize(from_file)); 297 EXPECT_EQ(1020, GetSize(from_file));
298 298
299 ASSERT_EQ(base::PLATFORM_FILE_OK, 299 ASSERT_EQ(base::File::FILE_OK,
300 NativeFileUtil::CopyOrMoveFile( 300 NativeFileUtil::CopyOrMoveFile(
301 from_file, to_file, FileSystemOperation::OPTION_NONE, move)); 301 from_file, to_file, FileSystemOperation::OPTION_NONE, move));
302 302
303 EXPECT_FALSE(FileExists(from_file)); 303 EXPECT_FALSE(FileExists(from_file));
304 EXPECT_TRUE(FileExists(to_file)); 304 EXPECT_TRUE(FileExists(to_file));
305 EXPECT_EQ(1020, GetSize(to_file)); 305 EXPECT_EQ(1020, GetSize(to_file));
306 306
307 ASSERT_EQ(base::PLATFORM_FILE_OK, 307 ASSERT_EQ(base::File::FILE_OK,
308 NativeFileUtil::EnsureFileExists(from_file, &created)); 308 NativeFileUtil::EnsureFileExists(from_file, &created));
309 ASSERT_TRUE(FileExists(from_file)); 309 ASSERT_TRUE(FileExists(from_file));
310 ASSERT_EQ(base::PLATFORM_FILE_OK, NativeFileUtil::Truncate(from_file, 1020)); 310 ASSERT_EQ(base::File::FILE_OK, NativeFileUtil::Truncate(from_file, 1020));
311 311
312 base::FilePath dir = Path("dir"); 312 base::FilePath dir = Path("dir");
313 ASSERT_EQ(base::PLATFORM_FILE_OK, 313 ASSERT_EQ(base::File::FILE_OK,
314 NativeFileUtil::CreateDirectory(dir, false, false)); 314 NativeFileUtil::CreateDirectory(dir, false, false));
315 ASSERT_TRUE(base::DirectoryExists(dir)); 315 ASSERT_TRUE(base::DirectoryExists(dir));
316 base::FilePath to_dir_file = dir.AppendASCII("file"); 316 base::FilePath to_dir_file = dir.AppendASCII("file");
317 ASSERT_EQ(base::PLATFORM_FILE_OK, 317 ASSERT_EQ(base::File::FILE_OK,
318 NativeFileUtil::CopyOrMoveFile( 318 NativeFileUtil::CopyOrMoveFile(
319 from_file, to_dir_file, 319 from_file, to_dir_file,
320 FileSystemOperation::OPTION_NONE, move)); 320 FileSystemOperation::OPTION_NONE, move));
321 EXPECT_FALSE(FileExists(from_file)); 321 EXPECT_FALSE(FileExists(from_file));
322 EXPECT_TRUE(FileExists(to_dir_file)); 322 EXPECT_TRUE(FileExists(to_dir_file));
323 EXPECT_EQ(1020, GetSize(to_dir_file)); 323 EXPECT_EQ(1020, GetSize(to_dir_file));
324 324
325 // Following is error checking. 325 // Following is error checking.
326 // Source doesn't exist. 326 // Source doesn't exist.
327 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, 327 EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND,
328 NativeFileUtil::CopyOrMoveFile( 328 NativeFileUtil::CopyOrMoveFile(
329 Path("nonexists"), Path("file"), 329 Path("nonexists"), Path("file"),
330 FileSystemOperation::OPTION_NONE, move)); 330 FileSystemOperation::OPTION_NONE, move));
331 331
332 // Source is not a file. 332 // Source is not a file.
333 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_A_FILE, 333 EXPECT_EQ(base::File::FILE_ERROR_NOT_A_FILE,
334 NativeFileUtil::CopyOrMoveFile( 334 NativeFileUtil::CopyOrMoveFile(
335 dir, Path("file"), FileSystemOperation::OPTION_NONE, move)); 335 dir, Path("file"), FileSystemOperation::OPTION_NONE, move));
336 ASSERT_EQ(base::PLATFORM_FILE_OK, 336 ASSERT_EQ(base::File::FILE_OK,
337 NativeFileUtil::EnsureFileExists(from_file, &created)); 337 NativeFileUtil::EnsureFileExists(from_file, &created));
338 ASSERT_TRUE(FileExists(from_file)); 338 ASSERT_TRUE(FileExists(from_file));
339 // Destination is not a file. 339 // Destination is not a file.
340 EXPECT_EQ(base::PLATFORM_FILE_ERROR_INVALID_OPERATION, 340 EXPECT_EQ(base::File::FILE_ERROR_INVALID_OPERATION,
341 NativeFileUtil::CopyOrMoveFile( 341 NativeFileUtil::CopyOrMoveFile(
342 from_file, dir, FileSystemOperation::OPTION_NONE, move)); 342 from_file, dir, FileSystemOperation::OPTION_NONE, move));
343 343
344 ASSERT_EQ(base::PLATFORM_FILE_OK, 344 ASSERT_EQ(base::File::FILE_OK,
345 NativeFileUtil::EnsureFileExists(from_file, &created)); 345 NativeFileUtil::EnsureFileExists(from_file, &created));
346 ASSERT_TRUE(FileExists(from_file)); 346 ASSERT_TRUE(FileExists(from_file));
347 // Destination's parent doesn't exist. 347 // Destination's parent doesn't exist.
348 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, 348 EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND,
349 NativeFileUtil::CopyOrMoveFile( 349 NativeFileUtil::CopyOrMoveFile(
350 from_file, Path("nodir").AppendASCII("file"), 350 from_file, Path("nodir").AppendASCII("file"),
351 FileSystemOperation::OPTION_NONE, move)); 351 FileSystemOperation::OPTION_NONE, move));
352 // Destination's parent is a file. 352 // Destination's parent is a file.
353 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, 353 EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND,
354 NativeFileUtil::CopyOrMoveFile( 354 NativeFileUtil::CopyOrMoveFile(
355 from_file, Path("tofile1").AppendASCII("file"), 355 from_file, Path("tofile1").AppendASCII("file"),
356 FileSystemOperation::OPTION_NONE, move)); 356 FileSystemOperation::OPTION_NONE, move));
357 } 357 }
358 358
359 TEST_F(NativeFileUtilTest, PreserveLastModified) { 359 TEST_F(NativeFileUtilTest, PreserveLastModified) {
360 base::FilePath from_file = Path("fromfile"); 360 base::FilePath from_file = Path("fromfile");
361 base::FilePath to_file1 = Path("tofile1"); 361 base::FilePath to_file1 = Path("tofile1");
362 base::FilePath to_file2 = Path("tofile2"); 362 base::FilePath to_file2 = Path("tofile2");
363 base::FilePath to_file3 = Path("tofile3"); 363 base::FilePath to_file3 = Path("tofile3");
364 bool created = false; 364 bool created = false;
365 ASSERT_EQ(base::PLATFORM_FILE_OK, 365 ASSERT_EQ(base::File::FILE_OK,
366 NativeFileUtil::EnsureFileExists(from_file, &created)); 366 NativeFileUtil::EnsureFileExists(from_file, &created));
367 ASSERT_TRUE(created); 367 ASSERT_TRUE(created);
368 EXPECT_TRUE(FileExists(from_file)); 368 EXPECT_TRUE(FileExists(from_file));
369 369
370 base::PlatformFileInfo file_info1; 370 base::File::Info file_info1;
371 ASSERT_EQ(base::PLATFORM_FILE_OK, 371 ASSERT_EQ(base::File::FILE_OK,
372 NativeFileUtil::GetFileInfo(from_file, &file_info1)); 372 NativeFileUtil::GetFileInfo(from_file, &file_info1));
373 373
374 // Test for copy (nosync). 374 // Test for copy (nosync).
375 ASSERT_EQ(base::PLATFORM_FILE_OK, 375 ASSERT_EQ(base::File::FILE_OK,
376 NativeFileUtil::CopyOrMoveFile( 376 NativeFileUtil::CopyOrMoveFile(
377 from_file, to_file1, 377 from_file, to_file1,
378 FileSystemOperation::OPTION_PRESERVE_LAST_MODIFIED, 378 FileSystemOperation::OPTION_PRESERVE_LAST_MODIFIED,
379 NativeFileUtil::COPY_NOSYNC)); 379 NativeFileUtil::COPY_NOSYNC));
380 380
381 base::PlatformFileInfo file_info2; 381 base::File::Info file_info2;
382 ASSERT_TRUE(FileExists(to_file1)); 382 ASSERT_TRUE(FileExists(to_file1));
383 ASSERT_EQ(base::PLATFORM_FILE_OK, 383 ASSERT_EQ(base::File::FILE_OK,
384 NativeFileUtil::GetFileInfo(to_file1, &file_info2)); 384 NativeFileUtil::GetFileInfo(to_file1, &file_info2));
385 EXPECT_EQ(file_info1.last_modified, file_info2.last_modified); 385 EXPECT_EQ(file_info1.last_modified, file_info2.last_modified);
386 386
387 // Test for copy (sync). 387 // Test for copy (sync).
388 ASSERT_EQ(base::PLATFORM_FILE_OK, 388 ASSERT_EQ(base::File::FILE_OK,
389 NativeFileUtil::CopyOrMoveFile( 389 NativeFileUtil::CopyOrMoveFile(
390 from_file, to_file2, 390 from_file, to_file2,
391 FileSystemOperation::OPTION_PRESERVE_LAST_MODIFIED, 391 FileSystemOperation::OPTION_PRESERVE_LAST_MODIFIED,
392 NativeFileUtil::COPY_SYNC)); 392 NativeFileUtil::COPY_SYNC));
393 393
394 ASSERT_TRUE(FileExists(to_file2)); 394 ASSERT_TRUE(FileExists(to_file2));
395 ASSERT_EQ(base::PLATFORM_FILE_OK, 395 ASSERT_EQ(base::File::FILE_OK,
396 NativeFileUtil::GetFileInfo(to_file1, &file_info2)); 396 NativeFileUtil::GetFileInfo(to_file1, &file_info2));
397 EXPECT_EQ(file_info1.last_modified, file_info2.last_modified); 397 EXPECT_EQ(file_info1.last_modified, file_info2.last_modified);
398 398
399 // Test for move. 399 // Test for move.
400 ASSERT_EQ(base::PLATFORM_FILE_OK, 400 ASSERT_EQ(base::File::FILE_OK,
401 NativeFileUtil::CopyOrMoveFile( 401 NativeFileUtil::CopyOrMoveFile(
402 from_file, to_file3, 402 from_file, to_file3,
403 FileSystemOperation::OPTION_PRESERVE_LAST_MODIFIED, 403 FileSystemOperation::OPTION_PRESERVE_LAST_MODIFIED,
404 NativeFileUtil::MOVE)); 404 NativeFileUtil::MOVE));
405 405
406 ASSERT_TRUE(FileExists(to_file3)); 406 ASSERT_TRUE(FileExists(to_file3));
407 ASSERT_EQ(base::PLATFORM_FILE_OK, 407 ASSERT_EQ(base::File::FILE_OK,
408 NativeFileUtil::GetFileInfo(to_file2, &file_info2)); 408 NativeFileUtil::GetFileInfo(to_file2, &file_info2));
409 EXPECT_EQ(file_info1.last_modified, file_info2.last_modified); 409 EXPECT_EQ(file_info1.last_modified, file_info2.last_modified);
410 } 410 }
411 411
412 } // namespace fileapi 412 } // namespace fileapi
OLDNEW
« no previous file with comments | « webkit/browser/fileapi/native_file_util.cc ('k') | webkit/browser/fileapi/obfuscated_file_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698