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

Side by Side Diff: content/browser/fileapi/local_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, 10 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 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 <string> 5 #include <string>
6 6
7 #include "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/files/file.h"
8 #include "base/files/file_path.h" 9 #include "base/files/file_path.h"
9 #include "base/files/scoped_temp_dir.h" 10 #include "base/files/scoped_temp_dir.h"
10 #include "base/message_loop/message_loop_proxy.h" 11 #include "base/message_loop/message_loop_proxy.h"
11 #include "base/platform_file.h" 12 #include "base/platform_file.h"
12 #include "base/run_loop.h" 13 #include "base/run_loop.h"
13 #include "base/strings/sys_string_conversions.h" 14 #include "base/strings/sys_string_conversions.h"
14 #include "base/strings/utf_string_conversions.h" 15 #include "base/strings/utf_string_conversions.h"
15 #include "content/public/test/test_file_system_context.h" 16 #include "content/public/test/test_file_system_context.h"
16 #include "testing/gtest/include/gtest/gtest.h" 17 #include "testing/gtest/include/gtest/gtest.h"
17 #include "webkit/browser/fileapi/async_file_test_helper.h" 18 #include "webkit/browser/fileapi/async_file_test_helper.h"
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 bool DirectoryExists(const char *file_name) { 91 bool DirectoryExists(const char *file_name) {
91 return base::DirectoryExists(LocalPath(file_name)); 92 return base::DirectoryExists(LocalPath(file_name));
92 } 93 }
93 94
94 int64 GetSize(const char *file_name) { 95 int64 GetSize(const char *file_name) {
95 base::File::Info info; 96 base::File::Info info;
96 base::GetFileInfo(LocalPath(file_name), &info); 97 base::GetFileInfo(LocalPath(file_name), &info);
97 return info.size; 98 return info.size;
98 } 99 }
99 100
100 base::PlatformFileError CreateFile(const char* file_name, 101 base::File::Error CreateFile(const char* file_name,
101 base::PlatformFile* file_handle, 102 base::PlatformFile* file_handle,
102 bool* created) { 103 bool* created) {
103 int file_flags = base::PLATFORM_FILE_CREATE | 104 int file_flags = base::PLATFORM_FILE_CREATE |
104 base::PLATFORM_FILE_WRITE | base::PLATFORM_FILE_ASYNC; 105 base::PLATFORM_FILE_WRITE | base::PLATFORM_FILE_ASYNC;
105 106
106 scoped_ptr<FileSystemOperationContext> context(NewContext()); 107 scoped_ptr<FileSystemOperationContext> context(NewContext());
107 return file_util()->CreateOrOpen( 108 return file_util()->CreateOrOpen(
108 context.get(), 109 context.get(),
109 CreateURL(file_name), 110 CreateURL(file_name),
110 file_flags, file_handle, created); 111 file_flags, file_handle, created);
111 } 112 }
112 113
113 base::PlatformFileError EnsureFileExists(const char* file_name, 114 base::File::Error EnsureFileExists(const char* file_name,
114 bool* created) { 115 bool* created) {
115 scoped_ptr<FileSystemOperationContext> context(NewContext()); 116 scoped_ptr<FileSystemOperationContext> context(NewContext());
116 return file_util()->EnsureFileExists( 117 return file_util()->EnsureFileExists(
117 context.get(), 118 context.get(),
118 CreateURL(file_name), created); 119 CreateURL(file_name), created);
119 } 120 }
120 121
121 FileSystemContext* file_system_context() { 122 FileSystemContext* file_system_context() {
122 return file_system_context_.get(); 123 return file_system_context_.get();
123 } 124 }
124 125
125 private: 126 private:
126 base::MessageLoop message_loop_; 127 base::MessageLoop message_loop_;
127 scoped_refptr<FileSystemContext> file_system_context_; 128 scoped_refptr<FileSystemContext> file_system_context_;
128 base::ScopedTempDir data_dir_; 129 base::ScopedTempDir data_dir_;
129 130
130 DISALLOW_COPY_AND_ASSIGN(LocalFileUtilTest); 131 DISALLOW_COPY_AND_ASSIGN(LocalFileUtilTest);
131 }; 132 };
132 133
133 TEST_F(LocalFileUtilTest, CreateAndClose) { 134 TEST_F(LocalFileUtilTest, CreateAndClose) {
134 const char *file_name = "test_file"; 135 const char *file_name = "test_file";
135 base::PlatformFile file_handle; 136 base::PlatformFile file_handle;
136 bool created; 137 bool created;
137 ASSERT_EQ(base::PLATFORM_FILE_OK, 138 ASSERT_EQ(base::File::FILE_OK,
138 CreateFile(file_name, &file_handle, &created)); 139 CreateFile(file_name, &file_handle, &created));
139 ASSERT_TRUE(created); 140 ASSERT_TRUE(created);
140 141
141 EXPECT_TRUE(FileExists(file_name)); 142 EXPECT_TRUE(FileExists(file_name));
142 EXPECT_EQ(0, GetSize(file_name)); 143 EXPECT_EQ(0, GetSize(file_name));
143 144
144 scoped_ptr<FileSystemOperationContext> context(NewContext()); 145 scoped_ptr<FileSystemOperationContext> context(NewContext());
145 EXPECT_EQ(base::PLATFORM_FILE_OK, 146 EXPECT_EQ(base::File::FILE_OK,
146 file_util()->Close(context.get(), file_handle)); 147 file_util()->Close(context.get(), file_handle));
147 } 148 }
148 149
149 // base::CreateSymbolicLink is only supported on POSIX. 150 // base::CreateSymbolicLink is only supported on POSIX.
150 #if defined(OS_POSIX) 151 #if defined(OS_POSIX)
151 TEST_F(LocalFileUtilTest, CreateFailForSymlink) { 152 TEST_F(LocalFileUtilTest, CreateFailForSymlink) {
152 // Create symlink target file. 153 // Create symlink target file.
153 const char *target_name = "symlink_target"; 154 const char *target_name = "symlink_target";
154 base::PlatformFile target_handle; 155 base::PlatformFile target_handle;
155 bool symlink_target_created = false; 156 bool symlink_target_created = false;
156 ASSERT_EQ(base::PLATFORM_FILE_OK, 157 ASSERT_EQ(base::File::FILE_OK,
157 CreateFile(target_name, &target_handle, &symlink_target_created)); 158 CreateFile(target_name, &target_handle, &symlink_target_created));
158 ASSERT_TRUE(symlink_target_created); 159 ASSERT_TRUE(symlink_target_created);
159 base::FilePath target_path = LocalPath(target_name); 160 base::FilePath target_path = LocalPath(target_name);
160 161
161 // Create symlink where target must be real file. 162 // Create symlink where target must be real file.
162 const char *symlink_name = "symlink_file"; 163 const char *symlink_name = "symlink_file";
163 base::FilePath symlink_path = LocalPath(symlink_name); 164 base::FilePath symlink_path = LocalPath(symlink_name);
164 ASSERT_TRUE(base::CreateSymbolicLink(target_path, symlink_path)); 165 ASSERT_TRUE(base::CreateSymbolicLink(target_path, symlink_path));
165 ASSERT_TRUE(FileExists(symlink_name)); 166 ASSERT_TRUE(FileExists(symlink_name));
166 167
167 // Try to open the symlink file which should fail. 168 // Try to open the symlink file which should fail.
168 scoped_ptr<FileSystemOperationContext> context(NewContext()); 169 scoped_ptr<FileSystemOperationContext> context(NewContext());
169 FileSystemURL url = CreateURL(symlink_name); 170 FileSystemURL url = CreateURL(symlink_name);
170 int file_flags = base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_READ; 171 int file_flags = base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_READ;
171 base::PlatformFile file_handle; 172 base::PlatformFile file_handle;
172 bool created = false; 173 bool created = false;
173 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, file_util()->CreateOrOpen( 174 EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND,
174 context.get(), url, file_flags, &file_handle, &created)); 175 file_util()->CreateOrOpen(context.get(), url, file_flags,
176 &file_handle, &created));
175 EXPECT_FALSE(created); 177 EXPECT_FALSE(created);
176 } 178 }
177 #endif 179 #endif
178 180
179 TEST_F(LocalFileUtilTest, EnsureFileExists) { 181 TEST_F(LocalFileUtilTest, EnsureFileExists) {
180 const char *file_name = "foobar"; 182 const char *file_name = "foobar";
181 bool created; 183 bool created;
182 ASSERT_EQ(base::PLATFORM_FILE_OK, EnsureFileExists(file_name, &created)); 184 ASSERT_EQ(base::File::FILE_OK, EnsureFileExists(file_name, &created));
183 ASSERT_TRUE(created); 185 ASSERT_TRUE(created);
184 186
185 EXPECT_TRUE(FileExists(file_name)); 187 EXPECT_TRUE(FileExists(file_name));
186 EXPECT_EQ(0, GetSize(file_name)); 188 EXPECT_EQ(0, GetSize(file_name));
187 189
188 ASSERT_EQ(base::PLATFORM_FILE_OK, EnsureFileExists(file_name, &created)); 190 ASSERT_EQ(base::File::FILE_OK, EnsureFileExists(file_name, &created));
189 EXPECT_FALSE(created); 191 EXPECT_FALSE(created);
190 } 192 }
191 193
192 TEST_F(LocalFileUtilTest, TouchFile) { 194 TEST_F(LocalFileUtilTest, TouchFile) {
193 const char *file_name = "test_file"; 195 const char *file_name = "test_file";
194 base::PlatformFile file_handle; 196 base::PlatformFile file_handle;
195 bool created; 197 bool created;
196 ASSERT_EQ(base::PLATFORM_FILE_OK, 198 ASSERT_EQ(base::File::FILE_OK,
197 CreateFile(file_name, &file_handle, &created)); 199 CreateFile(file_name, &file_handle, &created));
198 ASSERT_TRUE(created); 200 ASSERT_TRUE(created);
199 201
200 scoped_ptr<FileSystemOperationContext> context(NewContext()); 202 scoped_ptr<FileSystemOperationContext> context(NewContext());
201 203
202 base::File::Info info; 204 base::File::Info info;
203 ASSERT_TRUE(base::GetFileInfo(LocalPath(file_name), &info)); 205 ASSERT_TRUE(base::GetFileInfo(LocalPath(file_name), &info));
204 const base::Time new_accessed = 206 const base::Time new_accessed =
205 info.last_accessed + base::TimeDelta::FromHours(10); 207 info.last_accessed + base::TimeDelta::FromHours(10);
206 const base::Time new_modified = 208 const base::Time new_modified =
207 info.last_modified + base::TimeDelta::FromHours(5); 209 info.last_modified + base::TimeDelta::FromHours(5);
208 210
209 EXPECT_EQ(base::PLATFORM_FILE_OK, 211 EXPECT_EQ(base::File::FILE_OK,
210 file_util()->Touch(context.get(), CreateURL(file_name), 212 file_util()->Touch(context.get(), CreateURL(file_name),
211 new_accessed, new_modified)); 213 new_accessed, new_modified));
212 214
213 ASSERT_TRUE(base::GetFileInfo(LocalPath(file_name), &info)); 215 ASSERT_TRUE(base::GetFileInfo(LocalPath(file_name), &info));
214 EXPECT_EQ(new_accessed, info.last_accessed); 216 EXPECT_EQ(new_accessed, info.last_accessed);
215 EXPECT_EQ(new_modified, info.last_modified); 217 EXPECT_EQ(new_modified, info.last_modified);
216 218
217 EXPECT_EQ(base::PLATFORM_FILE_OK, 219 EXPECT_EQ(base::File::FILE_OK,
218 file_util()->Close(context.get(), file_handle)); 220 file_util()->Close(context.get(), file_handle));
219 } 221 }
220 222
221 TEST_F(LocalFileUtilTest, TouchDirectory) { 223 TEST_F(LocalFileUtilTest, TouchDirectory) {
222 const char *dir_name = "test_dir"; 224 const char *dir_name = "test_dir";
223 scoped_ptr<FileSystemOperationContext> context(NewContext()); 225 scoped_ptr<FileSystemOperationContext> context(NewContext());
224 ASSERT_EQ(base::PLATFORM_FILE_OK, 226 ASSERT_EQ(base::File::FILE_OK,
225 file_util()->CreateDirectory(context.get(), 227 file_util()->CreateDirectory(context.get(),
226 CreateURL(dir_name), 228 CreateURL(dir_name),
227 false /* exclusive */, 229 false /* exclusive */,
228 false /* recursive */)); 230 false /* recursive */));
229 231
230 base::File::Info info; 232 base::File::Info info;
231 ASSERT_TRUE(base::GetFileInfo(LocalPath(dir_name), &info)); 233 ASSERT_TRUE(base::GetFileInfo(LocalPath(dir_name), &info));
232 const base::Time new_accessed = 234 const base::Time new_accessed =
233 info.last_accessed + base::TimeDelta::FromHours(10); 235 info.last_accessed + base::TimeDelta::FromHours(10);
234 const base::Time new_modified = 236 const base::Time new_modified =
235 info.last_modified + base::TimeDelta::FromHours(5); 237 info.last_modified + base::TimeDelta::FromHours(5);
236 238
237 EXPECT_EQ(base::PLATFORM_FILE_OK, 239 EXPECT_EQ(base::File::FILE_OK,
238 file_util()->Touch(context.get(), CreateURL(dir_name), 240 file_util()->Touch(context.get(), CreateURL(dir_name),
239 new_accessed, new_modified)); 241 new_accessed, new_modified));
240 242
241 ASSERT_TRUE(base::GetFileInfo(LocalPath(dir_name), &info)); 243 ASSERT_TRUE(base::GetFileInfo(LocalPath(dir_name), &info));
242 EXPECT_EQ(new_accessed, info.last_accessed); 244 EXPECT_EQ(new_accessed, info.last_accessed);
243 EXPECT_EQ(new_modified, info.last_modified); 245 EXPECT_EQ(new_modified, info.last_modified);
244 } 246 }
245 247
246 TEST_F(LocalFileUtilTest, Truncate) { 248 TEST_F(LocalFileUtilTest, Truncate) {
247 const char *file_name = "truncated"; 249 const char *file_name = "truncated";
248 bool created; 250 bool created;
249 ASSERT_EQ(base::PLATFORM_FILE_OK, EnsureFileExists(file_name, &created)); 251 ASSERT_EQ(base::File::FILE_OK, EnsureFileExists(file_name, &created));
250 ASSERT_TRUE(created); 252 ASSERT_TRUE(created);
251 253
252 scoped_ptr<FileSystemOperationContext> context; 254 scoped_ptr<FileSystemOperationContext> context;
253 255
254 context.reset(NewContext()); 256 context.reset(NewContext());
255 ASSERT_EQ(base::PLATFORM_FILE_OK, 257 ASSERT_EQ(base::File::FILE_OK,
256 file_util()->Truncate(context.get(), CreateURL(file_name), 1020)); 258 file_util()->Truncate(context.get(), CreateURL(file_name), 1020));
257 259
258 EXPECT_TRUE(FileExists(file_name)); 260 EXPECT_TRUE(FileExists(file_name));
259 EXPECT_EQ(1020, GetSize(file_name)); 261 EXPECT_EQ(1020, GetSize(file_name));
260 } 262 }
261 263
262 TEST_F(LocalFileUtilTest, CopyFile) { 264 TEST_F(LocalFileUtilTest, CopyFile) {
263 const char *from_file = "fromfile"; 265 const char *from_file = "fromfile";
264 const char *to_file1 = "tofile1"; 266 const char *to_file1 = "tofile1";
265 const char *to_file2 = "tofile2"; 267 const char *to_file2 = "tofile2";
266 bool created; 268 bool created;
267 ASSERT_EQ(base::PLATFORM_FILE_OK, EnsureFileExists(from_file, &created)); 269 ASSERT_EQ(base::File::FILE_OK, EnsureFileExists(from_file, &created));
268 ASSERT_TRUE(created); 270 ASSERT_TRUE(created);
269 271
270 scoped_ptr<FileSystemOperationContext> context; 272 scoped_ptr<FileSystemOperationContext> context;
271 context.reset(NewContext()); 273 context.reset(NewContext());
272 ASSERT_EQ(base::PLATFORM_FILE_OK, 274 ASSERT_EQ(base::File::FILE_OK,
273 file_util()->Truncate(context.get(), CreateURL(from_file), 1020)); 275 file_util()->Truncate(context.get(), CreateURL(from_file), 1020));
274 276
275 EXPECT_TRUE(FileExists(from_file)); 277 EXPECT_TRUE(FileExists(from_file));
276 EXPECT_EQ(1020, GetSize(from_file)); 278 EXPECT_EQ(1020, GetSize(from_file));
277 279
278 ASSERT_EQ(base::PLATFORM_FILE_OK, 280 ASSERT_EQ(base::File::FILE_OK,
279 AsyncFileTestHelper::Copy(file_system_context(), 281 AsyncFileTestHelper::Copy(file_system_context(),
280 CreateURL(from_file), 282 CreateURL(from_file),
281 CreateURL(to_file1))); 283 CreateURL(to_file1)));
282 284
283 context.reset(NewContext()); 285 context.reset(NewContext());
284 ASSERT_EQ(base::PLATFORM_FILE_OK, 286 ASSERT_EQ(base::File::FILE_OK,
285 AsyncFileTestHelper::Copy(file_system_context(), 287 AsyncFileTestHelper::Copy(file_system_context(),
286 CreateURL(from_file), 288 CreateURL(from_file),
287 CreateURL(to_file2))); 289 CreateURL(to_file2)));
288 290
289 EXPECT_TRUE(FileExists(from_file)); 291 EXPECT_TRUE(FileExists(from_file));
290 EXPECT_EQ(1020, GetSize(from_file)); 292 EXPECT_EQ(1020, GetSize(from_file));
291 EXPECT_TRUE(FileExists(to_file1)); 293 EXPECT_TRUE(FileExists(to_file1));
292 EXPECT_EQ(1020, GetSize(to_file1)); 294 EXPECT_EQ(1020, GetSize(to_file1));
293 EXPECT_TRUE(FileExists(to_file2)); 295 EXPECT_TRUE(FileExists(to_file2));
294 EXPECT_EQ(1020, GetSize(to_file2)); 296 EXPECT_EQ(1020, GetSize(to_file2));
295 } 297 }
296 298
297 TEST_F(LocalFileUtilTest, CopyDirectory) { 299 TEST_F(LocalFileUtilTest, CopyDirectory) {
298 const char *from_dir = "fromdir"; 300 const char *from_dir = "fromdir";
299 const char *from_file = "fromdir/fromfile"; 301 const char *from_file = "fromdir/fromfile";
300 const char *to_dir = "todir"; 302 const char *to_dir = "todir";
301 const char *to_file = "todir/fromfile"; 303 const char *to_file = "todir/fromfile";
302 bool created; 304 bool created;
303 scoped_ptr<FileSystemOperationContext> context; 305 scoped_ptr<FileSystemOperationContext> context;
304 306
305 context.reset(NewContext()); 307 context.reset(NewContext());
306 ASSERT_EQ(base::PLATFORM_FILE_OK, 308 ASSERT_EQ(base::File::FILE_OK,
307 file_util()->CreateDirectory(context.get(), CreateURL(from_dir), 309 file_util()->CreateDirectory(context.get(), CreateURL(from_dir),
308 false, false)); 310 false, false));
309 ASSERT_EQ(base::PLATFORM_FILE_OK, EnsureFileExists(from_file, &created)); 311 ASSERT_EQ(base::File::FILE_OK, EnsureFileExists(from_file, &created));
310 ASSERT_TRUE(created); 312 ASSERT_TRUE(created);
311 313
312 context.reset(NewContext()); 314 context.reset(NewContext());
313 ASSERT_EQ(base::PLATFORM_FILE_OK, 315 ASSERT_EQ(base::File::FILE_OK,
314 file_util()->Truncate(context.get(), CreateURL(from_file), 1020)); 316 file_util()->Truncate(context.get(), CreateURL(from_file), 1020));
315 317
316 EXPECT_TRUE(DirectoryExists(from_dir)); 318 EXPECT_TRUE(DirectoryExists(from_dir));
317 EXPECT_TRUE(FileExists(from_file)); 319 EXPECT_TRUE(FileExists(from_file));
318 EXPECT_EQ(1020, GetSize(from_file)); 320 EXPECT_EQ(1020, GetSize(from_file));
319 EXPECT_FALSE(DirectoryExists(to_dir)); 321 EXPECT_FALSE(DirectoryExists(to_dir));
320 322
321 context.reset(NewContext()); 323 context.reset(NewContext());
322 ASSERT_EQ(base::PLATFORM_FILE_OK, 324 ASSERT_EQ(base::File::FILE_OK,
323 AsyncFileTestHelper::Copy(file_system_context(), 325 AsyncFileTestHelper::Copy(file_system_context(),
324 CreateURL(from_dir), CreateURL(to_dir))); 326 CreateURL(from_dir), CreateURL(to_dir)));
325 327
326 EXPECT_TRUE(DirectoryExists(from_dir)); 328 EXPECT_TRUE(DirectoryExists(from_dir));
327 EXPECT_TRUE(FileExists(from_file)); 329 EXPECT_TRUE(FileExists(from_file));
328 EXPECT_EQ(1020, GetSize(from_file)); 330 EXPECT_EQ(1020, GetSize(from_file));
329 EXPECT_TRUE(DirectoryExists(to_dir)); 331 EXPECT_TRUE(DirectoryExists(to_dir));
330 EXPECT_TRUE(FileExists(to_file)); 332 EXPECT_TRUE(FileExists(to_file));
331 EXPECT_EQ(1020, GetSize(to_file)); 333 EXPECT_EQ(1020, GetSize(to_file));
332 } 334 }
333 335
334 TEST_F(LocalFileUtilTest, MoveFile) { 336 TEST_F(LocalFileUtilTest, MoveFile) {
335 const char *from_file = "fromfile"; 337 const char *from_file = "fromfile";
336 const char *to_file = "tofile"; 338 const char *to_file = "tofile";
337 bool created; 339 bool created;
338 ASSERT_EQ(base::PLATFORM_FILE_OK, EnsureFileExists(from_file, &created)); 340 ASSERT_EQ(base::File::FILE_OK, EnsureFileExists(from_file, &created));
339 ASSERT_TRUE(created); 341 ASSERT_TRUE(created);
340 scoped_ptr<FileSystemOperationContext> context; 342 scoped_ptr<FileSystemOperationContext> context;
341 343
342 context.reset(NewContext()); 344 context.reset(NewContext());
343 ASSERT_EQ(base::PLATFORM_FILE_OK, 345 ASSERT_EQ(base::File::FILE_OK,
344 file_util()->Truncate(context.get(), CreateURL(from_file), 1020)); 346 file_util()->Truncate(context.get(), CreateURL(from_file), 1020));
345 347
346 EXPECT_TRUE(FileExists(from_file)); 348 EXPECT_TRUE(FileExists(from_file));
347 EXPECT_EQ(1020, GetSize(from_file)); 349 EXPECT_EQ(1020, GetSize(from_file));
348 350
349 context.reset(NewContext()); 351 context.reset(NewContext());
350 ASSERT_EQ(base::PLATFORM_FILE_OK, 352 ASSERT_EQ(base::File::FILE_OK,
351 AsyncFileTestHelper::Move(file_system_context(), 353 AsyncFileTestHelper::Move(file_system_context(),
352 CreateURL(from_file), 354 CreateURL(from_file),
353 CreateURL(to_file))); 355 CreateURL(to_file)));
354 356
355 EXPECT_FALSE(FileExists(from_file)); 357 EXPECT_FALSE(FileExists(from_file));
356 EXPECT_TRUE(FileExists(to_file)); 358 EXPECT_TRUE(FileExists(to_file));
357 EXPECT_EQ(1020, GetSize(to_file)); 359 EXPECT_EQ(1020, GetSize(to_file));
358 } 360 }
359 361
360 TEST_F(LocalFileUtilTest, MoveDirectory) { 362 TEST_F(LocalFileUtilTest, MoveDirectory) {
361 const char *from_dir = "fromdir"; 363 const char *from_dir = "fromdir";
362 const char *from_file = "fromdir/fromfile"; 364 const char *from_file = "fromdir/fromfile";
363 const char *to_dir = "todir"; 365 const char *to_dir = "todir";
364 const char *to_file = "todir/fromfile"; 366 const char *to_file = "todir/fromfile";
365 bool created; 367 bool created;
366 scoped_ptr<FileSystemOperationContext> context; 368 scoped_ptr<FileSystemOperationContext> context;
367 369
368 context.reset(NewContext()); 370 context.reset(NewContext());
369 ASSERT_EQ(base::PLATFORM_FILE_OK, 371 ASSERT_EQ(base::File::FILE_OK,
370 file_util()->CreateDirectory(context.get(), CreateURL(from_dir), 372 file_util()->CreateDirectory(context.get(), CreateURL(from_dir),
371 false, false)); 373 false, false));
372 ASSERT_EQ(base::PLATFORM_FILE_OK, EnsureFileExists(from_file, &created)); 374 ASSERT_EQ(base::File::FILE_OK, EnsureFileExists(from_file, &created));
373 ASSERT_TRUE(created); 375 ASSERT_TRUE(created);
374 376
375 context.reset(NewContext()); 377 context.reset(NewContext());
376 ASSERT_EQ(base::PLATFORM_FILE_OK, 378 ASSERT_EQ(base::File::FILE_OK,
377 file_util()->Truncate(context.get(), CreateURL(from_file), 1020)); 379 file_util()->Truncate(context.get(), CreateURL(from_file), 1020));
378 380
379 EXPECT_TRUE(DirectoryExists(from_dir)); 381 EXPECT_TRUE(DirectoryExists(from_dir));
380 EXPECT_TRUE(FileExists(from_file)); 382 EXPECT_TRUE(FileExists(from_file));
381 EXPECT_EQ(1020, GetSize(from_file)); 383 EXPECT_EQ(1020, GetSize(from_file));
382 EXPECT_FALSE(DirectoryExists(to_dir)); 384 EXPECT_FALSE(DirectoryExists(to_dir));
383 385
384 context.reset(NewContext()); 386 context.reset(NewContext());
385 ASSERT_EQ(base::PLATFORM_FILE_OK, 387 ASSERT_EQ(base::File::FILE_OK,
386 AsyncFileTestHelper::Move(file_system_context(), 388 AsyncFileTestHelper::Move(file_system_context(),
387 CreateURL(from_dir), 389 CreateURL(from_dir),
388 CreateURL(to_dir))); 390 CreateURL(to_dir)));
389 391
390 EXPECT_FALSE(DirectoryExists(from_dir)); 392 EXPECT_FALSE(DirectoryExists(from_dir));
391 EXPECT_TRUE(DirectoryExists(to_dir)); 393 EXPECT_TRUE(DirectoryExists(to_dir));
392 EXPECT_TRUE(FileExists(to_file)); 394 EXPECT_TRUE(FileExists(to_file));
393 EXPECT_EQ(1020, GetSize(to_file)); 395 EXPECT_EQ(1020, GetSize(to_file));
394 } 396 }
395 397
396 } // namespace content 398 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/fileapi/fileapi_message_filter.cc ('k') | content/browser/fileapi/obfuscated_file_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698