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

Side by Side Diff: chrome/browser/chromeos/gdata/gdata_file_system_unittest.cc

Issue 10545084: Move chromeos::GDataFileSystem::GetCacheDirectoryPath and GetCacheFilePath implementation to GDataC… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 293 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 bool RemoveEntry(const FilePath& file_path) { 304 bool RemoveEntry(const FilePath& file_path) {
305 return file_system_->RemoveEntryFromFileSystem(file_path) == 305 return file_system_->RemoveEntryFromFileSystem(file_path) ==
306 base::PLATFORM_FILE_OK; 306 base::PLATFORM_FILE_OK;
307 } 307 }
308 308
309 FilePath GetCachePathForFile(GDataFile* file) { 309 FilePath GetCachePathForFile(GDataFile* file) {
310 return file_system_->GetCacheFilePath( 310 return file_system_->GetCacheFilePath(
311 file->resource_id(), 311 file->resource_id(),
312 file->file_md5(), 312 file->file_md5(),
313 GDataCache::CACHE_TYPE_TMP, 313 GDataCache::CACHE_TYPE_TMP,
314 GDataFileSystem::CACHED_FILE_FROM_SERVER); 314 GDataCache::CACHED_FILE_FROM_SERVER);
315 } 315 }
316 316
317 GDataEntry* FindEntry(const FilePath& file_path) { 317 GDataEntry* FindEntry(const FilePath& file_path) {
318 GDataEntry* entry = NULL; 318 GDataEntry* entry = NULL;
319 file_system_->root_->FindEntryByPath( 319 file_system_->root_->FindEntryByPath(
320 file_path, base::Bind(&ReadOnlyFindEntryCallback, &entry)); 320 file_path, base::Bind(&ReadOnlyFindEntryCallback, &entry));
321 return entry; 321 return entry;
322 } 322 }
323 323
324 void FindAndTestFilePath(const FilePath& file_path) { 324 void FindAndTestFilePath(const FilePath& file_path) {
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
407 scoped_ptr<GDataDirectoryProto> directory_proto = 407 scoped_ptr<GDataDirectoryProto> directory_proto =
408 callback_helper_->directory_proto_.Pass(); 408 callback_helper_->directory_proto_.Pass();
409 return (directory->resource_id() == 409 return (directory->resource_id() ==
410 directory_proto->gdata_entry().resource_id()); 410 directory_proto->gdata_entry().resource_id());
411 } 411 }
412 412
413 FilePath GetCacheFilePath( 413 FilePath GetCacheFilePath(
414 const std::string& resource_id, 414 const std::string& resource_id,
415 const std::string& md5, 415 const std::string& md5,
416 GDataCache::CacheSubDirectoryType sub_dir_type, 416 GDataCache::CacheSubDirectoryType sub_dir_type,
417 GDataFileSystem::CachedFileOrigin file_origin) { 417 GDataCache::CachedFileOrigin file_origin) {
418 return file_system_->GetCacheFilePath(resource_id, md5, sub_dir_type, 418 return file_system_->GetCacheFilePath(resource_id, md5, sub_dir_type,
419 file_origin); 419 file_origin);
420 } 420 }
421 421
422 // Returns true if the cache entry exists for the given resource ID and MD5. 422 // Returns true if the cache entry exists for the given resource ID and MD5.
423 bool CacheEntryExists(const std::string& resource_id, 423 bool CacheEntryExists(const std::string& resource_id,
424 const std::string& md5) { 424 const std::string& md5) {
425 return file_system_->cache_->GetCacheEntry(resource_id, md5).get(); 425 return file_system_->cache_->GetCacheEntry(resource_id, md5).get();
426 } 426 }
427 427
428 // Returns true if the cache file exists for the given resource ID and MD5. 428 // Returns true if the cache file exists for the given resource ID and MD5.
429 bool CacheFileExists(const std::string& resource_id, 429 bool CacheFileExists(const std::string& resource_id,
430 const std::string& md5) { 430 const std::string& md5) {
431 const FilePath file_path = file_system_->GetCacheFilePath( 431 const FilePath file_path = file_system_->GetCacheFilePath(
432 resource_id, 432 resource_id,
433 md5, 433 md5,
434 GDataCache::CACHE_TYPE_TMP, 434 GDataCache::CACHE_TYPE_TMP,
435 GDataFileSystem::CACHED_FILE_FROM_SERVER); 435 GDataCache::CACHED_FILE_FROM_SERVER);
436 return file_util::PathExists(file_path); 436 return file_util::PathExists(file_path);
437 } 437 }
438 438
439 void TestGetCacheFilePath(const std::string& resource_id, 439 void TestGetCacheFilePath(const std::string& resource_id,
440 const std::string& md5, 440 const std::string& md5,
441 const std::string& expected_filename) { 441 const std::string& expected_filename) {
442 FilePath actual_path = file_system_->GetCacheFilePath( 442 FilePath actual_path = file_system_->GetCacheFilePath(
443 resource_id, 443 resource_id,
444 md5, 444 md5,
445 GDataCache::CACHE_TYPE_TMP, 445 GDataCache::CACHE_TYPE_TMP,
446 GDataFileSystem::CACHED_FILE_FROM_SERVER); 446 GDataCache::CACHED_FILE_FROM_SERVER);
447 FilePath expected_path = 447 FilePath expected_path =
448 file_system_->cache_paths_[GDataCache::CACHE_TYPE_TMP]; 448 file_system_->cache_->cache_paths()[GDataCache::CACHE_TYPE_TMP];
449 expected_path = expected_path.Append(expected_filename); 449 expected_path = expected_path.Append(expected_filename);
450 EXPECT_EQ(expected_path, actual_path); 450 EXPECT_EQ(expected_path, actual_path);
451 451
452 FilePath base_name = actual_path.BaseName(); 452 FilePath base_name = actual_path.BaseName();
453 453
454 // FilePath::Extension returns ".", so strip it. 454 // FilePath::Extension returns ".", so strip it.
455 std::string unescaped_md5 = util::UnescapeCacheFileName( 455 std::string unescaped_md5 = util::UnescapeCacheFileName(
456 base_name.Extension().substr(1)); 456 base_name.Extension().substr(1));
457 EXPECT_EQ(md5, unescaped_md5); 457 EXPECT_EQ(md5, unescaped_md5);
458 std::string unescaped_resource_id = util::UnescapeCacheFileName( 458 std::string unescaped_resource_id = util::UnescapeCacheFileName(
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
540 if (cache_entry.get()) 540 if (cache_entry.get())
541 EXPECT_TRUE(cache_entry->IsDirty()); 541 EXPECT_TRUE(cache_entry->IsDirty());
542 542
543 // If entry doesn't exist, verify that: 543 // If entry doesn't exist, verify that:
544 // - no files with "<resource_id>.* exists in persistent and tmp dirs 544 // - no files with "<resource_id>.* exists in persistent and tmp dirs
545 // - no "<resource_id>" symlink exists in pinned and outgoing dirs. 545 // - no "<resource_id>" symlink exists in pinned and outgoing dirs.
546 std::vector<PathToVerify> paths_to_verify; 546 std::vector<PathToVerify> paths_to_verify;
547 paths_to_verify.push_back( // Index 0: CACHE_TYPE_TMP. 547 paths_to_verify.push_back( // Index 0: CACHE_TYPE_TMP.
548 PathToVerify(file_system_->GetCacheFilePath(resource_id, "*", 548 PathToVerify(file_system_->GetCacheFilePath(resource_id, "*",
549 GDataCache::CACHE_TYPE_TMP, 549 GDataCache::CACHE_TYPE_TMP,
550 GDataFileSystem::CACHED_FILE_FROM_SERVER), FilePath())); 550 GDataCache::CACHED_FILE_FROM_SERVER), FilePath()));
551 paths_to_verify.push_back( // Index 1: CACHE_TYPE_PERSISTENT. 551 paths_to_verify.push_back( // Index 1: CACHE_TYPE_PERSISTENT.
552 PathToVerify(file_system_->GetCacheFilePath(resource_id, "*", 552 PathToVerify(file_system_->GetCacheFilePath(resource_id, "*",
553 GDataCache::CACHE_TYPE_PERSISTENT, 553 GDataCache::CACHE_TYPE_PERSISTENT,
554 GDataFileSystem::CACHED_FILE_FROM_SERVER), FilePath())); 554 GDataCache::CACHED_FILE_FROM_SERVER), FilePath()));
555 paths_to_verify.push_back( // Index 2: CACHE_TYPE_PINNED. 555 paths_to_verify.push_back( // Index 2: CACHE_TYPE_PINNED.
556 PathToVerify(file_system_->GetCacheFilePath(resource_id, "", 556 PathToVerify(file_system_->GetCacheFilePath(resource_id, "",
557 GDataCache::CACHE_TYPE_PINNED, 557 GDataCache::CACHE_TYPE_PINNED,
558 GDataFileSystem::CACHED_FILE_FROM_SERVER), FilePath())); 558 GDataCache::CACHED_FILE_FROM_SERVER), FilePath()));
559 paths_to_verify.push_back( // Index 3: CACHE_TYPE_OUTGOING. 559 paths_to_verify.push_back( // Index 3: CACHE_TYPE_OUTGOING.
560 PathToVerify(file_system_->GetCacheFilePath(resource_id, "", 560 PathToVerify(file_system_->GetCacheFilePath(resource_id, "",
561 GDataCache::CACHE_TYPE_OUTGOING, 561 GDataCache::CACHE_TYPE_OUTGOING,
562 GDataFileSystem::CACHED_FILE_FROM_SERVER), FilePath())); 562 GDataCache::CACHED_FILE_FROM_SERVER), FilePath()));
563 if (!cache_entry.get()) { 563 if (!cache_entry.get()) {
564 for (size_t i = 0; i < paths_to_verify.size(); ++i) { 564 for (size_t i = 0; i < paths_to_verify.size(); ++i) {
565 file_util::FileEnumerator enumerator( 565 file_util::FileEnumerator enumerator(
566 paths_to_verify[i].path_to_scan.DirName(), false /* not recursive*/, 566 paths_to_verify[i].path_to_scan.DirName(), false /* not recursive*/,
567 static_cast<file_util::FileEnumerator::FileType>( 567 static_cast<file_util::FileEnumerator::FileType>(
568 file_util::FileEnumerator::FILES | 568 file_util::FileEnumerator::FILES |
569 file_util::FileEnumerator::SHOW_SYM_LINKS), 569 file_util::FileEnumerator::SHOW_SYM_LINKS),
570 paths_to_verify[i].path_to_scan.BaseName().value()); 570 paths_to_verify[i].path_to_scan.BaseName().value());
571 EXPECT_TRUE(enumerator.Next().empty()); 571 EXPECT_TRUE(enumerator.Next().empty());
572 } 572 }
573 } else { 573 } else {
574 // Entry is dirty, verify that: 574 // Entry is dirty, verify that:
575 // - no files with "<resource_id>.*" exist in tmp dir 575 // - no files with "<resource_id>.*" exist in tmp dir
576 // - only 1 "<resource_id>.local" exists in persistent dir 576 // - only 1 "<resource_id>.local" exists in persistent dir
577 // - only 1 <resource_id> exists in outgoing dir 577 // - only 1 <resource_id> exists in outgoing dir
578 // - if entry is pinned, only 1 <resource_id> exists in pinned dir. 578 // - if entry is pinned, only 1 <resource_id> exists in pinned dir.
579 579
580 // Change expected_existing_path of CACHE_TYPE_PERSISTENT (index 1). 580 // Change expected_existing_path of CACHE_TYPE_PERSISTENT (index 1).
581 paths_to_verify[1].expected_existing_path = 581 paths_to_verify[1].expected_existing_path =
582 GetCacheFilePath(resource_id, 582 GetCacheFilePath(resource_id,
583 std::string(), 583 std::string(),
584 GDataCache::CACHE_TYPE_PERSISTENT, 584 GDataCache::CACHE_TYPE_PERSISTENT,
585 GDataFileSystem::CACHED_FILE_LOCALLY_MODIFIED); 585 GDataCache::CACHED_FILE_LOCALLY_MODIFIED);
586 586
587 // Change expected_existing_path of CACHE_TYPE_OUTGOING (index 3). 587 // Change expected_existing_path of CACHE_TYPE_OUTGOING (index 3).
588 paths_to_verify[3].expected_existing_path = 588 paths_to_verify[3].expected_existing_path =
589 GetCacheFilePath(resource_id, 589 GetCacheFilePath(resource_id,
590 std::string(), 590 std::string(),
591 GDataCache::CACHE_TYPE_OUTGOING, 591 GDataCache::CACHE_TYPE_OUTGOING,
592 GDataFileSystem::CACHED_FILE_FROM_SERVER); 592 GDataCache::CACHED_FILE_FROM_SERVER);
593 593
594 if (cache_entry->IsPinned()) { 594 if (cache_entry->IsPinned()) {
595 // Change expected_existing_path of CACHE_TYPE_PINNED (index 2). 595 // Change expected_existing_path of CACHE_TYPE_PINNED (index 2).
596 paths_to_verify[2].expected_existing_path = 596 paths_to_verify[2].expected_existing_path =
597 GetCacheFilePath(resource_id, 597 GetCacheFilePath(resource_id,
598 std::string(), 598 std::string(),
599 GDataCache::CACHE_TYPE_PINNED, 599 GDataCache::CACHE_TYPE_PINNED,
600 GDataFileSystem::CACHED_FILE_FROM_SERVER); 600 GDataCache::CACHED_FILE_FROM_SERVER);
601 } 601 }
602 602
603 for (size_t i = 0; i < paths_to_verify.size(); ++i) { 603 for (size_t i = 0; i < paths_to_verify.size(); ++i) {
604 const struct PathToVerify& verify = paths_to_verify[i]; 604 const struct PathToVerify& verify = paths_to_verify[i];
605 file_util::FileEnumerator enumerator( 605 file_util::FileEnumerator enumerator(
606 verify.path_to_scan.DirName(), false /* not recursive*/, 606 verify.path_to_scan.DirName(), false /* not recursive*/,
607 static_cast<file_util::FileEnumerator::FileType>( 607 static_cast<file_util::FileEnumerator::FileType>(
608 file_util::FileEnumerator::FILES | 608 file_util::FileEnumerator::FILES |
609 file_util::FileEnumerator::SHOW_SYM_LINKS), 609 file_util::FileEnumerator::SHOW_SYM_LINKS),
610 verify.path_to_scan.BaseName().value()); 610 verify.path_to_scan.BaseName().value());
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
785 bool to_mount, 785 bool to_mount,
786 base::PlatformFileError error, 786 base::PlatformFileError error,
787 const FilePath& file_path) { 787 const FilePath& file_path) {
788 ++num_callback_invocations_; 788 ++num_callback_invocations_;
789 EXPECT_TRUE(file_util::PathExists(file_path)); 789 EXPECT_TRUE(file_util::PathExists(file_path));
790 EXPECT_TRUE(file_path == file_system_->GetCacheFilePath( 790 EXPECT_TRUE(file_path == file_system_->GetCacheFilePath(
791 resource_id, 791 resource_id,
792 md5, 792 md5,
793 expected_sub_dir_type_, 793 expected_sub_dir_type_,
794 to_mount ? 794 to_mount ?
795 GDataFileSystemInterface::CACHED_FILE_MOUNTED : 795 GDataCache::CACHED_FILE_MOUNTED :
796 GDataFileSystemInterface::CACHED_FILE_FROM_SERVER)); 796 GDataCache::CACHED_FILE_FROM_SERVER));
797 } 797 }
798 798
799 void TestSetMountedState( 799 void TestSetMountedState(
800 const std::string& resource_id, 800 const std::string& resource_id,
801 const std::string& md5, 801 const std::string& md5,
802 const FilePath& file_path, 802 const FilePath& file_path,
803 bool to_mount, 803 bool to_mount,
804 base::PlatformFileError expected_error, 804 base::PlatformFileError expected_error,
805 int expected_cache_state, 805 int expected_cache_state,
806 GDataCache::CacheSubDirectoryType expected_sub_dir_type) { 806 GDataCache::CacheSubDirectoryType expected_sub_dir_type) {
807 expected_error_ = expected_error; 807 expected_error_ = expected_error;
808 expected_cache_state_ = expected_cache_state; 808 expected_cache_state_ = expected_cache_state;
809 expected_sub_dir_type_ = expected_sub_dir_type; 809 expected_sub_dir_type_ = expected_sub_dir_type;
810 expect_outgoing_symlink_ = false; 810 expect_outgoing_symlink_ = false;
811 811
812 file_system_->SetMountedState(file_path, to_mount, 812 file_system_->SetMountedState(file_path, to_mount,
813 base::Bind(&GDataFileSystemTest::VerifySetMountedState, 813 base::Bind(&GDataFileSystemTest::VerifySetMountedState,
814 base::Unretained(this), resource_id, md5, to_mount)); 814 base::Unretained(this), resource_id, md5, to_mount));
815 815
816 RunAllPendingForIO(); 816 RunAllPendingForIO();
817 } 817 }
818 818
819 void PrepareForInitCacheTest() { 819 void PrepareForInitCacheTest() {
820 RunAllPendingForIO(); // Allow InitializeCacheOnBlockingPool to finish. 820 RunAllPendingForIO(); // Allow InitializeCacheOnBlockingPool to finish.
821 821
822 DVLOG(1) << "PrepareForInitCacheTest start"; 822 DVLOG(1) << "PrepareForInitCacheTest start";
823 // Create gdata cache sub directories. 823 // Create gdata cache sub directories.
824 ASSERT_TRUE(file_util::CreateDirectory( 824 ASSERT_TRUE(file_util::CreateDirectory(
825 file_system_->cache_paths_[GDataCache::CACHE_TYPE_PERSISTENT])); 825 file_system_->cache_->cache_paths()[
826 GDataCache::CACHE_TYPE_PERSISTENT]));
826 ASSERT_TRUE(file_util::CreateDirectory( 827 ASSERT_TRUE(file_util::CreateDirectory(
827 file_system_->cache_paths_[GDataCache::CACHE_TYPE_TMP])); 828 file_system_->cache_->cache_paths()[GDataCache::CACHE_TYPE_TMP]));
828 ASSERT_TRUE(file_util::CreateDirectory( 829 ASSERT_TRUE(file_util::CreateDirectory(
829 file_system_->cache_paths_[GDataCache::CACHE_TYPE_PINNED])); 830 file_system_->cache_->cache_paths()[GDataCache::CACHE_TYPE_PINNED]));
830 ASSERT_TRUE(file_util::CreateDirectory( 831 ASSERT_TRUE(file_util::CreateDirectory(
831 file_system_->cache_paths_[GDataCache::CACHE_TYPE_OUTGOING])); 832 file_system_->cache_->cache_paths()[GDataCache::CACHE_TYPE_OUTGOING]));
832 833
833 // Dump some files into cache dirs so that 834 // Dump some files into cache dirs so that
834 // GDataFileSystem::InitializeCacheOnBlockingPool would scan through them 835 // GDataFileSystem::InitializeCacheOnBlockingPool would scan through them
835 // and populate cache map accordingly. 836 // and populate cache map accordingly.
836 837
837 // Copy files from data dir to cache dir to act as cached files. 838 // Copy files from data dir to cache dir to act as cached files.
838 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(initial_cache_resources); ++i) { 839 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(initial_cache_resources); ++i) {
839 const struct InitialCacheResource& resource = initial_cache_resources[i]; 840 const struct InitialCacheResource& resource = initial_cache_resources[i];
840 // Determine gdata cache file absolute path according to cache state. 841 // Determine gdata cache file absolute path according to cache state.
841 FilePath dest_path = file_system_->GetCacheFilePath( 842 FilePath dest_path = file_system_->GetCacheFilePath(
842 resource.resource_id, 843 resource.resource_id,
843 resource.md5, 844 resource.md5,
844 GDataCache::IsCachePinned(resource.cache_state) || 845 GDataCache::IsCachePinned(resource.cache_state) ||
845 GDataCache::IsCacheDirty(resource.cache_state) ? 846 GDataCache::IsCacheDirty(resource.cache_state) ?
846 GDataCache::CACHE_TYPE_PERSISTENT : 847 GDataCache::CACHE_TYPE_PERSISTENT :
847 GDataCache::CACHE_TYPE_TMP, 848 GDataCache::CACHE_TYPE_TMP,
848 GDataCache::IsCacheDirty(resource.cache_state) ? 849 GDataCache::IsCacheDirty(resource.cache_state) ?
849 GDataFileSystem::CACHED_FILE_LOCALLY_MODIFIED : 850 GDataCache::CACHED_FILE_LOCALLY_MODIFIED :
850 GDataFileSystem::CACHED_FILE_FROM_SERVER); 851 GDataCache::CACHED_FILE_FROM_SERVER);
851 852
852 // Copy file from data dir to cache subdir, naming it per cache files 853 // Copy file from data dir to cache subdir, naming it per cache files
853 // convention. 854 // convention.
854 if (GDataCache::IsCachePresent(resource.cache_state)) { 855 if (GDataCache::IsCachePresent(resource.cache_state)) {
855 FilePath source_path = GetTestFilePath(resource.source_file); 856 FilePath source_path = GetTestFilePath(resource.source_file);
856 ASSERT_TRUE(file_util::CopyFile(source_path, dest_path)); 857 ASSERT_TRUE(file_util::CopyFile(source_path, dest_path));
857 } else { 858 } else {
858 dest_path = FilePath(FILE_PATH_LITERAL(kSymLinkToDevNull)); 859 dest_path = FilePath(FILE_PATH_LITERAL(kSymLinkToDevNull));
859 } 860 }
860 861
861 // Create symbolic link in pinned dir, naming it per cache files 862 // Create symbolic link in pinned dir, naming it per cache files
862 // convention. 863 // convention.
863 if (GDataCache::IsCachePinned(resource.cache_state)) { 864 if (GDataCache::IsCachePinned(resource.cache_state)) {
864 FilePath link_path = file_system_->GetCacheFilePath( 865 FilePath link_path = file_system_->GetCacheFilePath(
865 resource.resource_id, 866 resource.resource_id,
866 "", 867 "",
867 GDataCache::CACHE_TYPE_PINNED, 868 GDataCache::CACHE_TYPE_PINNED,
868 GDataFileSystem::CACHED_FILE_FROM_SERVER); 869 GDataCache::CACHED_FILE_FROM_SERVER);
869 ASSERT_TRUE(file_util::CreateSymbolicLink(dest_path, link_path)); 870 ASSERT_TRUE(file_util::CreateSymbolicLink(dest_path, link_path));
870 } 871 }
871 872
872 // Create symbolic link in outgoing dir, naming it per cache files 873 // Create symbolic link in outgoing dir, naming it per cache files
873 // convention. 874 // convention.
874 if (GDataCache::IsCacheDirty(resource.cache_state)) { 875 if (GDataCache::IsCacheDirty(resource.cache_state)) {
875 FilePath link_path = file_system_->GetCacheFilePath( 876 FilePath link_path = file_system_->GetCacheFilePath(
876 resource.resource_id, 877 resource.resource_id,
877 "", 878 "",
878 GDataCache::CACHE_TYPE_OUTGOING, 879 GDataCache::CACHE_TYPE_OUTGOING,
879 GDataFileSystem::CACHED_FILE_FROM_SERVER); 880 GDataCache::CACHED_FILE_FROM_SERVER);
880 ASSERT_TRUE(file_util::CreateSymbolicLink(dest_path, link_path)); 881 ASSERT_TRUE(file_util::CreateSymbolicLink(dest_path, link_path));
881 } 882 }
882 } 883 }
883 DVLOG(1) << "PrepareForInitCacheTest finished"; 884 DVLOG(1) << "PrepareForInitCacheTest finished";
884 // Temporarily remove the mock sync client while rescanning. Otherwise, 885 // Temporarily remove the mock sync client while rescanning. Otherwise,
885 // OnCacheInitialized() is called again here, which breaks the 886 // OnCacheInitialized() is called again here, which breaks the
886 // expectation set in SetUp(). 887 // expectation set in SetUp().
887 file_system_->RemoveObserver(mock_sync_client_.get()); 888 file_system_->RemoveObserver(mock_sync_client_.get());
888 file_system_->RequestInitializeCacheForTesting(); // Force a re-scan. 889 file_system_->RequestInitializeCacheForTesting(); // Force a re-scan.
889 RunAllPendingForIO(); // Wait until the initialization is done. 890 RunAllPendingForIO(); // Wait until the initialization is done.
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
937 938
938 // Verify actual cache file. 939 // Verify actual cache file.
939 FilePath dest_path = file_system_->GetCacheFilePath( 940 FilePath dest_path = file_system_->GetCacheFilePath(
940 resource_id, 941 resource_id,
941 md5, 942 md5,
942 GDataCache::IsCachePinned(expected_cache_state_) || 943 GDataCache::IsCachePinned(expected_cache_state_) ||
943 GDataCache::IsCacheDirty(expected_cache_state_) ? 944 GDataCache::IsCacheDirty(expected_cache_state_) ?
944 GDataCache::CACHE_TYPE_PERSISTENT : 945 GDataCache::CACHE_TYPE_PERSISTENT :
945 GDataCache::CACHE_TYPE_TMP, 946 GDataCache::CACHE_TYPE_TMP,
946 GDataCache::IsCacheDirty(expected_cache_state_) ? 947 GDataCache::IsCacheDirty(expected_cache_state_) ?
947 GDataFileSystem::CACHED_FILE_LOCALLY_MODIFIED : 948 GDataCache::CACHED_FILE_LOCALLY_MODIFIED :
948 GDataFileSystem::CACHED_FILE_FROM_SERVER); 949 GDataCache::CACHED_FILE_FROM_SERVER);
949 bool exists = file_util::PathExists(dest_path); 950 bool exists = file_util::PathExists(dest_path);
950 if (GDataCache::IsCachePresent(expected_cache_state_)) 951 if (GDataCache::IsCachePresent(expected_cache_state_))
951 EXPECT_TRUE(exists); 952 EXPECT_TRUE(exists);
952 else 953 else
953 EXPECT_FALSE(exists); 954 EXPECT_FALSE(exists);
954 955
955 // Verify symlink in pinned dir. 956 // Verify symlink in pinned dir.
956 FilePath symlink_path = file_system_->GetCacheFilePath( 957 FilePath symlink_path = file_system_->GetCacheFilePath(
957 resource_id, 958 resource_id,
958 std::string(), 959 std::string(),
959 GDataCache::CACHE_TYPE_PINNED, 960 GDataCache::CACHE_TYPE_PINNED,
960 GDataFileSystem::CACHED_FILE_FROM_SERVER); 961 GDataCache::CACHED_FILE_FROM_SERVER);
961 // Check that pin symlink exists, without deferencing to target path. 962 // Check that pin symlink exists, without deferencing to target path.
962 exists = file_util::IsLink(symlink_path); 963 exists = file_util::IsLink(symlink_path);
963 if (GDataCache::IsCachePinned(expected_cache_state_)) { 964 if (GDataCache::IsCachePinned(expected_cache_state_)) {
964 EXPECT_TRUE(exists); 965 EXPECT_TRUE(exists);
965 FilePath target_path; 966 FilePath target_path;
966 EXPECT_TRUE(file_util::ReadSymbolicLink(symlink_path, &target_path)); 967 EXPECT_TRUE(file_util::ReadSymbolicLink(symlink_path, &target_path));
967 if (GDataCache::IsCachePresent(expected_cache_state_)) 968 if (GDataCache::IsCachePresent(expected_cache_state_))
968 EXPECT_EQ(dest_path, target_path); 969 EXPECT_EQ(dest_path, target_path);
969 else 970 else
970 EXPECT_EQ(kSymLinkToDevNull, target_path.value()); 971 EXPECT_EQ(kSymLinkToDevNull, target_path.value());
971 } else { 972 } else {
972 EXPECT_FALSE(exists); 973 EXPECT_FALSE(exists);
973 } 974 }
974 975
975 // Verify symlink in outgoing dir. 976 // Verify symlink in outgoing dir.
976 symlink_path = file_system_->GetCacheFilePath( 977 symlink_path = file_system_->GetCacheFilePath(
977 resource_id, 978 resource_id,
978 std::string(), 979 std::string(),
979 GDataCache::CACHE_TYPE_OUTGOING, 980 GDataCache::CACHE_TYPE_OUTGOING,
980 GDataFileSystem::CACHED_FILE_FROM_SERVER); 981 GDataCache::CACHED_FILE_FROM_SERVER);
981 // Check that outgoing symlink exists, without deferencing to target path. 982 // Check that outgoing symlink exists, without deferencing to target path.
982 exists = file_util::IsLink(symlink_path); 983 exists = file_util::IsLink(symlink_path);
983 if (expect_outgoing_symlink_ && 984 if (expect_outgoing_symlink_ &&
984 GDataCache::IsCacheDirty(expected_cache_state_)) { 985 GDataCache::IsCacheDirty(expected_cache_state_)) {
985 EXPECT_TRUE(exists); 986 EXPECT_TRUE(exists);
986 FilePath target_path; 987 FilePath target_path;
987 EXPECT_TRUE(file_util::ReadSymbolicLink(symlink_path, &target_path)); 988 EXPECT_TRUE(file_util::ReadSymbolicLink(symlink_path, &target_path));
988 EXPECT_TRUE(target_path.value() != kSymLinkToDevNull); 989 EXPECT_TRUE(target_path.value() != kSymLinkToDevNull);
989 if (GDataCache::IsCachePresent(expected_cache_state_)) 990 if (GDataCache::IsCachePresent(expected_cache_state_))
990 EXPECT_EQ(dest_path, target_path); 991 EXPECT_EQ(dest_path, target_path);
(...skipping 1347 matching lines...) Expand 10 before | Expand all | Expand 10 after
2338 base::PLATFORM_FILE_OK, GDataCache::CACHE_STATE_PRESENT, 2339 base::PLATFORM_FILE_OK, GDataCache::CACHE_STATE_PRESENT,
2339 GDataCache::CACHE_TYPE_TMP); 2340 GDataCache::CACHE_TYPE_TMP);
2340 EXPECT_EQ(1, num_callback_invocations_); 2341 EXPECT_EQ(1, num_callback_invocations_);
2341 2342
2342 // Verify that there's only one file with name <resource_id>, i.e. previously 2343 // Verify that there's only one file with name <resource_id>, i.e. previously
2343 // cached file with the different md5 should be deleted. 2344 // cached file with the different md5 should be deleted.
2344 FilePath path = GetCacheFilePath(resource_id, "*", 2345 FilePath path = GetCacheFilePath(resource_id, "*",
2345 (GDataCache::IsCachePinned(expected_cache_state_)) ? 2346 (GDataCache::IsCachePinned(expected_cache_state_)) ?
2346 GDataCache::CACHE_TYPE_PERSISTENT : 2347 GDataCache::CACHE_TYPE_PERSISTENT :
2347 GDataCache::CACHE_TYPE_TMP, 2348 GDataCache::CACHE_TYPE_TMP,
2348 GDataFileSystem::CACHED_FILE_FROM_SERVER); 2349 GDataCache::CACHED_FILE_FROM_SERVER);
2349 file_util::FileEnumerator enumerator(path.DirName(), false, 2350 file_util::FileEnumerator enumerator(path.DirName(), false,
2350 file_util::FileEnumerator::FILES, 2351 file_util::FileEnumerator::FILES,
2351 path.BaseName().value()); 2352 path.BaseName().value());
2352 size_t num_files_found = 0; 2353 size_t num_files_found = 0;
2353 for (FilePath current = enumerator.Next(); !current.empty(); 2354 for (FilePath current = enumerator.Next(); !current.empty();
2354 current = enumerator.Next()) { 2355 current = enumerator.Next()) {
2355 ++num_files_found; 2356 ++num_files_found;
2356 EXPECT_EQ(util::EscapeCacheFileName(resource_id) + 2357 EXPECT_EQ(util::EscapeCacheFileName(resource_id) +
2357 FilePath::kExtensionSeparator + 2358 FilePath::kExtensionSeparator +
2358 util::EscapeCacheFileName(md5), 2359 util::EscapeCacheFileName(md5),
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after
2665 GDataCache::CACHE_TYPE_TMP); 2666 GDataCache::CACHE_TYPE_TMP);
2666 TestMarkDirty(resource_id, md5, base::PLATFORM_FILE_OK, 2667 TestMarkDirty(resource_id, md5, base::PLATFORM_FILE_OK,
2667 GDataCache::CACHE_STATE_PRESENT | GDataCache::CACHE_STATE_DIRTY, 2668 GDataCache::CACHE_STATE_PRESENT | GDataCache::CACHE_STATE_DIRTY,
2668 GDataCache::CACHE_TYPE_PERSISTENT); 2669 GDataCache::CACHE_TYPE_PERSISTENT);
2669 2670
2670 // Verifies dirty file exists. 2671 // Verifies dirty file exists.
2671 FilePath dirty_path = GetCacheFilePath( 2672 FilePath dirty_path = GetCacheFilePath(
2672 resource_id, 2673 resource_id,
2673 md5, 2674 md5,
2674 GDataCache::CACHE_TYPE_PERSISTENT, 2675 GDataCache::CACHE_TYPE_PERSISTENT,
2675 GDataFileSystem::CACHED_FILE_LOCALLY_MODIFIED); 2676 GDataCache::CACHED_FILE_LOCALLY_MODIFIED);
2676 EXPECT_TRUE(file_util::PathExists(dirty_path)); 2677 EXPECT_TRUE(file_util::PathExists(dirty_path));
2677 2678
2678 // Pin the dirty file. 2679 // Pin the dirty file.
2679 TestPin(resource_id, md5, base::PLATFORM_FILE_OK, 2680 TestPin(resource_id, md5, base::PLATFORM_FILE_OK,
2680 GDataCache::CACHE_STATE_PRESENT | GDataCache::CACHE_STATE_DIRTY | 2681 GDataCache::CACHE_STATE_PRESENT | GDataCache::CACHE_STATE_DIRTY |
2681 GDataCache::CACHE_STATE_PINNED, 2682 GDataCache::CACHE_STATE_PINNED,
2682 GDataCache::CACHE_TYPE_PERSISTENT); 2683 GDataCache::CACHE_TYPE_PERSISTENT);
2683 2684
2684 // Verify dirty file still exist at the same pathname. 2685 // Verify dirty file still exist at the same pathname.
2685 EXPECT_TRUE(file_util::PathExists(dirty_path)); 2686 EXPECT_TRUE(file_util::PathExists(dirty_path));
(...skipping 1012 matching lines...) Expand 10 before | Expand all | Expand 10 after
3698 // First store a file to cache in the tmp subdir. 3699 // First store a file to cache in the tmp subdir.
3699 TestStoreToCache(resource_id, md5, GetTestFilePath("root_feed.json"), 3700 TestStoreToCache(resource_id, md5, GetTestFilePath("root_feed.json"),
3700 base::PLATFORM_FILE_OK, GDataCache::CACHE_STATE_PRESENT, 3701 base::PLATFORM_FILE_OK, GDataCache::CACHE_STATE_PRESENT,
3701 GDataCache::CACHE_TYPE_TMP); 3702 GDataCache::CACHE_TYPE_TMP);
3702 3703
3703 // Mark the file mounted. 3704 // Mark the file mounted.
3704 num_callback_invocations_ = 0; 3705 num_callback_invocations_ = 0;
3705 file_path = file_system_->GetCacheFilePath( 3706 file_path = file_system_->GetCacheFilePath(
3706 resource_id, md5, 3707 resource_id, md5,
3707 GDataCache::CACHE_TYPE_TMP, 3708 GDataCache::CACHE_TYPE_TMP,
3708 GDataFileSystemInterface::CACHED_FILE_FROM_SERVER); 3709 GDataCache::CACHED_FILE_FROM_SERVER);
3709 TestSetMountedState(resource_id, md5, file_path, true, 3710 TestSetMountedState(resource_id, md5, file_path, true,
3710 base::PLATFORM_FILE_OK, 3711 base::PLATFORM_FILE_OK,
3711 GDataCache::CACHE_STATE_PRESENT | 3712 GDataCache::CACHE_STATE_PRESENT |
3712 GDataCache::CACHE_STATE_MOUNTED, 3713 GDataCache::CACHE_STATE_MOUNTED,
3713 GDataCache::CACHE_TYPE_PERSISTENT); 3714 GDataCache::CACHE_TYPE_PERSISTENT);
3714 EXPECT_EQ(1, num_callback_invocations_); 3715 EXPECT_EQ(1, num_callback_invocations_);
3715 EXPECT_TRUE(CacheEntryExists(resource_id, md5)); 3716 EXPECT_TRUE(CacheEntryExists(resource_id, md5));
3716 3717
3717 // Clear mounted state of the file. 3718 // Clear mounted state of the file.
3718 num_callback_invocations_ = 0; 3719 num_callback_invocations_ = 0;
3719 file_path = file_system_->GetCacheFilePath( 3720 file_path = file_system_->GetCacheFilePath(
3720 resource_id, 3721 resource_id,
3721 md5, 3722 md5,
3722 GDataCache::CACHE_TYPE_PERSISTENT, 3723 GDataCache::CACHE_TYPE_PERSISTENT,
3723 GDataFileSystemInterface::CACHED_FILE_MOUNTED); 3724 GDataCache::CACHED_FILE_MOUNTED);
3724 TestSetMountedState(resource_id, md5, file_path, false, 3725 TestSetMountedState(resource_id, md5, file_path, false,
3725 base::PLATFORM_FILE_OK, 3726 base::PLATFORM_FILE_OK,
3726 GDataCache::CACHE_STATE_PRESENT, 3727 GDataCache::CACHE_STATE_PRESENT,
3727 GDataCache::CACHE_TYPE_TMP); 3728 GDataCache::CACHE_TYPE_TMP);
3728 EXPECT_EQ(1, num_callback_invocations_); 3729 EXPECT_EQ(1, num_callback_invocations_);
3729 EXPECT_TRUE(CacheEntryExists(resource_id, md5)); 3730 EXPECT_TRUE(CacheEntryExists(resource_id, md5));
3730 3731
3731 // Try to remove the file. 3732 // Try to remove the file.
3732 num_callback_invocations_ = 0; 3733 num_callback_invocations_ = 0;
3733 TestRemoveFromCache(resource_id, base::PLATFORM_FILE_OK); 3734 TestRemoveFromCache(resource_id, base::PLATFORM_FILE_OK);
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
3814 // Verify that the file was properly closed. 3815 // Verify that the file was properly closed.
3815 EXPECT_EQ(base::PLATFORM_FILE_OK, callback_helper_->last_error_); 3816 EXPECT_EQ(base::PLATFORM_FILE_OK, callback_helper_->last_error_);
3816 3817
3817 // Verify that the cache state was changed as expected. 3818 // Verify that the cache state was changed as expected.
3818 VerifyCacheStateAfterCloseFile(callback_helper_->last_error_, 3819 VerifyCacheStateAfterCloseFile(callback_helper_->last_error_,
3819 file_resource_id, 3820 file_resource_id,
3820 file_md5); 3821 file_md5);
3821 } 3822 }
3822 3823
3823 } // namespace gdata 3824 } // namespace gdata
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698