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

Side by Side Diff: net/disk_cache/backend_unittest.cc

Issue 2891022: Disk cache: Read the index and data_0 files in a single... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2006-2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2010 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/basictypes.h" 5 #include "base/basictypes.h"
6 #include "base/file_util.h" 6 #include "base/file_util.h"
7 #include "base/path_service.h"
8 #include "base/platform_thread.h" 7 #include "base/platform_thread.h"
9 #include "base/string_util.h" 8 #include "base/string_util.h"
10 #include "net/base/io_buffer.h" 9 #include "net/base/io_buffer.h"
11 #include "net/base/net_errors.h" 10 #include "net/base/net_errors.h"
12 #include "net/base/test_completion_callback.h" 11 #include "net/base/test_completion_callback.h"
13 #include "net/disk_cache/backend_impl.h" 12 #include "net/disk_cache/backend_impl.h"
14 #include "net/disk_cache/disk_cache_test_base.h" 13 #include "net/disk_cache/disk_cache_test_base.h"
15 #include "net/disk_cache/disk_cache_test_util.h" 14 #include "net/disk_cache/disk_cache_test_util.h"
16 #include "net/disk_cache/histogram_macros.h" 15 #include "net/disk_cache/histogram_macros.h"
17 #include "net/disk_cache/mapped_file.h" 16 #include "net/disk_cache/mapped_file.h"
18 #include "net/disk_cache/mem_backend_impl.h" 17 #include "net/disk_cache/mem_backend_impl.h"
19 #include "testing/gtest/include/gtest/gtest.h" 18 #include "testing/gtest/include/gtest/gtest.h"
20 19
21 using base::Time; 20 using base::Time;
22 21
23 namespace {
24
25 // Copies a set of cache files from the data folder to the test folder.
26 bool CopyTestCache(const std::wstring& name) {
27 FilePath path;
28 PathService::Get(base::DIR_SOURCE_ROOT, &path);
29 path = path.AppendASCII("net");
30 path = path.AppendASCII("data");
31 path = path.AppendASCII("cache_tests");
32 path = path.Append(FilePath::FromWStringHack(name));
33
34 FilePath dest = GetCacheFilePath();
35 if (!DeleteCache(dest))
36 return false;
37 return file_util::CopyDirectory(path, dest, false);
38 }
39
40 } // namespace
41
42 // Tests that can run with different types of caches. 22 // Tests that can run with different types of caches.
43 class DiskCacheBackendTest : public DiskCacheTestWithCache { 23 class DiskCacheBackendTest : public DiskCacheTestWithCache {
44 protected: 24 protected:
45 void BackendBasics(); 25 void BackendBasics();
46 void BackendKeying(); 26 void BackendKeying();
47 void BackendSetSize(); 27 void BackendSetSize();
48 void BackendLoad(); 28 void BackendLoad();
49 void BackendValidEntry(); 29 void BackendValidEntry();
50 void BackendInvalidEntry(); 30 void BackendInvalidEntry();
51 void BackendInvalidEntryRead(); 31 void BackendInvalidEntryRead();
52 void BackendInvalidEntryWithLoad(); 32 void BackendInvalidEntryWithLoad();
53 void BackendTrimInvalidEntry(); 33 void BackendTrimInvalidEntry();
54 void BackendTrimInvalidEntry2(); 34 void BackendTrimInvalidEntry2();
55 void BackendEnumerations(); 35 void BackendEnumerations();
56 void BackendEnumerations2(); 36 void BackendEnumerations2();
57 void BackendInvalidEntryEnumeration(); 37 void BackendInvalidEntryEnumeration();
58 void BackendFixEnumerators(); 38 void BackendFixEnumerators();
59 void BackendDoomRecent(); 39 void BackendDoomRecent();
60 void BackendDoomBetween(); 40 void BackendDoomBetween();
61 void BackendTransaction(const std::wstring& name, int num_entries, bool load); 41 void BackendTransaction(const std::string& name, int num_entries, bool load);
62 void BackendRecoverInsert(); 42 void BackendRecoverInsert();
63 void BackendRecoverRemove(); 43 void BackendRecoverRemove();
64 void BackendInvalidEntry2(); 44 void BackendInvalidEntry2();
65 void BackendNotMarkedButDirty(const std::wstring& name); 45 void BackendNotMarkedButDirty(const std::string& name);
66 void BackendDoomAll(); 46 void BackendDoomAll();
67 void BackendDoomAll2(); 47 void BackendDoomAll2();
68 void BackendInvalidRankings(); 48 void BackendInvalidRankings();
69 void BackendInvalidRankings2(); 49 void BackendInvalidRankings2();
70 void BackendDisable(); 50 void BackendDisable();
71 void BackendDisable2(); 51 void BackendDisable2();
72 void BackendDisable3(); 52 void BackendDisable3();
73 void BackendDisable4(); 53 void BackendDisable4();
74 }; 54 };
75 55
(...skipping 1004 matching lines...) Expand 10 before | Expand all | Expand 10 after
1080 TEST_F(DiskCacheBackendTest, NewEvictionDoomBetween) { 1060 TEST_F(DiskCacheBackendTest, NewEvictionDoomBetween) {
1081 SetNewEviction(); 1061 SetNewEviction();
1082 BackendDoomBetween(); 1062 BackendDoomBetween();
1083 } 1063 }
1084 1064
1085 TEST_F(DiskCacheBackendTest, MemoryOnlyDoomBetween) { 1065 TEST_F(DiskCacheBackendTest, MemoryOnlyDoomBetween) {
1086 SetMemoryOnlyMode(); 1066 SetMemoryOnlyMode();
1087 BackendDoomBetween(); 1067 BackendDoomBetween();
1088 } 1068 }
1089 1069
1090 void DiskCacheBackendTest::BackendTransaction(const std::wstring& name, 1070 void DiskCacheBackendTest::BackendTransaction(const std::string& name,
1091 int num_entries, bool load) { 1071 int num_entries, bool load) {
1092 success_ = false; 1072 success_ = false;
1093 ASSERT_TRUE(CopyTestCache(name)); 1073 ASSERT_TRUE(CopyTestCache(name));
1094 DisableFirstCleanup(); 1074 DisableFirstCleanup();
1095 1075
1096 if (load) { 1076 if (load) {
1097 SetMask(0xf); 1077 SetMask(0xf);
1098 SetMaxSize(0x100000); 1078 SetMaxSize(0x100000);
1099 } else { 1079 } else {
1100 // Clear the settings from the previous run. 1080 // Clear the settings from the previous run.
(...skipping 19 matching lines...) Expand all
1120 delete cache_; 1100 delete cache_;
1121 cache_ = NULL; 1101 cache_ = NULL;
1122 cache_impl_ = NULL; 1102 cache_impl_ = NULL;
1123 1103
1124 ASSERT_TRUE(CheckCacheIntegrity(GetCacheFilePath(), new_eviction_)); 1104 ASSERT_TRUE(CheckCacheIntegrity(GetCacheFilePath(), new_eviction_));
1125 success_ = true; 1105 success_ = true;
1126 } 1106 }
1127 1107
1128 void DiskCacheBackendTest::BackendRecoverInsert() { 1108 void DiskCacheBackendTest::BackendRecoverInsert() {
1129 // Tests with an empty cache. 1109 // Tests with an empty cache.
1130 BackendTransaction(L"insert_empty1", 0, false); 1110 BackendTransaction("insert_empty1", 0, false);
1131 ASSERT_TRUE(success_) << "insert_empty1"; 1111 ASSERT_TRUE(success_) << "insert_empty1";
1132 BackendTransaction(L"insert_empty2", 0, false); 1112 BackendTransaction("insert_empty2", 0, false);
1133 ASSERT_TRUE(success_) << "insert_empty2"; 1113 ASSERT_TRUE(success_) << "insert_empty2";
1134 BackendTransaction(L"insert_empty3", 0, false); 1114 BackendTransaction("insert_empty3", 0, false);
1135 ASSERT_TRUE(success_) << "insert_empty3"; 1115 ASSERT_TRUE(success_) << "insert_empty3";
1136 1116
1137 // Tests with one entry on the cache. 1117 // Tests with one entry on the cache.
1138 BackendTransaction(L"insert_one1", 1, false); 1118 BackendTransaction("insert_one1", 1, false);
1139 ASSERT_TRUE(success_) << "insert_one1"; 1119 ASSERT_TRUE(success_) << "insert_one1";
1140 BackendTransaction(L"insert_one2", 1, false); 1120 BackendTransaction("insert_one2", 1, false);
1141 ASSERT_TRUE(success_) << "insert_one2"; 1121 ASSERT_TRUE(success_) << "insert_one2";
1142 BackendTransaction(L"insert_one3", 1, false); 1122 BackendTransaction("insert_one3", 1, false);
1143 ASSERT_TRUE(success_) << "insert_one3"; 1123 ASSERT_TRUE(success_) << "insert_one3";
1144 1124
1145 // Tests with one hundred entries on the cache, tiny index. 1125 // Tests with one hundred entries on the cache, tiny index.
1146 BackendTransaction(L"insert_load1", 100, true); 1126 BackendTransaction("insert_load1", 100, true);
1147 ASSERT_TRUE(success_) << "insert_load1"; 1127 ASSERT_TRUE(success_) << "insert_load1";
1148 BackendTransaction(L"insert_load2", 100, true); 1128 BackendTransaction("insert_load2", 100, true);
1149 ASSERT_TRUE(success_) << "insert_load2"; 1129 ASSERT_TRUE(success_) << "insert_load2";
1150 } 1130 }
1151 1131
1152 TEST_F(DiskCacheBackendTest, RecoverInsert) { 1132 TEST_F(DiskCacheBackendTest, RecoverInsert) {
1153 BackendRecoverInsert(); 1133 BackendRecoverInsert();
1154 } 1134 }
1155 1135
1156 TEST_F(DiskCacheBackendTest, NewEvictionRecoverInsert) { 1136 TEST_F(DiskCacheBackendTest, NewEvictionRecoverInsert) {
1157 SetNewEviction(); 1137 SetNewEviction();
1158 BackendRecoverInsert(); 1138 BackendRecoverInsert();
1159 } 1139 }
1160 1140
1161 void DiskCacheBackendTest::BackendRecoverRemove() { 1141 void DiskCacheBackendTest::BackendRecoverRemove() {
1162 // Removing the only element. 1142 // Removing the only element.
1163 BackendTransaction(L"remove_one1", 0, false); 1143 BackendTransaction("remove_one1", 0, false);
1164 ASSERT_TRUE(success_) << "remove_one1"; 1144 ASSERT_TRUE(success_) << "remove_one1";
1165 BackendTransaction(L"remove_one2", 0, false); 1145 BackendTransaction("remove_one2", 0, false);
1166 ASSERT_TRUE(success_) << "remove_one2"; 1146 ASSERT_TRUE(success_) << "remove_one2";
1167 BackendTransaction(L"remove_one3", 0, false); 1147 BackendTransaction("remove_one3", 0, false);
1168 ASSERT_TRUE(success_) << "remove_one3"; 1148 ASSERT_TRUE(success_) << "remove_one3";
1169 1149
1170 // Removing the head. 1150 // Removing the head.
1171 BackendTransaction(L"remove_head1", 1, false); 1151 BackendTransaction("remove_head1", 1, false);
1172 ASSERT_TRUE(success_) << "remove_head1"; 1152 ASSERT_TRUE(success_) << "remove_head1";
1173 BackendTransaction(L"remove_head2", 1, false); 1153 BackendTransaction("remove_head2", 1, false);
1174 ASSERT_TRUE(success_) << "remove_head2"; 1154 ASSERT_TRUE(success_) << "remove_head2";
1175 BackendTransaction(L"remove_head3", 1, false); 1155 BackendTransaction("remove_head3", 1, false);
1176 ASSERT_TRUE(success_) << "remove_head3"; 1156 ASSERT_TRUE(success_) << "remove_head3";
1177 1157
1178 // Removing the tail. 1158 // Removing the tail.
1179 BackendTransaction(L"remove_tail1", 1, false); 1159 BackendTransaction("remove_tail1", 1, false);
1180 ASSERT_TRUE(success_) << "remove_tail1"; 1160 ASSERT_TRUE(success_) << "remove_tail1";
1181 BackendTransaction(L"remove_tail2", 1, false); 1161 BackendTransaction("remove_tail2", 1, false);
1182 ASSERT_TRUE(success_) << "remove_tail2"; 1162 ASSERT_TRUE(success_) << "remove_tail2";
1183 BackendTransaction(L"remove_tail3", 1, false); 1163 BackendTransaction("remove_tail3", 1, false);
1184 ASSERT_TRUE(success_) << "remove_tail3"; 1164 ASSERT_TRUE(success_) << "remove_tail3";
1185 1165
1186 // Removing with one hundred entries on the cache, tiny index. 1166 // Removing with one hundred entries on the cache, tiny index.
1187 BackendTransaction(L"remove_load1", 100, true); 1167 BackendTransaction("remove_load1", 100, true);
1188 ASSERT_TRUE(success_) << "remove_load1"; 1168 ASSERT_TRUE(success_) << "remove_load1";
1189 BackendTransaction(L"remove_load2", 100, true); 1169 BackendTransaction("remove_load2", 100, true);
1190 ASSERT_TRUE(success_) << "remove_load2"; 1170 ASSERT_TRUE(success_) << "remove_load2";
1191 BackendTransaction(L"remove_load3", 100, true); 1171 BackendTransaction("remove_load3", 100, true);
1192 ASSERT_TRUE(success_) << "remove_load3"; 1172 ASSERT_TRUE(success_) << "remove_load3";
1193 1173
1194 #ifdef NDEBUG 1174 #ifdef NDEBUG
1195 // This case cannot be reverted, so it will assert on debug builds. 1175 // This case cannot be reverted, so it will assert on debug builds.
1196 BackendTransaction(L"remove_one4", 0, false); 1176 BackendTransaction("remove_one4", 0, false);
1197 ASSERT_TRUE(success_) << "remove_one4"; 1177 ASSERT_TRUE(success_) << "remove_one4";
1198 BackendTransaction(L"remove_head4", 1, false); 1178 BackendTransaction("remove_head4", 1, false);
1199 ASSERT_TRUE(success_) << "remove_head4"; 1179 ASSERT_TRUE(success_) << "remove_head4";
1200 #endif 1180 #endif
1201 } 1181 }
1202 1182
1203 TEST_F(DiskCacheBackendTest, RecoverRemove) { 1183 TEST_F(DiskCacheBackendTest, RecoverRemove) {
1204 BackendRecoverRemove(); 1184 BackendRecoverRemove();
1205 } 1185 }
1206 1186
1207 TEST_F(DiskCacheBackendTest, NewEvictionRecoverRemove) { 1187 TEST_F(DiskCacheBackendTest, NewEvictionRecoverRemove) {
1208 SetNewEviction(); 1188 SetNewEviction();
1209 BackendRecoverRemove(); 1189 BackendRecoverRemove();
1210 } 1190 }
1211 1191
1212 // Tests dealing with cache files that cannot be recovered. 1192 // Tests dealing with cache files that cannot be recovered.
1213 TEST_F(DiskCacheTest, DeleteOld) { 1193 TEST_F(DiskCacheTest, DeleteOld) {
1214 ASSERT_TRUE(CopyTestCache(L"wrong_version")); 1194 ASSERT_TRUE(CopyTestCache("wrong_version"));
1215 FilePath path = GetCacheFilePath(); 1195 FilePath path = GetCacheFilePath();
1216 base::Thread cache_thread("CacheThread"); 1196 base::Thread cache_thread("CacheThread");
1217 ASSERT_TRUE(cache_thread.StartWithOptions( 1197 ASSERT_TRUE(cache_thread.StartWithOptions(
1218 base::Thread::Options(MessageLoop::TYPE_IO, 0))); 1198 base::Thread::Options(MessageLoop::TYPE_IO, 0)));
1219 TestCompletionCallback cb; 1199 TestCompletionCallback cb;
1220 1200
1221 disk_cache::Backend* cache; 1201 disk_cache::Backend* cache;
1222 int rv = disk_cache::BackendImpl::CreateBackend( 1202 int rv = disk_cache::BackendImpl::CreateBackend(
1223 path, true, 0, net::DISK_CACHE, disk_cache::kNoRandom, 1203 path, true, 0, net::DISK_CACHE, disk_cache::kNoRandom,
1224 cache_thread.message_loop_proxy(), &cache, &cb); 1204 cache_thread.message_loop_proxy(), &cache, &cb);
1225 ASSERT_EQ(net::OK, cb.GetResult(rv)); 1205 ASSERT_EQ(net::OK, cb.GetResult(rv));
1226 1206
1227 MessageLoopHelper helper; 1207 MessageLoopHelper helper;
1228 1208
1229 ASSERT_TRUE(NULL != cache); 1209 ASSERT_TRUE(NULL != cache);
1230 ASSERT_EQ(0, cache->GetEntryCount()); 1210 ASSERT_EQ(0, cache->GetEntryCount());
1231 1211
1232 delete cache; 1212 delete cache;
1233 } 1213 }
1234 1214
1235 // We want to be able to deal with messed up entries on disk. 1215 // We want to be able to deal with messed up entries on disk.
1236 void DiskCacheBackendTest::BackendInvalidEntry2() { 1216 void DiskCacheBackendTest::BackendInvalidEntry2() {
1237 ASSERT_TRUE(CopyTestCache(L"bad_entry")); 1217 ASSERT_TRUE(CopyTestCache("bad_entry"));
1238 DisableFirstCleanup(); 1218 DisableFirstCleanup();
1239 InitCache(); 1219 InitCache();
1240 1220
1241 disk_cache::Entry *entry1, *entry2; 1221 disk_cache::Entry *entry1, *entry2;
1242 ASSERT_EQ(net::OK, OpenEntry("the first key", &entry1)); 1222 ASSERT_EQ(net::OK, OpenEntry("the first key", &entry1));
1243 EXPECT_NE(net::OK, OpenEntry("some other key", &entry2)); 1223 EXPECT_NE(net::OK, OpenEntry("some other key", &entry2));
1244 entry1->Close(); 1224 entry1->Close();
1245 1225
1246 // CheckCacheIntegrity will fail at this point. 1226 // CheckCacheIntegrity will fail at this point.
1247 DisableIntegrityCheck(); 1227 DisableIntegrityCheck();
1248 } 1228 }
1249 1229
1250 TEST_F(DiskCacheBackendTest, InvalidEntry2) { 1230 TEST_F(DiskCacheBackendTest, InvalidEntry2) {
1251 BackendInvalidEntry2(); 1231 BackendInvalidEntry2();
1252 } 1232 }
1253 1233
1254 TEST_F(DiskCacheBackendTest, NewEvictionInvalidEntry2) { 1234 TEST_F(DiskCacheBackendTest, NewEvictionInvalidEntry2) {
1255 SetNewEviction(); 1235 SetNewEviction();
1256 BackendInvalidEntry2(); 1236 BackendInvalidEntry2();
1257 } 1237 }
1258 1238
1259 // We want to be able to deal with abnormal dirty entries. 1239 // We want to be able to deal with abnormal dirty entries.
1260 void DiskCacheBackendTest::BackendNotMarkedButDirty(const std::wstring& name) { 1240 void DiskCacheBackendTest::BackendNotMarkedButDirty(const std::string& name) {
1261 ASSERT_TRUE(CopyTestCache(name)); 1241 ASSERT_TRUE(CopyTestCache(name));
1262 DisableFirstCleanup(); 1242 DisableFirstCleanup();
1263 InitCache(); 1243 InitCache();
1264 1244
1265 disk_cache::Entry *entry1, *entry2; 1245 disk_cache::Entry *entry1, *entry2;
1266 ASSERT_EQ(net::OK, OpenEntry("the first key", &entry1)); 1246 ASSERT_EQ(net::OK, OpenEntry("the first key", &entry1));
1267 EXPECT_NE(net::OK, OpenEntry("some other key", &entry2)); 1247 EXPECT_NE(net::OK, OpenEntry("some other key", &entry2));
1268 entry1->Close(); 1248 entry1->Close();
1269 } 1249 }
1270 1250
1271 TEST_F(DiskCacheBackendTest, NotMarkedButDirty) { 1251 TEST_F(DiskCacheBackendTest, NotMarkedButDirty) {
1272 BackendNotMarkedButDirty(L"dirty_entry"); 1252 BackendNotMarkedButDirty("dirty_entry");
1273 } 1253 }
1274 1254
1275 TEST_F(DiskCacheBackendTest, NewEvictionNotMarkedButDirty) { 1255 TEST_F(DiskCacheBackendTest, NewEvictionNotMarkedButDirty) {
1276 SetNewEviction(); 1256 SetNewEviction();
1277 BackendNotMarkedButDirty(L"dirty_entry"); 1257 BackendNotMarkedButDirty("dirty_entry");
1278 } 1258 }
1279 1259
1280 TEST_F(DiskCacheBackendTest, NotMarkedButDirty2) { 1260 TEST_F(DiskCacheBackendTest, NotMarkedButDirty2) {
1281 BackendNotMarkedButDirty(L"dirty_entry2"); 1261 BackendNotMarkedButDirty("dirty_entry2");
1282 } 1262 }
1283 1263
1284 TEST_F(DiskCacheBackendTest, NewEvictionNotMarkedButDirty2) { 1264 TEST_F(DiskCacheBackendTest, NewEvictionNotMarkedButDirty2) {
1285 SetNewEviction(); 1265 SetNewEviction();
1286 BackendNotMarkedButDirty(L"dirty_entry2"); 1266 BackendNotMarkedButDirty("dirty_entry2");
1287 } 1267 }
1288 1268
1289 // We want to be able to deal with messed up entries on disk. 1269 // We want to be able to deal with messed up entries on disk.
1290 void DiskCacheBackendTest::BackendInvalidRankings2() { 1270 void DiskCacheBackendTest::BackendInvalidRankings2() {
1291 ASSERT_TRUE(CopyTestCache(L"bad_rankings")); 1271 ASSERT_TRUE(CopyTestCache("bad_rankings"));
1292 FilePath path = GetCacheFilePath(); 1272 FilePath path = GetCacheFilePath();
1293 DisableFirstCleanup(); 1273 DisableFirstCleanup();
1294 InitCache(); 1274 InitCache();
1295 1275
1296 disk_cache::Entry *entry1, *entry2; 1276 disk_cache::Entry *entry1, *entry2;
1297 EXPECT_NE(net::OK, OpenEntry("the first key", &entry1)); 1277 EXPECT_NE(net::OK, OpenEntry("the first key", &entry1));
1298 ASSERT_EQ(net::OK, OpenEntry("some other key", &entry2)); 1278 ASSERT_EQ(net::OK, OpenEntry("some other key", &entry2));
1299 entry2->Close(); 1279 entry2->Close();
1300 1280
1301 // CheckCacheIntegrity will fail at this point. 1281 // CheckCacheIntegrity will fail at this point.
(...skipping 16 matching lines...) Expand all
1318 ASSERT_EQ(net::OK, OpenNextEntry(&iter, &entry)); 1298 ASSERT_EQ(net::OK, OpenNextEntry(&iter, &entry));
1319 entry->Close(); 1299 entry->Close();
1320 EXPECT_EQ(2, cache_->GetEntryCount()); 1300 EXPECT_EQ(2, cache_->GetEntryCount());
1321 1301
1322 EXPECT_NE(net::OK, OpenNextEntry(&iter, &entry)); 1302 EXPECT_NE(net::OK, OpenNextEntry(&iter, &entry));
1323 FlushQueueForTest(); // Allow the restart to finish. 1303 FlushQueueForTest(); // Allow the restart to finish.
1324 EXPECT_EQ(0, cache_->GetEntryCount()); 1304 EXPECT_EQ(0, cache_->GetEntryCount());
1325 } 1305 }
1326 1306
1327 TEST_F(DiskCacheBackendTest, InvalidRankingsSuccess) { 1307 TEST_F(DiskCacheBackendTest, InvalidRankingsSuccess) {
1328 ASSERT_TRUE(CopyTestCache(L"bad_rankings")); 1308 ASSERT_TRUE(CopyTestCache("bad_rankings"));
1329 DisableFirstCleanup(); 1309 DisableFirstCleanup();
1330 SetDirectMode(); 1310 SetDirectMode();
1331 InitCache(); 1311 InitCache();
1332 BackendInvalidRankings(); 1312 BackendInvalidRankings();
1333 } 1313 }
1334 1314
1335 TEST_F(DiskCacheBackendTest, NewEvictionInvalidRankingsSuccess) { 1315 TEST_F(DiskCacheBackendTest, NewEvictionInvalidRankingsSuccess) {
1336 ASSERT_TRUE(CopyTestCache(L"bad_rankings")); 1316 ASSERT_TRUE(CopyTestCache("bad_rankings"));
1337 DisableFirstCleanup(); 1317 DisableFirstCleanup();
1338 SetDirectMode(); 1318 SetDirectMode();
1339 SetNewEviction(); 1319 SetNewEviction();
1340 InitCache(); 1320 InitCache();
1341 BackendInvalidRankings(); 1321 BackendInvalidRankings();
1342 } 1322 }
1343 1323
1344 TEST_F(DiskCacheBackendTest, InvalidRankingsFailure) { 1324 TEST_F(DiskCacheBackendTest, InvalidRankingsFailure) {
1345 ASSERT_TRUE(CopyTestCache(L"bad_rankings")); 1325 ASSERT_TRUE(CopyTestCache("bad_rankings"));
1346 DisableFirstCleanup(); 1326 DisableFirstCleanup();
1347 SetDirectMode(); 1327 SetDirectMode();
1348 InitCache(); 1328 InitCache();
1349 SetTestMode(); // Fail cache reinitialization. 1329 SetTestMode(); // Fail cache reinitialization.
1350 BackendInvalidRankings(); 1330 BackendInvalidRankings();
1351 } 1331 }
1352 1332
1353 TEST_F(DiskCacheBackendTest, NewEvictionInvalidRankingsFailure) { 1333 TEST_F(DiskCacheBackendTest, NewEvictionInvalidRankingsFailure) {
1354 ASSERT_TRUE(CopyTestCache(L"bad_rankings")); 1334 ASSERT_TRUE(CopyTestCache("bad_rankings"));
1355 DisableFirstCleanup(); 1335 DisableFirstCleanup();
1356 SetDirectMode(); 1336 SetDirectMode();
1357 SetNewEviction(); 1337 SetNewEviction();
1358 InitCache(); 1338 InitCache();
1359 SetTestMode(); // Fail cache reinitialization. 1339 SetTestMode(); // Fail cache reinitialization.
1360 BackendInvalidRankings(); 1340 BackendInvalidRankings();
1361 } 1341 }
1362 1342
1363 // If the LRU is corrupt and we have open entries, we disable the cache. 1343 // If the LRU is corrupt and we have open entries, we disable the cache.
1364 void DiskCacheBackendTest::BackendDisable() { 1344 void DiskCacheBackendTest::BackendDisable() {
1365 disk_cache::Entry *entry1, *entry2; 1345 disk_cache::Entry *entry1, *entry2;
1366 void* iter = NULL; 1346 void* iter = NULL;
1367 ASSERT_EQ(net::OK, OpenNextEntry(&iter, &entry1)); 1347 ASSERT_EQ(net::OK, OpenNextEntry(&iter, &entry1));
1368 1348
1369 EXPECT_NE(net::OK, OpenNextEntry(&iter, &entry2)); 1349 EXPECT_NE(net::OK, OpenNextEntry(&iter, &entry2));
1370 EXPECT_EQ(2, cache_->GetEntryCount()); 1350 EXPECT_EQ(2, cache_->GetEntryCount());
1371 EXPECT_NE(net::OK, CreateEntry("Something new", &entry2)); 1351 EXPECT_NE(net::OK, CreateEntry("Something new", &entry2));
1372 1352
1373 entry1->Close(); 1353 entry1->Close();
1374 FlushQueueForTest(); // Flushing the Close posts a task to restart the cache. 1354 FlushQueueForTest(); // Flushing the Close posts a task to restart the cache.
1375 FlushQueueForTest(); // This one actually allows that task to complete. 1355 FlushQueueForTest(); // This one actually allows that task to complete.
1376 1356
1377 EXPECT_EQ(0, cache_->GetEntryCount()); 1357 EXPECT_EQ(0, cache_->GetEntryCount());
1378 } 1358 }
1379 1359
1380 TEST_F(DiskCacheBackendTest, DisableSuccess) { 1360 TEST_F(DiskCacheBackendTest, DisableSuccess) {
1381 ASSERT_TRUE(CopyTestCache(L"bad_rankings")); 1361 ASSERT_TRUE(CopyTestCache("bad_rankings"));
1382 DisableFirstCleanup(); 1362 DisableFirstCleanup();
1383 SetDirectMode(); 1363 SetDirectMode();
1384 InitCache(); 1364 InitCache();
1385 BackendDisable(); 1365 BackendDisable();
1386 } 1366 }
1387 1367
1388 TEST_F(DiskCacheBackendTest, NewEvictionDisableSuccess) { 1368 TEST_F(DiskCacheBackendTest, NewEvictionDisableSuccess) {
1389 ASSERT_TRUE(CopyTestCache(L"bad_rankings")); 1369 ASSERT_TRUE(CopyTestCache("bad_rankings"));
1390 DisableFirstCleanup(); 1370 DisableFirstCleanup();
1391 SetDirectMode(); 1371 SetDirectMode();
1392 SetNewEviction(); 1372 SetNewEviction();
1393 InitCache(); 1373 InitCache();
1394 BackendDisable(); 1374 BackendDisable();
1395 } 1375 }
1396 1376
1397 TEST_F(DiskCacheBackendTest, DisableFailure) { 1377 TEST_F(DiskCacheBackendTest, DisableFailure) {
1398 ASSERT_TRUE(CopyTestCache(L"bad_rankings")); 1378 ASSERT_TRUE(CopyTestCache("bad_rankings"));
1399 DisableFirstCleanup(); 1379 DisableFirstCleanup();
1400 SetDirectMode(); 1380 SetDirectMode();
1401 InitCache(); 1381 InitCache();
1402 SetTestMode(); // Fail cache reinitialization. 1382 SetTestMode(); // Fail cache reinitialization.
1403 BackendDisable(); 1383 BackendDisable();
1404 } 1384 }
1405 1385
1406 TEST_F(DiskCacheBackendTest, NewEvictionDisableFailure) { 1386 TEST_F(DiskCacheBackendTest, NewEvictionDisableFailure) {
1407 ASSERT_TRUE(CopyTestCache(L"bad_rankings")); 1387 ASSERT_TRUE(CopyTestCache("bad_rankings"));
1408 DisableFirstCleanup(); 1388 DisableFirstCleanup();
1409 SetDirectMode(); 1389 SetDirectMode();
1410 SetNewEviction(); 1390 SetNewEviction();
1411 InitCache(); 1391 InitCache();
1412 SetTestMode(); // Fail cache reinitialization. 1392 SetTestMode(); // Fail cache reinitialization.
1413 BackendDisable(); 1393 BackendDisable();
1414 } 1394 }
1415 1395
1416 // This is another type of corruption on the LRU; disable the cache. 1396 // This is another type of corruption on the LRU; disable the cache.
1417 void DiskCacheBackendTest::BackendDisable2() { 1397 void DiskCacheBackendTest::BackendDisable2() {
1418 EXPECT_EQ(8, cache_->GetEntryCount()); 1398 EXPECT_EQ(8, cache_->GetEntryCount());
1419 1399
1420 disk_cache::Entry* entry; 1400 disk_cache::Entry* entry;
1421 void* iter = NULL; 1401 void* iter = NULL;
1422 int count = 0; 1402 int count = 0;
1423 while (OpenNextEntry(&iter, &entry) == net::OK) { 1403 while (OpenNextEntry(&iter, &entry) == net::OK) {
1424 ASSERT_TRUE(NULL != entry); 1404 ASSERT_TRUE(NULL != entry);
1425 entry->Close(); 1405 entry->Close();
1426 count++; 1406 count++;
1427 ASSERT_LT(count, 9); 1407 ASSERT_LT(count, 9);
1428 }; 1408 };
1429 1409
1430 FlushQueueForTest(); 1410 FlushQueueForTest();
1431 EXPECT_EQ(0, cache_->GetEntryCount()); 1411 EXPECT_EQ(0, cache_->GetEntryCount());
1432 } 1412 }
1433 1413
1434 TEST_F(DiskCacheBackendTest, DisableSuccess2) { 1414 TEST_F(DiskCacheBackendTest, DisableSuccess2) {
1435 ASSERT_TRUE(CopyTestCache(L"list_loop")); 1415 ASSERT_TRUE(CopyTestCache("list_loop"));
1436 DisableFirstCleanup(); 1416 DisableFirstCleanup();
1437 SetDirectMode(); 1417 SetDirectMode();
1438 InitCache(); 1418 InitCache();
1439 BackendDisable2(); 1419 BackendDisable2();
1440 } 1420 }
1441 1421
1442 TEST_F(DiskCacheBackendTest, NewEvictionDisableSuccess2) { 1422 TEST_F(DiskCacheBackendTest, NewEvictionDisableSuccess2) {
1443 ASSERT_TRUE(CopyTestCache(L"list_loop")); 1423 ASSERT_TRUE(CopyTestCache("list_loop"));
1444 DisableFirstCleanup(); 1424 DisableFirstCleanup();
1445 SetNewEviction(); 1425 SetNewEviction();
1446 SetDirectMode(); 1426 SetDirectMode();
1447 InitCache(); 1427 InitCache();
1448 BackendDisable2(); 1428 BackendDisable2();
1449 } 1429 }
1450 1430
1451 TEST_F(DiskCacheBackendTest, DisableFailure2) { 1431 TEST_F(DiskCacheBackendTest, DisableFailure2) {
1452 ASSERT_TRUE(CopyTestCache(L"list_loop")); 1432 ASSERT_TRUE(CopyTestCache("list_loop"));
1453 DisableFirstCleanup(); 1433 DisableFirstCleanup();
1454 SetDirectMode(); 1434 SetDirectMode();
1455 InitCache(); 1435 InitCache();
1456 SetTestMode(); // Fail cache reinitialization. 1436 SetTestMode(); // Fail cache reinitialization.
1457 BackendDisable2(); 1437 BackendDisable2();
1458 } 1438 }
1459 1439
1460 TEST_F(DiskCacheBackendTest, NewEvictionDisableFailure2) { 1440 TEST_F(DiskCacheBackendTest, NewEvictionDisableFailure2) {
1461 ASSERT_TRUE(CopyTestCache(L"list_loop")); 1441 ASSERT_TRUE(CopyTestCache("list_loop"));
1462 DisableFirstCleanup(); 1442 DisableFirstCleanup();
1463 SetDirectMode(); 1443 SetDirectMode();
1464 SetNewEviction(); 1444 SetNewEviction();
1465 InitCache(); 1445 InitCache();
1466 SetTestMode(); // Fail cache reinitialization. 1446 SetTestMode(); // Fail cache reinitialization.
1467 BackendDisable2(); 1447 BackendDisable2();
1468 } 1448 }
1469 1449
1470 // If the index size changes when we disable the cache, we should not crash. 1450 // If the index size changes when we disable the cache, we should not crash.
1471 void DiskCacheBackendTest::BackendDisable3() { 1451 void DiskCacheBackendTest::BackendDisable3() {
1472 disk_cache::Entry *entry1, *entry2; 1452 disk_cache::Entry *entry1, *entry2;
1473 void* iter = NULL; 1453 void* iter = NULL;
1474 EXPECT_EQ(2, cache_->GetEntryCount()); 1454 EXPECT_EQ(2, cache_->GetEntryCount());
1475 ASSERT_EQ(net::OK, OpenNextEntry(&iter, &entry1)); 1455 ASSERT_EQ(net::OK, OpenNextEntry(&iter, &entry1));
1476 entry1->Close(); 1456 entry1->Close();
1477 1457
1478 EXPECT_NE(net::OK, OpenNextEntry(&iter, &entry2)); 1458 EXPECT_NE(net::OK, OpenNextEntry(&iter, &entry2));
1479 FlushQueueForTest(); 1459 FlushQueueForTest();
1480 1460
1481 ASSERT_EQ(net::OK, CreateEntry("Something new", &entry2)); 1461 ASSERT_EQ(net::OK, CreateEntry("Something new", &entry2));
1482 entry2->Close(); 1462 entry2->Close();
1483 1463
1484 EXPECT_EQ(1, cache_->GetEntryCount()); 1464 EXPECT_EQ(1, cache_->GetEntryCount());
1485 } 1465 }
1486 1466
1487 TEST_F(DiskCacheBackendTest, DisableSuccess3) { 1467 TEST_F(DiskCacheBackendTest, DisableSuccess3) {
1488 ASSERT_TRUE(CopyTestCache(L"bad_rankings2")); 1468 ASSERT_TRUE(CopyTestCache("bad_rankings2"));
1489 DisableFirstCleanup(); 1469 DisableFirstCleanup();
1490 SetMaxSize(20 * 1024 * 1024); 1470 SetMaxSize(20 * 1024 * 1024);
1491 InitCache(); 1471 InitCache();
1492 BackendDisable3(); 1472 BackendDisable3();
1493 } 1473 }
1494 1474
1495 TEST_F(DiskCacheBackendTest, NewEvictionDisableSuccess3) { 1475 TEST_F(DiskCacheBackendTest, NewEvictionDisableSuccess3) {
1496 ASSERT_TRUE(CopyTestCache(L"bad_rankings2")); 1476 ASSERT_TRUE(CopyTestCache("bad_rankings2"));
1497 DisableFirstCleanup(); 1477 DisableFirstCleanup();
1498 SetMaxSize(20 * 1024 * 1024); 1478 SetMaxSize(20 * 1024 * 1024);
1499 SetNewEviction(); 1479 SetNewEviction();
1500 InitCache(); 1480 InitCache();
1501 BackendDisable3(); 1481 BackendDisable3();
1502 } 1482 }
1503 1483
1504 // If we disable the cache, already open entries should work as far as possible. 1484 // If we disable the cache, already open entries should work as far as possible.
1505 void DiskCacheBackendTest::BackendDisable4() { 1485 void DiskCacheBackendTest::BackendDisable4() {
1506 disk_cache::Entry *entry1, *entry2, *entry3, *entry4; 1486 disk_cache::Entry *entry1, *entry2, *entry3, *entry4;
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
1544 entry1->Close(); 1524 entry1->Close();
1545 entry2->Close(); 1525 entry2->Close();
1546 entry3->Close(); 1526 entry3->Close();
1547 FlushQueueForTest(); // Flushing the Close posts a task to restart the cache. 1527 FlushQueueForTest(); // Flushing the Close posts a task to restart the cache.
1548 FlushQueueForTest(); // This one actually allows that task to complete. 1528 FlushQueueForTest(); // This one actually allows that task to complete.
1549 1529
1550 EXPECT_EQ(0, cache_->GetEntryCount()); 1530 EXPECT_EQ(0, cache_->GetEntryCount());
1551 } 1531 }
1552 1532
1553 TEST_F(DiskCacheBackendTest, DisableSuccess4) { 1533 TEST_F(DiskCacheBackendTest, DisableSuccess4) {
1554 ASSERT_TRUE(CopyTestCache(L"bad_rankings")); 1534 ASSERT_TRUE(CopyTestCache("bad_rankings"));
1555 DisableFirstCleanup(); 1535 DisableFirstCleanup();
1556 SetDirectMode(); 1536 SetDirectMode();
1557 InitCache(); 1537 InitCache();
1558 BackendDisable4(); 1538 BackendDisable4();
1559 } 1539 }
1560 1540
1561 TEST_F(DiskCacheBackendTest, NewEvictionDisableSuccess4) { 1541 TEST_F(DiskCacheBackendTest, NewEvictionDisableSuccess4) {
1562 ASSERT_TRUE(CopyTestCache(L"bad_rankings")); 1542 ASSERT_TRUE(CopyTestCache("bad_rankings"));
1563 DisableFirstCleanup(); 1543 DisableFirstCleanup();
1564 SetDirectMode(); 1544 SetDirectMode();
1565 SetNewEviction(); 1545 SetNewEviction();
1566 InitCache(); 1546 InitCache();
1567 BackendDisable4(); 1547 BackendDisable4();
1568 } 1548 }
1569 1549
1570 TEST_F(DiskCacheTest, Backend_UsageStats) { 1550 TEST_F(DiskCacheTest, Backend_UsageStats) {
1571 MessageLoopHelper helper; 1551 MessageLoopHelper helper;
1572 1552
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
1648 EXPECT_EQ(net::OK, DoomAllEntries()); 1628 EXPECT_EQ(net::OK, DoomAllEntries());
1649 1629
1650 disk_cache::Entry* entry; 1630 disk_cache::Entry* entry;
1651 ASSERT_EQ(net::OK, CreateEntry("Something new", &entry)); 1631 ASSERT_EQ(net::OK, CreateEntry("Something new", &entry));
1652 entry->Close(); 1632 entry->Close();
1653 1633
1654 EXPECT_EQ(1, cache_->GetEntryCount()); 1634 EXPECT_EQ(1, cache_->GetEntryCount());
1655 } 1635 }
1656 1636
1657 TEST_F(DiskCacheBackendTest, DoomAll2) { 1637 TEST_F(DiskCacheBackendTest, DoomAll2) {
1658 ASSERT_TRUE(CopyTestCache(L"bad_rankings2")); 1638 ASSERT_TRUE(CopyTestCache("bad_rankings2"));
1659 DisableFirstCleanup(); 1639 DisableFirstCleanup();
1660 SetMaxSize(20 * 1024 * 1024); 1640 SetMaxSize(20 * 1024 * 1024);
1661 InitCache(); 1641 InitCache();
1662 BackendDoomAll2(); 1642 BackendDoomAll2();
1663 } 1643 }
1664 1644
1665 TEST_F(DiskCacheBackendTest, NewEvictionDoomAll2) { 1645 TEST_F(DiskCacheBackendTest, NewEvictionDoomAll2) {
1666 ASSERT_TRUE(CopyTestCache(L"bad_rankings2")); 1646 ASSERT_TRUE(CopyTestCache("bad_rankings2"));
1667 DisableFirstCleanup(); 1647 DisableFirstCleanup();
1668 SetMaxSize(20 * 1024 * 1024); 1648 SetMaxSize(20 * 1024 * 1024);
1669 SetNewEviction(); 1649 SetNewEviction();
1670 InitCache(); 1650 InitCache();
1671 BackendDoomAll2(); 1651 BackendDoomAll2();
1672 } 1652 }
1673 1653
1674 // We should be able to create the same entry on multiple simultaneous instances 1654 // We should be able to create the same entry on multiple simultaneous instances
1675 // of the cache. 1655 // of the cache.
1676 TEST_F(DiskCacheTest, MultipleInstances) { 1656 TEST_F(DiskCacheTest, MultipleInstances) {
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
1760 // another. 1740 // another.
1761 TEST_F(DiskCacheBackendTest, Histograms) { 1741 TEST_F(DiskCacheBackendTest, Histograms) {
1762 SetDirectMode(); 1742 SetDirectMode();
1763 InitCache(); 1743 InitCache();
1764 disk_cache::BackendImpl* backend_ = cache_impl_; // Needed be the macro. 1744 disk_cache::BackendImpl* backend_ = cache_impl_; // Needed be the macro.
1765 1745
1766 for (int i = 1; i < 3; i++) { 1746 for (int i = 1; i < 3; i++) {
1767 CACHE_UMA(HOURS, "FillupTime", i, 28); 1747 CACHE_UMA(HOURS, "FillupTime", i, 28);
1768 } 1748 }
1769 } 1749 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698