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

Side by Side Diff: content/browser/fileapi/file_system_operation_impl_unittest.cc

Issue 557273002: Use RunLoop::Run() instead of RunLoop::RunUntilIdle() in FileSystemOperationImplTest. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "webkit/browser/fileapi/file_system_operation_impl.h" 5 #include "webkit/browser/fileapi/file_system_operation_impl.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/files/file_util.h" 8 #include "base/files/file_util.h"
9 #include "base/files/scoped_temp_dir.h" 9 #include "base/files/scoped_temp_dir.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 26 matching lines...) Expand all
37 using storage::QuotaManager; 37 using storage::QuotaManager;
38 using storage::QuotaManagerProxy; 38 using storage::QuotaManagerProxy;
39 using storage::ShareableFileReference; 39 using storage::ShareableFileReference;
40 40
41 namespace content { 41 namespace content {
42 42
43 namespace { 43 namespace {
44 44
45 const int kFileOperationStatusNotSet = 1; 45 const int kFileOperationStatusNotSet = 1;
46 46
47 void AssertFileErrorEq(const tracked_objects::Location& from_here,
48 base::File::Error expected,
49 base::File::Error actual) {
50 ASSERT_EQ(expected, actual) << from_here.ToString();
51 }
52
53 void AssertFileErrorEqWithClosure(const tracked_objects::Location& from_here, 47 void AssertFileErrorEqWithClosure(const tracked_objects::Location& from_here,
54 base::File::Error expected, 48 base::File::Error expected,
55 base::Closure closure, 49 base::Closure closure,
56 base::File::Error actual) { 50 base::File::Error actual) {
57 ASSERT_EQ(expected, actual) << from_here.ToString(); 51 ASSERT_EQ(expected, actual) << from_here.ToString();
58 closure.Run(); 52 closure.Run();
59 } 53 }
60 54
61 } // namespace 55 } // namespace
62 56
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 return info.size; 173 return info.size;
180 } 174 }
181 175
182 // Callbacks for recording test results. 176 // Callbacks for recording test results.
183 FileSystemOperation::StatusCallback RecordStatusCallback() { 177 FileSystemOperation::StatusCallback RecordStatusCallback() {
184 return base::Bind(&FileSystemOperationImplTest::DidFinish, 178 return base::Bind(&FileSystemOperationImplTest::DidFinish,
185 weak_factory_.GetWeakPtr()); 179 weak_factory_.GetWeakPtr());
186 } 180 }
187 181
188 FileSystemOperation::ReadDirectoryCallback 182 FileSystemOperation::ReadDirectoryCallback
189 RecordReadDirectoryCallback() { 183 RecordReadDirectoryCallback(base::Closure closure) {
tzik 2014/09/10 08:45:14 const ref, here and elsewhere?
iseki 2014/09/11 01:07:32 Done.
190 return base::Bind(&FileSystemOperationImplTest::DidReadDirectory, 184 return base::Bind(&FileSystemOperationImplTest::DidReadDirectory,
191 weak_factory_.GetWeakPtr()); 185 weak_factory_.GetWeakPtr(), closure);
192 } 186 }
193 187
194 FileSystemOperation::GetMetadataCallback RecordMetadataCallback() { 188 FileSystemOperation::GetMetadataCallback RecordMetadataCallback(
195 return base::Bind(&FileSystemOperationImplTest::DidGetMetadata, 189 base::Closure closure) {
196 weak_factory_.GetWeakPtr()); 190 return base::Bind(
191 &FileSystemOperationImplTest::DidGetMetadata,
192 weak_factory_.GetWeakPtr(), closure);
197 } 193 }
198 194
199 FileSystemOperation::SnapshotFileCallback RecordSnapshotFileCallback() { 195 FileSystemOperation::SnapshotFileCallback RecordSnapshotFileCallback(
196 base::Closure closure) {
200 return base::Bind(&FileSystemOperationImplTest::DidCreateSnapshotFile, 197 return base::Bind(&FileSystemOperationImplTest::DidCreateSnapshotFile,
201 weak_factory_.GetWeakPtr()); 198 weak_factory_.GetWeakPtr(), closure);
202 } 199 }
203 200
204 void DidFinish(base::File::Error status) { 201 void DidFinish(base::File::Error status) {
205 status_ = status; 202 status_ = status;
206 } 203 }
207 204
208 void DidReadDirectory(base::File::Error status, 205 void DidReadDirectory(base::Closure closure,
206 base::File::Error status,
209 const std::vector<storage::DirectoryEntry>& entries, 207 const std::vector<storage::DirectoryEntry>& entries,
210 bool /* has_more */) { 208 bool /* has_more */) {
211 entries_ = entries; 209 entries_ = entries;
212 status_ = status; 210 status_ = status;
211 closure.Run();
213 } 212 }
214 213
215 void DidGetMetadata(base::File::Error status, 214 void DidGetMetadata(
216 const base::File::Info& info) { 215 base::Closure closure,
216 base::File::Error status,
217 const base::File::Info& info) {
217 info_ = info; 218 info_ = info;
218 status_ = status; 219 status_ = status;
220 closure.Run();
219 } 221 }
220 222
221 void DidCreateSnapshotFile( 223 void DidCreateSnapshotFile(
224 base::Closure closure,
222 base::File::Error status, 225 base::File::Error status,
223 const base::File::Info& info, 226 const base::File::Info& info,
224 const base::FilePath& platform_path, 227 const base::FilePath& platform_path,
225 const scoped_refptr<ShareableFileReference>& shareable_file_ref) { 228 const scoped_refptr<ShareableFileReference>& shareable_file_ref) {
226 info_ = info; 229 info_ = info;
227 path_ = platform_path; 230 path_ = platform_path;
228 status_ = status; 231 status_ = status;
229 shareable_file_ref_ = shareable_file_ref; 232 shareable_file_ref_ = shareable_file_ref;
233 closure.Run();
230 } 234 }
231 235
232 int64 GetDataSizeOnDisk() { 236 int64 GetDataSizeOnDisk() {
233 return sandbox_file_system_.ComputeCurrentOriginUsage() - 237 return sandbox_file_system_.ComputeCurrentOriginUsage() -
234 sandbox_file_system_.ComputeCurrentDirectoryDatabaseUsage(); 238 sandbox_file_system_.ComputeCurrentDirectoryDatabaseUsage();
235 } 239 }
236 240
237 void GetUsageAndQuota(int64* usage, int64* quota) { 241 void GetUsageAndQuota(int64* usage, int64* quota) {
238 storage::QuotaStatusCode status = 242 storage::QuotaStatusCode status =
239 AsyncFileTestHelper::GetUsageAndQuota(quota_manager_.get(), 243 AsyncFileTestHelper::GetUsageAndQuota(quota_manager_.get(),
240 sandbox_file_system_.origin(), 244 sandbox_file_system_.origin(),
241 sandbox_file_system_.type(), 245 sandbox_file_system_.type(),
242 usage, 246 usage,
243 quota); 247 quota);
244 base::RunLoop().RunUntilIdle(); 248 base::RunLoop().RunUntilIdle();
245 ASSERT_EQ(storage::kQuotaStatusOk, status); 249 ASSERT_EQ(storage::kQuotaStatusOk, status);
246 } 250 }
247 251
248 int64 ComputePathCost(const FileSystemURL& url) { 252 int64 ComputePathCost(const FileSystemURL& url) {
249 int64 base_usage; 253 int64 base_usage;
250 GetUsageAndQuota(&base_usage, NULL); 254 GetUsageAndQuota(&base_usage, NULL);
251 255
252 AsyncFileTestHelper::CreateFile( 256 AsyncFileTestHelper::CreateFile(
253 sandbox_file_system_.file_system_context(), url); 257 sandbox_file_system_.file_system_context(), url);
254 operation_runner()->Remove(url, false /* recursive */, 258 RemoveTest(url, false /* recursive */,
tzik 2014/09/10 08:45:14 Can this be pushed into one line?
iseki 2014/09/11 01:07:33 Done.
255 base::Bind(&AssertFileErrorEq, FROM_HERE, 259 base::File::FILE_OK);
256 base::File::FILE_OK)); 260
257 base::RunLoop().RunUntilIdle();
258 change_observer()->ResetCount(); 261 change_observer()->ResetCount();
259 262
260 int64 total_usage; 263 int64 total_usage;
261 GetUsageAndQuota(&total_usage, NULL); 264 GetUsageAndQuota(&total_usage, NULL);
262 return total_usage - base_usage; 265 return total_usage - base_usage;
263 } 266 }
264 267
265 void GrantQuotaForCurrentUsage() { 268 void GrantQuotaForCurrentUsage() {
266 int64 usage; 269 int64 usage;
267 GetUsageAndQuota(&usage, NULL); 270 GetUsageAndQuota(&usage, NULL);
268 quota_manager()->SetQuota(sandbox_file_system_.origin(), 271 quota_manager()->SetQuota(sandbox_file_system_.origin(),
269 sandbox_file_system_.storage_type(), 272 sandbox_file_system_.storage_type(),
270 usage); 273 usage);
271 } 274 }
272 275
273 int64 GetUsage() { 276 int64 GetUsage() {
274 int64 usage = 0; 277 int64 usage = 0;
275 GetUsageAndQuota(&usage, NULL); 278 GetUsageAndQuota(&usage, NULL);
276 return usage; 279 return usage;
277 } 280 }
278 281
279 void AddQuota(int64 quota_delta) { 282 void AddQuota(int64 quota_delta) {
280 int64 quota; 283 int64 quota;
281 GetUsageAndQuota(NULL, &quota); 284 GetUsageAndQuota(NULL, &quota);
282 quota_manager()->SetQuota(sandbox_file_system_.origin(), 285 quota_manager()->SetQuota(sandbox_file_system_.origin(),
283 sandbox_file_system_.storage_type(), 286 sandbox_file_system_.storage_type(),
284 quota + quota_delta); 287 quota + quota_delta);
285 } 288 }
286 289
290 void MoveTest(
tzik 2014/09/10 08:45:14 Could you change the return type from void to base
iseki 2014/09/11 01:07:32 Done.
291 const FileSystemURL& src,
tzik 2014/09/10 08:45:14 Can you push these param to previous line, here an
iseki 2014/09/11 01:07:32 Done.
292 const FileSystemURL& dest,
293 storage::FileSystemOperation::CopyOrMoveOption option,
294 base::File::Error expected) {
295 base::RunLoop run_loop;
296 operation_runner()->Move(
297 src, dest, option,
298 base::Bind(&AssertFileErrorEqWithClosure,
299 FROM_HERE,
300 expected,
301 run_loop.QuitClosure()));
302 run_loop.Run();
303 }
304
305 void CopyTest(
306 const FileSystemURL& src,
307 const FileSystemURL& dest,
308 storage::FileSystemOperation::CopyOrMoveOption option,
309 base::File::Error expected) {
310 base::RunLoop run_loop;
311 operation_runner()->Copy(
312 src, dest, option,
313 FileSystemOperationRunner::CopyProgressCallback(),
314 base::Bind(&AssertFileErrorEqWithClosure,
315 FROM_HERE,
316 expected,
317 run_loop.QuitClosure()));
318 run_loop.Run();
319 }
320
321 void CopyInForeignFileTest(
322 const base::FilePath& src,
323 const FileSystemURL& dest,
324 base::File::Error expected) {
325 base::RunLoop run_loop;
326 operation_runner()->CopyInForeignFile(
327 src, dest,
328 base::Bind(&AssertFileErrorEqWithClosure,
329 FROM_HERE,
330 expected,
331 run_loop.QuitClosure()));
332 run_loop.Run();
333 }
334
335 void TruncateTest(
336 const FileSystemURL& url,
337 int size,
338 base::File::Error expected) {
339 base::RunLoop run_loop;
340 operation_runner()->Truncate(url, size,
341 base::Bind(&AssertFileErrorEqWithClosure,
342 FROM_HERE,
343 expected,
344 run_loop.QuitClosure()));
345 run_loop.Run();
346 }
347
348 void CreateFileTest(
349 const FileSystemURL& url,
350 bool exclusive,
351 base::File::Error expected) {
352 base::RunLoop run_loop;
353 operation_runner()->CreateFile(
354 url, exclusive,
355 base::Bind(&AssertFileErrorEqWithClosure,
356 FROM_HERE,
357 expected,
358 run_loop.QuitClosure()));
359 run_loop.Run();
360 }
361
362 void RemoveTest(
363 const FileSystemURL& url,
364 bool recursive,
365 base::File::Error expected) {
366 base::RunLoop run_loop;
367 operation_runner()->Remove(
368 url, recursive,
369 base::Bind(&AssertFileErrorEqWithClosure,
370 FROM_HERE,
371 expected,
372 run_loop.QuitClosure()));
373 run_loop.Run();
374 }
375
376 void CreateDirectoryTest(
377 const FileSystemURL& url,
378 bool exclusive,
379 bool recursive,
380 base::File::Error expected) {
381 base::RunLoop run_loop;
382 operation_runner()->CreateDirectory(
383 url, exclusive, recursive,
384 base::Bind(&AssertFileErrorEqWithClosure,
385 FROM_HERE,
386 expected,
387 run_loop.QuitClosure()));
388 run_loop.Run();
389 }
390
391 void GetMetadataTest(const FileSystemURL& url) {
392 base::RunLoop run_loop;
393 operation_runner()->GetMetadata(
394 url,
395 RecordMetadataCallback(
396 run_loop.QuitClosure()));
397 run_loop.Run();
398 }
399
400 void ReadDirectoryTest(const FileSystemURL& url) {
401 base::RunLoop run_loop;
402 operation_runner()->ReadDirectory(
403 url, RecordReadDirectoryCallback(run_loop.QuitClosure()));
404 run_loop.Run();
405 }
406
407 void CreateSnapshotFileTest(const FileSystemURL& url) {
408 base::RunLoop run_loop;
409 operation_runner()->CreateSnapshotFile(
410 url, RecordSnapshotFileCallback(run_loop.QuitClosure()));
411 run_loop.Run();
412 }
413
414 void FileExistsTest(
415 const FileSystemURL& url,
416 base::File::Error expected) {
417 base::RunLoop run_loop;
418 operation_runner()->FileExists(
419 url,
420 base::Bind(&AssertFileErrorEqWithClosure,
421 FROM_HERE,
422 expected,
423 run_loop.QuitClosure()));
424 run_loop.Run();
425 }
426
427 void DirectoryExistsTest(
428 const FileSystemURL& url,
429 base::File::Error expected) {
430 base::RunLoop run_loop;
431 operation_runner()->DirectoryExists(
432 url,
433 base::Bind(&AssertFileErrorEqWithClosure,
434 FROM_HERE,
435 expected,
436 run_loop.QuitClosure()));
437 run_loop.Run();
438 }
439
440 void TouchFileTest(
441 const FileSystemURL& url,
442 const base::Time& last_access_time,
443 const base::Time& last_modified_time,
444 base::File::Error expected) {
445 base::RunLoop run_loop;
446 operation_runner()->TouchFile(
447 url, last_access_time, last_modified_time,
448 base::Bind(&AssertFileErrorEqWithClosure,
449 FROM_HERE,
450 expected,
451 run_loop.QuitClosure()));
452 run_loop.Run();
453 }
454
287 private: 455 private:
288 base::MessageLoopForIO message_loop_; 456 base::MessageLoopForIO message_loop_;
289 scoped_refptr<QuotaManager> quota_manager_; 457 scoped_refptr<QuotaManager> quota_manager_;
290 scoped_refptr<QuotaManagerProxy> quota_manager_proxy_; 458 scoped_refptr<QuotaManagerProxy> quota_manager_proxy_;
291 459
292 // Common temp base for nondestructive uses. 460 // Common temp base for nondestructive uses.
293 base::ScopedTempDir base_; 461 base::ScopedTempDir base_;
294 462
295 SandboxFileSystemTestHelper sandbox_file_system_; 463 SandboxFileSystemTestHelper sandbox_file_system_;
296 464
297 // For post-operation status. 465 // For post-operation status.
298 int status_; 466 int status_;
299 base::File::Info info_; 467 base::File::Info info_;
300 base::FilePath path_; 468 base::FilePath path_;
301 std::vector<storage::DirectoryEntry> entries_; 469 std::vector<storage::DirectoryEntry> entries_;
302 scoped_refptr<ShareableFileReference> shareable_file_ref_; 470 scoped_refptr<ShareableFileReference> shareable_file_ref_;
303 471
304 storage::MockFileChangeObserver change_observer_; 472 storage::MockFileChangeObserver change_observer_;
305 storage::ChangeObserverList change_observers_; 473 storage::ChangeObserverList change_observers_;
306 474
307 base::WeakPtrFactory<FileSystemOperationImplTest> weak_factory_; 475 base::WeakPtrFactory<FileSystemOperationImplTest> weak_factory_;
308 476
309 DISALLOW_COPY_AND_ASSIGN(FileSystemOperationImplTest); 477 DISALLOW_COPY_AND_ASSIGN(FileSystemOperationImplTest);
310 }; 478 };
311 479
312 TEST_F(FileSystemOperationImplTest, TestMoveFailureSrcDoesntExist) { 480 TEST_F(FileSystemOperationImplTest, TestMoveFailureSrcDoesntExist) {
313 change_observer()->ResetCount(); 481 change_observer()->ResetCount();
314 operation_runner()->Move(URLForPath("a"), URLForPath("b"), 482 MoveTest(URLForPath("a"), URLForPath("b"), FileSystemOperation::OPTION_NONE,
315 FileSystemOperation::OPTION_NONE, 483 base::File::FILE_ERROR_NOT_FOUND);
316 RecordStatusCallback());
317 base::RunLoop().RunUntilIdle();
318 EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND, status());
319 EXPECT_TRUE(change_observer()->HasNoChange()); 484 EXPECT_TRUE(change_observer()->HasNoChange());
320 } 485 }
321 486
322 TEST_F(FileSystemOperationImplTest, TestMoveFailureContainsPath) { 487 TEST_F(FileSystemOperationImplTest, TestMoveFailureContainsPath) {
323 FileSystemURL src_dir(CreateDirectory("src")); 488 FileSystemURL src_dir(CreateDirectory("src"));
324 FileSystemURL dest_dir(CreateDirectory("src/dest")); 489 FileSystemURL dest_dir(CreateDirectory("src/dest"));
325 490
326 operation_runner()->Move(src_dir, dest_dir, 491 MoveTest(src_dir, dest_dir, FileSystemOperation::OPTION_NONE,
327 FileSystemOperation::OPTION_NONE, 492 base::File::FILE_ERROR_INVALID_OPERATION);
328 RecordStatusCallback());
329 base::RunLoop().RunUntilIdle();
330 EXPECT_EQ(base::File::FILE_ERROR_INVALID_OPERATION, status());
331 EXPECT_TRUE(change_observer()->HasNoChange()); 493 EXPECT_TRUE(change_observer()->HasNoChange());
332 } 494 }
333 495
334 TEST_F(FileSystemOperationImplTest, TestMoveFailureSrcDirExistsDestFile) { 496 TEST_F(FileSystemOperationImplTest, TestMoveFailureSrcDirExistsDestFile) {
335 // Src exists and is dir. Dest is a file. 497 // Src exists and is dir. Dest is a file.
336 FileSystemURL src_dir(CreateDirectory("src")); 498 FileSystemURL src_dir(CreateDirectory("src"));
337 FileSystemURL dest_dir(CreateDirectory("dest")); 499 FileSystemURL dest_dir(CreateDirectory("dest"));
338 FileSystemURL dest_file(CreateFile("dest/file")); 500 FileSystemURL dest_file(CreateFile("dest/file"));
339 501
340 operation_runner()->Move(src_dir, dest_file, 502 MoveTest(src_dir, dest_file, FileSystemOperation::OPTION_NONE,
341 FileSystemOperation::OPTION_NONE, 503 base::File::FILE_ERROR_INVALID_OPERATION);
342 RecordStatusCallback());
343 base::RunLoop().RunUntilIdle();
344 EXPECT_EQ(base::File::FILE_ERROR_INVALID_OPERATION, status());
345 EXPECT_TRUE(change_observer()->HasNoChange()); 504 EXPECT_TRUE(change_observer()->HasNoChange());
346 } 505 }
347 506
348 TEST_F(FileSystemOperationImplTest, 507 TEST_F(FileSystemOperationImplTest,
349 TestMoveFailureSrcFileExistsDestNonEmptyDir) { 508 TestMoveFailureSrcFileExistsDestNonEmptyDir) {
350 // Src exists and is a directory. Dest is a non-empty directory. 509 // Src exists and is a directory. Dest is a non-empty directory.
351 FileSystemURL src_dir(CreateDirectory("src")); 510 FileSystemURL src_dir(CreateDirectory("src"));
352 FileSystemURL dest_dir(CreateDirectory("dest")); 511 FileSystemURL dest_dir(CreateDirectory("dest"));
353 FileSystemURL dest_file(CreateFile("dest/file")); 512 FileSystemURL dest_file(CreateFile("dest/file"));
354 513
355 operation_runner()->Move(src_dir, dest_dir, 514 MoveTest(src_dir, dest_dir, FileSystemOperation::OPTION_NONE,
356 FileSystemOperation::OPTION_NONE, 515 base::File::FILE_ERROR_NOT_EMPTY);
357 RecordStatusCallback());
358 base::RunLoop().RunUntilIdle();
359 EXPECT_EQ(base::File::FILE_ERROR_NOT_EMPTY, status());
360 EXPECT_TRUE(change_observer()->HasNoChange()); 516 EXPECT_TRUE(change_observer()->HasNoChange());
361 } 517 }
362 518
363 TEST_F(FileSystemOperationImplTest, TestMoveFailureSrcFileExistsDestDir) { 519 TEST_F(FileSystemOperationImplTest, TestMoveFailureSrcFileExistsDestDir) {
364 // Src exists and is a file. Dest is a directory. 520 // Src exists and is a file. Dest is a directory.
365 FileSystemURL src_dir(CreateDirectory("src")); 521 FileSystemURL src_dir(CreateDirectory("src"));
366 FileSystemURL src_file(CreateFile("src/file")); 522 FileSystemURL src_file(CreateFile("src/file"));
367 FileSystemURL dest_dir(CreateDirectory("dest")); 523 FileSystemURL dest_dir(CreateDirectory("dest"));
368 524
369 operation_runner()->Move(src_file, dest_dir, 525 MoveTest(src_file, dest_dir, FileSystemOperation::OPTION_NONE,
370 FileSystemOperation::OPTION_NONE, 526 base::File::FILE_ERROR_INVALID_OPERATION);
371 RecordStatusCallback());
372 base::RunLoop().RunUntilIdle();
373 EXPECT_EQ(base::File::FILE_ERROR_INVALID_OPERATION, status());
374 EXPECT_TRUE(change_observer()->HasNoChange()); 527 EXPECT_TRUE(change_observer()->HasNoChange());
375 } 528 }
376 529
377 TEST_F(FileSystemOperationImplTest, TestMoveFailureDestParentDoesntExist) { 530 TEST_F(FileSystemOperationImplTest, TestMoveFailureDestParentDoesntExist) {
378 // Dest. parent path does not exist. 531 // Dest. parent path does not exist.
379 FileSystemURL src_dir(CreateDirectory("src")); 532 FileSystemURL src_dir(CreateDirectory("src"));
380 operation_runner()->Move(src_dir, URLForPath("nonexistent/deset"), 533 MoveTest(src_dir, URLForPath("nonexistent/deset"),
381 FileSystemOperation::OPTION_NONE, 534 FileSystemOperation::OPTION_NONE,
382 RecordStatusCallback()); 535 base::File::FILE_ERROR_NOT_FOUND);
383 base::RunLoop().RunUntilIdle();
384 EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND, status());
385 EXPECT_TRUE(change_observer()->HasNoChange()); 536 EXPECT_TRUE(change_observer()->HasNoChange());
386 } 537 }
387 538
388 TEST_F(FileSystemOperationImplTest, TestMoveSuccessSrcFileAndOverwrite) { 539 TEST_F(FileSystemOperationImplTest, TestMoveSuccessSrcFileAndOverwrite) {
389 FileSystemURL src_file(CreateFile("src")); 540 FileSystemURL src_file(CreateFile("src"));
390 FileSystemURL dest_file(CreateFile("dest")); 541 FileSystemURL dest_file(CreateFile("dest"));
391 542
392 operation_runner()->Move(src_file, dest_file, 543 MoveTest(src_file, dest_file, FileSystemOperation::OPTION_NONE,
393 FileSystemOperation::OPTION_NONE, 544 base::File::FILE_OK);
394 RecordStatusCallback());
395 base::RunLoop().RunUntilIdle();
396 EXPECT_EQ(base::File::FILE_OK, status());
397 EXPECT_TRUE(FileExists("dest")); 545 EXPECT_TRUE(FileExists("dest"));
398 546
399 EXPECT_EQ(1, change_observer()->get_and_reset_modify_file_count()); 547 EXPECT_EQ(1, change_observer()->get_and_reset_modify_file_count());
400 EXPECT_EQ(1, change_observer()->get_and_reset_remove_file_count()); 548 EXPECT_EQ(1, change_observer()->get_and_reset_remove_file_count());
401 EXPECT_TRUE(change_observer()->HasNoChange()); 549 EXPECT_TRUE(change_observer()->HasNoChange());
402 550
403 EXPECT_EQ(1, quota_manager_proxy()->notify_storage_accessed_count()); 551 EXPECT_EQ(1, quota_manager_proxy()->notify_storage_accessed_count());
404 } 552 }
405 553
406 TEST_F(FileSystemOperationImplTest, TestMoveSuccessSrcFileAndNew) { 554 TEST_F(FileSystemOperationImplTest, TestMoveSuccessSrcFileAndNew) {
407 FileSystemURL src_file(CreateFile("src")); 555 FileSystemURL src_file(CreateFile("src"));
408 556
409 operation_runner()->Move(src_file, URLForPath("new"), 557 MoveTest(src_file, URLForPath("new"), FileSystemOperation::OPTION_NONE,
410 FileSystemOperation::OPTION_NONE, 558 base::File::FILE_OK);
411 RecordStatusCallback());
412 base::RunLoop().RunUntilIdle();
413 EXPECT_EQ(base::File::FILE_OK, status());
414 EXPECT_TRUE(FileExists("new")); 559 EXPECT_TRUE(FileExists("new"));
415 560
416 EXPECT_EQ(1, change_observer()->get_and_reset_create_file_from_count()); 561 EXPECT_EQ(1, change_observer()->get_and_reset_create_file_from_count());
417 EXPECT_EQ(1, change_observer()->get_and_reset_remove_file_count()); 562 EXPECT_EQ(1, change_observer()->get_and_reset_remove_file_count());
418 EXPECT_TRUE(change_observer()->HasNoChange()); 563 EXPECT_TRUE(change_observer()->HasNoChange());
419 } 564 }
420 565
421 TEST_F(FileSystemOperationImplTest, TestMoveSuccessSrcDirAndOverwrite) { 566 TEST_F(FileSystemOperationImplTest, TestMoveSuccessSrcDirAndOverwrite) {
422 FileSystemURL src_dir(CreateDirectory("src")); 567 FileSystemURL src_dir(CreateDirectory("src"));
423 FileSystemURL dest_dir(CreateDirectory("dest")); 568 FileSystemURL dest_dir(CreateDirectory("dest"));
424 569
425 operation_runner()->Move(src_dir, dest_dir, 570 MoveTest(src_dir, dest_dir, FileSystemOperation::OPTION_NONE,
426 FileSystemOperation::OPTION_NONE, 571 base::File::FILE_OK);
427 RecordStatusCallback());
428 base::RunLoop().RunUntilIdle();
429 EXPECT_EQ(base::File::FILE_OK, status());
430 EXPECT_FALSE(DirectoryExists("src")); 572 EXPECT_FALSE(DirectoryExists("src"));
431 573
432 EXPECT_EQ(1, change_observer()->get_and_reset_create_directory_count()); 574 EXPECT_EQ(1, change_observer()->get_and_reset_create_directory_count());
433 EXPECT_EQ(2, change_observer()->get_and_reset_remove_directory_count()); 575 EXPECT_EQ(2, change_observer()->get_and_reset_remove_directory_count());
434 EXPECT_TRUE(change_observer()->HasNoChange()); 576 EXPECT_TRUE(change_observer()->HasNoChange());
435 577
436 // Make sure we've overwritten but not moved the source under the |dest_dir|. 578 // Make sure we've overwritten but not moved the source under the |dest_dir|.
437 EXPECT_TRUE(DirectoryExists("dest")); 579 EXPECT_TRUE(DirectoryExists("dest"));
438 EXPECT_FALSE(DirectoryExists("dest/src")); 580 EXPECT_FALSE(DirectoryExists("dest/src"));
439 } 581 }
440 582
441 TEST_F(FileSystemOperationImplTest, TestMoveSuccessSrcDirAndNew) { 583 TEST_F(FileSystemOperationImplTest, TestMoveSuccessSrcDirAndNew) {
442 FileSystemURL src_dir(CreateDirectory("src")); 584 FileSystemURL src_dir(CreateDirectory("src"));
443 FileSystemURL dest_dir(CreateDirectory("dest")); 585 FileSystemURL dest_dir(CreateDirectory("dest"));
444 586
445 operation_runner()->Move(src_dir, URLForPath("dest/new"), 587 MoveTest(src_dir, URLForPath("dest/new"), FileSystemOperation::OPTION_NONE,
446 FileSystemOperation::OPTION_NONE, 588 base::File::FILE_OK);
447 RecordStatusCallback());
448 base::RunLoop().RunUntilIdle();
449 EXPECT_EQ(base::File::FILE_OK, status());
450 EXPECT_FALSE(DirectoryExists("src")); 589 EXPECT_FALSE(DirectoryExists("src"));
451 EXPECT_TRUE(DirectoryExists("dest/new")); 590 EXPECT_TRUE(DirectoryExists("dest/new"));
452 591
453 EXPECT_EQ(1, change_observer()->get_and_reset_remove_directory_count()); 592 EXPECT_EQ(1, change_observer()->get_and_reset_remove_directory_count());
454 EXPECT_EQ(1, change_observer()->get_and_reset_create_directory_count()); 593 EXPECT_EQ(1, change_observer()->get_and_reset_create_directory_count());
455 EXPECT_TRUE(change_observer()->HasNoChange()); 594 EXPECT_TRUE(change_observer()->HasNoChange());
456 } 595 }
457 596
458 TEST_F(FileSystemOperationImplTest, TestMoveSuccessSrcDirRecursive) { 597 TEST_F(FileSystemOperationImplTest, TestMoveSuccessSrcDirRecursive) {
459 FileSystemURL src_dir(CreateDirectory("src")); 598 FileSystemURL src_dir(CreateDirectory("src"));
460 CreateDirectory("src/dir"); 599 CreateDirectory("src/dir");
461 CreateFile("src/dir/sub"); 600 CreateFile("src/dir/sub");
462 601
463 FileSystemURL dest_dir(CreateDirectory("dest")); 602 FileSystemURL dest_dir(CreateDirectory("dest"));
464 603
465 operation_runner()->Move(src_dir, dest_dir, 604 MoveTest(src_dir, dest_dir, FileSystemOperation::OPTION_NONE,
466 FileSystemOperation::OPTION_NONE, 605 base::File::FILE_OK);
467 RecordStatusCallback());
468 base::RunLoop().RunUntilIdle();
469 EXPECT_EQ(base::File::FILE_OK, status());
470 EXPECT_TRUE(DirectoryExists("dest/dir")); 606 EXPECT_TRUE(DirectoryExists("dest/dir"));
471 EXPECT_TRUE(FileExists("dest/dir/sub")); 607 EXPECT_TRUE(FileExists("dest/dir/sub"));
472 608
473 EXPECT_EQ(3, change_observer()->get_and_reset_remove_directory_count()); 609 EXPECT_EQ(3, change_observer()->get_and_reset_remove_directory_count());
474 EXPECT_EQ(2, change_observer()->get_and_reset_create_directory_count()); 610 EXPECT_EQ(2, change_observer()->get_and_reset_create_directory_count());
475 EXPECT_EQ(1, change_observer()->get_and_reset_remove_file_count()); 611 EXPECT_EQ(1, change_observer()->get_and_reset_remove_file_count());
476 EXPECT_EQ(1, change_observer()->get_and_reset_create_file_from_count()); 612 EXPECT_EQ(1, change_observer()->get_and_reset_create_file_from_count());
477 EXPECT_TRUE(change_observer()->HasNoChange()); 613 EXPECT_TRUE(change_observer()->HasNoChange());
478 } 614 }
479 615
480 TEST_F(FileSystemOperationImplTest, TestMoveSuccessSamePath) { 616 TEST_F(FileSystemOperationImplTest, TestMoveSuccessSamePath) {
481 FileSystemURL src_dir(CreateDirectory("src")); 617 FileSystemURL src_dir(CreateDirectory("src"));
482 CreateDirectory("src/dir"); 618 CreateDirectory("src/dir");
483 CreateFile("src/dir/sub"); 619 CreateFile("src/dir/sub");
484 620
485 operation_runner()->Move(src_dir, src_dir, 621 MoveTest(src_dir, src_dir, FileSystemOperation::OPTION_NONE,
486 FileSystemOperation::OPTION_NONE, 622 base::File::FILE_OK);
487 RecordStatusCallback());
488 base::RunLoop().RunUntilIdle();
489 EXPECT_EQ(base::File::FILE_OK, status());
490 EXPECT_TRUE(DirectoryExists("src/dir")); 623 EXPECT_TRUE(DirectoryExists("src/dir"));
491 EXPECT_TRUE(FileExists("src/dir/sub")); 624 EXPECT_TRUE(FileExists("src/dir/sub"));
492 625
493 EXPECT_EQ(0, change_observer()->get_and_reset_remove_directory_count()); 626 EXPECT_EQ(0, change_observer()->get_and_reset_remove_directory_count());
494 EXPECT_EQ(0, change_observer()->get_and_reset_create_directory_count()); 627 EXPECT_EQ(0, change_observer()->get_and_reset_create_directory_count());
495 EXPECT_EQ(0, change_observer()->get_and_reset_remove_file_count()); 628 EXPECT_EQ(0, change_observer()->get_and_reset_remove_file_count());
496 EXPECT_EQ(0, change_observer()->get_and_reset_create_file_from_count()); 629 EXPECT_EQ(0, change_observer()->get_and_reset_create_file_from_count());
497 EXPECT_TRUE(change_observer()->HasNoChange()); 630 EXPECT_TRUE(change_observer()->HasNoChange());
498 } 631 }
499 632
500 TEST_F(FileSystemOperationImplTest, TestCopyFailureSrcDoesntExist) { 633 TEST_F(FileSystemOperationImplTest, TestCopyFailureSrcDoesntExist) {
501 operation_runner()->Copy(URLForPath("a"), URLForPath("b"), 634 CopyTest(URLForPath("a"), URLForPath("b"), FileSystemOperation::OPTION_NONE,
502 FileSystemOperation::OPTION_NONE, 635 base::File::FILE_ERROR_NOT_FOUND);
503 FileSystemOperationRunner::CopyProgressCallback(),
504 RecordStatusCallback());
505 base::RunLoop().RunUntilIdle();
506 EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND, status());
507 EXPECT_TRUE(change_observer()->HasNoChange()); 636 EXPECT_TRUE(change_observer()->HasNoChange());
508 } 637 }
509 638
510 TEST_F(FileSystemOperationImplTest, TestCopyFailureContainsPath) { 639 TEST_F(FileSystemOperationImplTest, TestCopyFailureContainsPath) {
511 FileSystemURL src_dir(CreateDirectory("src")); 640 FileSystemURL src_dir(CreateDirectory("src"));
512 FileSystemURL dest_dir(CreateDirectory("src/dir")); 641 FileSystemURL dest_dir(CreateDirectory("src/dir"));
513 642
514 operation_runner()->Copy(src_dir, dest_dir, 643 CopyTest(src_dir, dest_dir, FileSystemOperation::OPTION_NONE,
515 FileSystemOperation::OPTION_NONE, 644 base::File::FILE_ERROR_INVALID_OPERATION);
516 FileSystemOperationRunner::CopyProgressCallback(),
517 RecordStatusCallback());
518 base::RunLoop().RunUntilIdle();
519 EXPECT_EQ(base::File::FILE_ERROR_INVALID_OPERATION, status());
520 EXPECT_TRUE(change_observer()->HasNoChange()); 645 EXPECT_TRUE(change_observer()->HasNoChange());
521 } 646 }
522 647
523 TEST_F(FileSystemOperationImplTest, TestCopyFailureSrcDirExistsDestFile) { 648 TEST_F(FileSystemOperationImplTest, TestCopyFailureSrcDirExistsDestFile) {
524 // Src exists and is dir. Dest is a file. 649 // Src exists and is dir. Dest is a file.
525 FileSystemURL src_dir(CreateDirectory("src")); 650 FileSystemURL src_dir(CreateDirectory("src"));
526 FileSystemURL dest_dir(CreateDirectory("dest")); 651 FileSystemURL dest_dir(CreateDirectory("dest"));
527 FileSystemURL dest_file(CreateFile("dest/file")); 652 FileSystemURL dest_file(CreateFile("dest/file"));
528 653
529 operation_runner()->Copy(src_dir, dest_file, 654 CopyTest(src_dir, dest_file, FileSystemOperation::OPTION_NONE,
530 FileSystemOperation::OPTION_NONE, 655 base::File::FILE_ERROR_INVALID_OPERATION);
531 FileSystemOperationRunner::CopyProgressCallback(),
532 RecordStatusCallback());
533 base::RunLoop().RunUntilIdle();
534 EXPECT_EQ(base::File::FILE_ERROR_INVALID_OPERATION, status());
535 EXPECT_TRUE(change_observer()->HasNoChange()); 656 EXPECT_TRUE(change_observer()->HasNoChange());
536 } 657 }
537 658
538 TEST_F(FileSystemOperationImplTest, 659 TEST_F(FileSystemOperationImplTest,
539 TestCopyFailureSrcFileExistsDestNonEmptyDir) { 660 TestCopyFailureSrcFileExistsDestNonEmptyDir) {
540 // Src exists and is a directory. Dest is a non-empty directory. 661 // Src exists and is a directory. Dest is a non-empty directory.
541 FileSystemURL src_dir(CreateDirectory("src")); 662 FileSystemURL src_dir(CreateDirectory("src"));
542 FileSystemURL dest_dir(CreateDirectory("dest")); 663 FileSystemURL dest_dir(CreateDirectory("dest"));
543 FileSystemURL dest_file(CreateFile("dest/file")); 664 FileSystemURL dest_file(CreateFile("dest/file"));
544 665
545 operation_runner()->Copy(src_dir, dest_dir, 666 CopyTest(src_dir, dest_dir, FileSystemOperation::OPTION_NONE,
546 FileSystemOperation::OPTION_NONE, 667 base::File::FILE_ERROR_NOT_EMPTY);
547 FileSystemOperationRunner::CopyProgressCallback(),
548 RecordStatusCallback());
549 base::RunLoop().RunUntilIdle();
550 EXPECT_EQ(base::File::FILE_ERROR_NOT_EMPTY, status());
551 EXPECT_TRUE(change_observer()->HasNoChange()); 668 EXPECT_TRUE(change_observer()->HasNoChange());
552 } 669 }
553 670
554 TEST_F(FileSystemOperationImplTest, TestCopyFailureSrcFileExistsDestDir) { 671 TEST_F(FileSystemOperationImplTest, TestCopyFailureSrcFileExistsDestDir) {
555 // Src exists and is a file. Dest is a directory. 672 // Src exists and is a file. Dest is a directory.
556 FileSystemURL src_file(CreateFile("src")); 673 FileSystemURL src_file(CreateFile("src"));
557 FileSystemURL dest_dir(CreateDirectory("dest")); 674 FileSystemURL dest_dir(CreateDirectory("dest"));
558 675
559 operation_runner()->Copy(src_file, dest_dir, 676 CopyTest(src_file, dest_dir, FileSystemOperation::OPTION_NONE,
560 FileSystemOperation::OPTION_NONE, 677 base::File::FILE_ERROR_INVALID_OPERATION);
561 FileSystemOperationRunner::CopyProgressCallback(),
562 RecordStatusCallback());
563 base::RunLoop().RunUntilIdle();
564 EXPECT_EQ(base::File::FILE_ERROR_INVALID_OPERATION, status());
565 EXPECT_TRUE(change_observer()->HasNoChange()); 678 EXPECT_TRUE(change_observer()->HasNoChange());
566 } 679 }
567 680
568 TEST_F(FileSystemOperationImplTest, TestCopyFailureDestParentDoesntExist) { 681 TEST_F(FileSystemOperationImplTest, TestCopyFailureDestParentDoesntExist) {
569 // Dest. parent path does not exist. 682 // Dest. parent path does not exist.
570 FileSystemURL src_dir(CreateDirectory("src")); 683 FileSystemURL src_dir(CreateDirectory("src"));
571 684
572 operation_runner()->Copy(src_dir, URLForPath("nonexistent/dest"), 685 CopyTest(src_dir, URLForPath("nonexistent/dest"),
573 FileSystemOperation::OPTION_NONE, 686 FileSystemOperation::OPTION_NONE,
574 FileSystemOperationRunner::CopyProgressCallback(), 687 base::File::FILE_ERROR_NOT_FOUND);
575 RecordStatusCallback());
576 base::RunLoop().RunUntilIdle();
577 EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND, status());
578 EXPECT_TRUE(change_observer()->HasNoChange()); 688 EXPECT_TRUE(change_observer()->HasNoChange());
579 } 689 }
580 690
581 TEST_F(FileSystemOperationImplTest, TestCopyFailureByQuota) { 691 TEST_F(FileSystemOperationImplTest, TestCopyFailureByQuota) {
582 FileSystemURL src_dir(CreateDirectory("src")); 692 FileSystemURL src_dir(CreateDirectory("src"));
583 FileSystemURL src_file(CreateFile("src/file")); 693 FileSystemURL src_file(CreateFile("src/file"));
584 FileSystemURL dest_dir(CreateDirectory("dest")); 694 FileSystemURL dest_dir(CreateDirectory("dest"));
585 operation_runner()->Truncate(src_file, 6, RecordStatusCallback()); 695 TruncateTest(src_file, 6, base::File::FILE_OK);
586 base::RunLoop().RunUntilIdle();
587 EXPECT_EQ(base::File::FILE_OK, status());
588 EXPECT_EQ(6, GetFileSize("src/file")); 696 EXPECT_EQ(6, GetFileSize("src/file"));
589 697
590 FileSystemURL dest_file(URLForPath("dest/file")); 698 FileSystemURL dest_file(URLForPath("dest/file"));
591 int64 dest_path_cost = ComputePathCost(dest_file); 699 int64 dest_path_cost = ComputePathCost(dest_file);
592 GrantQuotaForCurrentUsage(); 700 GrantQuotaForCurrentUsage();
593 AddQuota(6 + dest_path_cost - 1); 701 AddQuota(6 + dest_path_cost - 1);
594 702
595 operation_runner()->Copy(src_file, dest_file, 703 CopyTest(src_file, dest_file, FileSystemOperation::OPTION_NONE,
596 FileSystemOperation::OPTION_NONE, 704 base::File::FILE_ERROR_NO_SPACE);
597 FileSystemOperationRunner::CopyProgressCallback(),
598 RecordStatusCallback());
599 base::RunLoop().RunUntilIdle();
600 EXPECT_EQ(base::File::FILE_ERROR_NO_SPACE, status());
601 EXPECT_FALSE(FileExists("dest/file")); 705 EXPECT_FALSE(FileExists("dest/file"));
602 } 706 }
603 707
604 TEST_F(FileSystemOperationImplTest, TestCopySuccessSrcFileAndOverwrite) { 708 TEST_F(FileSystemOperationImplTest, TestCopySuccessSrcFileAndOverwrite) {
605 FileSystemURL src_file(CreateFile("src")); 709 FileSystemURL src_file(CreateFile("src"));
606 FileSystemURL dest_file(CreateFile("dest")); 710 FileSystemURL dest_file(CreateFile("dest"));
607 711
608 operation_runner()->Copy(src_file, dest_file, 712 CopyTest(src_file, dest_file, FileSystemOperation::OPTION_NONE,
609 FileSystemOperation::OPTION_NONE, 713 base::File::FILE_OK);
610 FileSystemOperationRunner::CopyProgressCallback(), 714
611 RecordStatusCallback());
612 base::RunLoop().RunUntilIdle();
613 EXPECT_EQ(base::File::FILE_OK, status());
614 EXPECT_TRUE(FileExists("dest")); 715 EXPECT_TRUE(FileExists("dest"));
615 EXPECT_EQ(4, quota_manager_proxy()->notify_storage_accessed_count()); 716 EXPECT_EQ(4, quota_manager_proxy()->notify_storage_accessed_count());
616 EXPECT_EQ(2, change_observer()->get_and_reset_modify_file_count()); 717 EXPECT_EQ(2, change_observer()->get_and_reset_modify_file_count());
617 718
618 EXPECT_TRUE(change_observer()->HasNoChange()); 719 EXPECT_TRUE(change_observer()->HasNoChange());
619 } 720 }
620 721
621 TEST_F(FileSystemOperationImplTest, TestCopySuccessSrcFileAndNew) { 722 TEST_F(FileSystemOperationImplTest, TestCopySuccessSrcFileAndNew) {
622 FileSystemURL src_file(CreateFile("src")); 723 FileSystemURL src_file(CreateFile("src"));
623 724
624 operation_runner()->Copy(src_file, URLForPath("new"), 725 CopyTest(src_file, URLForPath("new"), FileSystemOperation::OPTION_NONE,
625 FileSystemOperation::OPTION_NONE, 726 base::File::FILE_OK);
626 FileSystemOperationRunner::CopyProgressCallback(),
627 RecordStatusCallback());
628 base::RunLoop().RunUntilIdle();
629 EXPECT_EQ(base::File::FILE_OK, status());
630 EXPECT_TRUE(FileExists("new")); 727 EXPECT_TRUE(FileExists("new"));
631 EXPECT_EQ(4, quota_manager_proxy()->notify_storage_accessed_count()); 728 EXPECT_EQ(4, quota_manager_proxy()->notify_storage_accessed_count());
632 729
633 EXPECT_EQ(1, change_observer()->get_and_reset_create_file_count()); 730 EXPECT_EQ(1, change_observer()->get_and_reset_create_file_count());
634 EXPECT_EQ(1, change_observer()->get_and_reset_modify_file_count()); 731 EXPECT_EQ(1, change_observer()->get_and_reset_modify_file_count());
635 EXPECT_TRUE(change_observer()->HasNoChange()); 732 EXPECT_TRUE(change_observer()->HasNoChange());
636 } 733 }
637 734
638 TEST_F(FileSystemOperationImplTest, TestCopySuccessSrcDirAndOverwrite) { 735 TEST_F(FileSystemOperationImplTest, TestCopySuccessSrcDirAndOverwrite) {
639 FileSystemURL src_dir(CreateDirectory("src")); 736 FileSystemURL src_dir(CreateDirectory("src"));
640 FileSystemURL dest_dir(CreateDirectory("dest")); 737 FileSystemURL dest_dir(CreateDirectory("dest"));
641 738
642 operation_runner()->Copy(src_dir, dest_dir, 739 CopyTest(src_dir, dest_dir, FileSystemOperation::OPTION_NONE,
643 FileSystemOperation::OPTION_NONE, 740 base::File::FILE_OK);
644 FileSystemOperationRunner::CopyProgressCallback(),
645 RecordStatusCallback());
646 base::RunLoop().RunUntilIdle();
647 EXPECT_EQ(base::File::FILE_OK, status());
648 741
649 // Make sure we've overwritten but not copied the source under the |dest_dir|. 742 // Make sure we've overwritten but not copied the source under the |dest_dir|.
650 EXPECT_TRUE(DirectoryExists("dest")); 743 EXPECT_TRUE(DirectoryExists("dest"));
651 EXPECT_FALSE(DirectoryExists("dest/src")); 744 EXPECT_FALSE(DirectoryExists("dest/src"));
652 EXPECT_GE(quota_manager_proxy()->notify_storage_accessed_count(), 3); 745 EXPECT_GE(quota_manager_proxy()->notify_storage_accessed_count(), 3);
653 746
654 EXPECT_EQ(1, change_observer()->get_and_reset_create_directory_count()); 747 EXPECT_EQ(1, change_observer()->get_and_reset_create_directory_count());
655 EXPECT_EQ(1, change_observer()->get_and_reset_remove_directory_count()); 748 EXPECT_EQ(1, change_observer()->get_and_reset_remove_directory_count());
656 EXPECT_TRUE(change_observer()->HasNoChange()); 749 EXPECT_TRUE(change_observer()->HasNoChange());
657 } 750 }
658 751
659 TEST_F(FileSystemOperationImplTest, TestCopySuccessSrcDirAndNew) { 752 TEST_F(FileSystemOperationImplTest, TestCopySuccessSrcDirAndNew) {
660 FileSystemURL src_dir(CreateDirectory("src")); 753 FileSystemURL src_dir(CreateDirectory("src"));
661 FileSystemURL dest_dir_new(URLForPath("dest")); 754 FileSystemURL dest_dir_new(URLForPath("dest"));
662 755
663 operation_runner()->Copy(src_dir, dest_dir_new, 756 CopyTest(src_dir, dest_dir_new, FileSystemOperation::OPTION_NONE,
664 FileSystemOperation::OPTION_NONE, 757 base::File::FILE_OK);
665 FileSystemOperationRunner::CopyProgressCallback(),
666 RecordStatusCallback());
667 base::RunLoop().RunUntilIdle();
668 EXPECT_EQ(base::File::FILE_OK, status());
669 EXPECT_TRUE(DirectoryExists("dest")); 758 EXPECT_TRUE(DirectoryExists("dest"));
670 EXPECT_GE(quota_manager_proxy()->notify_storage_accessed_count(), 2); 759 EXPECT_GE(quota_manager_proxy()->notify_storage_accessed_count(), 2);
671 760
672 EXPECT_EQ(1, change_observer()->get_and_reset_create_directory_count()); 761 EXPECT_EQ(1, change_observer()->get_and_reset_create_directory_count());
673 EXPECT_TRUE(change_observer()->HasNoChange()); 762 EXPECT_TRUE(change_observer()->HasNoChange());
674 } 763 }
675 764
676 TEST_F(FileSystemOperationImplTest, TestCopySuccessSrcDirRecursive) { 765 TEST_F(FileSystemOperationImplTest, TestCopySuccessSrcDirRecursive) {
677 FileSystemURL src_dir(CreateDirectory("src")); 766 FileSystemURL src_dir(CreateDirectory("src"));
678 CreateDirectory("src/dir"); 767 CreateDirectory("src/dir");
679 CreateFile("src/dir/sub"); 768 CreateFile("src/dir/sub");
680 769
681 FileSystemURL dest_dir(CreateDirectory("dest")); 770 FileSystemURL dest_dir(CreateDirectory("dest"));
682 771
683 operation_runner()->Copy(src_dir, dest_dir, 772 CopyTest(src_dir, dest_dir, FileSystemOperation::OPTION_NONE,
684 FileSystemOperation::OPTION_NONE, 773 base::File::FILE_OK);
685 FileSystemOperationRunner::CopyProgressCallback(),
686 RecordStatusCallback());
687 base::RunLoop().RunUntilIdle();
688 774
689 EXPECT_EQ(base::File::FILE_OK, status());
690 EXPECT_TRUE(DirectoryExists("dest/dir")); 775 EXPECT_TRUE(DirectoryExists("dest/dir"));
691 EXPECT_TRUE(FileExists("dest/dir/sub")); 776 EXPECT_TRUE(FileExists("dest/dir/sub"));
692 777
693 // For recursive copy we may record multiple read access. 778 // For recursive copy we may record multiple read access.
694 EXPECT_GE(quota_manager_proxy()->notify_storage_accessed_count(), 1); 779 EXPECT_GE(quota_manager_proxy()->notify_storage_accessed_count(), 1);
695 780
696 EXPECT_EQ(2, change_observer()->get_and_reset_create_directory_count()); 781 EXPECT_EQ(2, change_observer()->get_and_reset_create_directory_count());
697 EXPECT_EQ(1, change_observer()->get_and_reset_remove_directory_count()); 782 EXPECT_EQ(1, change_observer()->get_and_reset_remove_directory_count());
698 EXPECT_EQ(1, change_observer()->get_and_reset_create_file_count()); 783 EXPECT_EQ(1, change_observer()->get_and_reset_create_file_count());
699 EXPECT_EQ(1, change_observer()->get_and_reset_modify_file_count()); 784 EXPECT_EQ(1, change_observer()->get_and_reset_modify_file_count());
700 EXPECT_TRUE(change_observer()->HasNoChange()); 785 EXPECT_TRUE(change_observer()->HasNoChange());
701 } 786 }
702 787
703 TEST_F(FileSystemOperationImplTest, TestCopySuccessSamePath) { 788 TEST_F(FileSystemOperationImplTest, TestCopySuccessSamePath) {
704 FileSystemURL src_dir(CreateDirectory("src")); 789 FileSystemURL src_dir(CreateDirectory("src"));
705 CreateDirectory("src/dir"); 790 CreateDirectory("src/dir");
706 CreateFile("src/dir/sub"); 791 CreateFile("src/dir/sub");
707 792
708 operation_runner()->Copy(src_dir, src_dir, 793 CopyTest(src_dir, src_dir, FileSystemOperation::OPTION_NONE,
709 FileSystemOperation::OPTION_NONE, 794 base::File::FILE_OK);
710 FileSystemOperationRunner::CopyProgressCallback(),
711 RecordStatusCallback());
712 base::RunLoop().RunUntilIdle();
713 795
714 EXPECT_EQ(base::File::FILE_OK, status());
715 EXPECT_TRUE(DirectoryExists("src/dir")); 796 EXPECT_TRUE(DirectoryExists("src/dir"));
716 EXPECT_TRUE(FileExists("src/dir/sub")); 797 EXPECT_TRUE(FileExists("src/dir/sub"));
717 798
718 EXPECT_EQ(0, change_observer()->get_and_reset_create_directory_count()); 799 EXPECT_EQ(0, change_observer()->get_and_reset_create_directory_count());
719 EXPECT_EQ(0, change_observer()->get_and_reset_remove_file_count()); 800 EXPECT_EQ(0, change_observer()->get_and_reset_remove_file_count());
720 EXPECT_EQ(0, change_observer()->get_and_reset_create_file_from_count()); 801 EXPECT_EQ(0, change_observer()->get_and_reset_create_file_from_count());
721 EXPECT_TRUE(change_observer()->HasNoChange()); 802 EXPECT_TRUE(change_observer()->HasNoChange());
722 } 803 }
723 804
724 TEST_F(FileSystemOperationImplTest, TestCopyInForeignFileSuccess) { 805 TEST_F(FileSystemOperationImplTest, TestCopyInForeignFileSuccess) {
725 base::FilePath src_local_disk_file_path; 806 base::FilePath src_local_disk_file_path;
726 base::CreateTemporaryFile(&src_local_disk_file_path); 807 base::CreateTemporaryFile(&src_local_disk_file_path);
727 const char test_data[] = "foo"; 808 const char test_data[] = "foo";
728 int data_size = ARRAYSIZE_UNSAFE(test_data); 809 int data_size = ARRAYSIZE_UNSAFE(test_data);
729 base::WriteFile(src_local_disk_file_path, test_data, data_size); 810 base::WriteFile(src_local_disk_file_path, test_data, data_size);
730 811
731 FileSystemURL dest_dir(CreateDirectory("dest")); 812 FileSystemURL dest_dir(CreateDirectory("dest"));
732 813
733 int64 before_usage; 814 int64 before_usage;
734 GetUsageAndQuota(&before_usage, NULL); 815 GetUsageAndQuota(&before_usage, NULL);
735 816
736 // Check that the file copied and corresponding usage increased. 817 // Check that the file copied and corresponding usage increased.
737 operation_runner()->CopyInForeignFile(src_local_disk_file_path, 818 CopyInForeignFileTest(
738 URLForPath("dest/file"), 819 src_local_disk_file_path,
739 RecordStatusCallback()); 820 URLForPath("dest/file"),
740 base::RunLoop().RunUntilIdle(); 821 base::File::FILE_OK);
741 822
742 EXPECT_EQ(1, change_observer()->create_file_count()); 823 EXPECT_EQ(1, change_observer()->create_file_count());
743 EXPECT_EQ(base::File::FILE_OK, status());
744 EXPECT_TRUE(FileExists("dest/file")); 824 EXPECT_TRUE(FileExists("dest/file"));
745 int64 after_usage; 825 int64 after_usage;
746 GetUsageAndQuota(&after_usage, NULL); 826 GetUsageAndQuota(&after_usage, NULL);
747 EXPECT_GT(after_usage, before_usage); 827 EXPECT_GT(after_usage, before_usage);
748 828
749 // Compare contents of src and copied file. 829 // Compare contents of src and copied file.
750 char buffer[100]; 830 char buffer[100];
751 EXPECT_EQ(data_size, base::ReadFile(PlatformPath("dest/file"), 831 EXPECT_EQ(data_size, base::ReadFile(PlatformPath("dest/file"),
752 buffer, data_size)); 832 buffer, data_size));
753 for (int i = 0; i < data_size; ++i) 833 for (int i = 0; i < data_size; ++i)
754 EXPECT_EQ(test_data[i], buffer[i]); 834 EXPECT_EQ(test_data[i], buffer[i]);
755 } 835 }
756 836
757 TEST_F(FileSystemOperationImplTest, TestCopyInForeignFileFailureByQuota) { 837 TEST_F(FileSystemOperationImplTest, TestCopyInForeignFileFailureByQuota) {
758 base::FilePath src_local_disk_file_path; 838 base::FilePath src_local_disk_file_path;
759 base::CreateTemporaryFile(&src_local_disk_file_path); 839 base::CreateTemporaryFile(&src_local_disk_file_path);
760 const char test_data[] = "foo"; 840 const char test_data[] = "foo";
761 base::WriteFile(src_local_disk_file_path, test_data, 841 base::WriteFile(src_local_disk_file_path, test_data,
762 ARRAYSIZE_UNSAFE(test_data)); 842 ARRAYSIZE_UNSAFE(test_data));
763 843
764 FileSystemURL dest_dir(CreateDirectory("dest")); 844 FileSystemURL dest_dir(CreateDirectory("dest"));
765 845
766 GrantQuotaForCurrentUsage(); 846 GrantQuotaForCurrentUsage();
767 operation_runner()->CopyInForeignFile(src_local_disk_file_path, 847 CopyInForeignFileTest(
768 URLForPath("dest/file"), 848 src_local_disk_file_path,
769 RecordStatusCallback()); 849 URLForPath("dest/file"),
770 base::RunLoop().RunUntilIdle(); 850 base::File::FILE_ERROR_NO_SPACE);
771 851
772 EXPECT_FALSE(FileExists("dest/file")); 852 EXPECT_FALSE(FileExists("dest/file"));
773 EXPECT_EQ(0, change_observer()->create_file_count()); 853 EXPECT_EQ(0, change_observer()->create_file_count());
774 EXPECT_EQ(base::File::FILE_ERROR_NO_SPACE, status());
775 } 854 }
776 855
777 TEST_F(FileSystemOperationImplTest, TestCreateFileFailure) { 856 TEST_F(FileSystemOperationImplTest, TestCreateFileFailure) {
778 // Already existing file and exclusive true. 857 // Already existing file and exclusive true.
779 FileSystemURL file(CreateFile("file")); 858 FileSystemURL file(CreateFile("file"));
780 operation_runner()->CreateFile(file, true, RecordStatusCallback()); 859 CreateFileTest(file, true, base::File::FILE_ERROR_EXISTS);
781 base::RunLoop().RunUntilIdle();
782 EXPECT_EQ(base::File::FILE_ERROR_EXISTS, status());
783 EXPECT_TRUE(change_observer()->HasNoChange()); 860 EXPECT_TRUE(change_observer()->HasNoChange());
784 } 861 }
785 862
786 TEST_F(FileSystemOperationImplTest, TestCreateFileSuccessFileExists) { 863 TEST_F(FileSystemOperationImplTest, TestCreateFileSuccessFileExists) {
787 // Already existing file and exclusive false. 864 // Already existing file and exclusive false.
788 FileSystemURL file(CreateFile("file")); 865 FileSystemURL file(CreateFile("file"));
789 operation_runner()->CreateFile(file, false, RecordStatusCallback()); 866 CreateFileTest(file, false, base::File::FILE_OK);
790 base::RunLoop().RunUntilIdle();
791 EXPECT_EQ(base::File::FILE_OK, status());
792 EXPECT_TRUE(FileExists("file")); 867 EXPECT_TRUE(FileExists("file"));
793 868
794 // The file was already there; did nothing. 869 // The file was already there; did nothing.
795 EXPECT_TRUE(change_observer()->HasNoChange()); 870 EXPECT_TRUE(change_observer()->HasNoChange());
796 } 871 }
797 872
798 TEST_F(FileSystemOperationImplTest, TestCreateFileSuccessExclusive) { 873 TEST_F(FileSystemOperationImplTest, TestCreateFileSuccessExclusive) {
799 // File doesn't exist but exclusive is true. 874 // File doesn't exist but exclusive is true.
800 operation_runner()->CreateFile(URLForPath("new"), true, 875 CreateFileTest(URLForPath("new"), true, base::File::FILE_OK);
801 RecordStatusCallback());
802 base::RunLoop().RunUntilIdle();
803 EXPECT_EQ(base::File::FILE_OK, status());
804 EXPECT_TRUE(FileExists("new")); 876 EXPECT_TRUE(FileExists("new"));
805 EXPECT_EQ(1, change_observer()->get_and_reset_create_file_count()); 877 EXPECT_EQ(1, change_observer()->get_and_reset_create_file_count());
806 } 878 }
807 879
808 TEST_F(FileSystemOperationImplTest, TestCreateFileSuccessFileDoesntExist) { 880 TEST_F(FileSystemOperationImplTest, TestCreateFileSuccessFileDoesntExist) {
809 // Non existing file. 881 // Non existing file.
810 operation_runner()->CreateFile(URLForPath("nonexistent"), false, 882 CreateFileTest(URLForPath("nonexistent"), false, base::File::FILE_OK);
811 RecordStatusCallback());
812 base::RunLoop().RunUntilIdle();
813 EXPECT_EQ(base::File::FILE_OK, status());
814 EXPECT_EQ(1, change_observer()->get_and_reset_create_file_count()); 883 EXPECT_EQ(1, change_observer()->get_and_reset_create_file_count());
815 } 884 }
816 885
817 TEST_F(FileSystemOperationImplTest, 886 TEST_F(FileSystemOperationImplTest,
818 TestCreateDirFailureDestParentDoesntExist) { 887 TestCreateDirFailureDestParentDoesntExist) {
819 // Dest. parent path does not exist. 888 // Dest. parent path does not exist.
820 operation_runner()->CreateDirectory( 889 CreateDirectoryTest(URLForPath("nonexistent/dir"), false, false,
821 URLForPath("nonexistent/dir"), false, false, 890 base::File::FILE_ERROR_NOT_FOUND);
822 RecordStatusCallback());
823 base::RunLoop().RunUntilIdle();
824 EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND, status());
825 EXPECT_TRUE(change_observer()->HasNoChange()); 891 EXPECT_TRUE(change_observer()->HasNoChange());
826 } 892 }
827 893
828 TEST_F(FileSystemOperationImplTest, TestCreateDirFailureDirExists) { 894 TEST_F(FileSystemOperationImplTest, TestCreateDirFailureDirExists) {
829 // Exclusive and dir existing at path. 895 // Exclusive and dir existing at path.
830 FileSystemURL dir(CreateDirectory("dir")); 896 FileSystemURL dir(CreateDirectory("dir"));
831 operation_runner()->CreateDirectory(dir, true, false, 897 CreateDirectoryTest(dir, true, false,
832 RecordStatusCallback()); 898 base::File::FILE_ERROR_EXISTS);
833 base::RunLoop().RunUntilIdle();
834 EXPECT_EQ(base::File::FILE_ERROR_EXISTS, status());
835 EXPECT_TRUE(change_observer()->HasNoChange()); 899 EXPECT_TRUE(change_observer()->HasNoChange());
836 } 900 }
837 901
838 TEST_F(FileSystemOperationImplTest, TestCreateDirFailureFileExists) { 902 TEST_F(FileSystemOperationImplTest, TestCreateDirFailureFileExists) {
839 // Exclusive true and file existing at path. 903 // Exclusive true and file existing at path.
840 FileSystemURL file(CreateFile("file")); 904 FileSystemURL file(CreateFile("file"));
841 operation_runner()->CreateDirectory(file, true, false, 905 CreateDirectoryTest(file, true, false,
842 RecordStatusCallback()); 906 base::File::FILE_ERROR_EXISTS);
843 base::RunLoop().RunUntilIdle();
844 EXPECT_EQ(base::File::FILE_ERROR_EXISTS, status());
845 EXPECT_TRUE(change_observer()->HasNoChange()); 907 EXPECT_TRUE(change_observer()->HasNoChange());
846 } 908 }
847 909
848 TEST_F(FileSystemOperationImplTest, TestCreateDirSuccess) { 910 TEST_F(FileSystemOperationImplTest, TestCreateDirSuccess) {
849 // Dir exists and exclusive is false. 911 // Dir exists and exclusive is false.
850 FileSystemURL dir(CreateDirectory("dir")); 912 FileSystemURL dir(CreateDirectory("dir"));
851 operation_runner()->CreateDirectory(dir, false, false, 913 CreateDirectoryTest(dir, false, false,
852 RecordStatusCallback()); 914 base::File::FILE_OK);
853 base::RunLoop().RunUntilIdle();
854 EXPECT_EQ(base::File::FILE_OK, status());
855 EXPECT_TRUE(change_observer()->HasNoChange()); 915 EXPECT_TRUE(change_observer()->HasNoChange());
856 916
857 // Dir doesn't exist. 917 // Dir doesn't exist.
858 operation_runner()->CreateDirectory(URLForPath("new"), false, false, 918 CreateDirectoryTest(URLForPath("new"), false, false,
859 RecordStatusCallback()); 919 base::File::FILE_OK);
860 base::RunLoop().RunUntilIdle();
861 EXPECT_EQ(base::File::FILE_OK, status());
862 EXPECT_TRUE(DirectoryExists("new")); 920 EXPECT_TRUE(DirectoryExists("new"));
863 EXPECT_EQ(1, change_observer()->get_and_reset_create_directory_count()); 921 EXPECT_EQ(1, change_observer()->get_and_reset_create_directory_count());
864 } 922 }
865 923
866 TEST_F(FileSystemOperationImplTest, TestCreateDirSuccessExclusive) { 924 TEST_F(FileSystemOperationImplTest, TestCreateDirSuccessExclusive) {
867 // Dir doesn't exist. 925 // Dir doesn't exist.
868 operation_runner()->CreateDirectory(URLForPath("new"), true, false, 926 CreateDirectoryTest(URLForPath("new"), true, false,
869 RecordStatusCallback()); 927 base::File::FILE_OK);
870 base::RunLoop().RunUntilIdle();
871 EXPECT_EQ(base::File::FILE_OK, status());
872 EXPECT_TRUE(DirectoryExists("new")); 928 EXPECT_TRUE(DirectoryExists("new"));
873 EXPECT_EQ(1, change_observer()->get_and_reset_create_directory_count()); 929 EXPECT_EQ(1, change_observer()->get_and_reset_create_directory_count());
874 EXPECT_TRUE(change_observer()->HasNoChange()); 930 EXPECT_TRUE(change_observer()->HasNoChange());
875 } 931 }
876 932
877 TEST_F(FileSystemOperationImplTest, TestExistsAndMetadataFailure) { 933 TEST_F(FileSystemOperationImplTest, TestExistsAndMetadataFailure) {
878 operation_runner()->GetMetadata(URLForPath("nonexistent"), 934 GetMetadataTest(URLForPath("nonexistent"));
879 RecordMetadataCallback());
880 base::RunLoop().RunUntilIdle();
881 EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND, status()); 935 EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND, status());
882 936
883 operation_runner()->FileExists(URLForPath("nonexistent"), 937 FileExistsTest(
884 RecordStatusCallback()); 938 URLForPath("nonexistent"),
885 base::RunLoop().RunUntilIdle(); 939 base::File::FILE_ERROR_NOT_FOUND);
886 EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND, status());
887 940
888 operation_runner()->DirectoryExists(URLForPath("nonexistent"), 941 DirectoryExistsTest(URLForPath("nonexistent"),
889 RecordStatusCallback()); 942 base::File::FILE_ERROR_NOT_FOUND);
890 base::RunLoop().RunUntilIdle();
891 EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND, status());
892 EXPECT_TRUE(change_observer()->HasNoChange()); 943 EXPECT_TRUE(change_observer()->HasNoChange());
893 } 944 }
894 945
895 TEST_F(FileSystemOperationImplTest, TestExistsAndMetadataSuccess) { 946 TEST_F(FileSystemOperationImplTest, TestExistsAndMetadataSuccess) {
896 FileSystemURL dir(CreateDirectory("dir")); 947 FileSystemURL dir(CreateDirectory("dir"));
897 FileSystemURL file(CreateFile("dir/file")); 948 FileSystemURL file(CreateFile("dir/file"));
898 int read_access = 0; 949 int read_access = 0;
899 950
900 operation_runner()->DirectoryExists(dir, RecordStatusCallback()); 951 DirectoryExistsTest(dir, base::File::FILE_OK);
901 base::RunLoop().RunUntilIdle();
902 EXPECT_EQ(base::File::FILE_OK, status());
903 ++read_access; 952 ++read_access;
904 953
905 operation_runner()->GetMetadata(dir, RecordMetadataCallback()); 954 GetMetadataTest(dir);
906 base::RunLoop().RunUntilIdle();
907 EXPECT_EQ(base::File::FILE_OK, status()); 955 EXPECT_EQ(base::File::FILE_OK, status());
908 EXPECT_TRUE(info().is_directory); 956 EXPECT_TRUE(info().is_directory);
909 ++read_access; 957 ++read_access;
910 958
911 operation_runner()->FileExists(file, RecordStatusCallback()); 959 FileExistsTest(file, base::File::FILE_OK);
912 base::RunLoop().RunUntilIdle();
913 EXPECT_EQ(base::File::FILE_OK, status());
914 ++read_access; 960 ++read_access;
915 961
916 operation_runner()->GetMetadata(file, RecordMetadataCallback()); 962 GetMetadataTest(file);
917 base::RunLoop().RunUntilIdle();
918 EXPECT_EQ(base::File::FILE_OK, status()); 963 EXPECT_EQ(base::File::FILE_OK, status());
919 EXPECT_FALSE(info().is_directory); 964 EXPECT_FALSE(info().is_directory);
920 ++read_access; 965 ++read_access;
921 966
922 EXPECT_EQ(read_access, 967 EXPECT_EQ(read_access,
923 quota_manager_proxy()->notify_storage_accessed_count()); 968 quota_manager_proxy()->notify_storage_accessed_count());
924 EXPECT_TRUE(change_observer()->HasNoChange()); 969 EXPECT_TRUE(change_observer()->HasNoChange());
925 } 970 }
926 971
927 TEST_F(FileSystemOperationImplTest, TestTypeMismatchErrors) { 972 TEST_F(FileSystemOperationImplTest, TestTypeMismatchErrors) {
928 FileSystemURL dir(CreateDirectory("dir")); 973 FileSystemURL dir(CreateDirectory("dir"));
929 operation_runner()->FileExists(dir, RecordStatusCallback()); 974 FileExistsTest(dir, base::File::FILE_ERROR_NOT_A_FILE);
930 base::RunLoop().RunUntilIdle();
931 EXPECT_EQ(base::File::FILE_ERROR_NOT_A_FILE, status());
932 975
933 FileSystemURL file(CreateFile("file")); 976 FileSystemURL file(CreateFile("file"));
934 operation_runner()->DirectoryExists(file, RecordStatusCallback()); 977 DirectoryExistsTest(file, base::File::FILE_ERROR_NOT_A_DIRECTORY);
935 base::RunLoop().RunUntilIdle();
936 EXPECT_EQ(base::File::FILE_ERROR_NOT_A_DIRECTORY, status());
937 } 978 }
938 979
939 TEST_F(FileSystemOperationImplTest, TestReadDirFailure) { 980 TEST_F(FileSystemOperationImplTest, TestReadDirFailure) {
940 // Path doesn't exist 981 // Path doesn't exist
941 operation_runner()->ReadDirectory(URLForPath("nonexistent"), 982 ReadDirectoryTest(URLForPath("nonexistent"));
942 RecordReadDirectoryCallback());
943 base::RunLoop().RunUntilIdle();
944 EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND, status()); 983 EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND, status());
945 984
946 // File exists. 985 // File exists.
947 FileSystemURL file(CreateFile("file")); 986 FileSystemURL file(CreateFile("file"));
948 operation_runner()->ReadDirectory(file, RecordReadDirectoryCallback()); 987 ReadDirectoryTest(file);
949 base::RunLoop().RunUntilIdle();
950 EXPECT_EQ(base::File::FILE_ERROR_NOT_A_DIRECTORY, status()); 988 EXPECT_EQ(base::File::FILE_ERROR_NOT_A_DIRECTORY, status());
951 EXPECT_TRUE(change_observer()->HasNoChange()); 989 EXPECT_TRUE(change_observer()->HasNoChange());
952 } 990 }
953 991
954 TEST_F(FileSystemOperationImplTest, TestReadDirSuccess) { 992 TEST_F(FileSystemOperationImplTest, TestReadDirSuccess) {
955 // parent_dir 993 // parent_dir
956 // | | 994 // | |
957 // child_dir child_file 995 // child_dir child_file
958 // Verify reading parent_dir. 996 // Verify reading parent_dir.
959 FileSystemURL parent_dir(CreateDirectory("dir")); 997 FileSystemURL parent_dir(CreateDirectory("dir"));
960 FileSystemURL child_dir(CreateDirectory("dir/child_dir")); 998 FileSystemURL child_dir(CreateDirectory("dir/child_dir"));
961 FileSystemURL child_file(CreateFile("dir/child_file")); 999 FileSystemURL child_file(CreateFile("dir/child_file"));
962 1000
963 operation_runner()->ReadDirectory(parent_dir, RecordReadDirectoryCallback()); 1001 ReadDirectoryTest(parent_dir);
964 base::RunLoop().RunUntilIdle();
965 EXPECT_EQ(base::File::FILE_OK, status()); 1002 EXPECT_EQ(base::File::FILE_OK, status());
966 EXPECT_EQ(2u, entries().size()); 1003 EXPECT_EQ(2u, entries().size());
967 1004
968 for (size_t i = 0; i < entries().size(); ++i) { 1005 for (size_t i = 0; i < entries().size(); ++i) {
969 if (entries()[i].is_directory) 1006 if (entries()[i].is_directory)
970 EXPECT_EQ(FILE_PATH_LITERAL("child_dir"), entries()[i].name); 1007 EXPECT_EQ(FILE_PATH_LITERAL("child_dir"), entries()[i].name);
971 else 1008 else
972 EXPECT_EQ(FILE_PATH_LITERAL("child_file"), entries()[i].name); 1009 EXPECT_EQ(FILE_PATH_LITERAL("child_file"), entries()[i].name);
973 } 1010 }
974 EXPECT_EQ(1, quota_manager_proxy()->notify_storage_accessed_count()); 1011 EXPECT_EQ(1, quota_manager_proxy()->notify_storage_accessed_count());
975 EXPECT_TRUE(change_observer()->HasNoChange()); 1012 EXPECT_TRUE(change_observer()->HasNoChange());
976 } 1013 }
977 1014
978 TEST_F(FileSystemOperationImplTest, TestRemoveFailure) { 1015 TEST_F(FileSystemOperationImplTest, TestRemoveFailure) {
979 // Path doesn't exist. 1016 // Path doesn't exist.
980 operation_runner()->Remove(URLForPath("nonexistent"), false /* recursive */, 1017 RemoveTest(URLForPath("nonexistent"), false /* recursive */,
981 RecordStatusCallback()); 1018 base::File::FILE_ERROR_NOT_FOUND);
982 base::RunLoop().RunUntilIdle();
983 EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND, status());
984 1019
985 // It's an error to try to remove a non-empty directory if recursive flag 1020 // It's an error to try to remove a non-empty directory if recursive flag
986 // is false. 1021 // is false.
987 // parent_dir 1022 // parent_dir
988 // | | 1023 // | |
989 // child_dir child_file 1024 // child_dir child_file
990 // Verify deleting parent_dir. 1025 // Verify deleting parent_dir.
991 FileSystemURL parent_dir(CreateDirectory("dir")); 1026 FileSystemURL parent_dir(CreateDirectory("dir"));
992 FileSystemURL child_dir(CreateDirectory("dir/child_dir")); 1027 FileSystemURL child_dir(CreateDirectory("dir/child_dir"));
993 FileSystemURL child_file(CreateFile("dir/child_file")); 1028 FileSystemURL child_file(CreateFile("dir/child_file"));
994 1029
995 operation_runner()->Remove(parent_dir, false /* recursive */, 1030 RemoveTest(parent_dir, false /* recursive */,
996 RecordStatusCallback()); 1031 base::File::FILE_ERROR_NOT_EMPTY);
997 base::RunLoop().RunUntilIdle();
998 EXPECT_EQ(base::File::FILE_ERROR_NOT_EMPTY, status());
999 EXPECT_TRUE(change_observer()->HasNoChange()); 1032 EXPECT_TRUE(change_observer()->HasNoChange());
1000 } 1033 }
1001 1034
1002 TEST_F(FileSystemOperationImplTest, TestRemoveSuccess) { 1035 TEST_F(FileSystemOperationImplTest, TestRemoveSuccess) {
1003 FileSystemURL empty_dir(CreateDirectory("empty_dir")); 1036 FileSystemURL empty_dir(CreateDirectory("empty_dir"));
1004 EXPECT_TRUE(DirectoryExists("empty_dir")); 1037 EXPECT_TRUE(DirectoryExists("empty_dir"));
1005 operation_runner()->Remove(empty_dir, false /* recursive */, 1038 RemoveTest(empty_dir, false /* recursive */,
1006 RecordStatusCallback()); 1039 base::File::FILE_OK);
1007 base::RunLoop().RunUntilIdle();
1008 EXPECT_EQ(base::File::FILE_OK, status());
1009 EXPECT_FALSE(DirectoryExists("empty_dir")); 1040 EXPECT_FALSE(DirectoryExists("empty_dir"));
1010 1041
1011 EXPECT_EQ(1, change_observer()->get_and_reset_remove_directory_count()); 1042 EXPECT_EQ(1, change_observer()->get_and_reset_remove_directory_count());
1012 EXPECT_TRUE(change_observer()->HasNoChange()); 1043 EXPECT_TRUE(change_observer()->HasNoChange());
1013 } 1044 }
1014 1045
1015 TEST_F(FileSystemOperationImplTest, TestRemoveSuccessRecursive) { 1046 TEST_F(FileSystemOperationImplTest, TestRemoveSuccessRecursive) {
1016 // Removing a non-empty directory with recursive flag == true should be ok. 1047 // Removing a non-empty directory with recursive flag == true should be ok.
1017 // parent_dir 1048 // parent_dir
1018 // | | 1049 // | |
1019 // child_dir child_files 1050 // child_dir child_files
1020 // | 1051 // |
1021 // child_files 1052 // child_files
1022 // 1053 //
1023 // Verify deleting parent_dir. 1054 // Verify deleting parent_dir.
1024 FileSystemURL parent_dir(CreateDirectory("dir")); 1055 FileSystemURL parent_dir(CreateDirectory("dir"));
1025 for (int i = 0; i < 8; ++i) 1056 for (int i = 0; i < 8; ++i)
1026 CreateFile(base::StringPrintf("dir/file-%d", i)); 1057 CreateFile(base::StringPrintf("dir/file-%d", i));
1027 FileSystemURL child_dir(CreateDirectory("dir/child_dir")); 1058 FileSystemURL child_dir(CreateDirectory("dir/child_dir"));
1028 for (int i = 0; i < 8; ++i) 1059 for (int i = 0; i < 8; ++i)
1029 CreateFile(base::StringPrintf("dir/child_dir/file-%d", i)); 1060 CreateFile(base::StringPrintf("dir/child_dir/file-%d", i));
1030 1061
1031 operation_runner()->Remove(parent_dir, true /* recursive */, 1062 RemoveTest(parent_dir, true /* recursive */,
1032 RecordStatusCallback()); 1063 base::File::FILE_OK);
1033 base::RunLoop().RunUntilIdle();
1034 EXPECT_EQ(base::File::FILE_OK, status());
1035 EXPECT_FALSE(DirectoryExists("parent_dir")); 1064 EXPECT_FALSE(DirectoryExists("parent_dir"));
1036 1065
1037 EXPECT_EQ(2, change_observer()->get_and_reset_remove_directory_count()); 1066 EXPECT_EQ(2, change_observer()->get_and_reset_remove_directory_count());
1038 EXPECT_EQ(16, change_observer()->get_and_reset_remove_file_count()); 1067 EXPECT_EQ(16, change_observer()->get_and_reset_remove_file_count());
1039 EXPECT_TRUE(change_observer()->HasNoChange()); 1068 EXPECT_TRUE(change_observer()->HasNoChange());
1040 } 1069 }
1041 1070
1042 TEST_F(FileSystemOperationImplTest, TestTruncate) { 1071 TEST_F(FileSystemOperationImplTest, TestTruncate) {
1043 FileSystemURL file(CreateFile("file")); 1072 FileSystemURL file(CreateFile("file"));
1044 base::FilePath platform_path = PlatformPath("file"); 1073 base::FilePath platform_path = PlatformPath("file");
1045 1074
1046 char test_data[] = "test data"; 1075 char test_data[] = "test data";
1047 int data_size = static_cast<int>(sizeof(test_data)); 1076 int data_size = static_cast<int>(sizeof(test_data));
1048 EXPECT_EQ(data_size, 1077 EXPECT_EQ(data_size,
1049 base::WriteFile(platform_path, test_data, data_size)); 1078 base::WriteFile(platform_path, test_data, data_size));
1050 1079
1051 // Check that its length is the size of the data written. 1080 // Check that its length is the size of the data written.
1052 operation_runner()->GetMetadata(file, RecordMetadataCallback()); 1081 GetMetadataTest(file);
1053 base::RunLoop().RunUntilIdle();
1054 EXPECT_EQ(base::File::FILE_OK, status()); 1082 EXPECT_EQ(base::File::FILE_OK, status());
1055 EXPECT_FALSE(info().is_directory); 1083 EXPECT_FALSE(info().is_directory);
1056 EXPECT_EQ(data_size, info().size); 1084 EXPECT_EQ(data_size, info().size);
1057 1085
1058 // Extend the file by truncating it. 1086 // Extend the file by truncating it.
1059 int length = 17; 1087 int length = 17;
1060 operation_runner()->Truncate(file, length, RecordStatusCallback()); 1088 TruncateTest(file, length, base::File::FILE_OK);
1061 base::RunLoop().RunUntilIdle();
1062 EXPECT_EQ(base::File::FILE_OK, status());
1063 1089
1064 EXPECT_EQ(1, change_observer()->get_and_reset_modify_file_count()); 1090 EXPECT_EQ(1, change_observer()->get_and_reset_modify_file_count());
1065 EXPECT_TRUE(change_observer()->HasNoChange()); 1091 EXPECT_TRUE(change_observer()->HasNoChange());
1066 1092
1067 // Check that its length is now 17 and that it's all zeroes after the test 1093 // Check that its length is now 17 and that it's all zeroes after the test
1068 // data. 1094 // data.
1069 EXPECT_EQ(length, GetFileSize("file")); 1095 EXPECT_EQ(length, GetFileSize("file"));
1070 char data[100]; 1096 char data[100];
1071 EXPECT_EQ(length, base::ReadFile(platform_path, data, length)); 1097 EXPECT_EQ(length, base::ReadFile(platform_path, data, length));
1072 for (int i = 0; i < length; ++i) { 1098 for (int i = 0; i < length; ++i) {
1073 if (i < static_cast<int>(sizeof(test_data))) 1099 if (i < static_cast<int>(sizeof(test_data)))
1074 EXPECT_EQ(test_data[i], data[i]); 1100 EXPECT_EQ(test_data[i], data[i]);
1075 else 1101 else
1076 EXPECT_EQ(0, data[i]); 1102 EXPECT_EQ(0, data[i]);
1077 } 1103 }
1078 1104
1079 // Shorten the file by truncating it. 1105 // Shorten the file by truncating it.
1080 length = 3; 1106 length = 3;
1081 operation_runner()->Truncate(file, length, RecordStatusCallback()); 1107 TruncateTest(file, length, base::File::FILE_OK);
1082 base::RunLoop().RunUntilIdle();
1083 EXPECT_EQ(base::File::FILE_OK, status());
1084 1108
1085 EXPECT_EQ(1, change_observer()->get_and_reset_modify_file_count()); 1109 EXPECT_EQ(1, change_observer()->get_and_reset_modify_file_count());
1086 EXPECT_TRUE(change_observer()->HasNoChange()); 1110 EXPECT_TRUE(change_observer()->HasNoChange());
1087 1111
1088 // Check that its length is now 3 and that it contains only bits of test data. 1112 // Check that its length is now 3 and that it contains only bits of test data.
1089 EXPECT_EQ(length, GetFileSize("file")); 1113 EXPECT_EQ(length, GetFileSize("file"));
1090 EXPECT_EQ(length, base::ReadFile(platform_path, data, length)); 1114 EXPECT_EQ(length, base::ReadFile(platform_path, data, length));
1091 for (int i = 0; i < length; ++i) 1115 for (int i = 0; i < length; ++i)
1092 EXPECT_EQ(test_data[i], data[i]); 1116 EXPECT_EQ(test_data[i], data[i]);
1093 1117
1094 // Truncate is not a 'read' access. (Here expected access count is 1 1118 // Truncate is not a 'read' access. (Here expected access count is 1
1095 // since we made 1 read access for GetMetadata.) 1119 // since we made 1 read access for GetMetadata.)
1096 EXPECT_EQ(1, quota_manager_proxy()->notify_storage_accessed_count()); 1120 EXPECT_EQ(1, quota_manager_proxy()->notify_storage_accessed_count());
1097 } 1121 }
1098 1122
1099 TEST_F(FileSystemOperationImplTest, TestTruncateFailureByQuota) { 1123 TEST_F(FileSystemOperationImplTest, TestTruncateFailureByQuota) {
1100 FileSystemURL dir(CreateDirectory("dir")); 1124 FileSystemURL dir(CreateDirectory("dir"));
1101 FileSystemURL file(CreateFile("dir/file")); 1125 FileSystemURL file(CreateFile("dir/file"));
1102 1126
1103 GrantQuotaForCurrentUsage(); 1127 GrantQuotaForCurrentUsage();
1104 AddQuota(10); 1128 AddQuota(10);
1105 1129
1106 operation_runner()->Truncate(file, 10, RecordStatusCallback()); 1130 TruncateTest(file, 10, base::File::FILE_OK);
1107 base::RunLoop().RunUntilIdle();
1108 EXPECT_EQ(base::File::FILE_OK, status());
1109 EXPECT_EQ(1, change_observer()->get_and_reset_modify_file_count()); 1131 EXPECT_EQ(1, change_observer()->get_and_reset_modify_file_count());
1110 EXPECT_TRUE(change_observer()->HasNoChange()); 1132 EXPECT_TRUE(change_observer()->HasNoChange());
1111 1133
1112 EXPECT_EQ(10, GetFileSize("dir/file")); 1134 EXPECT_EQ(10, GetFileSize("dir/file"));
1113 1135
1114 operation_runner()->Truncate(file, 11, RecordStatusCallback()); 1136 TruncateTest(file, 11, base::File::FILE_ERROR_NO_SPACE);
1115 base::RunLoop().RunUntilIdle();
1116 EXPECT_EQ(base::File::FILE_ERROR_NO_SPACE, status());
1117 EXPECT_TRUE(change_observer()->HasNoChange()); 1137 EXPECT_TRUE(change_observer()->HasNoChange());
1118 1138
1119 EXPECT_EQ(10, GetFileSize("dir/file")); 1139 EXPECT_EQ(10, GetFileSize("dir/file"));
1120 } 1140 }
1121 1141
1122 TEST_F(FileSystemOperationImplTest, TestTouchFile) { 1142 TEST_F(FileSystemOperationImplTest, TestTouchFile) {
1123 FileSystemURL file(CreateFile("file")); 1143 FileSystemURL file(CreateFile("file"));
1124 base::FilePath platform_path = PlatformPath("file"); 1144 base::FilePath platform_path = PlatformPath("file");
1125 1145
1126 base::File::Info info; 1146 base::File::Info info;
1127 EXPECT_TRUE(base::GetFileInfo(platform_path, &info)); 1147 EXPECT_TRUE(base::GetFileInfo(platform_path, &info));
1128 EXPECT_FALSE(info.is_directory); 1148 EXPECT_FALSE(info.is_directory);
1129 EXPECT_EQ(0, info.size); 1149 EXPECT_EQ(0, info.size);
1130 const base::Time last_modified = info.last_modified; 1150 const base::Time last_modified = info.last_modified;
1131 const base::Time last_accessed = info.last_accessed; 1151 const base::Time last_accessed = info.last_accessed;
1132 1152
1133 const base::Time new_modified_time = base::Time::UnixEpoch(); 1153 const base::Time new_modified_time = base::Time::UnixEpoch();
1134 const base::Time new_accessed_time = new_modified_time + 1154 const base::Time new_accessed_time = new_modified_time +
1135 base::TimeDelta::FromHours(77); 1155 base::TimeDelta::FromHours(77);
1136 ASSERT_NE(last_modified, new_modified_time); 1156 ASSERT_NE(last_modified, new_modified_time);
1137 ASSERT_NE(last_accessed, new_accessed_time); 1157 ASSERT_NE(last_accessed, new_accessed_time);
1138 1158
1139 operation_runner()->TouchFile(file, new_accessed_time, new_modified_time, 1159 TouchFileTest(file, new_accessed_time, new_modified_time,
1140 RecordStatusCallback()); 1160 base::File::FILE_OK);
1141 base::RunLoop().RunUntilIdle();
1142 EXPECT_EQ(base::File::FILE_OK, status());
1143 EXPECT_TRUE(change_observer()->HasNoChange()); 1161 EXPECT_TRUE(change_observer()->HasNoChange());
1144 1162
1145 EXPECT_TRUE(base::GetFileInfo(platform_path, &info)); 1163 EXPECT_TRUE(base::GetFileInfo(platform_path, &info));
1146 // We compare as time_t here to lower our resolution, to avoid false 1164 // We compare as time_t here to lower our resolution, to avoid false
1147 // negatives caused by conversion to the local filesystem's native 1165 // negatives caused by conversion to the local filesystem's native
1148 // representation and back. 1166 // representation and back.
1149 EXPECT_EQ(new_modified_time.ToTimeT(), info.last_modified.ToTimeT()); 1167 EXPECT_EQ(new_modified_time.ToTimeT(), info.last_modified.ToTimeT());
1150 EXPECT_EQ(new_accessed_time.ToTimeT(), info.last_accessed.ToTimeT()); 1168 EXPECT_EQ(new_accessed_time.ToTimeT(), info.last_accessed.ToTimeT());
1151 } 1169 }
1152 1170
1153 TEST_F(FileSystemOperationImplTest, TestCreateSnapshotFile) { 1171 TEST_F(FileSystemOperationImplTest, TestCreateSnapshotFile) {
1154 FileSystemURL dir(CreateDirectory("dir")); 1172 FileSystemURL dir(CreateDirectory("dir"));
1155 1173
1156 // Create a file for the testing. 1174 // Create a file for the testing.
1157 operation_runner()->DirectoryExists(dir, RecordStatusCallback()); 1175 DirectoryExistsTest(dir, base::File::FILE_OK);
1158 FileSystemURL file(CreateFile("dir/file")); 1176 FileSystemURL file(CreateFile("dir/file"));
1159 operation_runner()->FileExists(file, RecordStatusCallback()); 1177 FileExistsTest(file, base::File::FILE_OK);
1160 base::RunLoop().RunUntilIdle();
1161 EXPECT_EQ(base::File::FILE_OK, status());
1162 1178
1163 // See if we can get a 'snapshot' file info for the file. 1179 // See if we can get a 'snapshot' file info for the file.
1164 // Since FileSystemOperationImpl assumes the file exists in the local 1180 // Since FileSystemOperationImpl assumes the file exists in the local
1165 // directory it should just returns the same metadata and platform_path 1181 // directory it should just returns the same metadata and platform_path
1166 // as the file itself. 1182 // as the file itself.
1167 operation_runner()->CreateSnapshotFile(file, RecordSnapshotFileCallback()); 1183 CreateSnapshotFileTest(file);
1168 base::RunLoop().RunUntilIdle();
1169 EXPECT_EQ(base::File::FILE_OK, status()); 1184 EXPECT_EQ(base::File::FILE_OK, status());
1170 EXPECT_FALSE(info().is_directory); 1185 EXPECT_FALSE(info().is_directory);
1171 EXPECT_EQ(PlatformPath("dir/file"), path()); 1186 EXPECT_EQ(PlatformPath("dir/file"), path());
1172 EXPECT_TRUE(change_observer()->HasNoChange()); 1187 EXPECT_TRUE(change_observer()->HasNoChange());
1173 1188
1174 // The FileSystemOpration implementation does not create a 1189 // The FileSystemOpration implementation does not create a
1175 // shareable file reference. 1190 // shareable file reference.
1176 EXPECT_EQ(NULL, shareable_file_ref()); 1191 EXPECT_EQ(NULL, shareable_file_ref());
1177 } 1192 }
1178 1193
1179 TEST_F(FileSystemOperationImplTest, 1194 TEST_F(FileSystemOperationImplTest,
1180 TestMoveSuccessSrcDirRecursiveWithQuota) { 1195 TestMoveSuccessSrcDirRecursiveWithQuota) {
1181 FileSystemURL src(CreateDirectory("src")); 1196 FileSystemURL src(CreateDirectory("src"));
1182 int src_path_cost = GetUsage(); 1197 int src_path_cost = GetUsage();
1183 1198
1184 FileSystemURL dest(CreateDirectory("dest")); 1199 FileSystemURL dest(CreateDirectory("dest"));
1185 FileSystemURL child_file1(CreateFile("src/file1")); 1200 FileSystemURL child_file1(CreateFile("src/file1"));
1186 FileSystemURL child_file2(CreateFile("src/file2")); 1201 FileSystemURL child_file2(CreateFile("src/file2"));
1187 FileSystemURL child_dir(CreateDirectory("src/dir")); 1202 FileSystemURL child_dir(CreateDirectory("src/dir"));
1188 FileSystemURL grandchild_file1(CreateFile("src/dir/file1")); 1203 FileSystemURL grandchild_file1(CreateFile("src/dir/file1"));
1189 FileSystemURL grandchild_file2(CreateFile("src/dir/file2")); 1204 FileSystemURL grandchild_file2(CreateFile("src/dir/file2"));
1190 1205
1191 int total_path_cost = GetUsage(); 1206 int total_path_cost = GetUsage();
1192 EXPECT_EQ(0, GetDataSizeOnDisk()); 1207 EXPECT_EQ(0, GetDataSizeOnDisk());
1193 1208
1194 operation_runner()->Truncate( 1209 TruncateTest(child_file1, 5000, base::File::FILE_OK);
1195 child_file1, 5000, 1210 TruncateTest(child_file2, 400, base::File::FILE_OK);
1196 base::Bind(&AssertFileErrorEq, FROM_HERE, base::File::FILE_OK)); 1211 TruncateTest(grandchild_file1, 30, base::File::FILE_OK);
1197 operation_runner()->Truncate( 1212 TruncateTest(grandchild_file2, 2, base::File::FILE_OK);
1198 child_file2, 400,
1199 base::Bind(&AssertFileErrorEq, FROM_HERE, base::File::FILE_OK));
1200 operation_runner()->Truncate(
1201 grandchild_file1, 30,
1202 base::Bind(&AssertFileErrorEq, FROM_HERE, base::File::FILE_OK));
1203 operation_runner()->Truncate(
1204 grandchild_file2, 2,
1205 base::Bind(&AssertFileErrorEq, FROM_HERE, base::File::FILE_OK));
1206 base::RunLoop().RunUntilIdle();
1207 1213
1208 const int64 all_file_size = 5000 + 400 + 30 + 2; 1214 const int64 all_file_size = 5000 + 400 + 30 + 2;
1209 EXPECT_EQ(all_file_size, GetDataSizeOnDisk()); 1215 EXPECT_EQ(all_file_size, GetDataSizeOnDisk());
1210 EXPECT_EQ(all_file_size + total_path_cost, GetUsage()); 1216 EXPECT_EQ(all_file_size + total_path_cost, GetUsage());
1211 1217
1212 operation_runner()->Move( 1218 MoveTest(src, dest, FileSystemOperation::OPTION_NONE,
1213 src, dest, FileSystemOperation::OPTION_NONE, 1219 base::File::FILE_OK);
1214 base::Bind(&AssertFileErrorEq, FROM_HERE, base::File::FILE_OK));
1215 base::RunLoop().RunUntilIdle();
1216 1220
1217 EXPECT_FALSE(DirectoryExists("src/dir")); 1221 EXPECT_FALSE(DirectoryExists("src/dir"));
1218 EXPECT_FALSE(FileExists("src/dir/file2")); 1222 EXPECT_FALSE(FileExists("src/dir/file2"));
1219 EXPECT_TRUE(DirectoryExists("dest/dir")); 1223 EXPECT_TRUE(DirectoryExists("dest/dir"));
1220 EXPECT_TRUE(FileExists("dest/dir/file2")); 1224 EXPECT_TRUE(FileExists("dest/dir/file2"));
1221 1225
1222 EXPECT_EQ(all_file_size, GetDataSizeOnDisk()); 1226 EXPECT_EQ(all_file_size, GetDataSizeOnDisk());
1223 EXPECT_EQ(all_file_size + total_path_cost - src_path_cost, 1227 EXPECT_EQ(all_file_size + total_path_cost - src_path_cost,
1224 GetUsage()); 1228 GetUsage());
1225 } 1229 }
(...skipping 11 matching lines...) Expand all
1237 int64 child_path_cost = GetUsage() - usage; 1241 int64 child_path_cost = GetUsage() - usage;
1238 usage += child_path_cost; 1242 usage += child_path_cost;
1239 1243
1240 FileSystemURL grandchild_file1(CreateFile("src/dir/file1")); 1244 FileSystemURL grandchild_file1(CreateFile("src/dir/file1"));
1241 FileSystemURL grandchild_file2(CreateFile("src/dir/file2")); 1245 FileSystemURL grandchild_file2(CreateFile("src/dir/file2"));
1242 int64 total_path_cost = GetUsage(); 1246 int64 total_path_cost = GetUsage();
1243 int64 grandchild_path_cost = total_path_cost - usage; 1247 int64 grandchild_path_cost = total_path_cost - usage;
1244 1248
1245 EXPECT_EQ(0, GetDataSizeOnDisk()); 1249 EXPECT_EQ(0, GetDataSizeOnDisk());
1246 1250
1247 operation_runner()->Truncate( 1251 TruncateTest(child_file1, 8000, base::File::FILE_OK);
1248 child_file1, 8000, 1252 TruncateTest(child_file2, 700, base::File::FILE_OK);
1249 base::Bind(&AssertFileErrorEq, FROM_HERE, base::File::FILE_OK)); 1253 TruncateTest(grandchild_file1, 60, base::File::FILE_OK);
1250 operation_runner()->Truncate( 1254 TruncateTest(grandchild_file2, 5, base::File::FILE_OK);
1251 child_file2, 700,
1252 base::Bind(&AssertFileErrorEq, FROM_HERE, base::File::FILE_OK));
1253 operation_runner()->Truncate(
1254 grandchild_file1, 60,
1255 base::Bind(&AssertFileErrorEq, FROM_HERE, base::File::FILE_OK));
1256 operation_runner()->Truncate(
1257 grandchild_file2, 5,
1258 base::Bind(&AssertFileErrorEq, FROM_HERE, base::File::FILE_OK));
1259 base::RunLoop().RunUntilIdle();
1260 1255
1261 const int64 child_file_size = 8000 + 700; 1256 const int64 child_file_size = 8000 + 700;
1262 const int64 grandchild_file_size = 60 + 5; 1257 const int64 grandchild_file_size = 60 + 5;
1263 const int64 all_file_size = child_file_size + grandchild_file_size; 1258 const int64 all_file_size = child_file_size + grandchild_file_size;
1264 int64 expected_usage = all_file_size + total_path_cost; 1259 int64 expected_usage = all_file_size + total_path_cost;
1265 1260
1266 usage = GetUsage(); 1261 usage = GetUsage();
1267 EXPECT_EQ(all_file_size, GetDataSizeOnDisk()); 1262 EXPECT_EQ(all_file_size, GetDataSizeOnDisk());
1268 EXPECT_EQ(expected_usage, usage); 1263 EXPECT_EQ(expected_usage, usage);
1269 1264
1270 { 1265 CopyTest(src, dest1, FileSystemOperation::OPTION_NONE,
1271 base::RunLoop run_loop; 1266 base::File::FILE_OK);
1272 // Copy src to dest1.
1273 operation_runner()->Copy(src,
1274 dest1,
1275 FileSystemOperation::OPTION_NONE,
1276 FileSystemOperationRunner::CopyProgressCallback(),
1277 base::Bind(&AssertFileErrorEqWithClosure,
1278 FROM_HERE,
1279 base::File::FILE_OK,
1280 run_loop.QuitClosure()));
1281 run_loop.Run();
1282 }
1283 1267
1284 expected_usage += all_file_size + child_path_cost + grandchild_path_cost; 1268 expected_usage += all_file_size + child_path_cost + grandchild_path_cost;
1285 EXPECT_TRUE(DirectoryExists("src/dir")); 1269 EXPECT_TRUE(DirectoryExists("src/dir"));
1286 EXPECT_TRUE(FileExists("src/dir/file2")); 1270 EXPECT_TRUE(FileExists("src/dir/file2"));
1287 EXPECT_TRUE(DirectoryExists("dest1/dir")); 1271 EXPECT_TRUE(DirectoryExists("dest1/dir"));
1288 EXPECT_TRUE(FileExists("dest1/dir/file2")); 1272 EXPECT_TRUE(FileExists("dest1/dir/file2"));
1289 1273
1290 EXPECT_EQ(2 * all_file_size, GetDataSizeOnDisk()); 1274 EXPECT_EQ(2 * all_file_size, GetDataSizeOnDisk());
1291 EXPECT_EQ(expected_usage, GetUsage()); 1275 EXPECT_EQ(expected_usage, GetUsage());
1292 1276
1293 { 1277 CopyTest(child_dir, dest2, FileSystemOperation::OPTION_NONE,
1294 base::RunLoop run_loop; 1278 base::File::FILE_OK);
1295 // Copy src/dir to dest2.
1296 operation_runner()->Copy(child_dir,
1297 dest2,
1298 FileSystemOperation::OPTION_NONE,
1299 FileSystemOperationRunner::CopyProgressCallback(),
1300 base::Bind(&AssertFileErrorEqWithClosure,
1301 FROM_HERE,
1302 base::File::FILE_OK,
1303 run_loop.QuitClosure()));
1304 run_loop.Run();
1305 }
1306 1279
1307 expected_usage += grandchild_file_size + grandchild_path_cost; 1280 expected_usage += grandchild_file_size + grandchild_path_cost;
1308 usage = GetUsage(); 1281 usage = GetUsage();
1309 EXPECT_EQ(2 * child_file_size + 3 * grandchild_file_size, 1282 EXPECT_EQ(2 * child_file_size + 3 * grandchild_file_size,
1310 GetDataSizeOnDisk()); 1283 GetDataSizeOnDisk());
1311 EXPECT_EQ(expected_usage, usage); 1284 EXPECT_EQ(expected_usage, usage);
1312 } 1285 }
1313 1286
1314 TEST_F(FileSystemOperationImplTest, 1287 TEST_F(FileSystemOperationImplTest,
1315 TestCopySuccessSrcFileWithDifferentFileSize) { 1288 TestCopySuccessSrcFileWithDifferentFileSize) {
1316 FileSystemURL src_file(CreateFile("src")); 1289 FileSystemURL src_file(CreateFile("src"));
1317 FileSystemURL dest_file(CreateFile("dest")); 1290 FileSystemURL dest_file(CreateFile("dest"));
1318 1291
1319 { 1292 TruncateTest(dest_file, 6, base::File::FILE_OK);
1320 base::RunLoop run_loop; 1293 CopyTest(src_file, dest_file, FileSystemOperation::OPTION_NONE,
1321 operation_runner()->Truncate( 1294 base::File::FILE_OK);
1322 dest_file, 6,
1323 base::Bind(&AssertFileErrorEqWithClosure,
1324 FROM_HERE,
1325 base::File::FILE_OK,
1326 run_loop.QuitClosure()));
1327 run_loop.Run();
1328 }
1329
1330 {
1331 base::RunLoop run_loop;
1332 operation_runner()->Copy(
1333 src_file, dest_file, FileSystemOperation::OPTION_NONE,
1334 FileSystemOperationRunner::CopyProgressCallback(),
1335 base::Bind(&AssertFileErrorEqWithClosure,
1336 FROM_HERE,
1337 base::File::FILE_OK,
1338 run_loop.QuitClosure()));
1339 run_loop.Run();
1340 }
1341 EXPECT_EQ(0, GetFileSize("dest")); 1295 EXPECT_EQ(0, GetFileSize("dest"));
1342 } 1296 }
1343 1297
1344 } // namespace content 1298 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698