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

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

Issue 10854110: Revert 151238 - Check for space before storing files to the cache. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/chromeos/gdata/gdata_cache.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <vector> 5 #include <vector>
6 6
7 #include "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/message_loop.h" 8 #include "base/message_loop.h"
9 #include "base/path_service.h" 9 #include "base/path_service.h"
10 #include "base/threading/sequenced_worker_pool.h" 10 #include "base/threading/sequenced_worker_pool.h"
(...skipping 791 matching lines...) Expand 10 before | Expand all | Expand 10 after
802 std::string escaped_resource_id = util::EscapeCacheFileName(resource_id); 802 std::string escaped_resource_id = util::EscapeCacheFileName(resource_id);
803 std::string escaped_md5 = util::EscapeCacheFileName(md5); 803 std::string escaped_md5 = util::EscapeCacheFileName(md5);
804 num_callback_invocations_ = 0; 804 num_callback_invocations_ = 0;
805 TestGetCacheFilePath(resource_id, md5, 805 TestGetCacheFilePath(resource_id, md5,
806 escaped_resource_id + FilePath::kExtensionSeparator + 806 escaped_resource_id + FilePath::kExtensionSeparator +
807 escaped_md5); 807 escaped_md5);
808 EXPECT_EQ(0, num_callback_invocations_); 808 EXPECT_EQ(0, num_callback_invocations_);
809 } 809 }
810 810
811 TEST_F(GDataCacheTest, StoreToCacheSimple) { 811 TEST_F(GDataCacheTest, StoreToCacheSimple) {
812 EXPECT_CALL(*mock_free_disk_space_checker_, AmountOfFreeDiskSpace())
813 .Times(AtLeast(1)).WillRepeatedly(Return(kLotsOfSpace));
814
815 std::string resource_id("pdf:1a2b"); 812 std::string resource_id("pdf:1a2b");
816 std::string md5("abcdef0123456789"); 813 std::string md5("abcdef0123456789");
817 814
818 // Store an existing file. 815 // Store an existing file.
819 TestStoreToCache(resource_id, md5, GetTestFilePath("root_feed.json"), 816 TestStoreToCache(resource_id, md5, GetTestFilePath("root_feed.json"),
820 GDATA_FILE_OK, test_util::TEST_CACHE_STATE_PRESENT, 817 GDATA_FILE_OK, test_util::TEST_CACHE_STATE_PRESENT,
821 GDataCache::CACHE_TYPE_TMP); 818 GDataCache::CACHE_TYPE_TMP);
822 EXPECT_EQ(1, num_callback_invocations_); 819 EXPECT_EQ(1, num_callback_invocations_);
823 820
824 // Store a non-existent file to the same |resource_id| and |md5|. 821 // Store a non-existent file to the same |resource_id| and |md5|.
(...skipping 12 matching lines...) Expand all
837 GDATA_FILE_OK, test_util::TEST_CACHE_STATE_PRESENT, 834 GDATA_FILE_OK, test_util::TEST_CACHE_STATE_PRESENT,
838 GDataCache::CACHE_TYPE_TMP); 835 GDataCache::CACHE_TYPE_TMP);
839 EXPECT_EQ(1, num_callback_invocations_); 836 EXPECT_EQ(1, num_callback_invocations_);
840 837
841 // Verify that there's only one file with name <resource_id>, i.e. previously 838 // Verify that there's only one file with name <resource_id>, i.e. previously
842 // cached file with the different md5 should be deleted. 839 // cached file with the different md5 should be deleted.
843 EXPECT_EQ(1U, CountCacheFiles(resource_id, md5)); 840 EXPECT_EQ(1U, CountCacheFiles(resource_id, md5));
844 } 841 }
845 842
846 TEST_F(GDataCacheTest, GetFromCacheSimple) { 843 TEST_F(GDataCacheTest, GetFromCacheSimple) {
847 EXPECT_CALL(*mock_free_disk_space_checker_, AmountOfFreeDiskSpace())
848 .Times(AtLeast(1)).WillRepeatedly(Return(kLotsOfSpace));
849
850 std::string resource_id("pdf:1a2b"); 844 std::string resource_id("pdf:1a2b");
851 std::string md5("abcdef0123456789"); 845 std::string md5("abcdef0123456789");
852 // First store a file to cache. 846 // First store a file to cache.
853 TestStoreToCache(resource_id, md5, GetTestFilePath("root_feed.json"), 847 TestStoreToCache(resource_id, md5, GetTestFilePath("root_feed.json"),
854 GDATA_FILE_OK, test_util::TEST_CACHE_STATE_PRESENT, 848 GDATA_FILE_OK, test_util::TEST_CACHE_STATE_PRESENT,
855 GDataCache::CACHE_TYPE_TMP); 849 GDataCache::CACHE_TYPE_TMP);
856 850
857 // Then try to get the existing file from cache. 851 // Then try to get the existing file from cache.
858 num_callback_invocations_ = 0; 852 num_callback_invocations_ = 0;
859 TestGetFileFromCacheByResourceIdAndMd5( 853 TestGetFileFromCacheByResourceIdAndMd5(
(...skipping 10 matching lines...) Expand all
870 // Get file from cache with different resource id from existing file but same 864 // Get file from cache with different resource id from existing file but same
871 // md5. 865 // md5.
872 num_callback_invocations_ = 0; 866 num_callback_invocations_ = 0;
873 resource_id = "document:1a2b"; 867 resource_id = "document:1a2b";
874 TestGetFileFromCacheByResourceIdAndMd5( 868 TestGetFileFromCacheByResourceIdAndMd5(
875 resource_id, md5, GDATA_FILE_ERROR_NOT_FOUND, md5); 869 resource_id, md5, GDATA_FILE_ERROR_NOT_FOUND, md5);
876 EXPECT_EQ(1, num_callback_invocations_); 870 EXPECT_EQ(1, num_callback_invocations_);
877 } 871 }
878 872
879 TEST_F(GDataCacheTest, RemoveFromCacheSimple) { 873 TEST_F(GDataCacheTest, RemoveFromCacheSimple) {
880 EXPECT_CALL(*mock_free_disk_space_checker_, AmountOfFreeDiskSpace())
881 .Times(AtLeast(1)).WillRepeatedly(Return(kLotsOfSpace));
882
883 // Use alphanumeric characters for resource id. 874 // Use alphanumeric characters for resource id.
884 std::string resource_id("pdf:1a2b"); 875 std::string resource_id("pdf:1a2b");
885 std::string md5("abcdef0123456789"); 876 std::string md5("abcdef0123456789");
886 // First store a file to cache. 877 // First store a file to cache.
887 TestStoreToCache(resource_id, md5, GetTestFilePath("root_feed.json"), 878 TestStoreToCache(resource_id, md5, GetTestFilePath("root_feed.json"),
888 GDATA_FILE_OK, test_util::TEST_CACHE_STATE_PRESENT, 879 GDATA_FILE_OK, test_util::TEST_CACHE_STATE_PRESENT,
889 GDataCache::CACHE_TYPE_TMP); 880 GDataCache::CACHE_TYPE_TMP);
890 881
891 // Then try to remove existing file from cache. 882 // Then try to remove existing file from cache.
892 num_callback_invocations_ = 0; 883 num_callback_invocations_ = 0;
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
972 .Times(0); 963 .Times(0);
973 964
974 num_callback_invocations_ = 0; 965 num_callback_invocations_ = 0;
975 TestUnpin(resource_id, md5, GDATA_FILE_ERROR_NOT_FOUND, 966 TestUnpin(resource_id, md5, GDATA_FILE_ERROR_NOT_FOUND,
976 test_util::TEST_CACHE_STATE_NONE, 967 test_util::TEST_CACHE_STATE_NONE,
977 GDataCache::CACHE_TYPE_TMP /* non-applicable */); 968 GDataCache::CACHE_TYPE_TMP /* non-applicable */);
978 EXPECT_EQ(1, num_callback_invocations_); 969 EXPECT_EQ(1, num_callback_invocations_);
979 } 970 }
980 971
981 TEST_F(GDataCacheTest, StoreToCachePinned) { 972 TEST_F(GDataCacheTest, StoreToCachePinned) {
982 EXPECT_CALL(*mock_free_disk_space_checker_, AmountOfFreeDiskSpace())
983 .Times(AtLeast(1)).WillRepeatedly(Return(kLotsOfSpace));
984
985 std::string resource_id("pdf:1a2b"); 973 std::string resource_id("pdf:1a2b");
986 std::string md5("abcdef0123456789"); 974 std::string md5("abcdef0123456789");
987 EXPECT_CALL(*mock_cache_observer_, OnCachePinned(resource_id, md5)).Times(1); 975 EXPECT_CALL(*mock_cache_observer_, OnCachePinned(resource_id, md5)).Times(1);
988 976
989 // Pin a non-existent file. 977 // Pin a non-existent file.
990 TestPin(resource_id, md5, GDATA_FILE_OK, 978 TestPin(resource_id, md5, GDATA_FILE_OK,
991 test_util::TEST_CACHE_STATE_PINNED, 979 test_util::TEST_CACHE_STATE_PINNED,
992 GDataCache::CACHE_TYPE_TMP); 980 GDataCache::CACHE_TYPE_TMP);
993 981
994 // Store an existing file to a previously pinned file. 982 // Store an existing file to a previously pinned file.
(...skipping 11 matching lines...) Expand all
1006 TestStoreToCache(resource_id, md5, FilePath("./non_existent.json"), 994 TestStoreToCache(resource_id, md5, FilePath("./non_existent.json"),
1007 GDATA_FILE_ERROR_FAILED, 995 GDATA_FILE_ERROR_FAILED,
1008 test_util::TEST_CACHE_STATE_PRESENT | 996 test_util::TEST_CACHE_STATE_PRESENT |
1009 test_util::TEST_CACHE_STATE_PINNED | 997 test_util::TEST_CACHE_STATE_PINNED |
1010 test_util::TEST_CACHE_STATE_PERSISTENT, 998 test_util::TEST_CACHE_STATE_PERSISTENT,
1011 GDataCache::CACHE_TYPE_PERSISTENT); 999 GDataCache::CACHE_TYPE_PERSISTENT);
1012 EXPECT_EQ(1, num_callback_invocations_); 1000 EXPECT_EQ(1, num_callback_invocations_);
1013 } 1001 }
1014 1002
1015 TEST_F(GDataCacheTest, GetFromCachePinned) { 1003 TEST_F(GDataCacheTest, GetFromCachePinned) {
1016 EXPECT_CALL(*mock_free_disk_space_checker_, AmountOfFreeDiskSpace())
1017 .Times(AtLeast(1)).WillRepeatedly(Return(kLotsOfSpace));
1018
1019 std::string resource_id("pdf:1a2b"); 1004 std::string resource_id("pdf:1a2b");
1020 std::string md5("abcdef0123456789"); 1005 std::string md5("abcdef0123456789");
1021 EXPECT_CALL(*mock_cache_observer_, OnCachePinned(resource_id, md5)).Times(1); 1006 EXPECT_CALL(*mock_cache_observer_, OnCachePinned(resource_id, md5)).Times(1);
1022 1007
1023 // Pin a non-existent file. 1008 // Pin a non-existent file.
1024 TestPin(resource_id, md5, GDATA_FILE_OK, 1009 TestPin(resource_id, md5, GDATA_FILE_OK,
1025 test_util::TEST_CACHE_STATE_PINNED, 1010 test_util::TEST_CACHE_STATE_PINNED,
1026 GDataCache::CACHE_TYPE_TMP); 1011 GDataCache::CACHE_TYPE_TMP);
1027 1012
1028 // Get the non-existent pinned file from cache. 1013 // Get the non-existent pinned file from cache.
(...skipping 11 matching lines...) Expand all
1040 GDataCache::CACHE_TYPE_PERSISTENT); 1025 GDataCache::CACHE_TYPE_PERSISTENT);
1041 1026
1042 // Get the previously pinned and stored file from cache. 1027 // Get the previously pinned and stored file from cache.
1043 num_callback_invocations_ = 0; 1028 num_callback_invocations_ = 0;
1044 TestGetFileFromCacheByResourceIdAndMd5( 1029 TestGetFileFromCacheByResourceIdAndMd5(
1045 resource_id, md5, GDATA_FILE_OK, md5); 1030 resource_id, md5, GDATA_FILE_OK, md5);
1046 EXPECT_EQ(1, num_callback_invocations_); 1031 EXPECT_EQ(1, num_callback_invocations_);
1047 } 1032 }
1048 1033
1049 TEST_F(GDataCacheTest, RemoveFromCachePinned) { 1034 TEST_F(GDataCacheTest, RemoveFromCachePinned) {
1050 EXPECT_CALL(*mock_free_disk_space_checker_, AmountOfFreeDiskSpace())
1051 .Times(AtLeast(1)).WillRepeatedly(Return(kLotsOfSpace));
1052
1053 // Use alphanumeric characters for resource_id. 1035 // Use alphanumeric characters for resource_id.
1054 std::string resource_id("pdf:1a2b"); 1036 std::string resource_id("pdf:1a2b");
1055 std::string md5("abcdef0123456789"); 1037 std::string md5("abcdef0123456789");
1056 EXPECT_CALL(*mock_cache_observer_, OnCachePinned(resource_id, md5)).Times(1); 1038 EXPECT_CALL(*mock_cache_observer_, OnCachePinned(resource_id, md5)).Times(1);
1057 1039
1058 // Store a file to cache, and pin it. 1040 // Store a file to cache, and pin it.
1059 TestStoreToCache(resource_id, md5, GetTestFilePath("root_feed.json"), 1041 TestStoreToCache(resource_id, md5, GetTestFilePath("root_feed.json"),
1060 GDATA_FILE_OK, test_util::TEST_CACHE_STATE_PRESENT, 1042 GDATA_FILE_OK, test_util::TEST_CACHE_STATE_PRESENT,
1061 GDataCache::CACHE_TYPE_TMP); 1043 GDataCache::CACHE_TYPE_TMP);
1062 TestPin(resource_id, md5, GDATA_FILE_OK, 1044 TestPin(resource_id, md5, GDATA_FILE_OK,
(...skipping 20 matching lines...) Expand all
1083 test_util::TEST_CACHE_STATE_PINNED | 1065 test_util::TEST_CACHE_STATE_PINNED |
1084 test_util::TEST_CACHE_STATE_PERSISTENT, 1066 test_util::TEST_CACHE_STATE_PERSISTENT,
1085 GDataCache::CACHE_TYPE_PERSISTENT); 1067 GDataCache::CACHE_TYPE_PERSISTENT);
1086 1068
1087 num_callback_invocations_ = 0; 1069 num_callback_invocations_ = 0;
1088 TestRemoveFromCache(resource_id, GDATA_FILE_OK); 1070 TestRemoveFromCache(resource_id, GDATA_FILE_OK);
1089 EXPECT_EQ(1, num_callback_invocations_); 1071 EXPECT_EQ(1, num_callback_invocations_);
1090 } 1072 }
1091 1073
1092 TEST_F(GDataCacheTest, DirtyCacheSimple) { 1074 TEST_F(GDataCacheTest, DirtyCacheSimple) {
1093 EXPECT_CALL(*mock_free_disk_space_checker_, AmountOfFreeDiskSpace())
1094 .Times(AtLeast(1)).WillRepeatedly(Return(kLotsOfSpace));
1095
1096 std::string resource_id("pdf:1a2b"); 1075 std::string resource_id("pdf:1a2b");
1097 std::string md5("abcdef0123456789"); 1076 std::string md5("abcdef0123456789");
1098 EXPECT_CALL(*mock_cache_observer_, OnCacheCommitted(resource_id)).Times(1); 1077 EXPECT_CALL(*mock_cache_observer_, OnCacheCommitted(resource_id)).Times(1);
1099 1078
1100 // First store a file to cache. 1079 // First store a file to cache.
1101 TestStoreToCache(resource_id, md5, GetTestFilePath("root_feed.json"), 1080 TestStoreToCache(resource_id, md5, GetTestFilePath("root_feed.json"),
1102 GDATA_FILE_OK, test_util::TEST_CACHE_STATE_PRESENT, 1081 GDATA_FILE_OK, test_util::TEST_CACHE_STATE_PRESENT,
1103 GDataCache::CACHE_TYPE_TMP); 1082 GDataCache::CACHE_TYPE_TMP);
1104 1083
1105 // Mark the file dirty. 1084 // Mark the file dirty.
(...skipping 16 matching lines...) Expand all
1122 1101
1123 // Clear dirty state of the file. 1102 // Clear dirty state of the file.
1124 num_callback_invocations_ = 0; 1103 num_callback_invocations_ = 0;
1125 TestClearDirty(resource_id, md5, GDATA_FILE_OK, 1104 TestClearDirty(resource_id, md5, GDATA_FILE_OK,
1126 test_util::TEST_CACHE_STATE_PRESENT, 1105 test_util::TEST_CACHE_STATE_PRESENT,
1127 GDataCache::CACHE_TYPE_TMP); 1106 GDataCache::CACHE_TYPE_TMP);
1128 EXPECT_EQ(1, num_callback_invocations_); 1107 EXPECT_EQ(1, num_callback_invocations_);
1129 } 1108 }
1130 1109
1131 TEST_F(GDataCacheTest, DirtyCachePinned) { 1110 TEST_F(GDataCacheTest, DirtyCachePinned) {
1132 EXPECT_CALL(*mock_free_disk_space_checker_, AmountOfFreeDiskSpace())
1133 .Times(AtLeast(1)).WillRepeatedly(Return(kLotsOfSpace));
1134
1135 std::string resource_id("pdf:1a2b"); 1111 std::string resource_id("pdf:1a2b");
1136 std::string md5("abcdef0123456789"); 1112 std::string md5("abcdef0123456789");
1137 EXPECT_CALL(*mock_cache_observer_, OnCachePinned(resource_id, md5)).Times(1); 1113 EXPECT_CALL(*mock_cache_observer_, OnCachePinned(resource_id, md5)).Times(1);
1138 EXPECT_CALL(*mock_cache_observer_, OnCacheCommitted(resource_id)).Times(1); 1114 EXPECT_CALL(*mock_cache_observer_, OnCacheCommitted(resource_id)).Times(1);
1139 1115
1140 // First store a file to cache and pin it. 1116 // First store a file to cache and pin it.
1141 TestStoreToCache(resource_id, md5, GetTestFilePath("root_feed.json"), 1117 TestStoreToCache(resource_id, md5, GetTestFilePath("root_feed.json"),
1142 GDATA_FILE_OK, test_util::TEST_CACHE_STATE_PRESENT, 1118 GDATA_FILE_OK, test_util::TEST_CACHE_STATE_PRESENT,
1143 GDataCache::CACHE_TYPE_TMP); 1119 GDataCache::CACHE_TYPE_TMP);
1144 TestPin(resource_id, md5, GDATA_FILE_OK, 1120 TestPin(resource_id, md5, GDATA_FILE_OK,
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
1222 test_util::TEST_CACHE_STATE_PRESENT | 1198 test_util::TEST_CACHE_STATE_PRESENT |
1223 test_util::TEST_CACHE_STATE_DIRTY | 1199 test_util::TEST_CACHE_STATE_DIRTY |
1224 test_util::TEST_CACHE_STATE_PERSISTENT, 1200 test_util::TEST_CACHE_STATE_PERSISTENT,
1225 GDataCache::CACHE_TYPE_PERSISTENT); 1201 GDataCache::CACHE_TYPE_PERSISTENT);
1226 1202
1227 // Verify dirty file still exist at the same pathname. 1203 // Verify dirty file still exist at the same pathname.
1228 EXPECT_TRUE(file_util::PathExists(dirty_path)); 1204 EXPECT_TRUE(file_util::PathExists(dirty_path));
1229 } 1205 }
1230 1206
1231 TEST_F(GDataCacheTest, DirtyCacheRepetitive) { 1207 TEST_F(GDataCacheTest, DirtyCacheRepetitive) {
1232 EXPECT_CALL(*mock_free_disk_space_checker_, AmountOfFreeDiskSpace())
1233 .Times(AtLeast(1)).WillRepeatedly(Return(kLotsOfSpace));
1234
1235 std::string resource_id("pdf:1a2b"); 1208 std::string resource_id("pdf:1a2b");
1236 std::string md5("abcdef0123456789"); 1209 std::string md5("abcdef0123456789");
1237 EXPECT_CALL(*mock_cache_observer_, OnCacheCommitted(resource_id)).Times(3); 1210 EXPECT_CALL(*mock_cache_observer_, OnCacheCommitted(resource_id)).Times(3);
1238 1211
1239 // First store a file to cache. 1212 // First store a file to cache.
1240 TestStoreToCache(resource_id, md5, GetTestFilePath("root_feed.json"), 1213 TestStoreToCache(resource_id, md5, GetTestFilePath("root_feed.json"),
1241 GDATA_FILE_OK, test_util::TEST_CACHE_STATE_PRESENT, 1214 GDATA_FILE_OK, test_util::TEST_CACHE_STATE_PRESENT,
1242 GDataCache::CACHE_TYPE_TMP); 1215 GDataCache::CACHE_TYPE_TMP);
1243 1216
1244 // Mark the file dirty. 1217 // Mark the file dirty.
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
1305 1278
1306 // Again, clear dirty state of the file, which is no longer dirty. 1279 // Again, clear dirty state of the file, which is no longer dirty.
1307 num_callback_invocations_ = 0; 1280 num_callback_invocations_ = 0;
1308 TestClearDirty(resource_id, md5, GDATA_FILE_ERROR_INVALID_OPERATION, 1281 TestClearDirty(resource_id, md5, GDATA_FILE_ERROR_INVALID_OPERATION,
1309 test_util::TEST_CACHE_STATE_PRESENT, 1282 test_util::TEST_CACHE_STATE_PRESENT,
1310 GDataCache::CACHE_TYPE_TMP); 1283 GDataCache::CACHE_TYPE_TMP);
1311 EXPECT_EQ(1, num_callback_invocations_); 1284 EXPECT_EQ(1, num_callback_invocations_);
1312 } 1285 }
1313 1286
1314 TEST_F(GDataCacheTest, DirtyCacheInvalid) { 1287 TEST_F(GDataCacheTest, DirtyCacheInvalid) {
1315 EXPECT_CALL(*mock_free_disk_space_checker_, AmountOfFreeDiskSpace())
1316 .Times(AtLeast(1)).WillRepeatedly(Return(kLotsOfSpace));
1317
1318 std::string resource_id("pdf:1a2b"); 1288 std::string resource_id("pdf:1a2b");
1319 std::string md5("abcdef0123456789"); 1289 std::string md5("abcdef0123456789");
1320 1290
1321 // Mark a non-existent file dirty. 1291 // Mark a non-existent file dirty.
1322 num_callback_invocations_ = 0; 1292 num_callback_invocations_ = 0;
1323 TestMarkDirty(resource_id, md5, GDATA_FILE_ERROR_NOT_FOUND, 1293 TestMarkDirty(resource_id, md5, GDATA_FILE_ERROR_NOT_FOUND,
1324 test_util::TEST_CACHE_STATE_NONE, 1294 test_util::TEST_CACHE_STATE_NONE,
1325 GDataCache::CACHE_TYPE_TMP); 1295 GDataCache::CACHE_TYPE_TMP);
1326 EXPECT_EQ(1, num_callback_invocations_); 1296 EXPECT_EQ(1, num_callback_invocations_);
1327 1297
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
1370 TestStoreToCache(resource_id, md5, GetTestFilePath("subdir_feed.json"), 1340 TestStoreToCache(resource_id, md5, GetTestFilePath("subdir_feed.json"),
1371 GDATA_FILE_ERROR_IN_USE, 1341 GDATA_FILE_ERROR_IN_USE,
1372 test_util::TEST_CACHE_STATE_PRESENT | 1342 test_util::TEST_CACHE_STATE_PRESENT |
1373 test_util::TEST_CACHE_STATE_DIRTY | 1343 test_util::TEST_CACHE_STATE_DIRTY |
1374 test_util::TEST_CACHE_STATE_PERSISTENT, 1344 test_util::TEST_CACHE_STATE_PERSISTENT,
1375 GDataCache::CACHE_TYPE_PERSISTENT); 1345 GDataCache::CACHE_TYPE_PERSISTENT);
1376 EXPECT_EQ(1, num_callback_invocations_); 1346 EXPECT_EQ(1, num_callback_invocations_);
1377 } 1347 }
1378 1348
1379 TEST_F(GDataCacheTest, RemoveFromDirtyCache) { 1349 TEST_F(GDataCacheTest, RemoveFromDirtyCache) {
1380 EXPECT_CALL(*mock_free_disk_space_checker_, AmountOfFreeDiskSpace())
1381 .Times(AtLeast(1)).WillRepeatedly(Return(kLotsOfSpace));
1382
1383 std::string resource_id("pdf:1a2b"); 1350 std::string resource_id("pdf:1a2b");
1384 std::string md5("abcdef0123456789"); 1351 std::string md5("abcdef0123456789");
1385 EXPECT_CALL(*mock_cache_observer_, OnCachePinned(resource_id, md5)).Times(1); 1352 EXPECT_CALL(*mock_cache_observer_, OnCachePinned(resource_id, md5)).Times(1);
1386 EXPECT_CALL(*mock_cache_observer_, OnCacheCommitted(resource_id)).Times(1); 1353 EXPECT_CALL(*mock_cache_observer_, OnCacheCommitted(resource_id)).Times(1);
1387 1354
1388 // Store a file to cache, pin it, mark it dirty and commit it. 1355 // Store a file to cache, pin it, mark it dirty and commit it.
1389 TestStoreToCache(resource_id, md5, GetTestFilePath("root_feed.json"), 1356 TestStoreToCache(resource_id, md5, GetTestFilePath("root_feed.json"),
1390 GDATA_FILE_OK, test_util::TEST_CACHE_STATE_PRESENT, 1357 GDATA_FILE_OK, test_util::TEST_CACHE_STATE_PRESENT,
1391 GDataCache::CACHE_TYPE_TMP); 1358 GDataCache::CACHE_TYPE_TMP);
1392 TestPin(resource_id, md5, GDATA_FILE_OK, 1359 TestPin(resource_id, md5, GDATA_FILE_OK,
(...skipping 15 matching lines...) Expand all
1408 GDataCache::CACHE_TYPE_PERSISTENT); 1375 GDataCache::CACHE_TYPE_PERSISTENT);
1409 1376
1410 // Try to remove the file. Since file is dirty, it and the corresponding 1377 // Try to remove the file. Since file is dirty, it and the corresponding
1411 // pinned and outgoing symlinks should not be removed. 1378 // pinned and outgoing symlinks should not be removed.
1412 num_callback_invocations_ = 0; 1379 num_callback_invocations_ = 0;
1413 TestRemoveFromCache(resource_id, GDATA_FILE_OK); 1380 TestRemoveFromCache(resource_id, GDATA_FILE_OK);
1414 EXPECT_EQ(1, num_callback_invocations_); 1381 EXPECT_EQ(1, num_callback_invocations_);
1415 } 1382 }
1416 1383
1417 TEST_F(GDataCacheTest, MountUnmount) { 1384 TEST_F(GDataCacheTest, MountUnmount) {
1418 EXPECT_CALL(*mock_free_disk_space_checker_, AmountOfFreeDiskSpace())
1419 .Times(AtLeast(1)).WillRepeatedly(Return(kLotsOfSpace));
1420
1421 FilePath file_path; 1385 FilePath file_path;
1422 std::string resource_id("pdf:1a2b"); 1386 std::string resource_id("pdf:1a2b");
1423 std::string md5("abcdef0123456789"); 1387 std::string md5("abcdef0123456789");
1424 1388
1425 // First store a file to cache in the tmp subdir. 1389 // First store a file to cache in the tmp subdir.
1426 TestStoreToCache(resource_id, md5, GetTestFilePath("root_feed.json"), 1390 TestStoreToCache(resource_id, md5, GetTestFilePath("root_feed.json"),
1427 GDATA_FILE_OK, test_util::TEST_CACHE_STATE_PRESENT, 1391 GDATA_FILE_OK, test_util::TEST_CACHE_STATE_PRESENT,
1428 GDataCache::CACHE_TYPE_TMP); 1392 GDataCache::CACHE_TYPE_TMP);
1429 1393
1430 // Mark the file mounted. 1394 // Mark the file mounted.
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
1508 EXPECT_EQ("pinned:existing", resource_ids[2]); 1472 EXPECT_EQ("pinned:existing", resource_ids[2]);
1509 EXPECT_EQ("pinned:non-existent", resource_ids[3]); 1473 EXPECT_EQ("pinned:non-existent", resource_ids[3]);
1510 EXPECT_EQ("tmp:`~!@#$%^&*()-_=+[{|]}\\;',<.>/?", resource_ids[4]); 1474 EXPECT_EQ("tmp:`~!@#$%^&*()-_=+[{|]}\\;',<.>/?", resource_ids[4]);
1511 EXPECT_EQ("tmp:resource_id", resource_ids[5]); 1475 EXPECT_EQ("tmp:resource_id", resource_ids[5]);
1512 } 1476 }
1513 1477
1514 1478
1515 TEST_F(GDataCacheTest, ClearAllOnUIThread) { 1479 TEST_F(GDataCacheTest, ClearAllOnUIThread) {
1516 PrepareForInitCacheTest(); 1480 PrepareForInitCacheTest();
1517 1481
1518 EXPECT_CALL(*mock_free_disk_space_checker_, AmountOfFreeDiskSpace())
1519 .Times(AtLeast(1)).WillRepeatedly(Return(kLotsOfSpace));
1520
1521 std::string resource_id("pdf:1a2b"); 1482 std::string resource_id("pdf:1a2b");
1522 std::string md5("abcdef0123456789"); 1483 std::string md5("abcdef0123456789");
1523 1484
1524 // Store an existing file. 1485 // Store an existing file.
1525 TestStoreToCache(resource_id, md5, GetTestFilePath("root_feed.json"), 1486 TestStoreToCache(resource_id, md5, GetTestFilePath("root_feed.json"),
1526 GDATA_FILE_OK, test_util::TEST_CACHE_STATE_PRESENT, 1487 GDATA_FILE_OK, test_util::TEST_CACHE_STATE_PRESENT,
1527 GDataCache::CACHE_TYPE_TMP); 1488 GDataCache::CACHE_TYPE_TMP);
1528 EXPECT_EQ(1, num_callback_invocations_); 1489 EXPECT_EQ(1, num_callback_invocations_);
1529 1490
1530 // Verify that there's only one cached file. 1491 // Verify that there's only one cached file.
1531 EXPECT_EQ(1U, CountCacheFiles(resource_id, md5)); 1492 EXPECT_EQ(1U, CountCacheFiles(resource_id, md5));
1532 1493
1533 // Clear cache. 1494 // Clear cache.
1534 GDataFileError error = GDATA_FILE_OK; 1495 GDataFileError error = GDATA_FILE_OK;
1535 FilePath file_path; 1496 FilePath file_path;
1536 cache_->ClearAllOnUIThread(base::Bind(&OnClearAll, 1497 cache_->ClearAllOnUIThread(base::Bind(&OnClearAll,
1537 &error, 1498 &error,
1538 &file_path)); 1499 &file_path));
1539 test_util::RunBlockingPoolTask(); 1500 test_util::RunBlockingPoolTask();
1540 EXPECT_EQ(GDATA_FILE_OK, error); 1501 EXPECT_EQ(GDATA_FILE_OK, error);
1541 1502
1542 // Verify that all the cache is removed. 1503 // Verify that all the cache is removed.
1543 VerifyRemoveFromCache(error, resource_id, md5); 1504 VerifyRemoveFromCache(error, resource_id, md5);
1544 EXPECT_EQ(0U, CountCacheFiles(resource_id, md5)); 1505 EXPECT_EQ(0U, CountCacheFiles(resource_id, md5));
1545 } 1506 }
1546 1507
1547 TEST_F(GDataCacheTest, StoreToCacheNoSpace) {
1548 EXPECT_CALL(*mock_free_disk_space_checker_, AmountOfFreeDiskSpace())
1549 .Times(AtLeast(1)).WillRepeatedly(Return(0));
1550
1551 std::string resource_id("pdf:1a2b");
1552 std::string md5("abcdef0123456789");
1553
1554 // Try to store an existing file.
1555 TestStoreToCache(resource_id, md5, GetTestFilePath("root_feed.json"),
1556 GDATA_FILE_ERROR_NO_SPACE,
1557 test_util::TEST_CACHE_STATE_NONE,
1558 GDataCache::CACHE_TYPE_TMP);
1559 EXPECT_EQ(1, num_callback_invocations_);
1560
1561 // Verify that there's no files added.
1562 EXPECT_EQ(0U, CountCacheFiles(resource_id, md5));
1563 }
1564
1565
1566 } // namespace gdata 1508 } // namespace gdata
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/gdata/gdata_cache.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698