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

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

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

Powered by Google App Engine
This is Rietveld 408576698