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

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

Issue 542733002: Remove void** from disk_cache interface. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: narrow given upstream Created 6 years, 3 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
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 "base/basictypes.h" 5 #include "base/basictypes.h"
6 #include "base/files/file_util.h" 6 #include "base/files/file_util.h"
7 #include "base/metrics/field_trial.h" 7 #include "base/metrics/field_trial.h"
8 #include "base/port.h" 8 #include "base/port.h"
9 #include "base/strings/string_util.h" 9 #include "base/strings/string_util.h"
10 #include "base/strings/stringprintf.h" 10 #include "base/strings/stringprintf.h"
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 // Perform IO operations on the cache until there is pending IO. 74 // Perform IO operations on the cache until there is pending IO.
75 int GeneratePendingIO(net::TestCompletionCallback* cb); 75 int GeneratePendingIO(net::TestCompletionCallback* cb);
76 76
77 // Adds 5 sparse entries. |doomed_start| and |doomed_end| if not NULL, 77 // Adds 5 sparse entries. |doomed_start| and |doomed_end| if not NULL,
78 // will be filled with times, used by DoomEntriesSince and DoomEntriesBetween. 78 // will be filled with times, used by DoomEntriesSince and DoomEntriesBetween.
79 // There are 4 entries after doomed_start and 2 after doomed_end. 79 // There are 4 entries after doomed_start and 2 after doomed_end.
80 void InitSparseCache(base::Time* doomed_start, base::Time* doomed_end); 80 void InitSparseCache(base::Time* doomed_start, base::Time* doomed_end);
81 81
82 bool CreateSetOfRandomEntries(std::set<std::string>* key_pool); 82 bool CreateSetOfRandomEntries(std::set<std::string>* key_pool);
83 bool EnumerateAndMatchKeys(int max_to_open, 83 bool EnumerateAndMatchKeys(int max_to_open,
84 void** iter, 84 disk_cache::Backend::Iterator* iter,
85 std::set<std::string>* keys_to_match, 85 std::set<std::string>* keys_to_match,
86 size_t* count); 86 size_t* count);
87 87
88 // Actual tests: 88 // Actual tests:
89 void BackendBasics(); 89 void BackendBasics();
90 void BackendKeying(); 90 void BackendKeying();
91 void BackendShutdownWithPendingFileIO(bool fast); 91 void BackendShutdownWithPendingFileIO(bool fast);
92 void BackendShutdownWithPendingIO(bool fast); 92 void BackendShutdownWithPendingIO(bool fast);
93 void BackendShutdownWithPendingCreate(bool fast); 93 void BackendShutdownWithPendingCreate(bool fast);
94 void BackendSetSize(); 94 void BackendSetSize();
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 } 249 }
250 return key_pool->size() == implicit_cast<size_t>(cache_->GetEntryCount()); 250 return key_pool->size() == implicit_cast<size_t>(cache_->GetEntryCount());
251 } 251 }
252 252
253 // Performs iteration over the backend and checks that the keys of entries 253 // Performs iteration over the backend and checks that the keys of entries
254 // opened are in |keys_to_match|, then erases them. Up to |max_to_open| entries 254 // opened are in |keys_to_match|, then erases them. Up to |max_to_open| entries
255 // will be opened, if it is positive. Otherwise, iteration will continue until 255 // will be opened, if it is positive. Otherwise, iteration will continue until
256 // OpenNextEntry stops returning net::OK. 256 // OpenNextEntry stops returning net::OK.
257 bool DiskCacheBackendTest::EnumerateAndMatchKeys( 257 bool DiskCacheBackendTest::EnumerateAndMatchKeys(
258 int max_to_open, 258 int max_to_open,
259 void** iter, 259 disk_cache::Backend::Iterator* iter,
260 std::set<std::string>* keys_to_match, 260 std::set<std::string>* keys_to_match,
261 size_t* count) { 261 size_t* count) {
262 disk_cache::Entry* entry; 262 disk_cache::Entry* entry;
263 263
264 while (OpenNextEntry(iter, &entry) == net::OK) { 264 while (OpenNextEntry(iter, &entry) == net::OK) {
265 if (!entry) 265 if (!entry)
266 return false; 266 return false;
267 EXPECT_EQ(1U, keys_to_match->erase(entry->GetKey())); 267 EXPECT_EQ(1U, keys_to_match->erase(entry->GetKey()));
268 entry->Close(); 268 entry->Close();
269 ++(*count); 269 ++(*count);
(...skipping 960 matching lines...) Expand 10 before | Expand all | Expand 10 after
1230 for (int i = 0; i < kNumEntries; i++) { 1230 for (int i = 0; i < kNumEntries; i++) {
1231 std::string key = GenerateKey(true); 1231 std::string key = GenerateKey(true);
1232 disk_cache::Entry* entry; 1232 disk_cache::Entry* entry;
1233 ASSERT_EQ(net::OK, CreateEntry(key, &entry)); 1233 ASSERT_EQ(net::OK, CreateEntry(key, &entry));
1234 entry->Close(); 1234 entry->Close();
1235 } 1235 }
1236 EXPECT_EQ(kNumEntries, cache_->GetEntryCount()); 1236 EXPECT_EQ(kNumEntries, cache_->GetEntryCount());
1237 Time final = Time::Now(); 1237 Time final = Time::Now();
1238 1238
1239 disk_cache::Entry* entry; 1239 disk_cache::Entry* entry;
1240 void* iter = NULL; 1240 disk_cache::Backend::Iterator iter;
1241 int count = 0; 1241 int count = 0;
1242 Time last_modified[kNumEntries]; 1242 Time last_modified[kNumEntries];
1243 Time last_used[kNumEntries]; 1243 Time last_used[kNumEntries];
1244 while (OpenNextEntry(&iter, &entry) == net::OK) { 1244 while (OpenNextEntry(&iter, &entry) == net::OK) {
1245 ASSERT_TRUE(NULL != entry); 1245 ASSERT_TRUE(NULL != entry);
1246 if (count < kNumEntries) { 1246 if (count < kNumEntries) {
1247 last_modified[count] = entry->GetLastModified(); 1247 last_modified[count] = entry->GetLastModified();
1248 last_used[count] = entry->GetLastUsed(); 1248 last_used[count] = entry->GetLastUsed();
1249 EXPECT_TRUE(initial <= last_modified[count]); 1249 EXPECT_TRUE(initial <= last_modified[count]);
1250 EXPECT_TRUE(final >= last_modified[count]); 1250 EXPECT_TRUE(final >= last_modified[count]);
1251 } 1251 }
1252 1252
1253 entry->Close(); 1253 entry->Close();
1254 count++; 1254 count++;
1255 }; 1255 };
1256 EXPECT_EQ(kNumEntries, count); 1256 EXPECT_EQ(kNumEntries, count);
1257 1257
1258 iter = NULL; 1258 iter.reset();
1259 count = 0; 1259 count = 0;
1260 // The previous enumeration should not have changed the timestamps. 1260 // The previous enumeration should not have changed the timestamps.
1261 while (OpenNextEntry(&iter, &entry) == net::OK) { 1261 while (OpenNextEntry(&iter, &entry) == net::OK) {
1262 ASSERT_TRUE(NULL != entry); 1262 ASSERT_TRUE(NULL != entry);
1263 if (count < kNumEntries) { 1263 if (count < kNumEntries) {
1264 EXPECT_TRUE(last_modified[count] == entry->GetLastModified()); 1264 EXPECT_TRUE(last_modified[count] == entry->GetLastModified());
1265 EXPECT_TRUE(last_used[count] == entry->GetLastUsed()); 1265 EXPECT_TRUE(last_used[count] == entry->GetLastUsed());
1266 } 1266 }
1267 entry->Close(); 1267 entry->Close();
1268 count++; 1268 count++;
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
1302 disk_cache::Entry *entry1, *entry2; 1302 disk_cache::Entry *entry1, *entry2;
1303 ASSERT_EQ(net::OK, CreateEntry(first, &entry1)); 1303 ASSERT_EQ(net::OK, CreateEntry(first, &entry1));
1304 entry1->Close(); 1304 entry1->Close();
1305 ASSERT_EQ(net::OK, CreateEntry(second, &entry2)); 1305 ASSERT_EQ(net::OK, CreateEntry(second, &entry2));
1306 entry2->Close(); 1306 entry2->Close();
1307 FlushQueueForTest(); 1307 FlushQueueForTest();
1308 1308
1309 // Make sure that the timestamp is not the same. 1309 // Make sure that the timestamp is not the same.
1310 AddDelay(); 1310 AddDelay();
1311 ASSERT_EQ(net::OK, OpenEntry(second, &entry1)); 1311 ASSERT_EQ(net::OK, OpenEntry(second, &entry1));
1312 void* iter = NULL; 1312 disk_cache::Backend::Iterator iter;
1313 ASSERT_EQ(net::OK, OpenNextEntry(&iter, &entry2)); 1313 ASSERT_EQ(net::OK, OpenNextEntry(&iter, &entry2));
1314 EXPECT_EQ(entry2->GetKey(), second); 1314 EXPECT_EQ(entry2->GetKey(), second);
1315 1315
1316 // Two entries and the iterator pointing at "first". 1316 // Two entries and the iterator pointing at "first".
1317 entry1->Close(); 1317 entry1->Close();
1318 entry2->Close(); 1318 entry2->Close();
1319 1319
1320 // The iterator should still be valid, so we should not crash. 1320 // The iterator should still be valid, so we should not crash.
1321 ASSERT_EQ(net::OK, OpenNextEntry(&iter, &entry2)); 1321 ASSERT_EQ(net::OK, OpenNextEntry(&iter, &entry2));
1322 EXPECT_EQ(entry2->GetKey(), first); 1322 EXPECT_EQ(entry2->GetKey(), first);
1323 entry2->Close(); 1323 entry2->Close();
1324 cache_->EndEnumeration(&iter); 1324 iter.reset();
1325 1325
1326 // Modify the oldest entry and get the newest element. 1326 // Modify the oldest entry and get the newest element.
1327 ASSERT_EQ(net::OK, OpenEntry(first, &entry1)); 1327 ASSERT_EQ(net::OK, OpenEntry(first, &entry1));
1328 EXPECT_EQ(0, WriteData(entry1, 0, 200, NULL, 0, false)); 1328 EXPECT_EQ(0, WriteData(entry1, 0, 200, NULL, 0, false));
1329 ASSERT_EQ(net::OK, OpenNextEntry(&iter, &entry2)); 1329 ASSERT_EQ(net::OK, OpenNextEntry(&iter, &entry2));
1330 if (type_ == net::APP_CACHE) { 1330 if (type_ == net::APP_CACHE) {
1331 // The list is not updated. 1331 // The list is not updated.
1332 EXPECT_EQ(entry2->GetKey(), second); 1332 EXPECT_EQ(entry2->GetKey(), second);
1333 } else { 1333 } else {
1334 EXPECT_EQ(entry2->GetKey(), first); 1334 EXPECT_EQ(entry2->GetKey(), first);
1335 } 1335 }
1336 1336
1337 entry1->Close(); 1337 entry1->Close();
1338 entry2->Close(); 1338 entry2->Close();
1339 cache_->EndEnumeration(&iter);
1340 } 1339 }
1341 1340
1342 TEST_F(DiskCacheBackendTest, Enumerations2) { 1341 TEST_F(DiskCacheBackendTest, Enumerations2) {
1343 BackendEnumerations2(); 1342 BackendEnumerations2();
1344 } 1343 }
1345 1344
1346 TEST_F(DiskCacheBackendTest, NewEvictionEnumerations2) { 1345 TEST_F(DiskCacheBackendTest, NewEvictionEnumerations2) {
1347 SetNewEviction(); 1346 SetNewEviction();
1348 BackendEnumerations2(); 1347 BackendEnumerations2();
1349 } 1348 }
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1384 1383
1385 FlushQueueForTest(); 1384 FlushQueueForTest();
1386 1385
1387 // Make sure that the timestamp is not the same. 1386 // Make sure that the timestamp is not the same.
1388 AddDelay(); 1387 AddDelay();
1389 1388
1390 // Read from the last item in the LRU. 1389 // Read from the last item in the LRU.
1391 EXPECT_EQ(kSize, ReadData(entry1, 0, 0, buffer1.get(), kSize)); 1390 EXPECT_EQ(kSize, ReadData(entry1, 0, 0, buffer1.get(), kSize));
1392 entry1->Close(); 1391 entry1->Close();
1393 1392
1394 void* iter = NULL; 1393 disk_cache::Backend::Iterator iter;
1395 ASSERT_EQ(net::OK, OpenNextEntry(&iter, &entry2)); 1394 ASSERT_EQ(net::OK, OpenNextEntry(&iter, &entry2));
1396 EXPECT_EQ(entry2->GetKey(), second); 1395 EXPECT_EQ(entry2->GetKey(), second);
1397 entry2->Close(); 1396 entry2->Close();
1398 cache_->EndEnumeration(&iter);
1399 } 1397 }
1400 1398
1401 #if !defined(LEAK_SANITIZER) 1399 #if !defined(LEAK_SANITIZER)
1402 // Verify handling of invalid entries while doing enumerations. 1400 // Verify handling of invalid entries while doing enumerations.
1403 // We'll be leaking memory from this test. 1401 // We'll be leaking memory from this test.
1404 void DiskCacheBackendTest::BackendInvalidEntryEnumeration() { 1402 void DiskCacheBackendTest::BackendInvalidEntryEnumeration() {
1405 InitCache(); 1403 InitCache();
1406 1404
1407 std::string key("Some key"); 1405 std::string key("Some key");
1408 disk_cache::Entry *entry, *entry1, *entry2; 1406 disk_cache::Entry *entry, *entry1, *entry2;
1409 ASSERT_EQ(net::OK, CreateEntry(key, &entry1)); 1407 ASSERT_EQ(net::OK, CreateEntry(key, &entry1));
1410 1408
1411 const int kSize = 50; 1409 const int kSize = 50;
1412 scoped_refptr<net::IOBuffer> buffer1(new net::IOBuffer(kSize)); 1410 scoped_refptr<net::IOBuffer> buffer1(new net::IOBuffer(kSize));
1413 memset(buffer1->data(), 0, kSize); 1411 memset(buffer1->data(), 0, kSize);
1414 base::strlcpy(buffer1->data(), "And the data to save", kSize); 1412 base::strlcpy(buffer1->data(), "And the data to save", kSize);
1415 EXPECT_EQ(kSize, WriteData(entry1, 0, 0, buffer1.get(), kSize, false)); 1413 EXPECT_EQ(kSize, WriteData(entry1, 0, 0, buffer1.get(), kSize, false));
1416 entry1->Close(); 1414 entry1->Close();
1417 ASSERT_EQ(net::OK, OpenEntry(key, &entry1)); 1415 ASSERT_EQ(net::OK, OpenEntry(key, &entry1));
1418 EXPECT_EQ(kSize, ReadData(entry1, 0, 0, buffer1.get(), kSize)); 1416 EXPECT_EQ(kSize, ReadData(entry1, 0, 0, buffer1.get(), kSize));
1419 1417
1420 std::string key2("Another key"); 1418 std::string key2("Another key");
1421 ASSERT_EQ(net::OK, CreateEntry(key2, &entry2)); 1419 ASSERT_EQ(net::OK, CreateEntry(key2, &entry2));
1422 entry2->Close(); 1420 entry2->Close();
1423 ASSERT_EQ(2, cache_->GetEntryCount()); 1421 ASSERT_EQ(2, cache_->GetEntryCount());
1424 1422
1425 SimulateCrash(); 1423 SimulateCrash();
1426 1424
1427 void* iter = NULL; 1425 disk_cache::Backend::Iterator iter;
1428 int count = 0; 1426 int count = 0;
1429 while (OpenNextEntry(&iter, &entry) == net::OK) { 1427 while (OpenNextEntry(&iter, &entry) == net::OK) {
1430 ASSERT_TRUE(NULL != entry); 1428 ASSERT_TRUE(NULL != entry);
1431 EXPECT_EQ(key2, entry->GetKey()); 1429 EXPECT_EQ(key2, entry->GetKey());
1432 entry->Close(); 1430 entry->Close();
1433 count++; 1431 count++;
1434 }; 1432 };
1435 EXPECT_EQ(1, count); 1433 EXPECT_EQ(1, count);
1436 EXPECT_EQ(1, cache_->GetEntryCount()); 1434 EXPECT_EQ(1, cache_->GetEntryCount());
1437 } 1435 }
(...skipping 21 matching lines...) Expand all
1459 const int kNumEntries = 10; 1457 const int kNumEntries = 10;
1460 for (int i = 0; i < kNumEntries; i++) { 1458 for (int i = 0; i < kNumEntries; i++) {
1461 std::string key = GenerateKey(true); 1459 std::string key = GenerateKey(true);
1462 disk_cache::Entry* entry; 1460 disk_cache::Entry* entry;
1463 ASSERT_EQ(net::OK, CreateEntry(key, &entry)); 1461 ASSERT_EQ(net::OK, CreateEntry(key, &entry));
1464 entry->Close(); 1462 entry->Close();
1465 } 1463 }
1466 EXPECT_EQ(kNumEntries, cache_->GetEntryCount()); 1464 EXPECT_EQ(kNumEntries, cache_->GetEntryCount());
1467 1465
1468 disk_cache::Entry *entry1, *entry2; 1466 disk_cache::Entry *entry1, *entry2;
1469 void* iter1 = NULL; 1467 disk_cache::Backend::Iterator iter1, iter2;
1470 void* iter2 = NULL;
1471 ASSERT_EQ(net::OK, OpenNextEntry(&iter1, &entry1)); 1468 ASSERT_EQ(net::OK, OpenNextEntry(&iter1, &entry1));
1472 ASSERT_TRUE(NULL != entry1); 1469 ASSERT_TRUE(NULL != entry1);
1473 entry1->Close(); 1470 entry1->Close();
1474 entry1 = NULL; 1471 entry1 = NULL;
1475 1472
1476 // Let's go to the middle of the list. 1473 // Let's go to the middle of the list.
1477 for (int i = 0; i < kNumEntries / 2; i++) { 1474 for (int i = 0; i < kNumEntries / 2; i++) {
1478 if (entry1) 1475 if (entry1)
1479 entry1->Close(); 1476 entry1->Close();
1480 ASSERT_EQ(net::OK, OpenNextEntry(&iter1, &entry1)); 1477 ASSERT_EQ(net::OK, OpenNextEntry(&iter1, &entry1));
(...skipping 11 matching lines...) Expand all
1492 1489
1493 // The link entry2->entry1 should be broken. 1490 // The link entry2->entry1 should be broken.
1494 EXPECT_NE(entry2->GetKey(), entry1->GetKey()); 1491 EXPECT_NE(entry2->GetKey(), entry1->GetKey());
1495 entry1->Close(); 1492 entry1->Close();
1496 entry2->Close(); 1493 entry2->Close();
1497 1494
1498 // And the second iterator should keep working. 1495 // And the second iterator should keep working.
1499 ASSERT_EQ(net::OK, OpenNextEntry(&iter2, &entry2)); 1496 ASSERT_EQ(net::OK, OpenNextEntry(&iter2, &entry2));
1500 ASSERT_TRUE(NULL != entry2); 1497 ASSERT_TRUE(NULL != entry2);
1501 entry2->Close(); 1498 entry2->Close();
1502
1503 cache_->EndEnumeration(&iter1);
1504 cache_->EndEnumeration(&iter2);
1505 } 1499 }
1506 1500
1507 TEST_F(DiskCacheBackendTest, FixEnumerators) { 1501 TEST_F(DiskCacheBackendTest, FixEnumerators) {
1508 BackendFixEnumerators(); 1502 BackendFixEnumerators();
1509 } 1503 }
1510 1504
1511 TEST_F(DiskCacheBackendTest, NewEvictionFixEnumerators) { 1505 TEST_F(DiskCacheBackendTest, NewEvictionFixEnumerators) {
1512 SetNewEviction(); 1506 SetNewEviction();
1513 BackendFixEnumerators(); 1507 BackendFixEnumerators();
1514 } 1508 }
(...skipping 505 matching lines...) Expand 10 before | Expand all | Expand 10 after
2020 } 2014 }
2021 2015
2022 // Tests that we don't crash or hang when enumerating this cache. 2016 // Tests that we don't crash or hang when enumerating this cache.
2023 void DiskCacheBackendTest::BackendInvalidEntry3() { 2017 void DiskCacheBackendTest::BackendInvalidEntry3() {
2024 SetMask(0x1); // 2-entry table. 2018 SetMask(0x1); // 2-entry table.
2025 SetMaxSize(0x3000); // 12 kB. 2019 SetMaxSize(0x3000); // 12 kB.
2026 DisableFirstCleanup(); 2020 DisableFirstCleanup();
2027 InitCache(); 2021 InitCache();
2028 2022
2029 disk_cache::Entry* entry; 2023 disk_cache::Entry* entry;
2030 void* iter = NULL; 2024 disk_cache::Backend::Iterator iter;
2031 while (OpenNextEntry(&iter, &entry) == net::OK) { 2025 while (OpenNextEntry(&iter, &entry) == net::OK) {
2032 entry->Close(); 2026 entry->Close();
2033 } 2027 }
2034 } 2028 }
2035 2029
2036 TEST_F(DiskCacheBackendTest, InvalidEntry3) { 2030 TEST_F(DiskCacheBackendTest, InvalidEntry3) {
2037 ASSERT_TRUE(CopyTestCache("dirty_entry3")); 2031 ASSERT_TRUE(CopyTestCache("dirty_entry3"));
2038 BackendInvalidEntry3(); 2032 BackendInvalidEntry3();
2039 } 2033 }
2040 2034
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
2165 entry_impl->rankings()->Store(); 2159 entry_impl->rankings()->Store();
2166 entry->Close(); 2160 entry->Close();
2167 FlushQueueForTest(); 2161 FlushQueueForTest();
2168 EXPECT_EQ(2, cache_->GetEntryCount()); 2162 EXPECT_EQ(2, cache_->GetEntryCount());
2169 2163
2170 // This should detect the bad entry. 2164 // This should detect the bad entry.
2171 EXPECT_NE(net::OK, OpenEntry(second, &entry)); 2165 EXPECT_NE(net::OK, OpenEntry(second, &entry));
2172 EXPECT_EQ(1, cache_->GetEntryCount()); 2166 EXPECT_EQ(1, cache_->GetEntryCount());
2173 2167
2174 // We should delete the cache. The list still has a corrupt node. 2168 // We should delete the cache. The list still has a corrupt node.
2175 void* iter = NULL; 2169 disk_cache::Backend::Iterator iter;
2176 EXPECT_NE(net::OK, OpenNextEntry(&iter, &entry)); 2170 EXPECT_NE(net::OK, OpenNextEntry(&iter, &entry));
2177 FlushQueueForTest(); 2171 FlushQueueForTest();
2178 EXPECT_EQ(0, cache_->GetEntryCount()); 2172 EXPECT_EQ(0, cache_->GetEntryCount());
2179 } 2173 }
2180 2174
2181 TEST_F(DiskCacheBackendTest, InvalidEntry7) { 2175 TEST_F(DiskCacheBackendTest, InvalidEntry7) {
2182 BackendInvalidEntry7(); 2176 BackendInvalidEntry7();
2183 } 2177 }
2184 2178
2185 TEST_F(DiskCacheBackendTest, NewEvictionInvalidEntry7) { 2179 TEST_F(DiskCacheBackendTest, NewEvictionInvalidEntry7) {
(...skipping 23 matching lines...) Expand all
2209 entry_impl->rankings()->Store(); 2203 entry_impl->rankings()->Store();
2210 entry->Close(); 2204 entry->Close();
2211 FlushQueueForTest(); 2205 FlushQueueForTest();
2212 EXPECT_EQ(2, cache_->GetEntryCount()); 2206 EXPECT_EQ(2, cache_->GetEntryCount());
2213 2207
2214 // This should detect the bad entry. 2208 // This should detect the bad entry.
2215 EXPECT_NE(net::OK, OpenEntry(second, &entry)); 2209 EXPECT_NE(net::OK, OpenEntry(second, &entry));
2216 EXPECT_EQ(1, cache_->GetEntryCount()); 2210 EXPECT_EQ(1, cache_->GetEntryCount());
2217 2211
2218 // We should not delete the cache. 2212 // We should not delete the cache.
2219 void* iter = NULL; 2213 disk_cache::Backend::Iterator iter;
2220 ASSERT_EQ(net::OK, OpenNextEntry(&iter, &entry)); 2214 ASSERT_EQ(net::OK, OpenNextEntry(&iter, &entry));
2221 entry->Close(); 2215 entry->Close();
2222 EXPECT_NE(net::OK, OpenNextEntry(&iter, &entry)); 2216 EXPECT_NE(net::OK, OpenNextEntry(&iter, &entry));
2223 EXPECT_EQ(1, cache_->GetEntryCount()); 2217 EXPECT_EQ(1, cache_->GetEntryCount());
2224 } 2218 }
2225 2219
2226 TEST_F(DiskCacheBackendTest, InvalidEntry8) { 2220 TEST_F(DiskCacheBackendTest, InvalidEntry8) {
2227 BackendInvalidEntry8(); 2221 BackendInvalidEntry8();
2228 } 2222 }
2229 2223
(...skipping 29 matching lines...) Expand all
2259 EXPECT_EQ(2, cache_->GetEntryCount()); 2253 EXPECT_EQ(2, cache_->GetEntryCount());
2260 2254
2261 if (eviction) { 2255 if (eviction) {
2262 TrimForTest(false); 2256 TrimForTest(false);
2263 EXPECT_EQ(1, cache_->GetEntryCount()); 2257 EXPECT_EQ(1, cache_->GetEntryCount());
2264 TrimForTest(false); 2258 TrimForTest(false);
2265 EXPECT_EQ(1, cache_->GetEntryCount()); 2259 EXPECT_EQ(1, cache_->GetEntryCount());
2266 } else { 2260 } else {
2267 // We should detect the problem through the list, but we should not delete 2261 // We should detect the problem through the list, but we should not delete
2268 // the entry, just fail the iteration. 2262 // the entry, just fail the iteration.
2269 void* iter = NULL; 2263 disk_cache::Backend::Iterator iter;
2270 EXPECT_NE(net::OK, OpenNextEntry(&iter, &entry)); 2264 EXPECT_NE(net::OK, OpenNextEntry(&iter, &entry));
2271 2265
2272 // Now a full iteration will work, and return one entry. 2266 // Now a full iteration will work, and return one entry.
2273 ASSERT_EQ(net::OK, OpenNextEntry(&iter, &entry)); 2267 ASSERT_EQ(net::OK, OpenNextEntry(&iter, &entry));
2274 entry->Close(); 2268 entry->Close();
2275 EXPECT_NE(net::OK, OpenNextEntry(&iter, &entry)); 2269 EXPECT_NE(net::OK, OpenNextEntry(&iter, &entry));
2276 2270
2277 // This should detect what's left of the bad entry. 2271 // This should detect what's left of the bad entry.
2278 EXPECT_NE(net::OK, OpenEntry(second, &entry)); 2272 EXPECT_NE(net::OK, OpenEntry(second, &entry));
2279 EXPECT_EQ(2, cache_->GetEntryCount()); 2273 EXPECT_EQ(2, cache_->GetEntryCount());
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
2336 TrimForTest(false); 2330 TrimForTest(false);
2337 EXPECT_EQ(3, cache_->GetEntryCount()); 2331 EXPECT_EQ(3, cache_->GetEntryCount());
2338 TrimForTest(false); 2332 TrimForTest(false);
2339 EXPECT_EQ(2, cache_->GetEntryCount()); 2333 EXPECT_EQ(2, cache_->GetEntryCount());
2340 TrimForTest(false); 2334 TrimForTest(false);
2341 EXPECT_EQ(1, cache_->GetEntryCount()); 2335 EXPECT_EQ(1, cache_->GetEntryCount());
2342 } else { 2336 } else {
2343 // Detection order: third -> second -> first. 2337 // Detection order: third -> second -> first.
2344 // We should detect the problem through the list, but we should not delete 2338 // We should detect the problem through the list, but we should not delete
2345 // the entry. 2339 // the entry.
2346 void* iter = NULL; 2340 disk_cache::Backend::Iterator iter;
2347 ASSERT_EQ(net::OK, OpenNextEntry(&iter, &entry)); 2341 ASSERT_EQ(net::OK, OpenNextEntry(&iter, &entry));
2348 entry->Close(); 2342 entry->Close();
2349 ASSERT_EQ(net::OK, OpenNextEntry(&iter, &entry)); 2343 ASSERT_EQ(net::OK, OpenNextEntry(&iter, &entry));
2350 EXPECT_EQ(first, entry->GetKey()); 2344 EXPECT_EQ(first, entry->GetKey());
2351 entry->Close(); 2345 entry->Close();
2352 EXPECT_NE(net::OK, OpenNextEntry(&iter, &entry)); 2346 EXPECT_NE(net::OK, OpenNextEntry(&iter, &entry));
2353 } 2347 }
2354 DisableIntegrityCheck(); 2348 DisableIntegrityCheck();
2355 } 2349 }
2356 2350
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
2403 TrimForTest(false); 2397 TrimForTest(false);
2404 EXPECT_EQ(2, cache_->GetEntryCount()); 2398 EXPECT_EQ(2, cache_->GetEntryCount());
2405 TrimForTest(false); 2399 TrimForTest(false);
2406 EXPECT_EQ(1, cache_->GetEntryCount()); 2400 EXPECT_EQ(1, cache_->GetEntryCount());
2407 TrimForTest(false); 2401 TrimForTest(false);
2408 EXPECT_EQ(1, cache_->GetEntryCount()); 2402 EXPECT_EQ(1, cache_->GetEntryCount());
2409 } else { 2403 } else {
2410 // Detection order: third -> second. 2404 // Detection order: third -> second.
2411 // We should detect the problem through the list, but we should not delete 2405 // We should detect the problem through the list, but we should not delete
2412 // the entry, just fail the iteration. 2406 // the entry, just fail the iteration.
2413 void* iter = NULL; 2407 disk_cache::Backend::Iterator iter;
2414 ASSERT_EQ(net::OK, OpenNextEntry(&iter, &entry)); 2408 ASSERT_EQ(net::OK, OpenNextEntry(&iter, &entry));
2415 entry->Close(); 2409 entry->Close();
2416 EXPECT_NE(net::OK, OpenNextEntry(&iter, &entry)); 2410 EXPECT_NE(net::OK, OpenNextEntry(&iter, &entry));
2417 2411
2418 // Now a full iteration will work, and return two entries. 2412 // Now a full iteration will work, and return two entries.
2419 ASSERT_EQ(net::OK, OpenNextEntry(&iter, &entry)); 2413 ASSERT_EQ(net::OK, OpenNextEntry(&iter, &entry));
2420 entry->Close(); 2414 entry->Close();
2421 ASSERT_EQ(net::OK, OpenNextEntry(&iter, &entry)); 2415 ASSERT_EQ(net::OK, OpenNextEntry(&iter, &entry));
2422 entry->Close(); 2416 entry->Close();
2423 EXPECT_NE(net::OK, OpenNextEntry(&iter, &entry)); 2417 EXPECT_NE(net::OK, OpenNextEntry(&iter, &entry));
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
2491 } 2485 }
2492 2486
2493 TEST_F(DiskCacheBackendTest, NewEvictionInvalidRankings2) { 2487 TEST_F(DiskCacheBackendTest, NewEvictionInvalidRankings2) {
2494 SetNewEviction(); 2488 SetNewEviction();
2495 BackendInvalidRankings2(); 2489 BackendInvalidRankings2();
2496 } 2490 }
2497 2491
2498 // If the LRU is corrupt, we delete the cache. 2492 // If the LRU is corrupt, we delete the cache.
2499 void DiskCacheBackendTest::BackendInvalidRankings() { 2493 void DiskCacheBackendTest::BackendInvalidRankings() {
2500 disk_cache::Entry* entry; 2494 disk_cache::Entry* entry;
2501 void* iter = NULL; 2495 disk_cache::Backend::Iterator iter;
2502 ASSERT_EQ(net::OK, OpenNextEntry(&iter, &entry)); 2496 ASSERT_EQ(net::OK, OpenNextEntry(&iter, &entry));
2503 entry->Close(); 2497 entry->Close();
2504 EXPECT_EQ(2, cache_->GetEntryCount()); 2498 EXPECT_EQ(2, cache_->GetEntryCount());
2505 2499
2506 EXPECT_NE(net::OK, OpenNextEntry(&iter, &entry)); 2500 EXPECT_NE(net::OK, OpenNextEntry(&iter, &entry));
2507 FlushQueueForTest(); // Allow the restart to finish. 2501 FlushQueueForTest(); // Allow the restart to finish.
2508 EXPECT_EQ(0, cache_->GetEntryCount()); 2502 EXPECT_EQ(0, cache_->GetEntryCount());
2509 } 2503 }
2510 2504
2511 TEST_F(DiskCacheBackendTest, InvalidRankingsSuccess) { 2505 TEST_F(DiskCacheBackendTest, InvalidRankingsSuccess) {
(...skipping 24 matching lines...) Expand all
2536 DisableFirstCleanup(); 2530 DisableFirstCleanup();
2537 SetNewEviction(); 2531 SetNewEviction();
2538 InitCache(); 2532 InitCache();
2539 SetTestMode(); // Fail cache reinitialization. 2533 SetTestMode(); // Fail cache reinitialization.
2540 BackendInvalidRankings(); 2534 BackendInvalidRankings();
2541 } 2535 }
2542 2536
2543 // If the LRU is corrupt and we have open entries, we disable the cache. 2537 // If the LRU is corrupt and we have open entries, we disable the cache.
2544 void DiskCacheBackendTest::BackendDisable() { 2538 void DiskCacheBackendTest::BackendDisable() {
2545 disk_cache::Entry *entry1, *entry2; 2539 disk_cache::Entry *entry1, *entry2;
2546 void* iter = NULL; 2540 disk_cache::Backend::Iterator iter;
2547 ASSERT_EQ(net::OK, OpenNextEntry(&iter, &entry1)); 2541 ASSERT_EQ(net::OK, OpenNextEntry(&iter, &entry1));
2548 2542
2549 EXPECT_NE(net::OK, OpenNextEntry(&iter, &entry2)); 2543 EXPECT_NE(net::OK, OpenNextEntry(&iter, &entry2));
2550 EXPECT_EQ(0, cache_->GetEntryCount()); 2544 EXPECT_EQ(0, cache_->GetEntryCount());
2551 EXPECT_NE(net::OK, CreateEntry("Something new", &entry2)); 2545 EXPECT_NE(net::OK, CreateEntry("Something new", &entry2));
2552 2546
2553 entry1->Close(); 2547 entry1->Close();
2554 FlushQueueForTest(); // Flushing the Close posts a task to restart the cache. 2548 FlushQueueForTest(); // Flushing the Close posts a task to restart the cache.
2555 FlushQueueForTest(); // This one actually allows that task to complete. 2549 FlushQueueForTest(); // This one actually allows that task to complete.
2556 2550
(...skipping 30 matching lines...) Expand all
2587 InitCache(); 2581 InitCache();
2588 SetTestMode(); // Fail cache reinitialization. 2582 SetTestMode(); // Fail cache reinitialization.
2589 BackendDisable(); 2583 BackendDisable();
2590 } 2584 }
2591 2585
2592 // This is another type of corruption on the LRU; disable the cache. 2586 // This is another type of corruption on the LRU; disable the cache.
2593 void DiskCacheBackendTest::BackendDisable2() { 2587 void DiskCacheBackendTest::BackendDisable2() {
2594 EXPECT_EQ(8, cache_->GetEntryCount()); 2588 EXPECT_EQ(8, cache_->GetEntryCount());
2595 2589
2596 disk_cache::Entry* entry; 2590 disk_cache::Entry* entry;
2597 void* iter = NULL; 2591 disk_cache::Backend::Iterator iter;
2598 int count = 0; 2592 int count = 0;
2599 while (OpenNextEntry(&iter, &entry) == net::OK) { 2593 while (OpenNextEntry(&iter, &entry) == net::OK) {
2600 ASSERT_TRUE(NULL != entry); 2594 ASSERT_TRUE(NULL != entry);
2601 entry->Close(); 2595 entry->Close();
2602 count++; 2596 count++;
2603 ASSERT_LT(count, 9); 2597 ASSERT_LT(count, 9);
2604 }; 2598 };
2605 2599
2606 FlushQueueForTest(); 2600 FlushQueueForTest();
2607 EXPECT_EQ(0, cache_->GetEntryCount()); 2601 EXPECT_EQ(0, cache_->GetEntryCount());
(...skipping 27 matching lines...) Expand all
2635 DisableFirstCleanup(); 2629 DisableFirstCleanup();
2636 SetNewEviction(); 2630 SetNewEviction();
2637 InitCache(); 2631 InitCache();
2638 SetTestMode(); // Fail cache reinitialization. 2632 SetTestMode(); // Fail cache reinitialization.
2639 BackendDisable2(); 2633 BackendDisable2();
2640 } 2634 }
2641 2635
2642 // If the index size changes when we disable the cache, we should not crash. 2636 // If the index size changes when we disable the cache, we should not crash.
2643 void DiskCacheBackendTest::BackendDisable3() { 2637 void DiskCacheBackendTest::BackendDisable3() {
2644 disk_cache::Entry *entry1, *entry2; 2638 disk_cache::Entry *entry1, *entry2;
2645 void* iter = NULL; 2639 disk_cache::Backend::Iterator iter;
2646 EXPECT_EQ(2, cache_->GetEntryCount()); 2640 EXPECT_EQ(2, cache_->GetEntryCount());
2647 ASSERT_EQ(net::OK, OpenNextEntry(&iter, &entry1)); 2641 ASSERT_EQ(net::OK, OpenNextEntry(&iter, &entry1));
2648 entry1->Close(); 2642 entry1->Close();
2649 2643
2650 EXPECT_NE(net::OK, OpenNextEntry(&iter, &entry2)); 2644 EXPECT_NE(net::OK, OpenNextEntry(&iter, &entry2));
2651 FlushQueueForTest(); 2645 FlushQueueForTest();
2652 2646
2653 ASSERT_EQ(net::OK, CreateEntry("Something new", &entry2)); 2647 ASSERT_EQ(net::OK, CreateEntry("Something new", &entry2));
2654 entry2->Close(); 2648 entry2->Close();
2655 2649
(...skipping 13 matching lines...) Expand all
2669 DisableFirstCleanup(); 2663 DisableFirstCleanup();
2670 SetMaxSize(20 * 1024 * 1024); 2664 SetMaxSize(20 * 1024 * 1024);
2671 SetNewEviction(); 2665 SetNewEviction();
2672 InitCache(); 2666 InitCache();
2673 BackendDisable3(); 2667 BackendDisable3();
2674 } 2668 }
2675 2669
2676 // If we disable the cache, already open entries should work as far as possible. 2670 // If we disable the cache, already open entries should work as far as possible.
2677 void DiskCacheBackendTest::BackendDisable4() { 2671 void DiskCacheBackendTest::BackendDisable4() {
2678 disk_cache::Entry *entry1, *entry2, *entry3, *entry4; 2672 disk_cache::Entry *entry1, *entry2, *entry3, *entry4;
2679 void* iter = NULL; 2673 disk_cache::Backend::Iterator iter;
2680 ASSERT_EQ(net::OK, OpenNextEntry(&iter, &entry1)); 2674 ASSERT_EQ(net::OK, OpenNextEntry(&iter, &entry1));
2681 2675
2682 char key2[2000]; 2676 char key2[2000];
2683 char key3[20000]; 2677 char key3[20000];
2684 CacheTestFillBuffer(key2, sizeof(key2), true); 2678 CacheTestFillBuffer(key2, sizeof(key2), true);
2685 CacheTestFillBuffer(key3, sizeof(key3), true); 2679 CacheTestFillBuffer(key3, sizeof(key3), true);
2686 key2[sizeof(key2) - 1] = '\0'; 2680 key2[sizeof(key2) - 1] = '\0';
2687 key3[sizeof(key3) - 1] = '\0'; 2681 key3[sizeof(key3) - 1] = '\0';
2688 ASSERT_EQ(net::OK, CreateEntry(key2, &entry2)); 2682 ASSERT_EQ(net::OK, CreateEntry(key2, &entry2));
2689 ASSERT_EQ(net::OK, CreateEntry(key3, &entry3)); 2683 ASSERT_EQ(net::OK, CreateEntry(key3, &entry3));
(...skipping 679 matching lines...) Expand 10 before | Expand all | Expand 10 after
3369 // Tests basic functionality of the SimpleBackend implementation of the 3363 // Tests basic functionality of the SimpleBackend implementation of the
3370 // enumeration API. 3364 // enumeration API.
3371 TEST_F(DiskCacheBackendTest, SimpleCacheEnumerationBasics) { 3365 TEST_F(DiskCacheBackendTest, SimpleCacheEnumerationBasics) {
3372 SetSimpleCacheMode(); 3366 SetSimpleCacheMode();
3373 InitCache(); 3367 InitCache();
3374 std::set<std::string> key_pool; 3368 std::set<std::string> key_pool;
3375 ASSERT_TRUE(CreateSetOfRandomEntries(&key_pool)); 3369 ASSERT_TRUE(CreateSetOfRandomEntries(&key_pool));
3376 3370
3377 // Check that enumeration returns all entries. 3371 // Check that enumeration returns all entries.
3378 std::set<std::string> keys_to_match(key_pool); 3372 std::set<std::string> keys_to_match(key_pool);
3379 void* iter = NULL; 3373 disk_cache::Backend::Iterator iter;
3380 size_t count = 0; 3374 size_t count = 0;
3381 ASSERT_TRUE(EnumerateAndMatchKeys(-1, &iter, &keys_to_match, &count)); 3375 ASSERT_TRUE(EnumerateAndMatchKeys(-1, &iter, &keys_to_match, &count));
3382 cache_->EndEnumeration(&iter); 3376 iter.reset();
3383 EXPECT_EQ(key_pool.size(), count); 3377 EXPECT_EQ(key_pool.size(), count);
3384 EXPECT_TRUE(keys_to_match.empty()); 3378 EXPECT_TRUE(keys_to_match.empty());
3385 3379
3386 // Check that opening entries does not affect enumeration. 3380 // Check that opening entries does not affect enumeration.
3387 keys_to_match = key_pool; 3381 keys_to_match = key_pool;
3388 iter = NULL; 3382 iter.reset();
3389 count = 0; 3383 count = 0;
3390 disk_cache::Entry* entry_opened_before; 3384 disk_cache::Entry* entry_opened_before;
3391 ASSERT_EQ(net::OK, OpenEntry(*(key_pool.begin()), &entry_opened_before)); 3385 ASSERT_EQ(net::OK, OpenEntry(*(key_pool.begin()), &entry_opened_before));
3392 ASSERT_TRUE(EnumerateAndMatchKeys(key_pool.size()/2, 3386 ASSERT_TRUE(EnumerateAndMatchKeys(key_pool.size()/2,
3393 &iter, 3387 &iter,
3394 &keys_to_match, 3388 &keys_to_match,
3395 &count)); 3389 &count));
3396 3390
3397 disk_cache::Entry* entry_opened_middle; 3391 disk_cache::Entry* entry_opened_middle;
3398 ASSERT_EQ(net::OK, 3392 ASSERT_EQ(net::OK,
3399 OpenEntry(*(keys_to_match.begin()), &entry_opened_middle)); 3393 OpenEntry(*(keys_to_match.begin()), &entry_opened_middle));
3400 ASSERT_TRUE(EnumerateAndMatchKeys(-1, &iter, &keys_to_match, &count)); 3394 ASSERT_TRUE(EnumerateAndMatchKeys(-1, &iter, &keys_to_match, &count));
3401 cache_->EndEnumeration(&iter); 3395 iter.reset();
3402 entry_opened_before->Close(); 3396 entry_opened_before->Close();
3403 entry_opened_middle->Close(); 3397 entry_opened_middle->Close();
3404 3398
3405 EXPECT_EQ(key_pool.size(), count); 3399 EXPECT_EQ(key_pool.size(), count);
3406 EXPECT_TRUE(keys_to_match.empty()); 3400 EXPECT_TRUE(keys_to_match.empty());
3407 } 3401 }
3408 3402
3409 // Tests that the enumerations are not affected by dooming an entry in the 3403 // Tests that the enumerations are not affected by dooming an entry in the
3410 // middle. 3404 // middle.
3411 TEST_F(DiskCacheBackendTest, SimpleCacheEnumerationWhileDoomed) { 3405 TEST_F(DiskCacheBackendTest, SimpleCacheEnumerationWhileDoomed) {
3412 SetSimpleCacheMode(); 3406 SetSimpleCacheMode();
3413 InitCache(); 3407 InitCache();
3414 std::set<std::string> key_pool; 3408 std::set<std::string> key_pool;
3415 ASSERT_TRUE(CreateSetOfRandomEntries(&key_pool)); 3409 ASSERT_TRUE(CreateSetOfRandomEntries(&key_pool));
3416 3410
3417 // Check that enumeration returns all entries but the doomed one. 3411 // Check that enumeration returns all entries but the doomed one.
3418 std::set<std::string> keys_to_match(key_pool); 3412 std::set<std::string> keys_to_match(key_pool);
3419 void* iter = NULL; 3413 disk_cache::Backend::Iterator iter;
3420 size_t count = 0; 3414 size_t count = 0;
3421 ASSERT_TRUE(EnumerateAndMatchKeys(key_pool.size()/2, 3415 ASSERT_TRUE(EnumerateAndMatchKeys(key_pool.size()/2,
3422 &iter, 3416 &iter,
3423 &keys_to_match, 3417 &keys_to_match,
3424 &count)); 3418 &count));
3425 3419
3426 std::string key_to_delete = *(keys_to_match.begin()); 3420 std::string key_to_delete = *(keys_to_match.begin());
3427 DoomEntry(key_to_delete); 3421 DoomEntry(key_to_delete);
3428 keys_to_match.erase(key_to_delete); 3422 keys_to_match.erase(key_to_delete);
3429 key_pool.erase(key_to_delete); 3423 key_pool.erase(key_to_delete);
3430 ASSERT_TRUE(EnumerateAndMatchKeys(-1, &iter, &keys_to_match, &count)); 3424 ASSERT_TRUE(EnumerateAndMatchKeys(-1, &iter, &keys_to_match, &count));
3431 cache_->EndEnumeration(&iter); 3425 iter.reset();
3432 3426
3433 EXPECT_EQ(key_pool.size(), count); 3427 EXPECT_EQ(key_pool.size(), count);
3434 EXPECT_TRUE(keys_to_match.empty()); 3428 EXPECT_TRUE(keys_to_match.empty());
3435 } 3429 }
3436 3430
3437 // Tests that enumerations are not affected by corrupt files. 3431 // Tests that enumerations are not affected by corrupt files.
3438 TEST_F(DiskCacheBackendTest, SimpleCacheEnumerationCorruption) { 3432 TEST_F(DiskCacheBackendTest, SimpleCacheEnumerationCorruption) {
3439 SetSimpleCacheMode(); 3433 SetSimpleCacheMode();
3440 InitCache(); 3434 InitCache();
3441 std::set<std::string> key_pool; 3435 std::set<std::string> key_pool;
(...skipping 15 matching lines...) Expand all
3457 ASSERT_EQ(kSize, ReadData(corrupted_entry, 0, 0, buffer.get(), kSize)); 3451 ASSERT_EQ(kSize, ReadData(corrupted_entry, 0, 0, buffer.get(), kSize));
3458 corrupted_entry->Close(); 3452 corrupted_entry->Close();
3459 3453
3460 EXPECT_TRUE(disk_cache::simple_util::CreateCorruptFileForTests( 3454 EXPECT_TRUE(disk_cache::simple_util::CreateCorruptFileForTests(
3461 key, cache_path_)); 3455 key, cache_path_));
3462 EXPECT_EQ(key_pool.size() + 1, 3456 EXPECT_EQ(key_pool.size() + 1,
3463 implicit_cast<size_t>(cache_->GetEntryCount())); 3457 implicit_cast<size_t>(cache_->GetEntryCount()));
3464 3458
3465 // Check that enumeration returns all entries but the corrupt one. 3459 // Check that enumeration returns all entries but the corrupt one.
3466 std::set<std::string> keys_to_match(key_pool); 3460 std::set<std::string> keys_to_match(key_pool);
3467 void* iter = NULL; 3461 disk_cache::Backend::Iterator iter;
3468 size_t count = 0; 3462 size_t count = 0;
3469 ASSERT_TRUE(EnumerateAndMatchKeys(-1, &iter, &keys_to_match, &count)); 3463 ASSERT_TRUE(EnumerateAndMatchKeys(-1, &iter, &keys_to_match, &count));
3470 cache_->EndEnumeration(&iter); 3464 iter.reset();
3471 3465
3472 EXPECT_EQ(key_pool.size(), count); 3466 EXPECT_EQ(key_pool.size(), count);
3473 EXPECT_TRUE(keys_to_match.empty()); 3467 EXPECT_TRUE(keys_to_match.empty());
3474 } 3468 }
3475 3469
3470 // Tests that enumerations don't leak memory when the backend is destructed
3471 // mid-enumeration.
3472 TEST_F(DiskCacheBackendTest, SimpleCacheEnumerationDestruction) {
3473 SetSimpleCacheMode();
3474 InitCache();
3475 std::set<std::string> key_pool;
3476 ASSERT_TRUE(CreateSetOfRandomEntries(&key_pool));
3477
3478 disk_cache::Backend::Iterator iter;
3479 disk_cache::Entry* entry = NULL;
3480 ASSERT_EQ(net::OK, OpenNextEntry(&iter, &entry));
3481 EXPECT_TRUE(entry);
3482 disk_cache::ScopedEntryPtr entry_closer(entry);
3483
3484 cache_.reset();
3485 // This test passes if we don't leak memory.
3486 }
3487
3476 #endif // defined(OS_POSIX) 3488 #endif // defined(OS_POSIX)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698