| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <errno.h> | 5 #include <errno.h> |
| 6 #include <string> | 6 #include <string> |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| (...skipping 464 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 475 | 475 |
| 476 cache_->StoreOnUIThread( | 476 cache_->StoreOnUIThread( |
| 477 resource_id, md5, source_path, | 477 resource_id, md5, source_path, |
| 478 GDataCache::FILE_OPERATION_COPY, | 478 GDataCache::FILE_OPERATION_COPY, |
| 479 base::Bind(&GDataFileSystemTest::VerifyCacheFileState, | 479 base::Bind(&GDataFileSystemTest::VerifyCacheFileState, |
| 480 base::Unretained(this))); | 480 base::Unretained(this))); |
| 481 | 481 |
| 482 test_util::RunBlockingPoolTask(); | 482 test_util::RunBlockingPoolTask(); |
| 483 } | 483 } |
| 484 | 484 |
| 485 void TestRemoveFromCache(const std::string& resource_id, | |
| 486 base::PlatformFileError expected_error) { | |
| 487 expected_error_ = expected_error; | |
| 488 | |
| 489 cache_->RemoveOnUIThread( | |
| 490 resource_id, | |
| 491 base::Bind(&GDataFileSystemTest::VerifyRemoveFromCache, | |
| 492 base::Unretained(this))); | |
| 493 | |
| 494 test_util::RunBlockingPoolTask(); | |
| 495 } | |
| 496 | |
| 497 void VerifyRemoveFromCache(base::PlatformFileError error, | |
| 498 const std::string& resource_id, | |
| 499 const std::string& md5) { | |
| 500 ++num_callback_invocations_; | |
| 501 | |
| 502 EXPECT_EQ(expected_error_, error); | |
| 503 | |
| 504 // Verify cache map. | |
| 505 scoped_ptr<GDataCacheEntry> cache_entry = | |
| 506 GetCacheEntryFromOriginThread(resource_id, md5); | |
| 507 if (cache_entry.get()) | |
| 508 EXPECT_TRUE(cache_entry->IsDirty()); | |
| 509 | |
| 510 // If entry doesn't exist, verify that: | |
| 511 // - no files with "<resource_id>.* exists in persistent and tmp dirs | |
| 512 // - no "<resource_id>" symlink exists in pinned and outgoing dirs. | |
| 513 std::vector<PathToVerify> paths_to_verify; | |
| 514 paths_to_verify.push_back( // Index 0: CACHE_TYPE_TMP. | |
| 515 PathToVerify(cache_->GetCacheFilePath(resource_id, "*", | |
| 516 GDataCache::CACHE_TYPE_TMP, | |
| 517 GDataCache::CACHED_FILE_FROM_SERVER), FilePath())); | |
| 518 paths_to_verify.push_back( // Index 1: CACHE_TYPE_PERSISTENT. | |
| 519 PathToVerify(cache_->GetCacheFilePath(resource_id, "*", | |
| 520 GDataCache::CACHE_TYPE_PERSISTENT, | |
| 521 GDataCache::CACHED_FILE_FROM_SERVER), FilePath())); | |
| 522 paths_to_verify.push_back( // Index 2: CACHE_TYPE_PINNED. | |
| 523 PathToVerify(cache_->GetCacheFilePath(resource_id, "", | |
| 524 GDataCache::CACHE_TYPE_PINNED, | |
| 525 GDataCache::CACHED_FILE_FROM_SERVER), FilePath())); | |
| 526 paths_to_verify.push_back( // Index 3: CACHE_TYPE_OUTGOING. | |
| 527 PathToVerify(cache_->GetCacheFilePath(resource_id, "", | |
| 528 GDataCache::CACHE_TYPE_OUTGOING, | |
| 529 GDataCache::CACHED_FILE_FROM_SERVER), FilePath())); | |
| 530 if (!cache_entry.get()) { | |
| 531 for (size_t i = 0; i < paths_to_verify.size(); ++i) { | |
| 532 file_util::FileEnumerator enumerator( | |
| 533 paths_to_verify[i].path_to_scan.DirName(), false /* not recursive*/, | |
| 534 static_cast<file_util::FileEnumerator::FileType>( | |
| 535 file_util::FileEnumerator::FILES | | |
| 536 file_util::FileEnumerator::SHOW_SYM_LINKS), | |
| 537 paths_to_verify[i].path_to_scan.BaseName().value()); | |
| 538 EXPECT_TRUE(enumerator.Next().empty()); | |
| 539 } | |
| 540 } else { | |
| 541 // Entry is dirty, verify that: | |
| 542 // - no files with "<resource_id>.*" exist in tmp dir | |
| 543 // - only 1 "<resource_id>.local" exists in persistent dir | |
| 544 // - only 1 <resource_id> exists in outgoing dir | |
| 545 // - if entry is pinned, only 1 <resource_id> exists in pinned dir. | |
| 546 | |
| 547 // Change expected_existing_path of CACHE_TYPE_PERSISTENT (index 1). | |
| 548 paths_to_verify[1].expected_existing_path = | |
| 549 GetCacheFilePath(resource_id, | |
| 550 std::string(), | |
| 551 GDataCache::CACHE_TYPE_PERSISTENT, | |
| 552 GDataCache::CACHED_FILE_LOCALLY_MODIFIED); | |
| 553 | |
| 554 // Change expected_existing_path of CACHE_TYPE_OUTGOING (index 3). | |
| 555 paths_to_verify[3].expected_existing_path = | |
| 556 GetCacheFilePath(resource_id, | |
| 557 std::string(), | |
| 558 GDataCache::CACHE_TYPE_OUTGOING, | |
| 559 GDataCache::CACHED_FILE_FROM_SERVER); | |
| 560 | |
| 561 if (cache_entry->IsPinned()) { | |
| 562 // Change expected_existing_path of CACHE_TYPE_PINNED (index 2). | |
| 563 paths_to_verify[2].expected_existing_path = | |
| 564 GetCacheFilePath(resource_id, | |
| 565 std::string(), | |
| 566 GDataCache::CACHE_TYPE_PINNED, | |
| 567 GDataCache::CACHED_FILE_FROM_SERVER); | |
| 568 } | |
| 569 | |
| 570 for (size_t i = 0; i < paths_to_verify.size(); ++i) { | |
| 571 const struct PathToVerify& verify = paths_to_verify[i]; | |
| 572 file_util::FileEnumerator enumerator( | |
| 573 verify.path_to_scan.DirName(), false /* not recursive*/, | |
| 574 static_cast<file_util::FileEnumerator::FileType>( | |
| 575 file_util::FileEnumerator::FILES | | |
| 576 file_util::FileEnumerator::SHOW_SYM_LINKS), | |
| 577 verify.path_to_scan.BaseName().value()); | |
| 578 size_t num_files_found = 0; | |
| 579 for (FilePath current = enumerator.Next(); !current.empty(); | |
| 580 current = enumerator.Next()) { | |
| 581 ++num_files_found; | |
| 582 EXPECT_EQ(verify.expected_existing_path, current); | |
| 583 } | |
| 584 if (verify.expected_existing_path.empty()) | |
| 585 EXPECT_EQ(0U, num_files_found); | |
| 586 else | |
| 587 EXPECT_EQ(1U, num_files_found); | |
| 588 } | |
| 589 } | |
| 590 } | |
| 591 | |
| 592 void TestPin( | 485 void TestPin( |
| 593 const std::string& resource_id, | 486 const std::string& resource_id, |
| 594 const std::string& md5, | 487 const std::string& md5, |
| 595 base::PlatformFileError expected_error, | 488 base::PlatformFileError expected_error, |
| 596 int expected_cache_state, | 489 int expected_cache_state, |
| 597 GDataCache::CacheSubDirectoryType expected_sub_dir_type) { | 490 GDataCache::CacheSubDirectoryType expected_sub_dir_type) { |
| 598 expected_error_ = expected_error; | 491 expected_error_ = expected_error; |
| 599 expected_cache_state_ = expected_cache_state; | 492 expected_cache_state_ = expected_cache_state; |
| 600 expected_sub_dir_type_ = expected_sub_dir_type; | 493 expected_sub_dir_type_ = expected_sub_dir_type; |
| 601 | 494 |
| (...skipping 2030 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2632 | 2525 |
| 2633 // Try to close the same file twice. | 2526 // Try to close the same file twice. |
| 2634 file_system_->CloseFile(kFileInRoot, close_file_callback); | 2527 file_system_->CloseFile(kFileInRoot, close_file_callback); |
| 2635 message_loop_.Run(); | 2528 message_loop_.Run(); |
| 2636 | 2529 |
| 2637 // It must fail. | 2530 // It must fail. |
| 2638 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, callback_helper_->last_error_); | 2531 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, callback_helper_->last_error_); |
| 2639 } | 2532 } |
| 2640 | 2533 |
| 2641 } // namespace gdata | 2534 } // namespace gdata |
| OLD | NEW |