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

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

Issue 10698157: gdata: Make GDataCache::CacheEntry a struct (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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 322 matching lines...) Expand 10 before | Expand all | Expand 10 after
333 resource.expected_file_extension); 333 resource.expected_file_extension);
334 EXPECT_EQ(1, num_callback_invocations_); 334 EXPECT_EQ(1, num_callback_invocations_);
335 335
336 // Verify cache state. 336 // Verify cache state.
337 std::string md5; 337 std::string md5;
338 if (ToCacheEntry(resource.cache_state).IsPresent()) 338 if (ToCacheEntry(resource.cache_state).IsPresent())
339 md5 = resource.md5; 339 md5 = resource.md5;
340 scoped_ptr<GDataCache::CacheEntry> cache_entry = 340 scoped_ptr<GDataCache::CacheEntry> cache_entry =
341 GetCacheEntryFromOriginThread(resource.resource_id, md5); 341 GetCacheEntryFromOriginThread(resource.resource_id, md5);
342 ASSERT_TRUE(cache_entry.get()); 342 ASSERT_TRUE(cache_entry.get());
343 EXPECT_EQ(resource.cache_state, cache_entry->cache_state); 343 EXPECT_EQ(resource.cache_state, cache_entry->cache_state());
344 EXPECT_EQ(resource.expected_sub_dir_type, 344 EXPECT_EQ(resource.expected_sub_dir_type,
345 cache_entry->GetSubDirectoryType()); 345 cache_entry->GetSubDirectoryType());
346 } 346 }
347 } 347 }
348 348
349 void TestGetFileFromCacheByResourceIdAndMd5( 349 void TestGetFileFromCacheByResourceIdAndMd5(
350 const std::string& resource_id, 350 const std::string& resource_id,
351 const std::string& md5, 351 const std::string& md5,
352 base::PlatformFileError expected_error, 352 base::PlatformFileError expected_error,
353 const std::string& expected_file_extension) { 353 const std::string& expected_file_extension) {
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
563 test_util::RunBlockingPoolTask(); 563 test_util::RunBlockingPoolTask();
564 } 564 }
565 565
566 void VerifyGetCacheState(bool success, 566 void VerifyGetCacheState(bool success,
567 const GDataCache::CacheEntry& cache_entry) { 567 const GDataCache::CacheEntry& cache_entry) {
568 ++num_callback_invocations_; 568 ++num_callback_invocations_;
569 569
570 EXPECT_EQ(expected_success_, success); 570 EXPECT_EQ(expected_success_, success);
571 571
572 if (success) { 572 if (success) {
573 EXPECT_EQ(expected_cache_state_, cache_entry.cache_state); 573 EXPECT_EQ(expected_cache_state_, cache_entry.cache_state());
574 } 574 }
575 } 575 }
576 576
577 void TestMarkDirty( 577 void TestMarkDirty(
578 const std::string& resource_id, 578 const std::string& resource_id,
579 const std::string& md5, 579 const std::string& md5,
580 base::PlatformFileError expected_error, 580 base::PlatformFileError expected_error,
581 int expected_cache_state, 581 int expected_cache_state,
582 GDataCache::CacheSubDirectoryType expected_sub_dir_type) { 582 GDataCache::CacheSubDirectoryType expected_sub_dir_type) {
583 expected_error_ = expected_error; 583 expected_error_ = expected_error;
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
690 ++num_callback_invocations_; 690 ++num_callback_invocations_;
691 691
692 EXPECT_EQ(expected_error_, error); 692 EXPECT_EQ(expected_error_, error);
693 693
694 // Verify cache map. 694 // Verify cache map.
695 scoped_ptr<GDataCache::CacheEntry> cache_entry = 695 scoped_ptr<GDataCache::CacheEntry> cache_entry =
696 GetCacheEntryFromOriginThread(resource_id, md5); 696 GetCacheEntryFromOriginThread(resource_id, md5);
697 if (ToCacheEntry(expected_cache_state_).IsPresent() || 697 if (ToCacheEntry(expected_cache_state_).IsPresent() ||
698 ToCacheEntry(expected_cache_state_).IsPinned()) { 698 ToCacheEntry(expected_cache_state_).IsPinned()) {
699 ASSERT_TRUE(cache_entry.get()); 699 ASSERT_TRUE(cache_entry.get());
700 EXPECT_EQ(expected_cache_state_, cache_entry->cache_state); 700 EXPECT_EQ(expected_cache_state_, cache_entry->cache_state());
701 EXPECT_EQ(expected_sub_dir_type_, cache_entry->GetSubDirectoryType()); 701 EXPECT_EQ(expected_sub_dir_type_, cache_entry->GetSubDirectoryType());
702 } else { 702 } else {
703 EXPECT_FALSE(cache_entry.get()); 703 EXPECT_FALSE(cache_entry.get());
704 } 704 }
705 705
706 // Verify actual cache file. 706 // Verify actual cache file.
707 FilePath dest_path = cache_->GetCacheFilePath( 707 FilePath dest_path = cache_->GetCacheFilePath(
708 resource_id, 708 resource_id,
709 md5, 709 md5,
710 ToCacheEntry(expected_cache_state_).IsPinned() || 710 ToCacheEntry(expected_cache_state_).IsPinned() ||
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
871 bool expect_outgoing_symlink_; 871 bool expect_outgoing_symlink_;
872 std::string expected_file_extension_; 872 std::string expected_file_extension_;
873 int root_feed_changestamp_; 873 int root_feed_changestamp_;
874 }; 874 };
875 875
876 TEST_F(GDataCacheTest, InitializeCache) { 876 TEST_F(GDataCacheTest, InitializeCache) {
877 PrepareForInitCacheTest(); 877 PrepareForInitCacheTest();
878 TestInitializeCache(); 878 TestInitializeCache();
879 } 879 }
880 880
881 TEST_F(GDataCacheTest, CacheEntry_Is) { 881 TEST_F(GDataCacheTest, CacheEntry_CacheStateChanges) {
882 GDataCache::CacheEntry cache_entry("dummy_md5", GDataCache::CACHE_STATE_NONE); 882 GDataCache::CacheEntry cache_entry("dummy_md5", GDataCache::CACHE_STATE_NONE);
883 EXPECT_FALSE(cache_entry.IsPresent()); 883 EXPECT_FALSE(cache_entry.IsPresent());
884 EXPECT_FALSE(cache_entry.IsPinned()); 884 EXPECT_FALSE(cache_entry.IsPinned());
885 EXPECT_FALSE(cache_entry.IsDirty()); 885 EXPECT_FALSE(cache_entry.IsDirty());
886 EXPECT_FALSE(cache_entry.IsMounted()); 886 EXPECT_FALSE(cache_entry.IsMounted());
887 EXPECT_FALSE(cache_entry.IsPersistent()); 887 EXPECT_FALSE(cache_entry.IsPersistent());
888 888
889 cache_entry.cache_state = GDataCache::CACHE_STATE_PRESENT; 889 cache_entry.SetPresent(true);
890 EXPECT_TRUE(cache_entry.IsPresent()); 890 EXPECT_TRUE(cache_entry.IsPresent());
891 EXPECT_FALSE(cache_entry.IsPinned()); 891 EXPECT_FALSE(cache_entry.IsPinned());
892 EXPECT_FALSE(cache_entry.IsDirty()); 892 EXPECT_FALSE(cache_entry.IsDirty());
893 EXPECT_FALSE(cache_entry.IsMounted()); 893 EXPECT_FALSE(cache_entry.IsMounted());
894 EXPECT_FALSE(cache_entry.IsPersistent()); 894 EXPECT_FALSE(cache_entry.IsPersistent());
895 895
896 cache_entry.cache_state |= GDataCache::CACHE_STATE_PINNED; 896 cache_entry.SetPinned(true);
897 EXPECT_TRUE(cache_entry.IsPresent()); 897 EXPECT_TRUE(cache_entry.IsPresent());
898 EXPECT_TRUE(cache_entry.IsPinned()); 898 EXPECT_TRUE(cache_entry.IsPinned());
899 EXPECT_FALSE(cache_entry.IsDirty()); 899 EXPECT_FALSE(cache_entry.IsDirty());
900 EXPECT_FALSE(cache_entry.IsMounted()); 900 EXPECT_FALSE(cache_entry.IsMounted());
901 EXPECT_FALSE(cache_entry.IsPersistent()); 901 EXPECT_FALSE(cache_entry.IsPersistent());
902 902
903 cache_entry.cache_state |= GDataCache::CACHE_STATE_DIRTY; 903 cache_entry.SetDirty(true);
904 EXPECT_TRUE(cache_entry.IsPresent()); 904 EXPECT_TRUE(cache_entry.IsPresent());
905 EXPECT_TRUE(cache_entry.IsPinned()); 905 EXPECT_TRUE(cache_entry.IsPinned());
906 EXPECT_TRUE(cache_entry.IsDirty()); 906 EXPECT_TRUE(cache_entry.IsDirty());
907 EXPECT_FALSE(cache_entry.IsMounted()); 907 EXPECT_FALSE(cache_entry.IsMounted());
908 EXPECT_FALSE(cache_entry.IsPersistent()); 908 EXPECT_FALSE(cache_entry.IsPersistent());
909 909
910 cache_entry.cache_state |= GDataCache::CACHE_STATE_MOUNTED; 910 cache_entry.SetMounted(true);
911 EXPECT_TRUE(cache_entry.IsPresent()); 911 EXPECT_TRUE(cache_entry.IsPresent());
912 EXPECT_TRUE(cache_entry.IsPinned()); 912 EXPECT_TRUE(cache_entry.IsPinned());
913 EXPECT_TRUE(cache_entry.IsDirty()); 913 EXPECT_TRUE(cache_entry.IsDirty());
914 EXPECT_TRUE(cache_entry.IsMounted()); 914 EXPECT_TRUE(cache_entry.IsMounted());
915 EXPECT_FALSE(cache_entry.IsPersistent()); 915 EXPECT_FALSE(cache_entry.IsPersistent());
916 916
917 cache_entry.cache_state |= GDataCache::CACHE_STATE_PERSISTENT; 917 cache_entry.SetPersistent(true);
918 EXPECT_TRUE(cache_entry.IsPresent()); 918 EXPECT_TRUE(cache_entry.IsPresent());
919 EXPECT_TRUE(cache_entry.IsPinned()); 919 EXPECT_TRUE(cache_entry.IsPinned());
920 EXPECT_TRUE(cache_entry.IsDirty()); 920 EXPECT_TRUE(cache_entry.IsDirty());
921 EXPECT_TRUE(cache_entry.IsMounted()); 921 EXPECT_TRUE(cache_entry.IsMounted());
922 EXPECT_TRUE(cache_entry.IsPersistent()); 922 EXPECT_TRUE(cache_entry.IsPersistent());
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 |
939 GDataCache::CACHE_STATE_DIRTY,
940 cache_entry.cache_state);
941
942 cache_entry.SetMounted(true);
943 EXPECT_EQ(GDataCache::CACHE_STATE_PRESENT |
944 GDataCache::CACHE_STATE_PINNED |
945 GDataCache::CACHE_STATE_DIRTY |
946 GDataCache::CACHE_STATE_MOUNTED,
947 cache_entry.cache_state);
948
949 cache_entry.SetPersistent(true);
950 EXPECT_EQ(GDataCache::CACHE_STATE_PRESENT |
951 GDataCache::CACHE_STATE_PINNED |
952 GDataCache::CACHE_STATE_DIRTY |
953 GDataCache::CACHE_STATE_MOUNTED |
954 GDataCache::CACHE_STATE_PERSISTENT,
955 cache_entry.cache_state);
956 923
957 cache_entry.SetPresent(false); 924 cache_entry.SetPresent(false);
958 EXPECT_EQ(GDataCache::CACHE_STATE_PINNED | 925 EXPECT_FALSE(cache_entry.IsPresent());
959 GDataCache::CACHE_STATE_DIRTY | 926 EXPECT_TRUE(cache_entry.IsPinned());
960 GDataCache::CACHE_STATE_MOUNTED | 927 EXPECT_TRUE(cache_entry.IsDirty());
961 GDataCache::CACHE_STATE_PERSISTENT, 928 EXPECT_TRUE(cache_entry.IsMounted());
962 cache_entry.cache_state); 929 EXPECT_TRUE(cache_entry.IsPersistent());
930
931 cache_entry.SetPresent(false);
932 EXPECT_FALSE(cache_entry.IsPresent());
933 EXPECT_TRUE(cache_entry.IsPinned());
934 EXPECT_TRUE(cache_entry.IsDirty());
935 EXPECT_TRUE(cache_entry.IsMounted());
936 EXPECT_TRUE(cache_entry.IsPersistent());
963 937
964 cache_entry.SetPinned(false); 938 cache_entry.SetPinned(false);
965 EXPECT_EQ(GDataCache::CACHE_STATE_DIRTY | 939 EXPECT_FALSE(cache_entry.IsPresent());
966 GDataCache::CACHE_STATE_MOUNTED | 940 EXPECT_FALSE(cache_entry.IsPinned());
967 GDataCache::CACHE_STATE_PERSISTENT, 941 EXPECT_TRUE(cache_entry.IsDirty());
968 cache_entry.cache_state); 942 EXPECT_TRUE(cache_entry.IsMounted());
943 EXPECT_TRUE(cache_entry.IsPersistent());
969 944
970 cache_entry.SetDirty(false); 945 cache_entry.SetDirty(false);
971 EXPECT_EQ(GDataCache::CACHE_STATE_MOUNTED | 946 EXPECT_FALSE(cache_entry.IsPresent());
972 GDataCache::CACHE_STATE_PERSISTENT, cache_entry.cache_state); 947 EXPECT_FALSE(cache_entry.IsPinned());
948 EXPECT_FALSE(cache_entry.IsDirty());
949 EXPECT_TRUE(cache_entry.IsMounted());
950 EXPECT_TRUE(cache_entry.IsPersistent());
973 951
974 cache_entry.SetMounted(false); 952 cache_entry.SetMounted(false);
975 EXPECT_EQ(GDataCache::CACHE_STATE_PERSISTENT, cache_entry.cache_state); 953 EXPECT_FALSE(cache_entry.IsPresent());
954 EXPECT_FALSE(cache_entry.IsPinned());
955 EXPECT_FALSE(cache_entry.IsDirty());
956 EXPECT_FALSE(cache_entry.IsMounted());
957 EXPECT_TRUE(cache_entry.IsPersistent());
976 958
977 cache_entry.SetPersistent(false); 959 cache_entry.SetPersistent(false);
978 EXPECT_EQ(GDataCache::CACHE_STATE_NONE, cache_entry.cache_state); 960 EXPECT_FALSE(cache_entry.IsPresent());
961 EXPECT_FALSE(cache_entry.IsPinned());
962 EXPECT_FALSE(cache_entry.IsDirty());
963 EXPECT_FALSE(cache_entry.IsMounted());
964 EXPECT_FALSE(cache_entry.IsPersistent());
979 } 965 }
980 966
981 TEST_F(GDataCacheTest, GetCacheFilePath) { 967 TEST_F(GDataCacheTest, GetCacheFilePath) {
982 // Use alphanumeric characters for resource id. 968 // Use alphanumeric characters for resource id.
983 std::string resource_id("pdf:1a2b"); 969 std::string resource_id("pdf:1a2b");
984 std::string md5("abcdef0123456789"); 970 std::string md5("abcdef0123456789");
985 TestGetCacheFilePath(resource_id, md5, 971 TestGetCacheFilePath(resource_id, md5,
986 resource_id + FilePath::kExtensionSeparator + md5); 972 resource_id + FilePath::kExtensionSeparator + md5);
987 EXPECT_EQ(0, num_callback_invocations_); 973 EXPECT_EQ(0, num_callback_invocations_);
988 974
(...skipping 690 matching lines...) Expand 10 before | Expand all | Expand 10 after
1679 EXPECT_EQ(1, num_callback_invocations_); 1665 EXPECT_EQ(1, num_callback_invocations_);
1680 EXPECT_TRUE(CacheEntryExists(resource_id, md5)); 1666 EXPECT_TRUE(CacheEntryExists(resource_id, md5));
1681 1667
1682 // Try to remove the file. 1668 // Try to remove the file.
1683 num_callback_invocations_ = 0; 1669 num_callback_invocations_ = 0;
1684 TestRemoveFromCache(resource_id, base::PLATFORM_FILE_OK); 1670 TestRemoveFromCache(resource_id, base::PLATFORM_FILE_OK);
1685 EXPECT_EQ(1, num_callback_invocations_); 1671 EXPECT_EQ(1, num_callback_invocations_);
1686 } 1672 }
1687 1673
1688 } // namespace gdata 1674 } // namespace gdata
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698