OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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" | 7 #include "base/path_service.h" |
8 #include "base/platform_thread.h" | 8 #include "base/platform_thread.h" |
9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
10 #include "net/base/io_buffer.h" | 10 #include "net/base/io_buffer.h" |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 void BackendInvalidEntryEnumeration(); | 52 void BackendInvalidEntryEnumeration(); |
53 void BackendFixEnumerators(); | 53 void BackendFixEnumerators(); |
54 void BackendDoomRecent(); | 54 void BackendDoomRecent(); |
55 void BackendDoomBetween(); | 55 void BackendDoomBetween(); |
56 void BackendTransaction(const std::wstring& name, int num_entries, bool load); | 56 void BackendTransaction(const std::wstring& name, int num_entries, bool load); |
57 void BackendRecoverInsert(); | 57 void BackendRecoverInsert(); |
58 void BackendRecoverRemove(); | 58 void BackendRecoverRemove(); |
59 void BackendInvalidEntry2(); | 59 void BackendInvalidEntry2(); |
60 void BackendNotMarkedButDirty(); | 60 void BackendNotMarkedButDirty(); |
61 void BackendDoomAll(); | 61 void BackendDoomAll(); |
| 62 void BackendDoomAll2(); |
62 void BackendInvalidRankings(); | 63 void BackendInvalidRankings(); |
63 void BackendInvalidRankings2(); | 64 void BackendInvalidRankings2(); |
64 void BackendDisable(); | 65 void BackendDisable(); |
65 void BackendDisable2(); | 66 void BackendDisable2(); |
| 67 void BackendDisable3(); |
66 }; | 68 }; |
67 | 69 |
68 void DiskCacheBackendTest::BackendBasics() { | 70 void DiskCacheBackendTest::BackendBasics() { |
69 InitCache(); | 71 InitCache(); |
70 disk_cache::Entry *entry1 = NULL, *entry2 = NULL; | 72 disk_cache::Entry *entry1 = NULL, *entry2 = NULL; |
71 EXPECT_FALSE(cache_->OpenEntry("the first key", &entry1)); | 73 EXPECT_FALSE(cache_->OpenEntry("the first key", &entry1)); |
72 ASSERT_TRUE(cache_->CreateEntry("the first key", &entry1)); | 74 ASSERT_TRUE(cache_->CreateEntry("the first key", &entry1)); |
73 ASSERT_TRUE(NULL != entry1); | 75 ASSERT_TRUE(NULL != entry1); |
74 entry1->Close(); | 76 entry1->Close(); |
75 entry1 = NULL; | 77 entry1 = NULL; |
(...skipping 1086 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1162 TEST_F(DiskCacheBackendTest, NewEvictionDisableFailure2) { | 1164 TEST_F(DiskCacheBackendTest, NewEvictionDisableFailure2) { |
1163 ASSERT_TRUE(CopyTestCache(L"list_loop")); | 1165 ASSERT_TRUE(CopyTestCache(L"list_loop")); |
1164 DisableFirstCleanup(); | 1166 DisableFirstCleanup(); |
1165 SetDirectMode(); | 1167 SetDirectMode(); |
1166 SetNewEviction(); | 1168 SetNewEviction(); |
1167 InitCache(); | 1169 InitCache(); |
1168 SetTestMode(); // Fail cache reinitialization. | 1170 SetTestMode(); // Fail cache reinitialization. |
1169 BackendDisable2(); | 1171 BackendDisable2(); |
1170 } | 1172 } |
1171 | 1173 |
| 1174 // If the index size changes when we disable the cache, we should not crash. |
| 1175 void DiskCacheBackendTest::BackendDisable3() { |
| 1176 disk_cache::Entry *entry1, *entry2; |
| 1177 void* iter = NULL; |
| 1178 EXPECT_EQ(2, cache_->GetEntryCount()); |
| 1179 ASSERT_TRUE(cache_->OpenNextEntry(&iter, &entry1)); |
| 1180 entry1->Close(); |
| 1181 |
| 1182 EXPECT_FALSE(cache_->OpenNextEntry(&iter, &entry2)); |
| 1183 ASSERT_TRUE(cache_->CreateEntry("Something new", &entry2)); |
| 1184 entry2->Close(); |
| 1185 |
| 1186 EXPECT_EQ(1, cache_->GetEntryCount()); |
| 1187 } |
| 1188 |
| 1189 TEST_F(DiskCacheBackendTest, DisableSuccess3) { |
| 1190 ASSERT_TRUE(CopyTestCache(L"bad_rankings2")); |
| 1191 DisableFirstCleanup(); |
| 1192 SetMaxSize(20 * 1024 * 1024); |
| 1193 InitCache(); |
| 1194 BackendDisable3(); |
| 1195 } |
| 1196 |
| 1197 TEST_F(DiskCacheBackendTest, NewEvictionDisableSuccess3) { |
| 1198 ASSERT_TRUE(CopyTestCache(L"bad_rankings2")); |
| 1199 DisableFirstCleanup(); |
| 1200 SetMaxSize(20 * 1024 * 1024); |
| 1201 SetNewEviction(); |
| 1202 InitCache(); |
| 1203 BackendDisable3(); |
| 1204 } |
| 1205 |
1172 TEST_F(DiskCacheTest, Backend_UsageStats) { | 1206 TEST_F(DiskCacheTest, Backend_UsageStats) { |
1173 MessageLoopHelper helper; | 1207 MessageLoopHelper helper; |
1174 | 1208 |
1175 std::wstring path = GetCachePath(); | 1209 std::wstring path = GetCachePath(); |
1176 ASSERT_TRUE(DeleteCache(path.c_str())); | 1210 ASSERT_TRUE(DeleteCache(path.c_str())); |
1177 scoped_ptr<disk_cache::BackendImpl> cache; | 1211 scoped_ptr<disk_cache::BackendImpl> cache; |
1178 cache.reset(new disk_cache::BackendImpl(path)); | 1212 cache.reset(new disk_cache::BackendImpl(path)); |
1179 ASSERT_TRUE(NULL != cache.get()); | 1213 ASSERT_TRUE(NULL != cache.get()); |
1180 cache->SetUnitTestMode(); | 1214 cache->SetUnitTestMode(); |
1181 ASSERT_TRUE(cache->Init()); | 1215 ASSERT_TRUE(cache->Init()); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1233 TEST_F(DiskCacheBackendTest, NewEvictionDoomAll) { | 1267 TEST_F(DiskCacheBackendTest, NewEvictionDoomAll) { |
1234 SetNewEviction(); | 1268 SetNewEviction(); |
1235 BackendDoomAll(); | 1269 BackendDoomAll(); |
1236 } | 1270 } |
1237 | 1271 |
1238 TEST_F(DiskCacheBackendTest, MemoryOnlyDoomAll) { | 1272 TEST_F(DiskCacheBackendTest, MemoryOnlyDoomAll) { |
1239 SetMemoryOnlyMode(); | 1273 SetMemoryOnlyMode(); |
1240 BackendDoomAll(); | 1274 BackendDoomAll(); |
1241 } | 1275 } |
1242 | 1276 |
| 1277 // If the index size changes when we doom the cache, we should not crash. |
| 1278 void DiskCacheBackendTest::BackendDoomAll2() { |
| 1279 EXPECT_EQ(2, cache_->GetEntryCount()); |
| 1280 EXPECT_TRUE(cache_->DoomAllEntries()); |
| 1281 |
| 1282 disk_cache::Entry* entry; |
| 1283 ASSERT_TRUE(cache_->CreateEntry("Something new", &entry)); |
| 1284 entry->Close(); |
| 1285 |
| 1286 EXPECT_EQ(1, cache_->GetEntryCount()); |
| 1287 } |
| 1288 |
| 1289 TEST_F(DiskCacheBackendTest, DoomAll2) { |
| 1290 ASSERT_TRUE(CopyTestCache(L"bad_rankings2")); |
| 1291 DisableFirstCleanup(); |
| 1292 SetMaxSize(20 * 1024 * 1024); |
| 1293 InitCache(); |
| 1294 BackendDoomAll2(); |
| 1295 } |
| 1296 |
| 1297 TEST_F(DiskCacheBackendTest, NewEvictionDoomAll2) { |
| 1298 ASSERT_TRUE(CopyTestCache(L"bad_rankings2")); |
| 1299 DisableFirstCleanup(); |
| 1300 SetMaxSize(20 * 1024 * 1024); |
| 1301 SetNewEviction(); |
| 1302 InitCache(); |
| 1303 BackendDoomAll2(); |
| 1304 } |
| 1305 |
1243 // We should be able to create the same entry on multiple simultaneous instances | 1306 // We should be able to create the same entry on multiple simultaneous instances |
1244 // of the cache. | 1307 // of the cache. |
1245 TEST_F(DiskCacheTest, MultipleInstances) { | 1308 TEST_F(DiskCacheTest, MultipleInstances) { |
1246 ScopedTestCache store1; | 1309 ScopedTestCache store1; |
1247 ScopedTestCache store2(L"cache_test2"); | 1310 ScopedTestCache store2(L"cache_test2"); |
1248 ScopedTestCache store3(L"cache_test3"); | 1311 ScopedTestCache store3(L"cache_test3"); |
1249 | 1312 |
1250 const int kNumberOfCaches = 3; | 1313 const int kNumberOfCaches = 3; |
1251 scoped_ptr<disk_cache::Backend> cache[kNumberOfCaches]; | 1314 scoped_ptr<disk_cache::Backend> cache[kNumberOfCaches]; |
1252 | 1315 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1290 EXPECT_EQ(kDefaultSize * 5 / 2, | 1353 EXPECT_EQ(kDefaultSize * 5 / 2, |
1291 disk_cache::PreferedCacheSize(large_size * 100 / 2)); | 1354 disk_cache::PreferedCacheSize(large_size * 100 / 2)); |
1292 EXPECT_EQ(kDefaultSize * 5 / 2, | 1355 EXPECT_EQ(kDefaultSize * 5 / 2, |
1293 disk_cache::PreferedCacheSize(large_size * 500 / 2)); | 1356 disk_cache::PreferedCacheSize(large_size * 500 / 2)); |
1294 | 1357 |
1295 EXPECT_EQ(kDefaultSize * 6 / 2, | 1358 EXPECT_EQ(kDefaultSize * 6 / 2, |
1296 disk_cache::PreferedCacheSize(large_size * 600 / 2)); | 1359 disk_cache::PreferedCacheSize(large_size * 600 / 2)); |
1297 EXPECT_EQ(kDefaultSize * 7 / 2, | 1360 EXPECT_EQ(kDefaultSize * 7 / 2, |
1298 disk_cache::PreferedCacheSize(large_size * 700 / 2)); | 1361 disk_cache::PreferedCacheSize(large_size * 700 / 2)); |
1299 } | 1362 } |
OLD | NEW |