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

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

Issue 10692154: gdata: Remove IsCache/SetCache/ClearCache* functions from GDataCache (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: address comments Created 8 years, 5 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 "base/file_util.h" 5 #include "base/file_util.h"
6 #include "base/json/json_file_value_serializer.h" 6 #include "base/json/json_file_value_serializer.h"
7 #include "base/message_loop.h" 7 #include "base/message_loop.h"
8 #include "base/path_service.h" 8 #include "base/path_service.h"
9 #include "chrome/browser/chromeos/cros/cros_library.h" 9 #include "chrome/browser/chromeos/cros/cros_library.h"
10 #include "chrome/browser/chromeos/gdata/drive_webapps_registry.h" 10 #include "chrome/browser/chromeos/gdata/drive_webapps_registry.h"
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 struct PathToVerify { 83 struct PathToVerify {
84 PathToVerify(const FilePath& in_path_to_scan, 84 PathToVerify(const FilePath& in_path_to_scan,
85 const FilePath& in_expected_existing_path) : 85 const FilePath& in_expected_existing_path) :
86 path_to_scan(in_path_to_scan), 86 path_to_scan(in_path_to_scan),
87 expected_existing_path(in_expected_existing_path) { 87 expected_existing_path(in_expected_existing_path) {
88 } 88 }
89 89
90 FilePath path_to_scan; 90 FilePath path_to_scan;
91 FilePath expected_existing_path; 91 FilePath expected_existing_path;
92 }; 92 };
93 } // anonymous namespace 93
94 // Converts |cache_state| to a GDataCache::CacheEntry.
95 GDataCache::CacheEntry ToCacheEntry(int cache_state) {
96 return GDataCache::CacheEntry("dummy_md5", cache_state);
97 }
98
99 } // namespace
94 100
95 class MockFreeDiskSpaceGetter : public FreeDiskSpaceGetterInterface { 101 class MockFreeDiskSpaceGetter : public FreeDiskSpaceGetterInterface {
96 public: 102 public:
97 virtual ~MockFreeDiskSpaceGetter() {} 103 virtual ~MockFreeDiskSpaceGetter() {}
98 MOCK_CONST_METHOD0(AmountOfFreeDiskSpace, int64()); 104 MOCK_CONST_METHOD0(AmountOfFreeDiskSpace, int64());
99 }; 105 };
100 106
101 class MockGDataUploader : public GDataUploaderInterface { 107 class MockGDataUploader : public GDataUploaderInterface {
102 public: 108 public:
103 virtual ~MockGDataUploader() {} 109 virtual ~MockGDataUploader() {}
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 // GDataFileSystem::InitializeCacheOnBlockingPool would scan through them 268 // GDataFileSystem::InitializeCacheOnBlockingPool would scan through them
263 // and populate cache map accordingly. 269 // and populate cache map accordingly.
264 270
265 // Copy files from data dir to cache dir to act as cached files. 271 // Copy files from data dir to cache dir to act as cached files.
266 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(initial_cache_resources); ++i) { 272 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(initial_cache_resources); ++i) {
267 const struct InitialCacheResource& resource = initial_cache_resources[i]; 273 const struct InitialCacheResource& resource = initial_cache_resources[i];
268 // Determine gdata cache file absolute path according to cache state. 274 // Determine gdata cache file absolute path according to cache state.
269 FilePath dest_path = cache_->GetCacheFilePath( 275 FilePath dest_path = cache_->GetCacheFilePath(
270 resource.resource_id, 276 resource.resource_id,
271 resource.md5, 277 resource.md5,
272 GDataCache::IsCachePinned(resource.cache_state) || 278 ToCacheEntry(resource.cache_state).IsPinned() ||
273 GDataCache::IsCacheDirty(resource.cache_state) ? 279 ToCacheEntry(resource.cache_state).IsDirty() ?
274 GDataCache::CACHE_TYPE_PERSISTENT : 280 GDataCache::CACHE_TYPE_PERSISTENT :
275 GDataCache::CACHE_TYPE_TMP, 281 GDataCache::CACHE_TYPE_TMP,
276 GDataCache::IsCacheDirty(resource.cache_state) ? 282 ToCacheEntry(resource.cache_state).IsDirty() ?
277 GDataCache::CACHED_FILE_LOCALLY_MODIFIED : 283 GDataCache::CACHED_FILE_LOCALLY_MODIFIED :
278 GDataCache::CACHED_FILE_FROM_SERVER); 284 GDataCache::CACHED_FILE_FROM_SERVER);
279 285
280 // Copy file from data dir to cache subdir, naming it per cache files 286 // Copy file from data dir to cache subdir, naming it per cache files
281 // convention. 287 // convention.
282 if (GDataCache::IsCachePresent(resource.cache_state)) { 288 if (ToCacheEntry(resource.cache_state).IsPresent()) {
283 FilePath source_path = GetTestFilePath(resource.source_file); 289 FilePath source_path = GetTestFilePath(resource.source_file);
284 ASSERT_TRUE(file_util::CopyFile(source_path, dest_path)); 290 ASSERT_TRUE(file_util::CopyFile(source_path, dest_path));
285 } else { 291 } else {
286 dest_path = FilePath(FILE_PATH_LITERAL(kSymLinkToDevNull)); 292 dest_path = FilePath(FILE_PATH_LITERAL(kSymLinkToDevNull));
287 } 293 }
288 294
289 // Create symbolic link in pinned dir, naming it per cache files 295 // Create symbolic link in pinned dir, naming it per cache files
290 // convention. 296 // convention.
291 if (GDataCache::IsCachePinned(resource.cache_state)) { 297 if (ToCacheEntry(resource.cache_state).IsPinned()) {
292 FilePath link_path = cache_->GetCacheFilePath( 298 FilePath link_path = cache_->GetCacheFilePath(
293 resource.resource_id, 299 resource.resource_id,
294 "", 300 "",
295 GDataCache::CACHE_TYPE_PINNED, 301 GDataCache::CACHE_TYPE_PINNED,
296 GDataCache::CACHED_FILE_FROM_SERVER); 302 GDataCache::CACHED_FILE_FROM_SERVER);
297 ASSERT_TRUE(file_util::CreateSymbolicLink(dest_path, link_path)); 303 ASSERT_TRUE(file_util::CreateSymbolicLink(dest_path, link_path));
298 } 304 }
299 305
300 // Create symbolic link in outgoing dir, naming it per cache files 306 // Create symbolic link in outgoing dir, naming it per cache files
301 // convention. 307 // convention.
302 if (GDataCache::IsCacheDirty(resource.cache_state)) { 308 if (ToCacheEntry(resource.cache_state).IsDirty()) {
303 FilePath link_path = cache_->GetCacheFilePath( 309 FilePath link_path = cache_->GetCacheFilePath(
304 resource.resource_id, 310 resource.resource_id,
305 "", 311 "",
306 GDataCache::CACHE_TYPE_OUTGOING, 312 GDataCache::CACHE_TYPE_OUTGOING,
307 GDataCache::CACHED_FILE_FROM_SERVER); 313 GDataCache::CACHED_FILE_FROM_SERVER);
308 ASSERT_TRUE(file_util::CreateSymbolicLink(dest_path, link_path)); 314 ASSERT_TRUE(file_util::CreateSymbolicLink(dest_path, link_path));
309 } 315 }
310 } 316 }
311 DVLOG(1) << "PrepareForInitCacheTest finished"; 317 DVLOG(1) << "PrepareForInitCacheTest finished";
312 cache_->RequestInitializeOnUIThread(); // Force a re-scan. 318 cache_->RequestInitializeOnUIThread(); // Force a re-scan.
313 test_util::RunBlockingPoolTask(); 319 test_util::RunBlockingPoolTask();
314 } 320 }
315 321
316 void TestInitializeCache() { 322 void TestInitializeCache() {
317 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(initial_cache_resources); ++i) { 323 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(initial_cache_resources); ++i) {
318 const struct InitialCacheResource& resource = initial_cache_resources[i]; 324 const struct InitialCacheResource& resource = initial_cache_resources[i];
319 // Check cache file. 325 // Check cache file.
320 num_callback_invocations_ = 0; 326 num_callback_invocations_ = 0;
321 TestGetFileFromCacheByResourceIdAndMd5( 327 TestGetFileFromCacheByResourceIdAndMd5(
322 resource.resource_id, 328 resource.resource_id,
323 resource.md5, 329 resource.md5,
324 GDataCache::IsCachePresent(resource.cache_state) ? 330 ToCacheEntry(resource.cache_state).IsPresent() ?
325 base::PLATFORM_FILE_OK : 331 base::PLATFORM_FILE_OK :
326 base::PLATFORM_FILE_ERROR_NOT_FOUND, 332 base::PLATFORM_FILE_ERROR_NOT_FOUND,
327 resource.expected_file_extension); 333 resource.expected_file_extension);
328 EXPECT_EQ(1, num_callback_invocations_); 334 EXPECT_EQ(1, num_callback_invocations_);
329 335
330 // Verify cache state. 336 // Verify cache state.
331 std::string md5; 337 std::string md5;
332 if (GDataCache::IsCachePresent(resource.cache_state)) 338 if (ToCacheEntry(resource.cache_state).IsPresent())
333 md5 = resource.md5; 339 md5 = resource.md5;
334 scoped_ptr<GDataCache::CacheEntry> cache_entry = 340 scoped_ptr<GDataCache::CacheEntry> cache_entry =
335 GetCacheEntryFromOriginThread(resource.resource_id, md5); 341 GetCacheEntryFromOriginThread(resource.resource_id, md5);
336 ASSERT_TRUE(cache_entry.get()); 342 ASSERT_TRUE(cache_entry.get());
337 EXPECT_EQ(resource.cache_state, cache_entry->cache_state); 343 EXPECT_EQ(resource.cache_state, cache_entry->cache_state);
338 EXPECT_EQ(resource.expected_sub_dir_type, 344 EXPECT_EQ(resource.expected_sub_dir_type,
339 cache_entry->GetSubDirectoryType()); 345 cache_entry->GetSubDirectoryType());
340 } 346 }
341 } 347 }
342 348
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after
681 void VerifyCacheFileState(base::PlatformFileError error, 687 void VerifyCacheFileState(base::PlatformFileError error,
682 const std::string& resource_id, 688 const std::string& resource_id,
683 const std::string& md5) { 689 const std::string& md5) {
684 ++num_callback_invocations_; 690 ++num_callback_invocations_;
685 691
686 EXPECT_EQ(expected_error_, error); 692 EXPECT_EQ(expected_error_, error);
687 693
688 // Verify cache map. 694 // Verify cache map.
689 scoped_ptr<GDataCache::CacheEntry> cache_entry = 695 scoped_ptr<GDataCache::CacheEntry> cache_entry =
690 GetCacheEntryFromOriginThread(resource_id, md5); 696 GetCacheEntryFromOriginThread(resource_id, md5);
691 if (GDataCache::IsCachePresent(expected_cache_state_) || 697 if (ToCacheEntry(expected_cache_state_).IsPresent() ||
692 GDataCache::IsCachePinned(expected_cache_state_)) { 698 ToCacheEntry(expected_cache_state_).IsPinned()) {
693 ASSERT_TRUE(cache_entry.get()); 699 ASSERT_TRUE(cache_entry.get());
694 EXPECT_EQ(expected_cache_state_, cache_entry->cache_state); 700 EXPECT_EQ(expected_cache_state_, cache_entry->cache_state);
695 EXPECT_EQ(expected_sub_dir_type_, cache_entry->GetSubDirectoryType()); 701 EXPECT_EQ(expected_sub_dir_type_, cache_entry->GetSubDirectoryType());
696 } else { 702 } else {
697 EXPECT_FALSE(cache_entry.get()); 703 EXPECT_FALSE(cache_entry.get());
698 } 704 }
699 705
700 // Verify actual cache file. 706 // Verify actual cache file.
701 FilePath dest_path = cache_->GetCacheFilePath( 707 FilePath dest_path = cache_->GetCacheFilePath(
702 resource_id, 708 resource_id,
703 md5, 709 md5,
704 GDataCache::IsCachePinned(expected_cache_state_) || 710 ToCacheEntry(expected_cache_state_).IsPinned() ||
705 GDataCache::IsCacheDirty(expected_cache_state_) ? 711 ToCacheEntry(expected_cache_state_).IsDirty() ?
706 GDataCache::CACHE_TYPE_PERSISTENT : 712 GDataCache::CACHE_TYPE_PERSISTENT :
707 GDataCache::CACHE_TYPE_TMP, 713 GDataCache::CACHE_TYPE_TMP,
708 GDataCache::IsCacheDirty(expected_cache_state_) ? 714 ToCacheEntry(expected_cache_state_).IsDirty() ?
709 GDataCache::CACHED_FILE_LOCALLY_MODIFIED : 715 GDataCache::CACHED_FILE_LOCALLY_MODIFIED :
710 GDataCache::CACHED_FILE_FROM_SERVER); 716 GDataCache::CACHED_FILE_FROM_SERVER);
711 bool exists = file_util::PathExists(dest_path); 717 bool exists = file_util::PathExists(dest_path);
712 if (GDataCache::IsCachePresent(expected_cache_state_)) 718 if (ToCacheEntry(expected_cache_state_).IsPresent())
713 EXPECT_TRUE(exists); 719 EXPECT_TRUE(exists);
714 else 720 else
715 EXPECT_FALSE(exists); 721 EXPECT_FALSE(exists);
716 722
717 // Verify symlink in pinned dir. 723 // Verify symlink in pinned dir.
718 FilePath symlink_path = cache_->GetCacheFilePath( 724 FilePath symlink_path = cache_->GetCacheFilePath(
719 resource_id, 725 resource_id,
720 std::string(), 726 std::string(),
721 GDataCache::CACHE_TYPE_PINNED, 727 GDataCache::CACHE_TYPE_PINNED,
722 GDataCache::CACHED_FILE_FROM_SERVER); 728 GDataCache::CACHED_FILE_FROM_SERVER);
723 // Check that pin symlink exists, without deferencing to target path. 729 // Check that pin symlink exists, without deferencing to target path.
724 exists = file_util::IsLink(symlink_path); 730 exists = file_util::IsLink(symlink_path);
725 if (GDataCache::IsCachePinned(expected_cache_state_)) { 731 if (ToCacheEntry(expected_cache_state_).IsPinned()) {
726 EXPECT_TRUE(exists); 732 EXPECT_TRUE(exists);
727 FilePath target_path; 733 FilePath target_path;
728 EXPECT_TRUE(file_util::ReadSymbolicLink(symlink_path, &target_path)); 734 EXPECT_TRUE(file_util::ReadSymbolicLink(symlink_path, &target_path));
729 if (GDataCache::IsCachePresent(expected_cache_state_)) 735 if (ToCacheEntry(expected_cache_state_).IsPresent())
730 EXPECT_EQ(dest_path, target_path); 736 EXPECT_EQ(dest_path, target_path);
731 else 737 else
732 EXPECT_EQ(kSymLinkToDevNull, target_path.value()); 738 EXPECT_EQ(kSymLinkToDevNull, target_path.value());
733 } else { 739 } else {
734 EXPECT_FALSE(exists); 740 EXPECT_FALSE(exists);
735 } 741 }
736 742
737 // Verify symlink in outgoing dir. 743 // Verify symlink in outgoing dir.
738 symlink_path = cache_->GetCacheFilePath( 744 symlink_path = cache_->GetCacheFilePath(
739 resource_id, 745 resource_id,
740 std::string(), 746 std::string(),
741 GDataCache::CACHE_TYPE_OUTGOING, 747 GDataCache::CACHE_TYPE_OUTGOING,
742 GDataCache::CACHED_FILE_FROM_SERVER); 748 GDataCache::CACHED_FILE_FROM_SERVER);
743 // Check that outgoing symlink exists, without deferencing to target path. 749 // Check that outgoing symlink exists, without deferencing to target path.
744 exists = file_util::IsLink(symlink_path); 750 exists = file_util::IsLink(symlink_path);
745 if (expect_outgoing_symlink_ && 751 if (expect_outgoing_symlink_ &&
746 GDataCache::IsCacheDirty(expected_cache_state_)) { 752 ToCacheEntry(expected_cache_state_).IsDirty()) {
747 EXPECT_TRUE(exists); 753 EXPECT_TRUE(exists);
748 FilePath target_path; 754 FilePath target_path;
749 EXPECT_TRUE(file_util::ReadSymbolicLink(symlink_path, &target_path)); 755 EXPECT_TRUE(file_util::ReadSymbolicLink(symlink_path, &target_path));
750 EXPECT_TRUE(target_path.value() != kSymLinkToDevNull); 756 EXPECT_TRUE(target_path.value() != kSymLinkToDevNull);
751 if (GDataCache::IsCachePresent(expected_cache_state_)) 757 if (ToCacheEntry(expected_cache_state_).IsPresent())
752 EXPECT_EQ(dest_path, target_path); 758 EXPECT_EQ(dest_path, target_path);
753 } else { 759 } else {
754 EXPECT_FALSE(exists); 760 EXPECT_FALSE(exists);
755 } 761 }
756 } 762 }
757 763
758 FilePath GetCacheFilePath(const std::string& resource_id, 764 FilePath GetCacheFilePath(const std::string& resource_id,
759 const std::string& md5, 765 const std::string& md5,
760 GDataCache::CacheSubDirectoryType sub_dir_type, 766 GDataCache::CacheSubDirectoryType sub_dir_type,
761 GDataCache::CachedFileOrigin file_origin) { 767 GDataCache::CachedFileOrigin file_origin) {
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
865 bool expect_outgoing_symlink_; 871 bool expect_outgoing_symlink_;
866 std::string expected_file_extension_; 872 std::string expected_file_extension_;
867 int root_feed_changestamp_; 873 int root_feed_changestamp_;
868 }; 874 };
869 875
870 TEST_F(GDataCacheTest, InitializeCache) { 876 TEST_F(GDataCacheTest, InitializeCache) {
871 PrepareForInitCacheTest(); 877 PrepareForInitCacheTest();
872 TestInitializeCache(); 878 TestInitializeCache();
873 } 879 }
874 880
875 TEST_F(GDataCacheTest, CacheStateBitmasks) { 881 TEST_F(GDataCacheTest, CacheEntry_Is) {
876 GDataCache::CacheEntry cache_entry("md5_cache_state_bitmasks", 882 GDataCache::CacheEntry cache_entry("dummy_md5", GDataCache::CACHE_STATE_NONE);
877 GDataCache::CACHE_STATE_NONE);
878 EXPECT_FALSE(cache_entry.IsPresent()); 883 EXPECT_FALSE(cache_entry.IsPresent());
879 EXPECT_FALSE(cache_entry.IsPinned()); 884 EXPECT_FALSE(cache_entry.IsPinned());
880 EXPECT_FALSE(cache_entry.IsDirty()); 885 EXPECT_FALSE(cache_entry.IsDirty());
886 EXPECT_FALSE(cache_entry.IsMounted());
887 EXPECT_FALSE(cache_entry.IsPersistent());
881 888
882 cache_entry.cache_state = GDataCache::CACHE_STATE_PRESENT; 889 cache_entry.cache_state = GDataCache::CACHE_STATE_PRESENT;
883 EXPECT_TRUE(cache_entry.IsPresent()); 890 EXPECT_TRUE(cache_entry.IsPresent());
884 EXPECT_FALSE(cache_entry.IsPinned()); 891 EXPECT_FALSE(cache_entry.IsPinned());
885 EXPECT_FALSE(cache_entry.IsDirty()); 892 EXPECT_FALSE(cache_entry.IsDirty());
893 EXPECT_FALSE(cache_entry.IsMounted());
894 EXPECT_FALSE(cache_entry.IsPersistent());
886 895
887 cache_entry.cache_state = GDataCache::CACHE_STATE_PINNED; 896 cache_entry.cache_state |= GDataCache::CACHE_STATE_PINNED;
888 EXPECT_FALSE(cache_entry.IsPresent());
889 EXPECT_TRUE(cache_entry.IsPinned());
890 EXPECT_FALSE(cache_entry.IsDirty());
891
892 cache_entry.cache_state = GDataCache::CACHE_STATE_PRESENT |
893 GDataCache::CACHE_STATE_PINNED;
894 EXPECT_TRUE(cache_entry.IsPresent()); 897 EXPECT_TRUE(cache_entry.IsPresent());
895 EXPECT_TRUE(cache_entry.IsPinned()); 898 EXPECT_TRUE(cache_entry.IsPinned());
896 EXPECT_FALSE(cache_entry.IsDirty()); 899 EXPECT_FALSE(cache_entry.IsDirty());
900 EXPECT_FALSE(cache_entry.IsMounted());
901 EXPECT_FALSE(cache_entry.IsPersistent());
897 902
898 cache_entry.cache_state = GDataCache::CACHE_STATE_PRESENT | 903 cache_entry.cache_state |= GDataCache::CACHE_STATE_DIRTY;
899 GDataCache::CACHE_STATE_DIRTY;
900 EXPECT_TRUE(cache_entry.IsPresent());
901 EXPECT_FALSE(cache_entry.IsPinned());
902 EXPECT_TRUE(cache_entry.IsDirty());
903
904 cache_entry.cache_state = GDataCache::CACHE_STATE_PRESENT |
905 GDataCache::CACHE_STATE_PINNED |
906 GDataCache::CACHE_STATE_DIRTY;
907 EXPECT_TRUE(cache_entry.IsPresent()); 904 EXPECT_TRUE(cache_entry.IsPresent());
908 EXPECT_TRUE(cache_entry.IsPinned()); 905 EXPECT_TRUE(cache_entry.IsPinned());
909 EXPECT_TRUE(cache_entry.IsDirty()); 906 EXPECT_TRUE(cache_entry.IsDirty());
907 EXPECT_FALSE(cache_entry.IsMounted());
908 EXPECT_FALSE(cache_entry.IsPersistent());
910 909
911 int cache_state = GDataCache::CACHE_STATE_NONE; 910 cache_entry.cache_state |= GDataCache::CACHE_STATE_MOUNTED;
912 EXPECT_EQ(GDataCache::CACHE_STATE_PRESENT, 911 EXPECT_TRUE(cache_entry.IsPresent());
913 GDataCache::SetCachePresent(cache_state)); 912 EXPECT_TRUE(cache_entry.IsPinned());
914 EXPECT_EQ(GDataCache::CACHE_STATE_PINNED, 913 EXPECT_TRUE(cache_entry.IsDirty());
915 GDataCache::SetCachePinned(cache_state)); 914 EXPECT_TRUE(cache_entry.IsMounted());
915 EXPECT_FALSE(cache_entry.IsPersistent());
916 916
917 cache_state = GDataCache::CACHE_STATE_PRESENT; 917 cache_entry.cache_state |= GDataCache::CACHE_STATE_PERSISTENT;
918 EXPECT_EQ(GDataCache::CACHE_STATE_PRESENT | GDataCache::CACHE_STATE_PINNED, 918 EXPECT_TRUE(cache_entry.IsPresent());
919 GDataCache::SetCachePinned(cache_state)); 919 EXPECT_TRUE(cache_entry.IsPinned());
920 EXPECT_EQ(GDataCache::CACHE_STATE_PRESENT | GDataCache::CACHE_STATE_DIRTY, 920 EXPECT_TRUE(cache_entry.IsDirty());
921 GDataCache::SetCacheDirty(cache_state)); 921 EXPECT_TRUE(cache_entry.IsMounted());
922 cache_state |= GDataCache::CACHE_STATE_PINNED; 922 EXPECT_TRUE(cache_entry.IsPersistent());
923 EXPECT_EQ(GDataCache::CACHE_STATE_PRESENT | GDataCache::CACHE_STATE_PINNED | 923 }
924
925 TEST_F(GDataCacheTest, CacheEntry_Set) {
926 GDataCache::CacheEntry cache_entry("dummy_md5", GDataCache::CACHE_STATE_NONE);
927
928 cache_entry.SetPresent(true);
929 EXPECT_EQ(GDataCache::CACHE_STATE_PRESENT, cache_entry.cache_state);
930
931 cache_entry.SetPinned(true);
932 EXPECT_EQ(GDataCache::CACHE_STATE_PRESENT |
933 GDataCache::CACHE_STATE_PINNED,
934 cache_entry.cache_state);
935
936 cache_entry.SetDirty(true);
937 EXPECT_EQ(GDataCache::CACHE_STATE_PRESENT |
938 GDataCache::CACHE_STATE_PINNED |
924 GDataCache::CACHE_STATE_DIRTY, 939 GDataCache::CACHE_STATE_DIRTY,
925 GDataCache::SetCacheDirty(cache_state)); 940 cache_entry.cache_state);
926 941
927 cache_state = GDataCache::CACHE_STATE_PINNED; 942 cache_entry.SetMounted(true);
928 EXPECT_EQ(GDataCache::CACHE_STATE_PRESENT | GDataCache::CACHE_STATE_PINNED, 943 EXPECT_EQ(GDataCache::CACHE_STATE_PRESENT |
929 GDataCache::SetCachePresent(cache_state)); 944 GDataCache::CACHE_STATE_PINNED |
945 GDataCache::CACHE_STATE_DIRTY |
946 GDataCache::CACHE_STATE_MOUNTED,
947 cache_entry.cache_state);
930 948
931 cache_state = GDataCache::CACHE_STATE_PRESENT | 949 cache_entry.SetPersistent(true);
932 GDataCache::CACHE_STATE_PINNED | 950 EXPECT_EQ(GDataCache::CACHE_STATE_PRESENT |
933 GDataCache::CACHE_STATE_DIRTY; 951 GDataCache::CACHE_STATE_PINNED |
934 EXPECT_EQ(cache_state & ~GDataCache::CACHE_STATE_PRESENT, 952 GDataCache::CACHE_STATE_DIRTY |
935 GDataCache::ClearCachePresent(cache_state)); 953 GDataCache::CACHE_STATE_MOUNTED |
936 EXPECT_EQ(cache_state & ~GDataCache::CACHE_STATE_PINNED, 954 GDataCache::CACHE_STATE_PERSISTENT,
937 GDataCache::ClearCachePinned(cache_state)); 955 cache_entry.cache_state);
938 EXPECT_EQ(cache_state & ~GDataCache::CACHE_STATE_DIRTY, 956
939 GDataCache::ClearCacheDirty(cache_state)); 957 cache_entry.SetPresent(false);
958 EXPECT_EQ(GDataCache::CACHE_STATE_PINNED |
959 GDataCache::CACHE_STATE_DIRTY |
960 GDataCache::CACHE_STATE_MOUNTED |
961 GDataCache::CACHE_STATE_PERSISTENT,
962 cache_entry.cache_state);
963
964 cache_entry.SetPinned(false);
965 EXPECT_EQ(GDataCache::CACHE_STATE_DIRTY |
966 GDataCache::CACHE_STATE_MOUNTED |
967 GDataCache::CACHE_STATE_PERSISTENT,
968 cache_entry.cache_state);
969
970 cache_entry.SetDirty(false);
971 EXPECT_EQ(GDataCache::CACHE_STATE_MOUNTED |
972 GDataCache::CACHE_STATE_PERSISTENT, cache_entry.cache_state);
973
974 cache_entry.SetMounted(false);
975 EXPECT_EQ(GDataCache::CACHE_STATE_PERSISTENT, cache_entry.cache_state);
976
977 cache_entry.SetPersistent(false);
978 EXPECT_EQ(GDataCache::CACHE_STATE_NONE, cache_entry.cache_state);
940 } 979 }
941 980
942 TEST_F(GDataCacheTest, GetCacheFilePath) { 981 TEST_F(GDataCacheTest, GetCacheFilePath) {
943 // Use alphanumeric characters for resource id. 982 // Use alphanumeric characters for resource id.
944 std::string resource_id("pdf:1a2b"); 983 std::string resource_id("pdf:1a2b");
945 std::string md5("abcdef0123456789"); 984 std::string md5("abcdef0123456789");
946 TestGetCacheFilePath(resource_id, md5, 985 TestGetCacheFilePath(resource_id, md5,
947 resource_id + FilePath::kExtensionSeparator + md5); 986 resource_id + FilePath::kExtensionSeparator + md5);
948 EXPECT_EQ(0, num_callback_invocations_); 987 EXPECT_EQ(0, num_callback_invocations_);
949 988
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
982 // |md5|. 1021 // |md5|.
983 md5 = "new_md5"; 1022 md5 = "new_md5";
984 num_callback_invocations_ = 0; 1023 num_callback_invocations_ = 0;
985 TestStoreToCache(resource_id, md5, GetTestFilePath("subdir_feed.json"), 1024 TestStoreToCache(resource_id, md5, GetTestFilePath("subdir_feed.json"),
986 base::PLATFORM_FILE_OK, GDataCache::CACHE_STATE_PRESENT, 1025 base::PLATFORM_FILE_OK, GDataCache::CACHE_STATE_PRESENT,
987 GDataCache::CACHE_TYPE_TMP); 1026 GDataCache::CACHE_TYPE_TMP);
988 EXPECT_EQ(1, num_callback_invocations_); 1027 EXPECT_EQ(1, num_callback_invocations_);
989 1028
990 // Verify that there's only one file with name <resource_id>, i.e. previously 1029 // Verify that there's only one file with name <resource_id>, i.e. previously
991 // cached file with the different md5 should be deleted. 1030 // cached file with the different md5 should be deleted.
992 FilePath path = GetCacheFilePath(resource_id, "*", 1031 FilePath path = GetCacheFilePath(
993 (GDataCache::IsCachePinned(expected_cache_state_)) ? 1032 resource_id, "*",
994 GDataCache::CACHE_TYPE_PERSISTENT : 1033 (ToCacheEntry(expected_cache_state_).IsPinned() ?
995 GDataCache::CACHE_TYPE_TMP, 1034 GDataCache::CACHE_TYPE_PERSISTENT :
1035 GDataCache::CACHE_TYPE_TMP),
996 GDataCache::CACHED_FILE_FROM_SERVER); 1036 GDataCache::CACHED_FILE_FROM_SERVER);
997 file_util::FileEnumerator enumerator(path.DirName(), false, 1037 file_util::FileEnumerator enumerator(path.DirName(), false,
998 file_util::FileEnumerator::FILES, 1038 file_util::FileEnumerator::FILES,
999 path.BaseName().value()); 1039 path.BaseName().value());
1000 size_t num_files_found = 0; 1040 size_t num_files_found = 0;
1001 for (FilePath current = enumerator.Next(); !current.empty(); 1041 for (FilePath current = enumerator.Next(); !current.empty();
1002 current = enumerator.Next()) { 1042 current = enumerator.Next()) {
1003 ++num_files_found; 1043 ++num_files_found;
1004 EXPECT_EQ(util::EscapeCacheFileName(resource_id) + 1044 EXPECT_EQ(util::EscapeCacheFileName(resource_id) +
1005 FilePath::kExtensionSeparator + 1045 FilePath::kExtensionSeparator +
(...skipping 633 matching lines...) Expand 10 before | Expand all | Expand 10 after
1639 EXPECT_EQ(1, num_callback_invocations_); 1679 EXPECT_EQ(1, num_callback_invocations_);
1640 EXPECT_TRUE(CacheEntryExists(resource_id, md5)); 1680 EXPECT_TRUE(CacheEntryExists(resource_id, md5));
1641 1681
1642 // Try to remove the file. 1682 // Try to remove the file.
1643 num_callback_invocations_ = 0; 1683 num_callback_invocations_ = 0;
1644 TestRemoveFromCache(resource_id, base::PLATFORM_FILE_OK); 1684 TestRemoveFromCache(resource_id, base::PLATFORM_FILE_OK);
1645 EXPECT_EQ(1, num_callback_invocations_); 1685 EXPECT_EQ(1, num_callback_invocations_);
1646 } 1686 }
1647 1687
1648 } // namespace gdata 1688 } // namespace gdata
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/gdata/gdata_cache_metadata.cc ('k') | chrome/browser/chromeos/gdata/gdata_file_system_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698