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 "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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 // containing non-alphanumeric characters, to test resource_id is escaped and | 45 // containing non-alphanumeric characters, to test resource_id is escaped and |
46 // unescaped correctly. | 46 // unescaped correctly. |
47 { "subdir_feed.json", "tmp:`~!@#$%^&*()-_=+[{|]}\\;',<.>/?", | 47 { "subdir_feed.json", "tmp:`~!@#$%^&*()-_=+[{|]}\\;',<.>/?", |
48 "md5_tmp_non_alphanumeric", | 48 "md5_tmp_non_alphanumeric", |
49 GDataCache::CACHE_STATE_PRESENT, | 49 GDataCache::CACHE_STATE_PRESENT, |
50 "md5_tmp_non_alphanumeric", GDataCache::CACHE_TYPE_TMP }, | 50 "md5_tmp_non_alphanumeric", GDataCache::CACHE_TYPE_TMP }, |
51 // Cache resource that is pinned, to test a pinned file is in persistent dir | 51 // Cache resource that is pinned, to test a pinned file is in persistent dir |
52 // with a symlink in pinned dir referencing it. | 52 // with a symlink in pinned dir referencing it. |
53 { "directory_entry_atom.json", "pinned:existing", "md5_pinned_existing", | 53 { "directory_entry_atom.json", "pinned:existing", "md5_pinned_existing", |
54 GDataCache::CACHE_STATE_PRESENT | | 54 GDataCache::CACHE_STATE_PRESENT | |
55 GDataCache::CACHE_STATE_PINNED | | 55 GDataCache::CACHE_STATE_PINNED, |
56 GDataCache::CACHE_STATE_PERSISTENT, | |
57 "md5_pinned_existing", GDataCache::CACHE_TYPE_PERSISTENT }, | 56 "md5_pinned_existing", GDataCache::CACHE_TYPE_PERSISTENT }, |
58 // Cache resource with a non-existent source file that is pinned, to test that | 57 // Cache resource with a non-existent source file that is pinned, to test that |
59 // a pinned file can reference a non-existent file. | 58 // a pinned file can reference a non-existent file. |
60 { "", "pinned:non-existent", "md5_pinned_non_existent", | 59 { "", "pinned:non-existent", "md5_pinned_non_existent", |
61 GDataCache::CACHE_STATE_PINNED, | 60 GDataCache::CACHE_STATE_PINNED, |
62 "md5_pinned_non_existent", GDataCache::CACHE_TYPE_TMP }, | 61 "md5_pinned_non_existent", GDataCache::CACHE_TYPE_TMP }, |
63 // Cache resource that is dirty, to test a dirty file is in persistent dir | 62 // Cache resource that is dirty, to test a dirty file is in persistent dir |
64 // with a symlink in outgoing dir referencing it. | 63 // with a symlink in outgoing dir referencing it. |
65 { "account_metadata.json", "dirty:existing", "md5_dirty_existing", | 64 { "account_metadata.json", "dirty:existing", "md5_dirty_existing", |
66 GDataCache::CACHE_STATE_PRESENT | | 65 GDataCache::CACHE_STATE_PRESENT | |
67 GDataCache::CACHE_STATE_DIRTY | | 66 GDataCache::CACHE_STATE_DIRTY, |
68 GDataCache::CACHE_STATE_PERSISTENT, | |
69 "local", GDataCache::CACHE_TYPE_PERSISTENT }, | 67 "local", GDataCache::CACHE_TYPE_PERSISTENT }, |
70 // Cache resource that is pinned and dirty, to test a dirty pinned file is in | 68 // Cache resource that is pinned and dirty, to test a dirty pinned file is in |
71 // persistent dir with symlink in pinned and outgoing dirs referencing it. | 69 // persistent dir with symlink in pinned and outgoing dirs referencing it. |
72 { "basic_feed.json", "dirty_and_pinned:existing", | 70 { "basic_feed.json", "dirty_and_pinned:existing", |
73 "md5_dirty_and_pinned_existing", | 71 "md5_dirty_and_pinned_existing", |
74 GDataCache::CACHE_STATE_PRESENT | | 72 GDataCache::CACHE_STATE_PRESENT | |
75 GDataCache::CACHE_STATE_PINNED | | 73 GDataCache::CACHE_STATE_PINNED | |
76 GDataCache::CACHE_STATE_DIRTY | | 74 GDataCache::CACHE_STATE_DIRTY, |
77 GDataCache::CACHE_STATE_PERSISTENT, | |
78 "local", GDataCache::CACHE_TYPE_PERSISTENT }, | 75 "local", GDataCache::CACHE_TYPE_PERSISTENT }, |
79 }; | 76 }; |
80 | 77 |
81 const int64 kLotsOfSpace = kMinFreeSpace * 10; | 78 const int64 kLotsOfSpace = kMinFreeSpace * 10; |
82 | 79 |
83 struct PathToVerify { | 80 struct PathToVerify { |
84 PathToVerify(const FilePath& in_path_to_scan, | 81 PathToVerify(const FilePath& in_path_to_scan, |
85 const FilePath& in_expected_existing_path) : | 82 const FilePath& in_expected_existing_path) : |
86 path_to_scan(in_path_to_scan), | 83 path_to_scan(in_path_to_scan), |
87 expected_existing_path(in_expected_existing_path) { | 84 expected_existing_path(in_expected_existing_path) { |
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
328 EXPECT_EQ(1, num_callback_invocations_); | 325 EXPECT_EQ(1, num_callback_invocations_); |
329 | 326 |
330 // Verify cache state. | 327 // Verify cache state. |
331 std::string md5; | 328 std::string md5; |
332 if (GDataCache::IsCachePresent(resource.cache_state)) | 329 if (GDataCache::IsCachePresent(resource.cache_state)) |
333 md5 = resource.md5; | 330 md5 = resource.md5; |
334 scoped_ptr<GDataCache::CacheEntry> cache_entry = | 331 scoped_ptr<GDataCache::CacheEntry> cache_entry = |
335 GetCacheEntryFromOriginThread(resource.resource_id, md5); | 332 GetCacheEntryFromOriginThread(resource.resource_id, md5); |
336 ASSERT_TRUE(cache_entry.get()); | 333 ASSERT_TRUE(cache_entry.get()); |
337 EXPECT_EQ(resource.cache_state, cache_entry->cache_state); | 334 EXPECT_EQ(resource.cache_state, cache_entry->cache_state); |
338 EXPECT_EQ(resource.expected_sub_dir_type, | 335 EXPECT_EQ(resource.expected_sub_dir_type, cache_entry->sub_dir_type); |
339 cache_entry->GetSubDirectoryType()); | |
340 } | 336 } |
341 } | 337 } |
342 | 338 |
343 void TestGetFileFromCacheByResourceIdAndMd5( | 339 void TestGetFileFromCacheByResourceIdAndMd5( |
344 const std::string& resource_id, | 340 const std::string& resource_id, |
345 const std::string& md5, | 341 const std::string& md5, |
346 base::PlatformFileError expected_error, | 342 base::PlatformFileError expected_error, |
347 const std::string& expected_file_extension) { | 343 const std::string& expected_file_extension) { |
348 expected_error_ = expected_error; | 344 expected_error_ = expected_error; |
349 expected_file_extension_ = expected_file_extension; | 345 expected_file_extension_ = expected_file_extension; |
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
685 | 681 |
686 EXPECT_EQ(expected_error_, error); | 682 EXPECT_EQ(expected_error_, error); |
687 | 683 |
688 // Verify cache map. | 684 // Verify cache map. |
689 scoped_ptr<GDataCache::CacheEntry> cache_entry = | 685 scoped_ptr<GDataCache::CacheEntry> cache_entry = |
690 GetCacheEntryFromOriginThread(resource_id, md5); | 686 GetCacheEntryFromOriginThread(resource_id, md5); |
691 if (GDataCache::IsCachePresent(expected_cache_state_) || | 687 if (GDataCache::IsCachePresent(expected_cache_state_) || |
692 GDataCache::IsCachePinned(expected_cache_state_)) { | 688 GDataCache::IsCachePinned(expected_cache_state_)) { |
693 ASSERT_TRUE(cache_entry.get()); | 689 ASSERT_TRUE(cache_entry.get()); |
694 EXPECT_EQ(expected_cache_state_, cache_entry->cache_state); | 690 EXPECT_EQ(expected_cache_state_, cache_entry->cache_state); |
695 EXPECT_EQ(expected_sub_dir_type_, cache_entry->GetSubDirectoryType()); | 691 EXPECT_EQ(expected_sub_dir_type_, cache_entry->sub_dir_type); |
696 } else { | 692 } else { |
697 EXPECT_FALSE(cache_entry.get()); | 693 EXPECT_FALSE(cache_entry.get()); |
698 } | 694 } |
699 | 695 |
700 // Verify actual cache file. | 696 // Verify actual cache file. |
701 FilePath dest_path = cache_->GetCacheFilePath( | 697 FilePath dest_path = cache_->GetCacheFilePath( |
702 resource_id, | 698 resource_id, |
703 md5, | 699 md5, |
704 GDataCache::IsCachePinned(expected_cache_state_) || | 700 GDataCache::IsCachePinned(expected_cache_state_) || |
705 GDataCache::IsCacheDirty(expected_cache_state_) ? | 701 GDataCache::IsCacheDirty(expected_cache_state_) ? |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
867 int root_feed_changestamp_; | 863 int root_feed_changestamp_; |
868 }; | 864 }; |
869 | 865 |
870 TEST_F(GDataCacheTest, InitializeCache) { | 866 TEST_F(GDataCacheTest, InitializeCache) { |
871 PrepareForInitCacheTest(); | 867 PrepareForInitCacheTest(); |
872 TestInitializeCache(); | 868 TestInitializeCache(); |
873 } | 869 } |
874 | 870 |
875 TEST_F(GDataCacheTest, CacheStateBitmasks) { | 871 TEST_F(GDataCacheTest, CacheStateBitmasks) { |
876 GDataCache::CacheEntry cache_entry("md5_cache_state_bitmasks", | 872 GDataCache::CacheEntry cache_entry("md5_cache_state_bitmasks", |
| 873 GDataCache::CACHE_TYPE_TMP, |
877 GDataCache::CACHE_STATE_NONE); | 874 GDataCache::CACHE_STATE_NONE); |
878 EXPECT_FALSE(cache_entry.IsPresent()); | 875 EXPECT_FALSE(cache_entry.IsPresent()); |
879 EXPECT_FALSE(cache_entry.IsPinned()); | 876 EXPECT_FALSE(cache_entry.IsPinned()); |
880 EXPECT_FALSE(cache_entry.IsDirty()); | 877 EXPECT_FALSE(cache_entry.IsDirty()); |
881 | 878 |
882 cache_entry.cache_state = GDataCache::CACHE_STATE_PRESENT; | 879 cache_entry.cache_state = GDataCache::CACHE_STATE_PRESENT; |
883 EXPECT_TRUE(cache_entry.IsPresent()); | 880 EXPECT_TRUE(cache_entry.IsPresent()); |
884 EXPECT_FALSE(cache_entry.IsPinned()); | 881 EXPECT_FALSE(cache_entry.IsPinned()); |
885 EXPECT_FALSE(cache_entry.IsDirty()); | 882 EXPECT_FALSE(cache_entry.IsDirty()); |
886 | 883 |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1075 EXPECT_CALL(*mock_sync_client_, OnCacheUnpinned(resource_id, md5)).Times(1); | 1072 EXPECT_CALL(*mock_sync_client_, OnCacheUnpinned(resource_id, md5)).Times(1); |
1076 | 1073 |
1077 // First store a file to cache. | 1074 // First store a file to cache. |
1078 TestStoreToCache(resource_id, md5, GetTestFilePath("root_feed.json"), | 1075 TestStoreToCache(resource_id, md5, GetTestFilePath("root_feed.json"), |
1079 base::PLATFORM_FILE_OK, GDataCache::CACHE_STATE_PRESENT, | 1076 base::PLATFORM_FILE_OK, GDataCache::CACHE_STATE_PRESENT, |
1080 GDataCache::CACHE_TYPE_TMP); | 1077 GDataCache::CACHE_TYPE_TMP); |
1081 | 1078 |
1082 // Pin the existing file in cache. | 1079 // Pin the existing file in cache. |
1083 num_callback_invocations_ = 0; | 1080 num_callback_invocations_ = 0; |
1084 TestPin(resource_id, md5, base::PLATFORM_FILE_OK, | 1081 TestPin(resource_id, md5, base::PLATFORM_FILE_OK, |
1085 GDataCache::CACHE_STATE_PRESENT | GDataCache::CACHE_STATE_PINNED | | 1082 GDataCache::CACHE_STATE_PRESENT | GDataCache::CACHE_STATE_PINNED, |
1086 GDataCache::CACHE_STATE_PERSISTENT, | |
1087 GDataCache::CACHE_TYPE_PERSISTENT); | 1083 GDataCache::CACHE_TYPE_PERSISTENT); |
1088 EXPECT_EQ(1, num_callback_invocations_); | 1084 EXPECT_EQ(1, num_callback_invocations_); |
1089 | 1085 |
1090 // Unpin the existing file in cache. | 1086 // Unpin the existing file in cache. |
1091 num_callback_invocations_ = 0; | 1087 num_callback_invocations_ = 0; |
1092 TestUnpin(resource_id, md5, base::PLATFORM_FILE_OK, | 1088 TestUnpin(resource_id, md5, base::PLATFORM_FILE_OK, |
1093 GDataCache::CACHE_STATE_PRESENT, | 1089 GDataCache::CACHE_STATE_PRESENT, |
1094 GDataCache::CACHE_TYPE_TMP); | 1090 GDataCache::CACHE_TYPE_TMP); |
1095 EXPECT_EQ(1, num_callback_invocations_); | 1091 EXPECT_EQ(1, num_callback_invocations_); |
1096 | 1092 |
1097 // Pin back the same existing file in cache. | 1093 // Pin back the same existing file in cache. |
1098 num_callback_invocations_ = 0; | 1094 num_callback_invocations_ = 0; |
1099 TestPin(resource_id, md5, base::PLATFORM_FILE_OK, | 1095 TestPin(resource_id, md5, base::PLATFORM_FILE_OK, |
1100 GDataCache::CACHE_STATE_PRESENT | GDataCache::CACHE_STATE_PINNED | | 1096 GDataCache::CACHE_STATE_PRESENT | GDataCache::CACHE_STATE_PINNED, |
1101 GDataCache::CACHE_STATE_PERSISTENT, | |
1102 GDataCache::CACHE_TYPE_PERSISTENT); | 1097 GDataCache::CACHE_TYPE_PERSISTENT); |
1103 EXPECT_EQ(1, num_callback_invocations_); | 1098 EXPECT_EQ(1, num_callback_invocations_); |
1104 | 1099 |
1105 // Pin a non-existent file in cache. | 1100 // Pin a non-existent file in cache. |
1106 resource_id = "document:1a2b"; | 1101 resource_id = "document:1a2b"; |
1107 EXPECT_CALL(*mock_sync_client_, OnCachePinned(resource_id, md5)).Times(1); | 1102 EXPECT_CALL(*mock_sync_client_, OnCachePinned(resource_id, md5)).Times(1); |
1108 EXPECT_CALL(*mock_sync_client_, OnCacheUnpinned(resource_id, md5)).Times(1); | 1103 EXPECT_CALL(*mock_sync_client_, OnCacheUnpinned(resource_id, md5)).Times(1); |
1109 | 1104 |
1110 num_callback_invocations_ = 0; | 1105 num_callback_invocations_ = 0; |
1111 TestPin(resource_id, md5, base::PLATFORM_FILE_OK, | 1106 TestPin(resource_id, md5, base::PLATFORM_FILE_OK, |
(...skipping 29 matching lines...) Expand all Loading... |
1141 // Pin a non-existent file. | 1136 // Pin a non-existent file. |
1142 TestPin(resource_id, md5, base::PLATFORM_FILE_OK, | 1137 TestPin(resource_id, md5, base::PLATFORM_FILE_OK, |
1143 GDataCache::CACHE_STATE_PINNED, | 1138 GDataCache::CACHE_STATE_PINNED, |
1144 GDataCache::CACHE_TYPE_TMP); | 1139 GDataCache::CACHE_TYPE_TMP); |
1145 | 1140 |
1146 // Store an existing file to a previously pinned file. | 1141 // Store an existing file to a previously pinned file. |
1147 num_callback_invocations_ = 0; | 1142 num_callback_invocations_ = 0; |
1148 TestStoreToCache(resource_id, md5, GetTestFilePath("root_feed.json"), | 1143 TestStoreToCache(resource_id, md5, GetTestFilePath("root_feed.json"), |
1149 base::PLATFORM_FILE_OK, | 1144 base::PLATFORM_FILE_OK, |
1150 GDataCache::CACHE_STATE_PRESENT | | 1145 GDataCache::CACHE_STATE_PRESENT | |
1151 GDataCache::CACHE_STATE_PINNED | | 1146 GDataCache::CACHE_STATE_PINNED, |
1152 GDataCache::CACHE_STATE_PERSISTENT, | |
1153 GDataCache::CACHE_TYPE_PERSISTENT); | 1147 GDataCache::CACHE_TYPE_PERSISTENT); |
1154 EXPECT_EQ(1, num_callback_invocations_); | 1148 EXPECT_EQ(1, num_callback_invocations_); |
1155 | 1149 |
1156 // Store a non-existent file to a previously pinned and stored file. | 1150 // Store a non-existent file to a previously pinned and stored file. |
1157 num_callback_invocations_ = 0; | 1151 num_callback_invocations_ = 0; |
1158 TestStoreToCache(resource_id, md5, FilePath("./non_existent.json"), | 1152 TestStoreToCache(resource_id, md5, FilePath("./non_existent.json"), |
1159 base::PLATFORM_FILE_ERROR_NOT_FOUND, | 1153 base::PLATFORM_FILE_ERROR_NOT_FOUND, |
1160 GDataCache::CACHE_STATE_PRESENT | | 1154 GDataCache::CACHE_STATE_PRESENT | |
1161 GDataCache::CACHE_STATE_PINNED | | 1155 GDataCache::CACHE_STATE_PINNED, |
1162 GDataCache::CACHE_STATE_PERSISTENT, | |
1163 GDataCache::CACHE_TYPE_PERSISTENT); | 1156 GDataCache::CACHE_TYPE_PERSISTENT); |
1164 EXPECT_EQ(1, num_callback_invocations_); | 1157 EXPECT_EQ(1, num_callback_invocations_); |
1165 } | 1158 } |
1166 | 1159 |
1167 TEST_F(GDataCacheTest, GetFromCachePinned) { | 1160 TEST_F(GDataCacheTest, GetFromCachePinned) { |
1168 std::string resource_id("pdf:1a2b"); | 1161 std::string resource_id("pdf:1a2b"); |
1169 std::string md5("abcdef0123456789"); | 1162 std::string md5("abcdef0123456789"); |
1170 EXPECT_CALL(*mock_sync_client_, OnCachePinned(resource_id, md5)).Times(1); | 1163 EXPECT_CALL(*mock_sync_client_, OnCachePinned(resource_id, md5)).Times(1); |
1171 | 1164 |
1172 // Pin a non-existent file. | 1165 // Pin a non-existent file. |
1173 TestPin(resource_id, md5, base::PLATFORM_FILE_OK, | 1166 TestPin(resource_id, md5, base::PLATFORM_FILE_OK, |
1174 GDataCache::CACHE_STATE_PINNED, | 1167 GDataCache::CACHE_STATE_PINNED, |
1175 GDataCache::CACHE_TYPE_TMP); | 1168 GDataCache::CACHE_TYPE_TMP); |
1176 | 1169 |
1177 // Get the non-existent pinned file from cache. | 1170 // Get the non-existent pinned file from cache. |
1178 num_callback_invocations_ = 0; | 1171 num_callback_invocations_ = 0; |
1179 TestGetFileFromCacheByResourceIdAndMd5( | 1172 TestGetFileFromCacheByResourceIdAndMd5( |
1180 resource_id, md5, base::PLATFORM_FILE_ERROR_NOT_FOUND, md5); | 1173 resource_id, md5, base::PLATFORM_FILE_ERROR_NOT_FOUND, md5); |
1181 EXPECT_EQ(1, num_callback_invocations_); | 1174 EXPECT_EQ(1, num_callback_invocations_); |
1182 | 1175 |
1183 // Store an existing file to the previously pinned non-existent file. | 1176 // Store an existing file to the previously pinned non-existent file. |
1184 TestStoreToCache(resource_id, md5, GetTestFilePath("root_feed.json"), | 1177 TestStoreToCache(resource_id, md5, GetTestFilePath("root_feed.json"), |
1185 base::PLATFORM_FILE_OK, | 1178 base::PLATFORM_FILE_OK, |
1186 GDataCache::CACHE_STATE_PRESENT | | 1179 GDataCache::CACHE_STATE_PRESENT | |
1187 GDataCache::CACHE_STATE_PINNED | | 1180 GDataCache::CACHE_STATE_PINNED, |
1188 GDataCache::CACHE_STATE_PERSISTENT, | |
1189 GDataCache::CACHE_TYPE_PERSISTENT); | 1181 GDataCache::CACHE_TYPE_PERSISTENT); |
1190 | 1182 |
1191 // Get the previously pinned and stored file from cache. | 1183 // Get the previously pinned and stored file from cache. |
1192 num_callback_invocations_ = 0; | 1184 num_callback_invocations_ = 0; |
1193 TestGetFileFromCacheByResourceIdAndMd5( | 1185 TestGetFileFromCacheByResourceIdAndMd5( |
1194 resource_id, md5, base::PLATFORM_FILE_OK, md5); | 1186 resource_id, md5, base::PLATFORM_FILE_OK, md5); |
1195 EXPECT_EQ(1, num_callback_invocations_); | 1187 EXPECT_EQ(1, num_callback_invocations_); |
1196 } | 1188 } |
1197 | 1189 |
1198 TEST_F(GDataCacheTest, RemoveFromCachePinned) { | 1190 TEST_F(GDataCacheTest, RemoveFromCachePinned) { |
1199 // Use alphanumeric characters for resource_id. | 1191 // Use alphanumeric characters for resource_id. |
1200 std::string resource_id("pdf:1a2b"); | 1192 std::string resource_id("pdf:1a2b"); |
1201 std::string md5("abcdef0123456789"); | 1193 std::string md5("abcdef0123456789"); |
1202 EXPECT_CALL(*mock_sync_client_, OnCachePinned(resource_id, md5)).Times(1); | 1194 EXPECT_CALL(*mock_sync_client_, OnCachePinned(resource_id, md5)).Times(1); |
1203 | 1195 |
1204 // Store a file to cache, and pin it. | 1196 // Store a file to cache, and pin it. |
1205 TestStoreToCache(resource_id, md5, GetTestFilePath("root_feed.json"), | 1197 TestStoreToCache(resource_id, md5, GetTestFilePath("root_feed.json"), |
1206 base::PLATFORM_FILE_OK, GDataCache::CACHE_STATE_PRESENT, | 1198 base::PLATFORM_FILE_OK, GDataCache::CACHE_STATE_PRESENT, |
1207 GDataCache::CACHE_TYPE_TMP); | 1199 GDataCache::CACHE_TYPE_TMP); |
1208 TestPin(resource_id, md5, base::PLATFORM_FILE_OK, | 1200 TestPin(resource_id, md5, base::PLATFORM_FILE_OK, |
1209 GDataCache::CACHE_STATE_PRESENT | GDataCache::CACHE_STATE_PINNED | | 1201 GDataCache::CACHE_STATE_PRESENT | GDataCache::CACHE_STATE_PINNED, |
1210 GDataCache::CACHE_STATE_PERSISTENT, | |
1211 GDataCache::CACHE_TYPE_PERSISTENT); | 1202 GDataCache::CACHE_TYPE_PERSISTENT); |
1212 | 1203 |
1213 // Remove |resource_id| from cache. | 1204 // Remove |resource_id| from cache. |
1214 num_callback_invocations_ = 0; | 1205 num_callback_invocations_ = 0; |
1215 TestRemoveFromCache(resource_id, base::PLATFORM_FILE_OK); | 1206 TestRemoveFromCache(resource_id, base::PLATFORM_FILE_OK); |
1216 EXPECT_EQ(1, num_callback_invocations_); | 1207 EXPECT_EQ(1, num_callback_invocations_); |
1217 | 1208 |
1218 // Repeat using non-alphanumeric characters for resource id, including '.' | 1209 // Repeat using non-alphanumeric characters for resource id, including '.' |
1219 // which is an extension separator. | 1210 // which is an extension separator. |
1220 resource_id = "pdf:`~!@#$%^&*()-_=+[{|]}\\;',<.>/?"; | 1211 resource_id = "pdf:`~!@#$%^&*()-_=+[{|]}\\;',<.>/?"; |
1221 EXPECT_CALL(*mock_sync_client_, OnCachePinned(resource_id, md5)).Times(1); | 1212 EXPECT_CALL(*mock_sync_client_, OnCachePinned(resource_id, md5)).Times(1); |
1222 | 1213 |
1223 TestStoreToCache(resource_id, md5, GetTestFilePath("root_feed.json"), | 1214 TestStoreToCache(resource_id, md5, GetTestFilePath("root_feed.json"), |
1224 base::PLATFORM_FILE_OK, GDataCache::CACHE_STATE_PRESENT, | 1215 base::PLATFORM_FILE_OK, GDataCache::CACHE_STATE_PRESENT, |
1225 GDataCache::CACHE_TYPE_TMP); | 1216 GDataCache::CACHE_TYPE_TMP); |
1226 TestPin(resource_id, md5, base::PLATFORM_FILE_OK, | 1217 TestPin(resource_id, md5, base::PLATFORM_FILE_OK, |
1227 GDataCache::CACHE_STATE_PRESENT | GDataCache::CACHE_STATE_PINNED | | 1218 GDataCache::CACHE_STATE_PRESENT | GDataCache::CACHE_STATE_PINNED, |
1228 GDataCache::CACHE_STATE_PERSISTENT, | |
1229 GDataCache::CACHE_TYPE_PERSISTENT); | 1219 GDataCache::CACHE_TYPE_PERSISTENT); |
1230 | 1220 |
1231 num_callback_invocations_ = 0; | 1221 num_callback_invocations_ = 0; |
1232 TestRemoveFromCache(resource_id, base::PLATFORM_FILE_OK); | 1222 TestRemoveFromCache(resource_id, base::PLATFORM_FILE_OK); |
1233 EXPECT_EQ(1, num_callback_invocations_); | 1223 EXPECT_EQ(1, num_callback_invocations_); |
1234 } | 1224 } |
1235 | 1225 |
1236 TEST_F(GDataCacheTest, DirtyCacheSimple) { | 1226 TEST_F(GDataCacheTest, DirtyCacheSimple) { |
1237 std::string resource_id("pdf:1a2b"); | 1227 std::string resource_id("pdf:1a2b"); |
1238 std::string md5("abcdef0123456789"); | 1228 std::string md5("abcdef0123456789"); |
1239 EXPECT_CALL(*mock_sync_client_, OnCacheCommitted(resource_id)).Times(1); | 1229 EXPECT_CALL(*mock_sync_client_, OnCacheCommitted(resource_id)).Times(1); |
1240 | 1230 |
1241 // First store a file to cache. | 1231 // First store a file to cache. |
1242 TestStoreToCache(resource_id, md5, GetTestFilePath("root_feed.json"), | 1232 TestStoreToCache(resource_id, md5, GetTestFilePath("root_feed.json"), |
1243 base::PLATFORM_FILE_OK, GDataCache::CACHE_STATE_PRESENT, | 1233 base::PLATFORM_FILE_OK, GDataCache::CACHE_STATE_PRESENT, |
1244 GDataCache::CACHE_TYPE_TMP); | 1234 GDataCache::CACHE_TYPE_TMP); |
1245 | 1235 |
1246 // Mark the file dirty. | 1236 // Mark the file dirty. |
1247 num_callback_invocations_ = 0; | 1237 num_callback_invocations_ = 0; |
1248 TestMarkDirty(resource_id, md5, base::PLATFORM_FILE_OK, | 1238 TestMarkDirty(resource_id, md5, base::PLATFORM_FILE_OK, |
1249 GDataCache::CACHE_STATE_PRESENT | | 1239 GDataCache::CACHE_STATE_PRESENT | GDataCache::CACHE_STATE_DIRTY, |
1250 GDataCache::CACHE_STATE_DIRTY | | |
1251 GDataCache::CACHE_STATE_PERSISTENT, | |
1252 GDataCache::CACHE_TYPE_PERSISTENT); | 1240 GDataCache::CACHE_TYPE_PERSISTENT); |
1253 EXPECT_EQ(1, num_callback_invocations_); | 1241 EXPECT_EQ(1, num_callback_invocations_); |
1254 | 1242 |
1255 // Commit the file dirty. | 1243 // Commit the file dirty. |
1256 num_callback_invocations_ = 0; | 1244 num_callback_invocations_ = 0; |
1257 TestCommitDirty(resource_id, md5, base::PLATFORM_FILE_OK, | 1245 TestCommitDirty(resource_id, md5, base::PLATFORM_FILE_OK, |
1258 GDataCache::CACHE_STATE_PRESENT | | 1246 GDataCache::CACHE_STATE_PRESENT | |
1259 GDataCache::CACHE_STATE_DIRTY | | 1247 GDataCache::CACHE_STATE_DIRTY, |
1260 GDataCache::CACHE_STATE_PERSISTENT, | 1248 GDataCache::CACHE_TYPE_PERSISTENT); |
1261 GDataCache::CACHE_TYPE_PERSISTENT); | |
1262 EXPECT_EQ(1, num_callback_invocations_); | 1249 EXPECT_EQ(1, num_callback_invocations_); |
1263 | 1250 |
1264 // Clear dirty state of the file. | 1251 // Clear dirty state of the file. |
1265 num_callback_invocations_ = 0; | 1252 num_callback_invocations_ = 0; |
1266 TestClearDirty(resource_id, md5, base::PLATFORM_FILE_OK, | 1253 TestClearDirty(resource_id, md5, base::PLATFORM_FILE_OK, |
1267 GDataCache::CACHE_STATE_PRESENT, | 1254 GDataCache::CACHE_STATE_PRESENT, |
1268 GDataCache::CACHE_TYPE_TMP); | 1255 GDataCache::CACHE_TYPE_TMP); |
1269 EXPECT_EQ(1, num_callback_invocations_); | 1256 EXPECT_EQ(1, num_callback_invocations_); |
1270 } | 1257 } |
1271 | 1258 |
1272 TEST_F(GDataCacheTest, DirtyCachePinned) { | 1259 TEST_F(GDataCacheTest, DirtyCachePinned) { |
1273 std::string resource_id("pdf:1a2b"); | 1260 std::string resource_id("pdf:1a2b"); |
1274 std::string md5("abcdef0123456789"); | 1261 std::string md5("abcdef0123456789"); |
1275 EXPECT_CALL(*mock_sync_client_, OnCachePinned(resource_id, md5)).Times(1); | 1262 EXPECT_CALL(*mock_sync_client_, OnCachePinned(resource_id, md5)).Times(1); |
1276 EXPECT_CALL(*mock_sync_client_, OnCacheCommitted(resource_id)).Times(1); | 1263 EXPECT_CALL(*mock_sync_client_, OnCacheCommitted(resource_id)).Times(1); |
1277 | 1264 |
1278 // First store a file to cache and pin it. | 1265 // First store a file to cache and pin it. |
1279 TestStoreToCache(resource_id, md5, GetTestFilePath("root_feed.json"), | 1266 TestStoreToCache(resource_id, md5, GetTestFilePath("root_feed.json"), |
1280 base::PLATFORM_FILE_OK, GDataCache::CACHE_STATE_PRESENT, | 1267 base::PLATFORM_FILE_OK, GDataCache::CACHE_STATE_PRESENT, |
1281 GDataCache::CACHE_TYPE_TMP); | 1268 GDataCache::CACHE_TYPE_TMP); |
1282 TestPin(resource_id, md5, base::PLATFORM_FILE_OK, | 1269 TestPin(resource_id, md5, base::PLATFORM_FILE_OK, |
1283 GDataCache::CACHE_STATE_PRESENT | GDataCache::CACHE_STATE_PINNED | | 1270 GDataCache::CACHE_STATE_PRESENT | GDataCache::CACHE_STATE_PINNED, |
1284 GDataCache::CACHE_STATE_PERSISTENT, | |
1285 GDataCache::CACHE_TYPE_PERSISTENT); | 1271 GDataCache::CACHE_TYPE_PERSISTENT); |
1286 | 1272 |
1287 // Mark the file dirty. | 1273 // Mark the file dirty. |
1288 num_callback_invocations_ = 0; | 1274 num_callback_invocations_ = 0; |
1289 TestMarkDirty(resource_id, md5, base::PLATFORM_FILE_OK, | 1275 TestMarkDirty(resource_id, md5, base::PLATFORM_FILE_OK, |
1290 GDataCache::CACHE_STATE_PRESENT | | 1276 GDataCache::CACHE_STATE_PRESENT | |
1291 GDataCache::CACHE_STATE_DIRTY | | 1277 GDataCache::CACHE_STATE_DIRTY | |
1292 GDataCache::CACHE_STATE_PINNED | | 1278 GDataCache::CACHE_STATE_PINNED, |
1293 GDataCache::CACHE_STATE_PERSISTENT, | |
1294 GDataCache::CACHE_TYPE_PERSISTENT); | 1279 GDataCache::CACHE_TYPE_PERSISTENT); |
1295 EXPECT_EQ(1, num_callback_invocations_); | 1280 EXPECT_EQ(1, num_callback_invocations_); |
1296 | 1281 |
1297 // Commit the file dirty. | 1282 // Commit the file dirty. |
1298 num_callback_invocations_ = 0; | 1283 num_callback_invocations_ = 0; |
1299 TestCommitDirty(resource_id, md5, base::PLATFORM_FILE_OK, | 1284 TestCommitDirty(resource_id, md5, base::PLATFORM_FILE_OK, |
1300 GDataCache::CACHE_STATE_PRESENT | | 1285 GDataCache::CACHE_STATE_PRESENT | |
1301 GDataCache::CACHE_STATE_DIRTY | | 1286 GDataCache::CACHE_STATE_DIRTY | |
1302 GDataCache::CACHE_STATE_PINNED | | 1287 GDataCache::CACHE_STATE_PINNED, |
1303 GDataCache::CACHE_STATE_PERSISTENT, | 1288 GDataCache::CACHE_TYPE_PERSISTENT); |
1304 GDataCache::CACHE_TYPE_PERSISTENT); | |
1305 EXPECT_EQ(1, num_callback_invocations_); | 1289 EXPECT_EQ(1, num_callback_invocations_); |
1306 | 1290 |
1307 // Clear dirty state of the file. | 1291 // Clear dirty state of the file. |
1308 num_callback_invocations_ = 0; | 1292 num_callback_invocations_ = 0; |
1309 TestClearDirty(resource_id, md5, base::PLATFORM_FILE_OK, | 1293 TestClearDirty(resource_id, md5, base::PLATFORM_FILE_OK, |
1310 GDataCache::CACHE_STATE_PRESENT | | 1294 GDataCache::CACHE_STATE_PRESENT | |
1311 GDataCache::CACHE_STATE_PINNED | | 1295 GDataCache::CACHE_STATE_PINNED, |
1312 GDataCache::CACHE_STATE_PERSISTENT, | |
1313 GDataCache::CACHE_TYPE_PERSISTENT); | 1296 GDataCache::CACHE_TYPE_PERSISTENT); |
1314 EXPECT_EQ(1, num_callback_invocations_); | 1297 EXPECT_EQ(1, num_callback_invocations_); |
1315 } | 1298 } |
1316 | 1299 |
1317 // Test is disabled because it is flaky (http://crbug.com/134146) | 1300 // Test is disabled because it is flaky (http://crbug.com/134146) |
1318 TEST_F(GDataCacheTest, PinAndUnpinDirtyCache) { | 1301 TEST_F(GDataCacheTest, PinAndUnpinDirtyCache) { |
1319 EXPECT_CALL(*mock_free_disk_space_checker_, AmountOfFreeDiskSpace()) | 1302 EXPECT_CALL(*mock_free_disk_space_checker_, AmountOfFreeDiskSpace()) |
1320 .Times(AtLeast(1)).WillRepeatedly(Return(kLotsOfSpace)); | 1303 .Times(AtLeast(1)).WillRepeatedly(Return(kLotsOfSpace)); |
1321 | 1304 |
1322 std::string resource_id("pdf:1a2b"); | 1305 std::string resource_id("pdf:1a2b"); |
1323 std::string md5("abcdef0123456789"); | 1306 std::string md5("abcdef0123456789"); |
1324 EXPECT_CALL(*mock_sync_client_, OnCachePinned(resource_id, md5)).Times(1); | 1307 EXPECT_CALL(*mock_sync_client_, OnCachePinned(resource_id, md5)).Times(1); |
1325 EXPECT_CALL(*mock_sync_client_, OnCacheUnpinned(resource_id, md5)).Times(1); | 1308 EXPECT_CALL(*mock_sync_client_, OnCacheUnpinned(resource_id, md5)).Times(1); |
1326 | 1309 |
1327 // First store a file to cache and mark it as dirty. | 1310 // First store a file to cache and mark it as dirty. |
1328 TestStoreToCache(resource_id, md5, GetTestFilePath("root_feed.json"), | 1311 TestStoreToCache(resource_id, md5, GetTestFilePath("root_feed.json"), |
1329 base::PLATFORM_FILE_OK, GDataCache::CACHE_STATE_PRESENT, | 1312 base::PLATFORM_FILE_OK, GDataCache::CACHE_STATE_PRESENT, |
1330 GDataCache::CACHE_TYPE_TMP); | 1313 GDataCache::CACHE_TYPE_TMP); |
1331 TestMarkDirty(resource_id, md5, base::PLATFORM_FILE_OK, | 1314 TestMarkDirty(resource_id, md5, base::PLATFORM_FILE_OK, |
1332 GDataCache::CACHE_STATE_PRESENT | | 1315 GDataCache::CACHE_STATE_PRESENT | GDataCache::CACHE_STATE_DIRTY, |
1333 GDataCache::CACHE_STATE_DIRTY | | |
1334 GDataCache::CACHE_STATE_PERSISTENT, | |
1335 GDataCache::CACHE_TYPE_PERSISTENT); | 1316 GDataCache::CACHE_TYPE_PERSISTENT); |
1336 | 1317 |
1337 // Verifies dirty file exists. | 1318 // Verifies dirty file exists. |
1338 FilePath dirty_path = GetCacheFilePath( | 1319 FilePath dirty_path = GetCacheFilePath( |
1339 resource_id, | 1320 resource_id, |
1340 md5, | 1321 md5, |
1341 GDataCache::CACHE_TYPE_PERSISTENT, | 1322 GDataCache::CACHE_TYPE_PERSISTENT, |
1342 GDataCache::CACHED_FILE_LOCALLY_MODIFIED); | 1323 GDataCache::CACHED_FILE_LOCALLY_MODIFIED); |
1343 EXPECT_TRUE(file_util::PathExists(dirty_path)); | 1324 EXPECT_TRUE(file_util::PathExists(dirty_path)); |
1344 | 1325 |
1345 // Pin the dirty file. | 1326 // Pin the dirty file. |
1346 TestPin(resource_id, md5, base::PLATFORM_FILE_OK, | 1327 TestPin(resource_id, md5, base::PLATFORM_FILE_OK, |
1347 GDataCache::CACHE_STATE_PRESENT | GDataCache::CACHE_STATE_DIRTY | | 1328 GDataCache::CACHE_STATE_PRESENT | GDataCache::CACHE_STATE_DIRTY | |
1348 GDataCache::CACHE_STATE_PINNED | GDataCache::CACHE_STATE_PERSISTENT, | 1329 GDataCache::CACHE_STATE_PINNED, |
1349 GDataCache::CACHE_TYPE_PERSISTENT); | 1330 GDataCache::CACHE_TYPE_PERSISTENT); |
1350 | 1331 |
1351 // Verify dirty file still exist at the same pathname. | 1332 // Verify dirty file still exist at the same pathname. |
1352 EXPECT_TRUE(file_util::PathExists(dirty_path)); | 1333 EXPECT_TRUE(file_util::PathExists(dirty_path)); |
1353 | 1334 |
1354 // Unpin the dirty file. | 1335 // Unpin the dirty file. |
1355 TestUnpin(resource_id, md5, base::PLATFORM_FILE_OK, | 1336 TestUnpin(resource_id, md5, base::PLATFORM_FILE_OK, |
1356 GDataCache::CACHE_STATE_PRESENT | GDataCache::CACHE_STATE_DIRTY | | 1337 GDataCache::CACHE_STATE_PRESENT | GDataCache::CACHE_STATE_DIRTY, |
1357 GDataCache::CACHE_STATE_PERSISTENT, | |
1358 GDataCache::CACHE_TYPE_PERSISTENT); | 1338 GDataCache::CACHE_TYPE_PERSISTENT); |
1359 | 1339 |
1360 // Verify dirty file still exist at the same pathname. | 1340 // Verify dirty file still exist at the same pathname. |
1361 EXPECT_TRUE(file_util::PathExists(dirty_path)); | 1341 EXPECT_TRUE(file_util::PathExists(dirty_path)); |
1362 } | 1342 } |
1363 | 1343 |
1364 TEST_F(GDataCacheTest, DirtyCacheRepetitive) { | 1344 TEST_F(GDataCacheTest, DirtyCacheRepetitive) { |
1365 std::string resource_id("pdf:1a2b"); | 1345 std::string resource_id("pdf:1a2b"); |
1366 std::string md5("abcdef0123456789"); | 1346 std::string md5("abcdef0123456789"); |
1367 EXPECT_CALL(*mock_sync_client_, OnCacheCommitted(resource_id)).Times(3); | 1347 EXPECT_CALL(*mock_sync_client_, OnCacheCommitted(resource_id)).Times(3); |
1368 | 1348 |
1369 // First store a file to cache. | 1349 // First store a file to cache. |
1370 TestStoreToCache(resource_id, md5, GetTestFilePath("root_feed.json"), | 1350 TestStoreToCache(resource_id, md5, GetTestFilePath("root_feed.json"), |
1371 base::PLATFORM_FILE_OK, GDataCache::CACHE_STATE_PRESENT, | 1351 base::PLATFORM_FILE_OK, GDataCache::CACHE_STATE_PRESENT, |
1372 GDataCache::CACHE_TYPE_TMP); | 1352 GDataCache::CACHE_TYPE_TMP); |
1373 | 1353 |
1374 // Mark the file dirty. | 1354 // Mark the file dirty. |
1375 num_callback_invocations_ = 0; | 1355 num_callback_invocations_ = 0; |
1376 TestMarkDirty(resource_id, md5, base::PLATFORM_FILE_OK, | 1356 TestMarkDirty(resource_id, md5, base::PLATFORM_FILE_OK, |
1377 GDataCache::CACHE_STATE_PRESENT | | 1357 GDataCache::CACHE_STATE_PRESENT | GDataCache::CACHE_STATE_DIRTY, |
1378 GDataCache::CACHE_STATE_DIRTY | | |
1379 GDataCache::CACHE_STATE_PERSISTENT, | |
1380 GDataCache::CACHE_TYPE_PERSISTENT); | 1358 GDataCache::CACHE_TYPE_PERSISTENT); |
1381 EXPECT_EQ(1, num_callback_invocations_); | 1359 EXPECT_EQ(1, num_callback_invocations_); |
1382 | 1360 |
1383 // Again, mark the file dirty. Nothing should change. | 1361 // Again, mark the file dirty. Nothing should change. |
1384 num_callback_invocations_ = 0; | 1362 num_callback_invocations_ = 0; |
1385 TestMarkDirty(resource_id, md5, base::PLATFORM_FILE_OK, | 1363 TestMarkDirty(resource_id, md5, base::PLATFORM_FILE_OK, |
1386 GDataCache::CACHE_STATE_PRESENT | | 1364 GDataCache::CACHE_STATE_PRESENT | GDataCache::CACHE_STATE_DIRTY, |
1387 GDataCache::CACHE_STATE_DIRTY | | |
1388 GDataCache::CACHE_STATE_PERSISTENT, | |
1389 GDataCache::CACHE_TYPE_PERSISTENT); | 1365 GDataCache::CACHE_TYPE_PERSISTENT); |
1390 EXPECT_EQ(1, num_callback_invocations_); | 1366 EXPECT_EQ(1, num_callback_invocations_); |
1391 | 1367 |
1392 // Commit the file dirty. Outgoing symlink should be created. | 1368 // Commit the file dirty. Outgoing symlink should be created. |
1393 num_callback_invocations_ = 0; | 1369 num_callback_invocations_ = 0; |
1394 TestCommitDirty(resource_id, md5, base::PLATFORM_FILE_OK, | 1370 TestCommitDirty(resource_id, md5, base::PLATFORM_FILE_OK, |
1395 GDataCache::CACHE_STATE_PRESENT | | 1371 GDataCache::CACHE_STATE_PRESENT | |
1396 GDataCache::CACHE_STATE_DIRTY | | 1372 GDataCache::CACHE_STATE_DIRTY, |
1397 GDataCache::CACHE_STATE_PERSISTENT, | 1373 GDataCache::CACHE_TYPE_PERSISTENT); |
1398 GDataCache::CACHE_TYPE_PERSISTENT); | |
1399 EXPECT_EQ(1, num_callback_invocations_); | 1374 EXPECT_EQ(1, num_callback_invocations_); |
1400 | 1375 |
1401 // Again, commit the file dirty. Nothing should change. | 1376 // Again, commit the file dirty. Nothing should change. |
1402 num_callback_invocations_ = 0; | 1377 num_callback_invocations_ = 0; |
1403 TestCommitDirty(resource_id, md5, base::PLATFORM_FILE_OK, | 1378 TestCommitDirty(resource_id, md5, base::PLATFORM_FILE_OK, |
1404 GDataCache::CACHE_STATE_PRESENT | | 1379 GDataCache::CACHE_STATE_PRESENT | |
1405 GDataCache::CACHE_STATE_DIRTY | | 1380 GDataCache::CACHE_STATE_DIRTY, |
1406 GDataCache::CACHE_STATE_PERSISTENT, | 1381 GDataCache::CACHE_TYPE_PERSISTENT); |
1407 GDataCache::CACHE_TYPE_PERSISTENT); | |
1408 EXPECT_EQ(1, num_callback_invocations_); | 1382 EXPECT_EQ(1, num_callback_invocations_); |
1409 | 1383 |
1410 // Mark the file dirty agian after it's being committed. Outgoing symlink | 1384 // Mark the file dirty agian after it's being committed. Outgoing symlink |
1411 // should be deleted. | 1385 // should be deleted. |
1412 num_callback_invocations_ = 0; | 1386 num_callback_invocations_ = 0; |
1413 TestMarkDirty(resource_id, md5, base::PLATFORM_FILE_OK, | 1387 TestMarkDirty(resource_id, md5, base::PLATFORM_FILE_OK, |
1414 GDataCache::CACHE_STATE_PRESENT | | 1388 GDataCache::CACHE_STATE_PRESENT | |
1415 GDataCache::CACHE_STATE_DIRTY | | 1389 GDataCache::CACHE_STATE_DIRTY, |
1416 GDataCache::CACHE_STATE_PERSISTENT, | |
1417 GDataCache::CACHE_TYPE_PERSISTENT); | 1390 GDataCache::CACHE_TYPE_PERSISTENT); |
1418 EXPECT_EQ(1, num_callback_invocations_); | 1391 EXPECT_EQ(1, num_callback_invocations_); |
1419 | 1392 |
1420 // Commit the file dirty. Outgoing symlink should be created again. | 1393 // Commit the file dirty. Outgoing symlink should be created again. |
1421 num_callback_invocations_ = 0; | 1394 num_callback_invocations_ = 0; |
1422 TestCommitDirty(resource_id, md5, base::PLATFORM_FILE_OK, | 1395 TestCommitDirty(resource_id, md5, base::PLATFORM_FILE_OK, |
1423 GDataCache::CACHE_STATE_PRESENT | | 1396 GDataCache::CACHE_STATE_PRESENT | |
1424 GDataCache::CACHE_STATE_DIRTY | | 1397 GDataCache::CACHE_STATE_DIRTY, |
1425 GDataCache::CACHE_STATE_PERSISTENT, | 1398 GDataCache::CACHE_TYPE_PERSISTENT); |
1426 GDataCache::CACHE_TYPE_PERSISTENT); | |
1427 EXPECT_EQ(1, num_callback_invocations_); | 1399 EXPECT_EQ(1, num_callback_invocations_); |
1428 | 1400 |
1429 // Clear dirty state of the file. | 1401 // Clear dirty state of the file. |
1430 num_callback_invocations_ = 0; | 1402 num_callback_invocations_ = 0; |
1431 TestClearDirty(resource_id, md5, base::PLATFORM_FILE_OK, | 1403 TestClearDirty(resource_id, md5, base::PLATFORM_FILE_OK, |
1432 GDataCache::CACHE_STATE_PRESENT, | 1404 GDataCache::CACHE_STATE_PRESENT, |
1433 GDataCache::CACHE_TYPE_TMP); | 1405 GDataCache::CACHE_TYPE_TMP); |
1434 EXPECT_EQ(1, num_callback_invocations_); | 1406 EXPECT_EQ(1, num_callback_invocations_); |
1435 | 1407 |
1436 // Again, clear dirty state of the file, which is no longer dirty. | 1408 // Again, clear dirty state of the file, which is no longer dirty. |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1481 // Clear dirty state of a non-dirty existing file. | 1453 // Clear dirty state of a non-dirty existing file. |
1482 num_callback_invocations_ = 0; | 1454 num_callback_invocations_ = 0; |
1483 TestClearDirty(resource_id, md5, base::PLATFORM_FILE_ERROR_INVALID_OPERATION, | 1455 TestClearDirty(resource_id, md5, base::PLATFORM_FILE_ERROR_INVALID_OPERATION, |
1484 GDataCache::CACHE_STATE_PRESENT, | 1456 GDataCache::CACHE_STATE_PRESENT, |
1485 GDataCache::CACHE_TYPE_TMP); | 1457 GDataCache::CACHE_TYPE_TMP); |
1486 EXPECT_EQ(1, num_callback_invocations_); | 1458 EXPECT_EQ(1, num_callback_invocations_); |
1487 | 1459 |
1488 // Mark an existing file dirty, then store a new file to the same resource id | 1460 // Mark an existing file dirty, then store a new file to the same resource id |
1489 // but different md5, which should fail. | 1461 // but different md5, which should fail. |
1490 TestMarkDirty(resource_id, md5, base::PLATFORM_FILE_OK, | 1462 TestMarkDirty(resource_id, md5, base::PLATFORM_FILE_OK, |
1491 GDataCache::CACHE_STATE_PRESENT | | 1463 GDataCache::CACHE_STATE_PRESENT | GDataCache::CACHE_STATE_DIRTY, |
1492 GDataCache::CACHE_STATE_DIRTY | | |
1493 GDataCache::CACHE_STATE_PERSISTENT, | |
1494 GDataCache::CACHE_TYPE_PERSISTENT); | 1464 GDataCache::CACHE_TYPE_PERSISTENT); |
1495 num_callback_invocations_ = 0; | 1465 num_callback_invocations_ = 0; |
1496 md5 = "new_md5"; | 1466 md5 = "new_md5"; |
1497 TestStoreToCache(resource_id, md5, GetTestFilePath("subdir_feed.json"), | 1467 TestStoreToCache(resource_id, md5, GetTestFilePath("subdir_feed.json"), |
1498 base::PLATFORM_FILE_ERROR_IN_USE, | 1468 base::PLATFORM_FILE_ERROR_IN_USE, |
1499 GDataCache::CACHE_STATE_PRESENT | | 1469 GDataCache::CACHE_STATE_PRESENT | |
1500 GDataCache::CACHE_STATE_DIRTY | | 1470 GDataCache::CACHE_STATE_DIRTY, |
1501 GDataCache::CACHE_STATE_PERSISTENT, | |
1502 GDataCache::CACHE_TYPE_PERSISTENT); | 1471 GDataCache::CACHE_TYPE_PERSISTENT); |
1503 EXPECT_EQ(1, num_callback_invocations_); | 1472 EXPECT_EQ(1, num_callback_invocations_); |
1504 } | 1473 } |
1505 | 1474 |
1506 TEST_F(GDataCacheTest, RemoveFromDirtyCache) { | 1475 TEST_F(GDataCacheTest, RemoveFromDirtyCache) { |
1507 std::string resource_id("pdf:1a2b"); | 1476 std::string resource_id("pdf:1a2b"); |
1508 std::string md5("abcdef0123456789"); | 1477 std::string md5("abcdef0123456789"); |
1509 EXPECT_CALL(*mock_sync_client_, OnCachePinned(resource_id, md5)).Times(1); | 1478 EXPECT_CALL(*mock_sync_client_, OnCachePinned(resource_id, md5)).Times(1); |
1510 EXPECT_CALL(*mock_sync_client_, OnCacheCommitted(resource_id)).Times(1); | 1479 EXPECT_CALL(*mock_sync_client_, OnCacheCommitted(resource_id)).Times(1); |
1511 | 1480 |
1512 // Store a file to cache, pin it, mark it dirty and commit it. | 1481 // Store a file to cache, pin it, mark it dirty and commit it. |
1513 TestStoreToCache(resource_id, md5, GetTestFilePath("root_feed.json"), | 1482 TestStoreToCache(resource_id, md5, GetTestFilePath("root_feed.json"), |
1514 base::PLATFORM_FILE_OK, GDataCache::CACHE_STATE_PRESENT, | 1483 base::PLATFORM_FILE_OK, GDataCache::CACHE_STATE_PRESENT, |
1515 GDataCache::CACHE_TYPE_TMP); | 1484 GDataCache::CACHE_TYPE_TMP); |
1516 TestPin(resource_id, md5, base::PLATFORM_FILE_OK, | 1485 TestPin(resource_id, md5, base::PLATFORM_FILE_OK, |
1517 GDataCache::CACHE_STATE_PRESENT | GDataCache::CACHE_STATE_PINNED | | 1486 GDataCache::CACHE_STATE_PRESENT | GDataCache::CACHE_STATE_PINNED, |
1518 GDataCache::CACHE_STATE_PERSISTENT, | |
1519 GDataCache::CACHE_TYPE_PERSISTENT); | 1487 GDataCache::CACHE_TYPE_PERSISTENT); |
1520 TestMarkDirty(resource_id, md5, base::PLATFORM_FILE_OK, | 1488 TestMarkDirty(resource_id, md5, base::PLATFORM_FILE_OK, |
1521 GDataCache::CACHE_STATE_PRESENT | | 1489 GDataCache::CACHE_STATE_PRESENT | |
1522 GDataCache::CACHE_STATE_PINNED | | 1490 GDataCache::CACHE_STATE_PINNED | |
1523 GDataCache::CACHE_STATE_DIRTY | | 1491 GDataCache::CACHE_STATE_DIRTY, |
1524 GDataCache::CACHE_STATE_PERSISTENT, | |
1525 GDataCache::CACHE_TYPE_PERSISTENT); | 1492 GDataCache::CACHE_TYPE_PERSISTENT); |
1526 TestCommitDirty(resource_id, md5, base::PLATFORM_FILE_OK, | 1493 TestCommitDirty(resource_id, md5, base::PLATFORM_FILE_OK, |
1527 GDataCache::CACHE_STATE_PRESENT | | 1494 GDataCache::CACHE_STATE_PRESENT | |
1528 GDataCache::CACHE_STATE_PINNED | | 1495 GDataCache::CACHE_STATE_PINNED | |
1529 GDataCache::CACHE_STATE_DIRTY | | 1496 GDataCache::CACHE_STATE_DIRTY, |
1530 GDataCache::CACHE_STATE_PERSISTENT, | 1497 GDataCache::CACHE_TYPE_PERSISTENT); |
1531 GDataCache::CACHE_TYPE_PERSISTENT); | |
1532 | 1498 |
1533 // Try to remove the file. Since file is dirty, it and the corresponding | 1499 // Try to remove the file. Since file is dirty, it and the corresponding |
1534 // pinned and outgoing symlinks should not be removed. | 1500 // pinned and outgoing symlinks should not be removed. |
1535 num_callback_invocations_ = 0; | 1501 num_callback_invocations_ = 0; |
1536 TestRemoveFromCache(resource_id, base::PLATFORM_FILE_OK); | 1502 TestRemoveFromCache(resource_id, base::PLATFORM_FILE_OK); |
1537 EXPECT_EQ(1, num_callback_invocations_); | 1503 EXPECT_EQ(1, num_callback_invocations_); |
1538 } | 1504 } |
1539 | 1505 |
1540 TEST_F(GDataCacheTest, GetCacheState) { | 1506 TEST_F(GDataCacheTest, GetCacheState) { |
1541 // Populate gdata file system. | 1507 // Populate gdata file system. |
(...skipping 29 matching lines...) Expand all Loading... |
1571 ASSERT_TRUE(entry != NULL); | 1537 ASSERT_TRUE(entry != NULL); |
1572 GDataFile* file = entry->AsGDataFile(); | 1538 GDataFile* file = entry->AsGDataFile(); |
1573 ASSERT_TRUE(file != NULL); | 1539 ASSERT_TRUE(file != NULL); |
1574 std::string resource_id = file->resource_id(); | 1540 std::string resource_id = file->resource_id(); |
1575 std::string md5 = file->file_md5(); | 1541 std::string md5 = file->file_md5(); |
1576 | 1542 |
1577 EXPECT_CALL(*mock_sync_client_, OnCachePinned(resource_id, md5)).Times(1); | 1543 EXPECT_CALL(*mock_sync_client_, OnCachePinned(resource_id, md5)).Times(1); |
1578 | 1544 |
1579 // Store a file corresponding to |resource_id| and |md5| to cache, and pin | 1545 // Store a file corresponding to |resource_id| and |md5| to cache, and pin |
1580 // it. | 1546 // it. |
1581 int expected_cache_state = (GDataCache::CACHE_STATE_PRESENT | | 1547 int expected_cache_state = GDataCache::CACHE_STATE_PRESENT | |
1582 GDataCache::CACHE_STATE_PINNED | | 1548 GDataCache::CACHE_STATE_PINNED; |
1583 GDataCache::CACHE_STATE_PERSISTENT); | |
1584 TestStoreToCache(resource_id, md5, GetTestFilePath("root_feed.json"), | 1549 TestStoreToCache(resource_id, md5, GetTestFilePath("root_feed.json"), |
1585 base::PLATFORM_FILE_OK, GDataCache::CACHE_STATE_PRESENT, | 1550 base::PLATFORM_FILE_OK, GDataCache::CACHE_STATE_PRESENT, |
1586 GDataCache::CACHE_TYPE_TMP); | 1551 GDataCache::CACHE_TYPE_TMP); |
1587 TestPin(resource_id, md5, base::PLATFORM_FILE_OK, expected_cache_state, | 1552 TestPin(resource_id, md5, base::PLATFORM_FILE_OK, expected_cache_state, |
1588 GDataCache::CACHE_TYPE_PERSISTENT); | 1553 GDataCache::CACHE_TYPE_PERSISTENT); |
1589 | 1554 |
1590 // Get its cache state. | 1555 // Get its cache state. |
1591 num_callback_invocations_ = 0; | 1556 num_callback_invocations_ = 0; |
1592 TestGetCacheState(resource_id, md5, true, | 1557 TestGetCacheState(resource_id, md5, true, |
1593 expected_cache_state, file); | 1558 expected_cache_state, file); |
(...skipping 19 matching lines...) Expand all Loading... |
1613 GDataCache::CACHE_TYPE_TMP); | 1578 GDataCache::CACHE_TYPE_TMP); |
1614 | 1579 |
1615 // Mark the file mounted. | 1580 // Mark the file mounted. |
1616 num_callback_invocations_ = 0; | 1581 num_callback_invocations_ = 0; |
1617 file_path = cache_->GetCacheFilePath(resource_id, md5, | 1582 file_path = cache_->GetCacheFilePath(resource_id, md5, |
1618 GDataCache::CACHE_TYPE_TMP, | 1583 GDataCache::CACHE_TYPE_TMP, |
1619 GDataCache::CACHED_FILE_FROM_SERVER); | 1584 GDataCache::CACHED_FILE_FROM_SERVER); |
1620 TestSetMountedState(resource_id, md5, file_path, true, | 1585 TestSetMountedState(resource_id, md5, file_path, true, |
1621 base::PLATFORM_FILE_OK, | 1586 base::PLATFORM_FILE_OK, |
1622 GDataCache::CACHE_STATE_PRESENT | | 1587 GDataCache::CACHE_STATE_PRESENT | |
1623 GDataCache::CACHE_STATE_MOUNTED | | 1588 GDataCache::CACHE_STATE_MOUNTED, |
1624 GDataCache::CACHE_STATE_PERSISTENT, | |
1625 GDataCache::CACHE_TYPE_PERSISTENT); | 1589 GDataCache::CACHE_TYPE_PERSISTENT); |
1626 EXPECT_EQ(1, num_callback_invocations_); | 1590 EXPECT_EQ(1, num_callback_invocations_); |
1627 EXPECT_TRUE(CacheEntryExists(resource_id, md5)); | 1591 EXPECT_TRUE(CacheEntryExists(resource_id, md5)); |
1628 | 1592 |
1629 // Clear mounted state of the file. | 1593 // Clear mounted state of the file. |
1630 num_callback_invocations_ = 0; | 1594 num_callback_invocations_ = 0; |
1631 file_path = cache_->GetCacheFilePath(resource_id, | 1595 file_path = cache_->GetCacheFilePath(resource_id, |
1632 md5, | 1596 md5, |
1633 GDataCache::CACHE_TYPE_PERSISTENT, | 1597 GDataCache::CACHE_TYPE_PERSISTENT, |
1634 GDataCache::CACHED_FILE_MOUNTED); | 1598 GDataCache::CACHED_FILE_MOUNTED); |
1635 TestSetMountedState(resource_id, md5, file_path, false, | 1599 TestSetMountedState(resource_id, md5, file_path, false, |
1636 base::PLATFORM_FILE_OK, | 1600 base::PLATFORM_FILE_OK, |
1637 GDataCache::CACHE_STATE_PRESENT, | 1601 GDataCache::CACHE_STATE_PRESENT, |
1638 GDataCache::CACHE_TYPE_TMP); | 1602 GDataCache::CACHE_TYPE_TMP); |
1639 EXPECT_EQ(1, num_callback_invocations_); | 1603 EXPECT_EQ(1, num_callback_invocations_); |
1640 EXPECT_TRUE(CacheEntryExists(resource_id, md5)); | 1604 EXPECT_TRUE(CacheEntryExists(resource_id, md5)); |
1641 | 1605 |
1642 // Try to remove the file. | 1606 // Try to remove the file. |
1643 num_callback_invocations_ = 0; | 1607 num_callback_invocations_ = 0; |
1644 TestRemoveFromCache(resource_id, base::PLATFORM_FILE_OK); | 1608 TestRemoveFromCache(resource_id, base::PLATFORM_FILE_OK); |
1645 EXPECT_EQ(1, num_callback_invocations_); | 1609 EXPECT_EQ(1, num_callback_invocations_); |
1646 } | 1610 } |
1647 | 1611 |
1648 } // namespace gdata | 1612 } // namespace gdata |
OLD | NEW |