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