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

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

Issue 585833002: Revert of Remove void** from disk_cache interface. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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 TestIterator* iter, 84 void** 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 TestIterator* iter, 259 void** 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 if (!iter) 264 while (OpenNextEntry(iter, &entry) == net::OK) {
265 return false;
266 while (iter->OpenNextEntry(&entry) == net::OK) {
267 if (!entry) 265 if (!entry)
268 return false; 266 return false;
269 EXPECT_EQ(1U, keys_to_match->erase(entry->GetKey())); 267 EXPECT_EQ(1U, keys_to_match->erase(entry->GetKey()));
270 entry->Close(); 268 entry->Close();
271 ++(*count); 269 ++(*count);
272 if (max_to_open >= 0 && implicit_cast<int>(*count) >= max_to_open) 270 if (max_to_open >= 0 && implicit_cast<int>(*count) >= max_to_open)
273 break; 271 break;
274 }; 272 };
275 273
276 return true; 274 return true;
(...skipping 955 matching lines...) Expand 10 before | Expand all | Expand 10 after
1232 for (int i = 0; i < kNumEntries; i++) { 1230 for (int i = 0; i < kNumEntries; i++) {
1233 std::string key = GenerateKey(true); 1231 std::string key = GenerateKey(true);
1234 disk_cache::Entry* entry; 1232 disk_cache::Entry* entry;
1235 ASSERT_EQ(net::OK, CreateEntry(key, &entry)); 1233 ASSERT_EQ(net::OK, CreateEntry(key, &entry));
1236 entry->Close(); 1234 entry->Close();
1237 } 1235 }
1238 EXPECT_EQ(kNumEntries, cache_->GetEntryCount()); 1236 EXPECT_EQ(kNumEntries, cache_->GetEntryCount());
1239 Time final = Time::Now(); 1237 Time final = Time::Now();
1240 1238
1241 disk_cache::Entry* entry; 1239 disk_cache::Entry* entry;
1242 scoped_ptr<TestIterator> iter = CreateIterator(); 1240 void* iter = NULL;
1243 int count = 0; 1241 int count = 0;
1244 Time last_modified[kNumEntries]; 1242 Time last_modified[kNumEntries];
1245 Time last_used[kNumEntries]; 1243 Time last_used[kNumEntries];
1246 while (iter->OpenNextEntry(&entry) == net::OK) { 1244 while (OpenNextEntry(&iter, &entry) == net::OK) {
1247 ASSERT_TRUE(NULL != entry); 1245 ASSERT_TRUE(NULL != entry);
1248 if (count < kNumEntries) { 1246 if (count < kNumEntries) {
1249 last_modified[count] = entry->GetLastModified(); 1247 last_modified[count] = entry->GetLastModified();
1250 last_used[count] = entry->GetLastUsed(); 1248 last_used[count] = entry->GetLastUsed();
1251 EXPECT_TRUE(initial <= last_modified[count]); 1249 EXPECT_TRUE(initial <= last_modified[count]);
1252 EXPECT_TRUE(final >= last_modified[count]); 1250 EXPECT_TRUE(final >= last_modified[count]);
1253 } 1251 }
1254 1252
1255 entry->Close(); 1253 entry->Close();
1256 count++; 1254 count++;
1257 }; 1255 };
1258 EXPECT_EQ(kNumEntries, count); 1256 EXPECT_EQ(kNumEntries, count);
1259 1257
1260 iter = CreateIterator(); 1258 iter = NULL;
1261 count = 0; 1259 count = 0;
1262 // The previous enumeration should not have changed the timestamps. 1260 // The previous enumeration should not have changed the timestamps.
1263 while (iter->OpenNextEntry(&entry) == net::OK) { 1261 while (OpenNextEntry(&iter, &entry) == net::OK) {
1264 ASSERT_TRUE(NULL != entry); 1262 ASSERT_TRUE(NULL != entry);
1265 if (count < kNumEntries) { 1263 if (count < kNumEntries) {
1266 EXPECT_TRUE(last_modified[count] == entry->GetLastModified()); 1264 EXPECT_TRUE(last_modified[count] == entry->GetLastModified());
1267 EXPECT_TRUE(last_used[count] == entry->GetLastUsed()); 1265 EXPECT_TRUE(last_used[count] == entry->GetLastUsed());
1268 } 1266 }
1269 entry->Close(); 1267 entry->Close();
1270 count++; 1268 count++;
1271 }; 1269 };
1272 EXPECT_EQ(kNumEntries, count); 1270 EXPECT_EQ(kNumEntries, count);
1273 } 1271 }
(...skipping 30 matching lines...) Expand all
1304 disk_cache::Entry *entry1, *entry2; 1302 disk_cache::Entry *entry1, *entry2;
1305 ASSERT_EQ(net::OK, CreateEntry(first, &entry1)); 1303 ASSERT_EQ(net::OK, CreateEntry(first, &entry1));
1306 entry1->Close(); 1304 entry1->Close();
1307 ASSERT_EQ(net::OK, CreateEntry(second, &entry2)); 1305 ASSERT_EQ(net::OK, CreateEntry(second, &entry2));
1308 entry2->Close(); 1306 entry2->Close();
1309 FlushQueueForTest(); 1307 FlushQueueForTest();
1310 1308
1311 // Make sure that the timestamp is not the same. 1309 // Make sure that the timestamp is not the same.
1312 AddDelay(); 1310 AddDelay();
1313 ASSERT_EQ(net::OK, OpenEntry(second, &entry1)); 1311 ASSERT_EQ(net::OK, OpenEntry(second, &entry1));
1314 scoped_ptr<TestIterator> iter = CreateIterator(); 1312 void* iter = NULL;
1315 ASSERT_EQ(net::OK, iter->OpenNextEntry(&entry2)); 1313 ASSERT_EQ(net::OK, OpenNextEntry(&iter, &entry2));
1316 EXPECT_EQ(entry2->GetKey(), second); 1314 EXPECT_EQ(entry2->GetKey(), second);
1317 1315
1318 // Two entries and the iterator pointing at "first". 1316 // Two entries and the iterator pointing at "first".
1319 entry1->Close(); 1317 entry1->Close();
1320 entry2->Close(); 1318 entry2->Close();
1321 1319
1322 // The iterator should still be valid, so we should not crash. 1320 // The iterator should still be valid, so we should not crash.
1323 ASSERT_EQ(net::OK, iter->OpenNextEntry(&entry2)); 1321 ASSERT_EQ(net::OK, OpenNextEntry(&iter, &entry2));
1324 EXPECT_EQ(entry2->GetKey(), first); 1322 EXPECT_EQ(entry2->GetKey(), first);
1325 entry2->Close(); 1323 entry2->Close();
1326 iter = CreateIterator(); 1324 cache_->EndEnumeration(&iter);
1327 1325
1328 // Modify the oldest entry and get the newest element. 1326 // Modify the oldest entry and get the newest element.
1329 ASSERT_EQ(net::OK, OpenEntry(first, &entry1)); 1327 ASSERT_EQ(net::OK, OpenEntry(first, &entry1));
1330 EXPECT_EQ(0, WriteData(entry1, 0, 200, NULL, 0, false)); 1328 EXPECT_EQ(0, WriteData(entry1, 0, 200, NULL, 0, false));
1331 ASSERT_EQ(net::OK, iter->OpenNextEntry(&entry2)); 1329 ASSERT_EQ(net::OK, OpenNextEntry(&iter, &entry2));
1332 if (type_ == net::APP_CACHE) { 1330 if (type_ == net::APP_CACHE) {
1333 // The list is not updated. 1331 // The list is not updated.
1334 EXPECT_EQ(entry2->GetKey(), second); 1332 EXPECT_EQ(entry2->GetKey(), second);
1335 } else { 1333 } else {
1336 EXPECT_EQ(entry2->GetKey(), first); 1334 EXPECT_EQ(entry2->GetKey(), first);
1337 } 1335 }
1338 1336
1339 entry1->Close(); 1337 entry1->Close();
1340 entry2->Close(); 1338 entry2->Close();
1339 cache_->EndEnumeration(&iter);
1341 } 1340 }
1342 1341
1343 TEST_F(DiskCacheBackendTest, Enumerations2) { 1342 TEST_F(DiskCacheBackendTest, Enumerations2) {
1344 BackendEnumerations2(); 1343 BackendEnumerations2();
1345 } 1344 }
1346 1345
1347 TEST_F(DiskCacheBackendTest, NewEvictionEnumerations2) { 1346 TEST_F(DiskCacheBackendTest, NewEvictionEnumerations2) {
1348 SetNewEviction(); 1347 SetNewEviction();
1349 BackendEnumerations2(); 1348 BackendEnumerations2();
1350 } 1349 }
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1385 1384
1386 FlushQueueForTest(); 1385 FlushQueueForTest();
1387 1386
1388 // Make sure that the timestamp is not the same. 1387 // Make sure that the timestamp is not the same.
1389 AddDelay(); 1388 AddDelay();
1390 1389
1391 // Read from the last item in the LRU. 1390 // Read from the last item in the LRU.
1392 EXPECT_EQ(kSize, ReadData(entry1, 0, 0, buffer1.get(), kSize)); 1391 EXPECT_EQ(kSize, ReadData(entry1, 0, 0, buffer1.get(), kSize));
1393 entry1->Close(); 1392 entry1->Close();
1394 1393
1395 scoped_ptr<TestIterator> iter = CreateIterator(); 1394 void* iter = NULL;
1396 ASSERT_EQ(net::OK, iter->OpenNextEntry(&entry2)); 1395 ASSERT_EQ(net::OK, OpenNextEntry(&iter, &entry2));
1397 EXPECT_EQ(entry2->GetKey(), second); 1396 EXPECT_EQ(entry2->GetKey(), second);
1398 entry2->Close(); 1397 entry2->Close();
1398 cache_->EndEnumeration(&iter);
1399 } 1399 }
1400 1400
1401 #if !defined(LEAK_SANITIZER) 1401 #if !defined(LEAK_SANITIZER)
1402 // Verify handling of invalid entries while doing enumerations. 1402 // Verify handling of invalid entries while doing enumerations.
1403 // We'll be leaking memory from this test. 1403 // We'll be leaking memory from this test.
1404 void DiskCacheBackendTest::BackendInvalidEntryEnumeration() { 1404 void DiskCacheBackendTest::BackendInvalidEntryEnumeration() {
1405 InitCache(); 1405 InitCache();
1406 1406
1407 std::string key("Some key"); 1407 std::string key("Some key");
1408 disk_cache::Entry *entry, *entry1, *entry2; 1408 disk_cache::Entry *entry, *entry1, *entry2;
1409 ASSERT_EQ(net::OK, CreateEntry(key, &entry1)); 1409 ASSERT_EQ(net::OK, CreateEntry(key, &entry1));
1410 1410
1411 const int kSize = 50; 1411 const int kSize = 50;
1412 scoped_refptr<net::IOBuffer> buffer1(new net::IOBuffer(kSize)); 1412 scoped_refptr<net::IOBuffer> buffer1(new net::IOBuffer(kSize));
1413 memset(buffer1->data(), 0, kSize); 1413 memset(buffer1->data(), 0, kSize);
1414 base::strlcpy(buffer1->data(), "And the data to save", kSize); 1414 base::strlcpy(buffer1->data(), "And the data to save", kSize);
1415 EXPECT_EQ(kSize, WriteData(entry1, 0, 0, buffer1.get(), kSize, false)); 1415 EXPECT_EQ(kSize, WriteData(entry1, 0, 0, buffer1.get(), kSize, false));
1416 entry1->Close(); 1416 entry1->Close();
1417 ASSERT_EQ(net::OK, OpenEntry(key, &entry1)); 1417 ASSERT_EQ(net::OK, OpenEntry(key, &entry1));
1418 EXPECT_EQ(kSize, ReadData(entry1, 0, 0, buffer1.get(), kSize)); 1418 EXPECT_EQ(kSize, ReadData(entry1, 0, 0, buffer1.get(), kSize));
1419 1419
1420 std::string key2("Another key"); 1420 std::string key2("Another key");
1421 ASSERT_EQ(net::OK, CreateEntry(key2, &entry2)); 1421 ASSERT_EQ(net::OK, CreateEntry(key2, &entry2));
1422 entry2->Close(); 1422 entry2->Close();
1423 ASSERT_EQ(2, cache_->GetEntryCount()); 1423 ASSERT_EQ(2, cache_->GetEntryCount());
1424 1424
1425 SimulateCrash(); 1425 SimulateCrash();
1426 1426
1427 scoped_ptr<TestIterator> iter = CreateIterator(); 1427 void* iter = NULL;
1428 int count = 0; 1428 int count = 0;
1429 while (iter->OpenNextEntry(&entry) == net::OK) { 1429 while (OpenNextEntry(&iter, &entry) == net::OK) {
1430 ASSERT_TRUE(NULL != entry); 1430 ASSERT_TRUE(NULL != entry);
1431 EXPECT_EQ(key2, entry->GetKey()); 1431 EXPECT_EQ(key2, entry->GetKey());
1432 entry->Close(); 1432 entry->Close();
1433 count++; 1433 count++;
1434 }; 1434 };
1435 EXPECT_EQ(1, count); 1435 EXPECT_EQ(1, count);
1436 EXPECT_EQ(1, cache_->GetEntryCount()); 1436 EXPECT_EQ(1, cache_->GetEntryCount());
1437 } 1437 }
1438 1438
1439 // We'll be leaking memory from this test. 1439 // We'll be leaking memory from this test.
(...skipping 19 matching lines...) Expand all
1459 const int kNumEntries = 10; 1459 const int kNumEntries = 10;
1460 for (int i = 0; i < kNumEntries; i++) { 1460 for (int i = 0; i < kNumEntries; i++) {
1461 std::string key = GenerateKey(true); 1461 std::string key = GenerateKey(true);
1462 disk_cache::Entry* entry; 1462 disk_cache::Entry* entry;
1463 ASSERT_EQ(net::OK, CreateEntry(key, &entry)); 1463 ASSERT_EQ(net::OK, CreateEntry(key, &entry));
1464 entry->Close(); 1464 entry->Close();
1465 } 1465 }
1466 EXPECT_EQ(kNumEntries, cache_->GetEntryCount()); 1466 EXPECT_EQ(kNumEntries, cache_->GetEntryCount());
1467 1467
1468 disk_cache::Entry *entry1, *entry2; 1468 disk_cache::Entry *entry1, *entry2;
1469 scoped_ptr<TestIterator> iter1 = CreateIterator(), iter2 = CreateIterator(); 1469 void* iter1 = NULL;
1470 ASSERT_EQ(net::OK, iter1->OpenNextEntry(&entry1)); 1470 void* iter2 = NULL;
1471 ASSERT_EQ(net::OK, OpenNextEntry(&iter1, &entry1));
1471 ASSERT_TRUE(NULL != entry1); 1472 ASSERT_TRUE(NULL != entry1);
1472 entry1->Close(); 1473 entry1->Close();
1473 entry1 = NULL; 1474 entry1 = NULL;
1474 1475
1475 // Let's go to the middle of the list. 1476 // Let's go to the middle of the list.
1476 for (int i = 0; i < kNumEntries / 2; i++) { 1477 for (int i = 0; i < kNumEntries / 2; i++) {
1477 if (entry1) 1478 if (entry1)
1478 entry1->Close(); 1479 entry1->Close();
1479 ASSERT_EQ(net::OK, iter1->OpenNextEntry(&entry1)); 1480 ASSERT_EQ(net::OK, OpenNextEntry(&iter1, &entry1));
1480 ASSERT_TRUE(NULL != entry1); 1481 ASSERT_TRUE(NULL != entry1);
1481 1482
1482 ASSERT_EQ(net::OK, iter2->OpenNextEntry(&entry2)); 1483 ASSERT_EQ(net::OK, OpenNextEntry(&iter2, &entry2));
1483 ASSERT_TRUE(NULL != entry2); 1484 ASSERT_TRUE(NULL != entry2);
1484 entry2->Close(); 1485 entry2->Close();
1485 } 1486 }
1486 1487
1487 // Messing up with entry1 will modify entry2->next. 1488 // Messing up with entry1 will modify entry2->next.
1488 entry1->Doom(); 1489 entry1->Doom();
1489 ASSERT_EQ(net::OK, iter2->OpenNextEntry(&entry2)); 1490 ASSERT_EQ(net::OK, OpenNextEntry(&iter2, &entry2));
1490 ASSERT_TRUE(NULL != entry2); 1491 ASSERT_TRUE(NULL != entry2);
1491 1492
1492 // The link entry2->entry1 should be broken. 1493 // The link entry2->entry1 should be broken.
1493 EXPECT_NE(entry2->GetKey(), entry1->GetKey()); 1494 EXPECT_NE(entry2->GetKey(), entry1->GetKey());
1494 entry1->Close(); 1495 entry1->Close();
1495 entry2->Close(); 1496 entry2->Close();
1496 1497
1497 // And the second iterator should keep working. 1498 // And the second iterator should keep working.
1498 ASSERT_EQ(net::OK, iter2->OpenNextEntry(&entry2)); 1499 ASSERT_EQ(net::OK, OpenNextEntry(&iter2, &entry2));
1499 ASSERT_TRUE(NULL != entry2); 1500 ASSERT_TRUE(NULL != entry2);
1500 entry2->Close(); 1501 entry2->Close();
1502
1503 cache_->EndEnumeration(&iter1);
1504 cache_->EndEnumeration(&iter2);
1501 } 1505 }
1502 1506
1503 TEST_F(DiskCacheBackendTest, FixEnumerators) { 1507 TEST_F(DiskCacheBackendTest, FixEnumerators) {
1504 BackendFixEnumerators(); 1508 BackendFixEnumerators();
1505 } 1509 }
1506 1510
1507 TEST_F(DiskCacheBackendTest, NewEvictionFixEnumerators) { 1511 TEST_F(DiskCacheBackendTest, NewEvictionFixEnumerators) {
1508 SetNewEviction(); 1512 SetNewEviction();
1509 BackendFixEnumerators(); 1513 BackendFixEnumerators();
1510 } 1514 }
(...skipping 505 matching lines...) Expand 10 before | Expand all | Expand 10 after
2016 } 2020 }
2017 2021
2018 // Tests that we don't crash or hang when enumerating this cache. 2022 // Tests that we don't crash or hang when enumerating this cache.
2019 void DiskCacheBackendTest::BackendInvalidEntry3() { 2023 void DiskCacheBackendTest::BackendInvalidEntry3() {
2020 SetMask(0x1); // 2-entry table. 2024 SetMask(0x1); // 2-entry table.
2021 SetMaxSize(0x3000); // 12 kB. 2025 SetMaxSize(0x3000); // 12 kB.
2022 DisableFirstCleanup(); 2026 DisableFirstCleanup();
2023 InitCache(); 2027 InitCache();
2024 2028
2025 disk_cache::Entry* entry; 2029 disk_cache::Entry* entry;
2026 scoped_ptr<TestIterator> iter = CreateIterator(); 2030 void* iter = NULL;
2027 while (iter->OpenNextEntry(&entry) == net::OK) { 2031 while (OpenNextEntry(&iter, &entry) == net::OK) {
2028 entry->Close(); 2032 entry->Close();
2029 } 2033 }
2030 } 2034 }
2031 2035
2032 TEST_F(DiskCacheBackendTest, InvalidEntry3) { 2036 TEST_F(DiskCacheBackendTest, InvalidEntry3) {
2033 ASSERT_TRUE(CopyTestCache("dirty_entry3")); 2037 ASSERT_TRUE(CopyTestCache("dirty_entry3"));
2034 BackendInvalidEntry3(); 2038 BackendInvalidEntry3();
2035 } 2039 }
2036 2040
2037 TEST_F(DiskCacheBackendTest, NewEvictionInvalidEntry3) { 2041 TEST_F(DiskCacheBackendTest, NewEvictionInvalidEntry3) {
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
2161 entry_impl->rankings()->Store(); 2165 entry_impl->rankings()->Store();
2162 entry->Close(); 2166 entry->Close();
2163 FlushQueueForTest(); 2167 FlushQueueForTest();
2164 EXPECT_EQ(2, cache_->GetEntryCount()); 2168 EXPECT_EQ(2, cache_->GetEntryCount());
2165 2169
2166 // This should detect the bad entry. 2170 // This should detect the bad entry.
2167 EXPECT_NE(net::OK, OpenEntry(second, &entry)); 2171 EXPECT_NE(net::OK, OpenEntry(second, &entry));
2168 EXPECT_EQ(1, cache_->GetEntryCount()); 2172 EXPECT_EQ(1, cache_->GetEntryCount());
2169 2173
2170 // We should delete the cache. The list still has a corrupt node. 2174 // We should delete the cache. The list still has a corrupt node.
2171 scoped_ptr<TestIterator> iter = CreateIterator(); 2175 void* iter = NULL;
2172 EXPECT_NE(net::OK, iter->OpenNextEntry(&entry)); 2176 EXPECT_NE(net::OK, OpenNextEntry(&iter, &entry));
2173 FlushQueueForTest(); 2177 FlushQueueForTest();
2174 EXPECT_EQ(0, cache_->GetEntryCount()); 2178 EXPECT_EQ(0, cache_->GetEntryCount());
2175 } 2179 }
2176 2180
2177 TEST_F(DiskCacheBackendTest, InvalidEntry7) { 2181 TEST_F(DiskCacheBackendTest, InvalidEntry7) {
2178 BackendInvalidEntry7(); 2182 BackendInvalidEntry7();
2179 } 2183 }
2180 2184
2181 TEST_F(DiskCacheBackendTest, NewEvictionInvalidEntry7) { 2185 TEST_F(DiskCacheBackendTest, NewEvictionInvalidEntry7) {
2182 SetNewEviction(); 2186 SetNewEviction();
(...skipping 22 matching lines...) Expand all
2205 entry_impl->rankings()->Store(); 2209 entry_impl->rankings()->Store();
2206 entry->Close(); 2210 entry->Close();
2207 FlushQueueForTest(); 2211 FlushQueueForTest();
2208 EXPECT_EQ(2, cache_->GetEntryCount()); 2212 EXPECT_EQ(2, cache_->GetEntryCount());
2209 2213
2210 // This should detect the bad entry. 2214 // This should detect the bad entry.
2211 EXPECT_NE(net::OK, OpenEntry(second, &entry)); 2215 EXPECT_NE(net::OK, OpenEntry(second, &entry));
2212 EXPECT_EQ(1, cache_->GetEntryCount()); 2216 EXPECT_EQ(1, cache_->GetEntryCount());
2213 2217
2214 // We should not delete the cache. 2218 // We should not delete the cache.
2215 scoped_ptr<TestIterator> iter = CreateIterator(); 2219 void* iter = NULL;
2216 ASSERT_EQ(net::OK, iter->OpenNextEntry(&entry)); 2220 ASSERT_EQ(net::OK, OpenNextEntry(&iter, &entry));
2217 entry->Close(); 2221 entry->Close();
2218 EXPECT_NE(net::OK, iter->OpenNextEntry(&entry)); 2222 EXPECT_NE(net::OK, OpenNextEntry(&iter, &entry));
2219 EXPECT_EQ(1, cache_->GetEntryCount()); 2223 EXPECT_EQ(1, cache_->GetEntryCount());
2220 } 2224 }
2221 2225
2222 TEST_F(DiskCacheBackendTest, InvalidEntry8) { 2226 TEST_F(DiskCacheBackendTest, InvalidEntry8) {
2223 BackendInvalidEntry8(); 2227 BackendInvalidEntry8();
2224 } 2228 }
2225 2229
2226 TEST_F(DiskCacheBackendTest, NewEvictionInvalidEntry8) { 2230 TEST_F(DiskCacheBackendTest, NewEvictionInvalidEntry8) {
2227 SetNewEviction(); 2231 SetNewEviction();
2228 BackendInvalidEntry8(); 2232 BackendInvalidEntry8();
(...skipping 26 matching lines...) Expand all
2255 EXPECT_EQ(2, cache_->GetEntryCount()); 2259 EXPECT_EQ(2, cache_->GetEntryCount());
2256 2260
2257 if (eviction) { 2261 if (eviction) {
2258 TrimForTest(false); 2262 TrimForTest(false);
2259 EXPECT_EQ(1, cache_->GetEntryCount()); 2263 EXPECT_EQ(1, cache_->GetEntryCount());
2260 TrimForTest(false); 2264 TrimForTest(false);
2261 EXPECT_EQ(1, cache_->GetEntryCount()); 2265 EXPECT_EQ(1, cache_->GetEntryCount());
2262 } else { 2266 } else {
2263 // We should detect the problem through the list, but we should not delete 2267 // We should detect the problem through the list, but we should not delete
2264 // the entry, just fail the iteration. 2268 // the entry, just fail the iteration.
2265 scoped_ptr<TestIterator> iter = CreateIterator(); 2269 void* iter = NULL;
2266 EXPECT_NE(net::OK, iter->OpenNextEntry(&entry)); 2270 EXPECT_NE(net::OK, OpenNextEntry(&iter, &entry));
2267 2271
2268 // Now a full iteration will work, and return one entry. 2272 // Now a full iteration will work, and return one entry.
2269 ASSERT_EQ(net::OK, iter->OpenNextEntry(&entry)); 2273 ASSERT_EQ(net::OK, OpenNextEntry(&iter, &entry));
2270 entry->Close(); 2274 entry->Close();
2271 EXPECT_NE(net::OK, iter->OpenNextEntry(&entry)); 2275 EXPECT_NE(net::OK, OpenNextEntry(&iter, &entry));
2272 2276
2273 // This should detect what's left of the bad entry. 2277 // This should detect what's left of the bad entry.
2274 EXPECT_NE(net::OK, OpenEntry(second, &entry)); 2278 EXPECT_NE(net::OK, OpenEntry(second, &entry));
2275 EXPECT_EQ(2, cache_->GetEntryCount()); 2279 EXPECT_EQ(2, cache_->GetEntryCount());
2276 } 2280 }
2277 DisableIntegrityCheck(); 2281 DisableIntegrityCheck();
2278 } 2282 }
2279 2283
2280 TEST_F(DiskCacheBackendTest, InvalidEntry9) { 2284 TEST_F(DiskCacheBackendTest, InvalidEntry9) {
2281 BackendInvalidEntry9(false); 2285 BackendInvalidEntry9(false);
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
2332 TrimForTest(false); 2336 TrimForTest(false);
2333 EXPECT_EQ(3, cache_->GetEntryCount()); 2337 EXPECT_EQ(3, cache_->GetEntryCount());
2334 TrimForTest(false); 2338 TrimForTest(false);
2335 EXPECT_EQ(2, cache_->GetEntryCount()); 2339 EXPECT_EQ(2, cache_->GetEntryCount());
2336 TrimForTest(false); 2340 TrimForTest(false);
2337 EXPECT_EQ(1, cache_->GetEntryCount()); 2341 EXPECT_EQ(1, cache_->GetEntryCount());
2338 } else { 2342 } else {
2339 // Detection order: third -> second -> first. 2343 // Detection order: third -> second -> first.
2340 // We should detect the problem through the list, but we should not delete 2344 // We should detect the problem through the list, but we should not delete
2341 // the entry. 2345 // the entry.
2342 scoped_ptr<TestIterator> iter = CreateIterator(); 2346 void* iter = NULL;
2343 ASSERT_EQ(net::OK, iter->OpenNextEntry(&entry)); 2347 ASSERT_EQ(net::OK, OpenNextEntry(&iter, &entry));
2344 entry->Close(); 2348 entry->Close();
2345 ASSERT_EQ(net::OK, iter->OpenNextEntry(&entry)); 2349 ASSERT_EQ(net::OK, OpenNextEntry(&iter, &entry));
2346 EXPECT_EQ(first, entry->GetKey()); 2350 EXPECT_EQ(first, entry->GetKey());
2347 entry->Close(); 2351 entry->Close();
2348 EXPECT_NE(net::OK, iter->OpenNextEntry(&entry)); 2352 EXPECT_NE(net::OK, OpenNextEntry(&iter, &entry));
2349 } 2353 }
2350 DisableIntegrityCheck(); 2354 DisableIntegrityCheck();
2351 } 2355 }
2352 2356
2353 TEST_F(DiskCacheBackendTest, InvalidEntry10) { 2357 TEST_F(DiskCacheBackendTest, InvalidEntry10) {
2354 BackendInvalidEntry10(false); 2358 BackendInvalidEntry10(false);
2355 } 2359 }
2356 2360
2357 TEST_F(DiskCacheBackendTest, TrimInvalidEntry10) { 2361 TEST_F(DiskCacheBackendTest, TrimInvalidEntry10) {
2358 BackendInvalidEntry10(true); 2362 BackendInvalidEntry10(true);
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
2399 TrimForTest(false); 2403 TrimForTest(false);
2400 EXPECT_EQ(2, cache_->GetEntryCount()); 2404 EXPECT_EQ(2, cache_->GetEntryCount());
2401 TrimForTest(false); 2405 TrimForTest(false);
2402 EXPECT_EQ(1, cache_->GetEntryCount()); 2406 EXPECT_EQ(1, cache_->GetEntryCount());
2403 TrimForTest(false); 2407 TrimForTest(false);
2404 EXPECT_EQ(1, cache_->GetEntryCount()); 2408 EXPECT_EQ(1, cache_->GetEntryCount());
2405 } else { 2409 } else {
2406 // Detection order: third -> second. 2410 // Detection order: third -> second.
2407 // We should detect the problem through the list, but we should not delete 2411 // We should detect the problem through the list, but we should not delete
2408 // the entry, just fail the iteration. 2412 // the entry, just fail the iteration.
2409 scoped_ptr<TestIterator> iter = CreateIterator(); 2413 void* iter = NULL;
2410 ASSERT_EQ(net::OK, iter->OpenNextEntry(&entry)); 2414 ASSERT_EQ(net::OK, OpenNextEntry(&iter, &entry));
2411 entry->Close(); 2415 entry->Close();
2412 EXPECT_NE(net::OK, iter->OpenNextEntry(&entry)); 2416 EXPECT_NE(net::OK, OpenNextEntry(&iter, &entry));
2413 2417
2414 // Now a full iteration will work, and return two entries. 2418 // Now a full iteration will work, and return two entries.
2415 ASSERT_EQ(net::OK, iter->OpenNextEntry(&entry)); 2419 ASSERT_EQ(net::OK, OpenNextEntry(&iter, &entry));
2416 entry->Close(); 2420 entry->Close();
2417 ASSERT_EQ(net::OK, iter->OpenNextEntry(&entry)); 2421 ASSERT_EQ(net::OK, OpenNextEntry(&iter, &entry));
2418 entry->Close(); 2422 entry->Close();
2419 EXPECT_NE(net::OK, iter->OpenNextEntry(&entry)); 2423 EXPECT_NE(net::OK, OpenNextEntry(&iter, &entry));
2420 } 2424 }
2421 DisableIntegrityCheck(); 2425 DisableIntegrityCheck();
2422 } 2426 }
2423 2427
2424 TEST_F(DiskCacheBackendTest, InvalidEntry11) { 2428 TEST_F(DiskCacheBackendTest, InvalidEntry11) {
2425 BackendInvalidEntry11(false); 2429 BackendInvalidEntry11(false);
2426 } 2430 }
2427 2431
2428 TEST_F(DiskCacheBackendTest, TrimInvalidEntry11) { 2432 TEST_F(DiskCacheBackendTest, TrimInvalidEntry11) {
2429 BackendInvalidEntry11(true); 2433 BackendInvalidEntry11(true);
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
2487 } 2491 }
2488 2492
2489 TEST_F(DiskCacheBackendTest, NewEvictionInvalidRankings2) { 2493 TEST_F(DiskCacheBackendTest, NewEvictionInvalidRankings2) {
2490 SetNewEviction(); 2494 SetNewEviction();
2491 BackendInvalidRankings2(); 2495 BackendInvalidRankings2();
2492 } 2496 }
2493 2497
2494 // If the LRU is corrupt, we delete the cache. 2498 // If the LRU is corrupt, we delete the cache.
2495 void DiskCacheBackendTest::BackendInvalidRankings() { 2499 void DiskCacheBackendTest::BackendInvalidRankings() {
2496 disk_cache::Entry* entry; 2500 disk_cache::Entry* entry;
2497 scoped_ptr<TestIterator> iter = CreateIterator(); 2501 void* iter = NULL;
2498 ASSERT_EQ(net::OK, iter->OpenNextEntry(&entry)); 2502 ASSERT_EQ(net::OK, OpenNextEntry(&iter, &entry));
2499 entry->Close(); 2503 entry->Close();
2500 EXPECT_EQ(2, cache_->GetEntryCount()); 2504 EXPECT_EQ(2, cache_->GetEntryCount());
2501 2505
2502 EXPECT_NE(net::OK, iter->OpenNextEntry(&entry)); 2506 EXPECT_NE(net::OK, OpenNextEntry(&iter, &entry));
2503 FlushQueueForTest(); // Allow the restart to finish. 2507 FlushQueueForTest(); // Allow the restart to finish.
2504 EXPECT_EQ(0, cache_->GetEntryCount()); 2508 EXPECT_EQ(0, cache_->GetEntryCount());
2505 } 2509 }
2506 2510
2507 TEST_F(DiskCacheBackendTest, InvalidRankingsSuccess) { 2511 TEST_F(DiskCacheBackendTest, InvalidRankingsSuccess) {
2508 ASSERT_TRUE(CopyTestCache("bad_rankings")); 2512 ASSERT_TRUE(CopyTestCache("bad_rankings"));
2509 DisableFirstCleanup(); 2513 DisableFirstCleanup();
2510 InitCache(); 2514 InitCache();
2511 BackendInvalidRankings(); 2515 BackendInvalidRankings();
2512 } 2516 }
(...skipping 19 matching lines...) Expand all
2532 DisableFirstCleanup(); 2536 DisableFirstCleanup();
2533 SetNewEviction(); 2537 SetNewEviction();
2534 InitCache(); 2538 InitCache();
2535 SetTestMode(); // Fail cache reinitialization. 2539 SetTestMode(); // Fail cache reinitialization.
2536 BackendInvalidRankings(); 2540 BackendInvalidRankings();
2537 } 2541 }
2538 2542
2539 // If the LRU is corrupt and we have open entries, we disable the cache. 2543 // If the LRU is corrupt and we have open entries, we disable the cache.
2540 void DiskCacheBackendTest::BackendDisable() { 2544 void DiskCacheBackendTest::BackendDisable() {
2541 disk_cache::Entry *entry1, *entry2; 2545 disk_cache::Entry *entry1, *entry2;
2542 scoped_ptr<TestIterator> iter = CreateIterator(); 2546 void* iter = NULL;
2543 ASSERT_EQ(net::OK, iter->OpenNextEntry(&entry1)); 2547 ASSERT_EQ(net::OK, OpenNextEntry(&iter, &entry1));
2544 2548
2545 EXPECT_NE(net::OK, iter->OpenNextEntry(&entry2)); 2549 EXPECT_NE(net::OK, OpenNextEntry(&iter, &entry2));
2546 EXPECT_EQ(0, cache_->GetEntryCount()); 2550 EXPECT_EQ(0, cache_->GetEntryCount());
2547 EXPECT_NE(net::OK, CreateEntry("Something new", &entry2)); 2551 EXPECT_NE(net::OK, CreateEntry("Something new", &entry2));
2548 2552
2549 entry1->Close(); 2553 entry1->Close();
2550 FlushQueueForTest(); // Flushing the Close posts a task to restart the cache. 2554 FlushQueueForTest(); // Flushing the Close posts a task to restart the cache.
2551 FlushQueueForTest(); // This one actually allows that task to complete. 2555 FlushQueueForTest(); // This one actually allows that task to complete.
2552 2556
2553 EXPECT_EQ(0, cache_->GetEntryCount()); 2557 EXPECT_EQ(0, cache_->GetEntryCount());
2554 } 2558 }
2555 2559
(...skipping 27 matching lines...) Expand all
2583 InitCache(); 2587 InitCache();
2584 SetTestMode(); // Fail cache reinitialization. 2588 SetTestMode(); // Fail cache reinitialization.
2585 BackendDisable(); 2589 BackendDisable();
2586 } 2590 }
2587 2591
2588 // This is another type of corruption on the LRU; disable the cache. 2592 // This is another type of corruption on the LRU; disable the cache.
2589 void DiskCacheBackendTest::BackendDisable2() { 2593 void DiskCacheBackendTest::BackendDisable2() {
2590 EXPECT_EQ(8, cache_->GetEntryCount()); 2594 EXPECT_EQ(8, cache_->GetEntryCount());
2591 2595
2592 disk_cache::Entry* entry; 2596 disk_cache::Entry* entry;
2593 scoped_ptr<TestIterator> iter = CreateIterator(); 2597 void* iter = NULL;
2594 int count = 0; 2598 int count = 0;
2595 while (iter->OpenNextEntry(&entry) == net::OK) { 2599 while (OpenNextEntry(&iter, &entry) == net::OK) {
2596 ASSERT_TRUE(NULL != entry); 2600 ASSERT_TRUE(NULL != entry);
2597 entry->Close(); 2601 entry->Close();
2598 count++; 2602 count++;
2599 ASSERT_LT(count, 9); 2603 ASSERT_LT(count, 9);
2600 }; 2604 };
2601 2605
2602 FlushQueueForTest(); 2606 FlushQueueForTest();
2603 EXPECT_EQ(0, cache_->GetEntryCount()); 2607 EXPECT_EQ(0, cache_->GetEntryCount());
2604 } 2608 }
2605 2609
(...skipping 25 matching lines...) Expand all
2631 DisableFirstCleanup(); 2635 DisableFirstCleanup();
2632 SetNewEviction(); 2636 SetNewEviction();
2633 InitCache(); 2637 InitCache();
2634 SetTestMode(); // Fail cache reinitialization. 2638 SetTestMode(); // Fail cache reinitialization.
2635 BackendDisable2(); 2639 BackendDisable2();
2636 } 2640 }
2637 2641
2638 // If the index size changes when we disable the cache, we should not crash. 2642 // If the index size changes when we disable the cache, we should not crash.
2639 void DiskCacheBackendTest::BackendDisable3() { 2643 void DiskCacheBackendTest::BackendDisable3() {
2640 disk_cache::Entry *entry1, *entry2; 2644 disk_cache::Entry *entry1, *entry2;
2641 scoped_ptr<TestIterator> iter = CreateIterator(); 2645 void* iter = NULL;
2642 EXPECT_EQ(2, cache_->GetEntryCount()); 2646 EXPECT_EQ(2, cache_->GetEntryCount());
2643 ASSERT_EQ(net::OK, iter->OpenNextEntry(&entry1)); 2647 ASSERT_EQ(net::OK, OpenNextEntry(&iter, &entry1));
2644 entry1->Close(); 2648 entry1->Close();
2645 2649
2646 EXPECT_NE(net::OK, iter->OpenNextEntry(&entry2)); 2650 EXPECT_NE(net::OK, OpenNextEntry(&iter, &entry2));
2647 FlushQueueForTest(); 2651 FlushQueueForTest();
2648 2652
2649 ASSERT_EQ(net::OK, CreateEntry("Something new", &entry2)); 2653 ASSERT_EQ(net::OK, CreateEntry("Something new", &entry2));
2650 entry2->Close(); 2654 entry2->Close();
2651 2655
2652 EXPECT_EQ(1, cache_->GetEntryCount()); 2656 EXPECT_EQ(1, cache_->GetEntryCount());
2653 } 2657 }
2654 2658
2655 TEST_F(DiskCacheBackendTest, DisableSuccess3) { 2659 TEST_F(DiskCacheBackendTest, DisableSuccess3) {
2656 ASSERT_TRUE(CopyTestCache("bad_rankings2")); 2660 ASSERT_TRUE(CopyTestCache("bad_rankings2"));
2657 DisableFirstCleanup(); 2661 DisableFirstCleanup();
2658 SetMaxSize(20 * 1024 * 1024); 2662 SetMaxSize(20 * 1024 * 1024);
2659 InitCache(); 2663 InitCache();
2660 BackendDisable3(); 2664 BackendDisable3();
2661 } 2665 }
2662 2666
2663 TEST_F(DiskCacheBackendTest, NewEvictionDisableSuccess3) { 2667 TEST_F(DiskCacheBackendTest, NewEvictionDisableSuccess3) {
2664 ASSERT_TRUE(CopyTestCache("bad_rankings2")); 2668 ASSERT_TRUE(CopyTestCache("bad_rankings2"));
2665 DisableFirstCleanup(); 2669 DisableFirstCleanup();
2666 SetMaxSize(20 * 1024 * 1024); 2670 SetMaxSize(20 * 1024 * 1024);
2667 SetNewEviction(); 2671 SetNewEviction();
2668 InitCache(); 2672 InitCache();
2669 BackendDisable3(); 2673 BackendDisable3();
2670 } 2674 }
2671 2675
2672 // If we disable the cache, already open entries should work as far as possible. 2676 // If we disable the cache, already open entries should work as far as possible.
2673 void DiskCacheBackendTest::BackendDisable4() { 2677 void DiskCacheBackendTest::BackendDisable4() {
2674 disk_cache::Entry *entry1, *entry2, *entry3, *entry4; 2678 disk_cache::Entry *entry1, *entry2, *entry3, *entry4;
2675 scoped_ptr<TestIterator> iter = CreateIterator(); 2679 void* iter = NULL;
2676 ASSERT_EQ(net::OK, iter->OpenNextEntry(&entry1)); 2680 ASSERT_EQ(net::OK, OpenNextEntry(&iter, &entry1));
2677 2681
2678 char key2[2000]; 2682 char key2[2000];
2679 char key3[20000]; 2683 char key3[20000];
2680 CacheTestFillBuffer(key2, sizeof(key2), true); 2684 CacheTestFillBuffer(key2, sizeof(key2), true);
2681 CacheTestFillBuffer(key3, sizeof(key3), true); 2685 CacheTestFillBuffer(key3, sizeof(key3), true);
2682 key2[sizeof(key2) - 1] = '\0'; 2686 key2[sizeof(key2) - 1] = '\0';
2683 key3[sizeof(key3) - 1] = '\0'; 2687 key3[sizeof(key3) - 1] = '\0';
2684 ASSERT_EQ(net::OK, CreateEntry(key2, &entry2)); 2688 ASSERT_EQ(net::OK, CreateEntry(key2, &entry2));
2685 ASSERT_EQ(net::OK, CreateEntry(key3, &entry3)); 2689 ASSERT_EQ(net::OK, CreateEntry(key3, &entry3));
2686 2690
2687 const int kBufSize = 20000; 2691 const int kBufSize = 20000;
2688 scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(kBufSize)); 2692 scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(kBufSize));
2689 memset(buf->data(), 0, kBufSize); 2693 memset(buf->data(), 0, kBufSize);
2690 EXPECT_EQ(100, WriteData(entry2, 0, 0, buf.get(), 100, false)); 2694 EXPECT_EQ(100, WriteData(entry2, 0, 0, buf.get(), 100, false));
2691 EXPECT_EQ(kBufSize, WriteData(entry3, 0, 0, buf.get(), kBufSize, false)); 2695 EXPECT_EQ(kBufSize, WriteData(entry3, 0, 0, buf.get(), kBufSize, false));
2692 2696
2693 // This line should disable the cache but not delete it. 2697 // This line should disable the cache but not delete it.
2694 EXPECT_NE(net::OK, iter->OpenNextEntry(&entry4)); 2698 EXPECT_NE(net::OK, OpenNextEntry(&iter, &entry4));
2695 EXPECT_EQ(0, cache_->GetEntryCount()); 2699 EXPECT_EQ(0, cache_->GetEntryCount());
2696 2700
2697 EXPECT_NE(net::OK, CreateEntry("cache is disabled", &entry4)); 2701 EXPECT_NE(net::OK, CreateEntry("cache is disabled", &entry4));
2698 2702
2699 EXPECT_EQ(100, ReadData(entry2, 0, 0, buf.get(), 100)); 2703 EXPECT_EQ(100, ReadData(entry2, 0, 0, buf.get(), 100));
2700 EXPECT_EQ(100, WriteData(entry2, 0, 0, buf.get(), 100, false)); 2704 EXPECT_EQ(100, WriteData(entry2, 0, 0, buf.get(), 100, false));
2701 EXPECT_EQ(100, WriteData(entry2, 1, 0, buf.get(), 100, false)); 2705 EXPECT_EQ(100, WriteData(entry2, 1, 0, buf.get(), 100, false));
2702 2706
2703 EXPECT_EQ(kBufSize, ReadData(entry3, 0, 0, buf.get(), kBufSize)); 2707 EXPECT_EQ(kBufSize, ReadData(entry3, 0, 0, buf.get(), kBufSize));
2704 EXPECT_EQ(kBufSize, WriteData(entry3, 0, 0, buf.get(), kBufSize, false)); 2708 EXPECT_EQ(kBufSize, WriteData(entry3, 0, 0, buf.get(), kBufSize, false));
(...skipping 660 matching lines...) Expand 10 before | Expand all | Expand 10 after
3365 // Tests basic functionality of the SimpleBackend implementation of the 3369 // Tests basic functionality of the SimpleBackend implementation of the
3366 // enumeration API. 3370 // enumeration API.
3367 TEST_F(DiskCacheBackendTest, SimpleCacheEnumerationBasics) { 3371 TEST_F(DiskCacheBackendTest, SimpleCacheEnumerationBasics) {
3368 SetSimpleCacheMode(); 3372 SetSimpleCacheMode();
3369 InitCache(); 3373 InitCache();
3370 std::set<std::string> key_pool; 3374 std::set<std::string> key_pool;
3371 ASSERT_TRUE(CreateSetOfRandomEntries(&key_pool)); 3375 ASSERT_TRUE(CreateSetOfRandomEntries(&key_pool));
3372 3376
3373 // Check that enumeration returns all entries. 3377 // Check that enumeration returns all entries.
3374 std::set<std::string> keys_to_match(key_pool); 3378 std::set<std::string> keys_to_match(key_pool);
3375 scoped_ptr<TestIterator> iter = CreateIterator(); 3379 void* iter = NULL;
3376 size_t count = 0; 3380 size_t count = 0;
3377 ASSERT_TRUE(EnumerateAndMatchKeys(-1, iter.get(), &keys_to_match, &count)); 3381 ASSERT_TRUE(EnumerateAndMatchKeys(-1, &iter, &keys_to_match, &count));
3378 iter.reset(); 3382 cache_->EndEnumeration(&iter);
3379 EXPECT_EQ(key_pool.size(), count); 3383 EXPECT_EQ(key_pool.size(), count);
3380 EXPECT_TRUE(keys_to_match.empty()); 3384 EXPECT_TRUE(keys_to_match.empty());
3381 3385
3382 // Check that opening entries does not affect enumeration. 3386 // Check that opening entries does not affect enumeration.
3383 keys_to_match = key_pool; 3387 keys_to_match = key_pool;
3384 iter = CreateIterator(); 3388 iter = NULL;
3385 count = 0; 3389 count = 0;
3386 disk_cache::Entry* entry_opened_before; 3390 disk_cache::Entry* entry_opened_before;
3387 ASSERT_EQ(net::OK, OpenEntry(*(key_pool.begin()), &entry_opened_before)); 3391 ASSERT_EQ(net::OK, OpenEntry(*(key_pool.begin()), &entry_opened_before));
3388 ASSERT_TRUE(EnumerateAndMatchKeys(key_pool.size()/2, 3392 ASSERT_TRUE(EnumerateAndMatchKeys(key_pool.size()/2,
3389 iter.get(), 3393 &iter,
3390 &keys_to_match, 3394 &keys_to_match,
3391 &count)); 3395 &count));
3392 3396
3393 disk_cache::Entry* entry_opened_middle; 3397 disk_cache::Entry* entry_opened_middle;
3394 ASSERT_EQ(net::OK, 3398 ASSERT_EQ(net::OK,
3395 OpenEntry(*(keys_to_match.begin()), &entry_opened_middle)); 3399 OpenEntry(*(keys_to_match.begin()), &entry_opened_middle));
3396 ASSERT_TRUE(EnumerateAndMatchKeys(-1, iter.get(), &keys_to_match, &count)); 3400 ASSERT_TRUE(EnumerateAndMatchKeys(-1, &iter, &keys_to_match, &count));
3397 iter.reset(); 3401 cache_->EndEnumeration(&iter);
3398 entry_opened_before->Close(); 3402 entry_opened_before->Close();
3399 entry_opened_middle->Close(); 3403 entry_opened_middle->Close();
3400 3404
3401 EXPECT_EQ(key_pool.size(), count); 3405 EXPECT_EQ(key_pool.size(), count);
3402 EXPECT_TRUE(keys_to_match.empty()); 3406 EXPECT_TRUE(keys_to_match.empty());
3403 } 3407 }
3404 3408
3405 // Tests that the enumerations are not affected by dooming an entry in the 3409 // Tests that the enumerations are not affected by dooming an entry in the
3406 // middle. 3410 // middle.
3407 TEST_F(DiskCacheBackendTest, SimpleCacheEnumerationWhileDoomed) { 3411 TEST_F(DiskCacheBackendTest, SimpleCacheEnumerationWhileDoomed) {
3408 SetSimpleCacheMode(); 3412 SetSimpleCacheMode();
3409 InitCache(); 3413 InitCache();
3410 std::set<std::string> key_pool; 3414 std::set<std::string> key_pool;
3411 ASSERT_TRUE(CreateSetOfRandomEntries(&key_pool)); 3415 ASSERT_TRUE(CreateSetOfRandomEntries(&key_pool));
3412 3416
3413 // Check that enumeration returns all entries but the doomed one. 3417 // Check that enumeration returns all entries but the doomed one.
3414 std::set<std::string> keys_to_match(key_pool); 3418 std::set<std::string> keys_to_match(key_pool);
3415 scoped_ptr<TestIterator> iter = CreateIterator(); 3419 void* iter = NULL;
3416 size_t count = 0; 3420 size_t count = 0;
3417 ASSERT_TRUE(EnumerateAndMatchKeys(key_pool.size()/2, 3421 ASSERT_TRUE(EnumerateAndMatchKeys(key_pool.size()/2,
3418 iter.get(), 3422 &iter,
3419 &keys_to_match, 3423 &keys_to_match,
3420 &count)); 3424 &count));
3421 3425
3422 std::string key_to_delete = *(keys_to_match.begin()); 3426 std::string key_to_delete = *(keys_to_match.begin());
3423 DoomEntry(key_to_delete); 3427 DoomEntry(key_to_delete);
3424 keys_to_match.erase(key_to_delete); 3428 keys_to_match.erase(key_to_delete);
3425 key_pool.erase(key_to_delete); 3429 key_pool.erase(key_to_delete);
3426 ASSERT_TRUE(EnumerateAndMatchKeys(-1, iter.get(), &keys_to_match, &count)); 3430 ASSERT_TRUE(EnumerateAndMatchKeys(-1, &iter, &keys_to_match, &count));
3427 iter.reset(); 3431 cache_->EndEnumeration(&iter);
3428 3432
3429 EXPECT_EQ(key_pool.size(), count); 3433 EXPECT_EQ(key_pool.size(), count);
3430 EXPECT_TRUE(keys_to_match.empty()); 3434 EXPECT_TRUE(keys_to_match.empty());
3431 } 3435 }
3432 3436
3433 // Tests that enumerations are not affected by corrupt files. 3437 // Tests that enumerations are not affected by corrupt files.
3434 TEST_F(DiskCacheBackendTest, SimpleCacheEnumerationCorruption) { 3438 TEST_F(DiskCacheBackendTest, SimpleCacheEnumerationCorruption) {
3435 SetSimpleCacheMode(); 3439 SetSimpleCacheMode();
3436 InitCache(); 3440 InitCache();
3437 std::set<std::string> key_pool; 3441 std::set<std::string> key_pool;
(...skipping 15 matching lines...) Expand all
3453 ASSERT_EQ(kSize, ReadData(corrupted_entry, 0, 0, buffer.get(), kSize)); 3457 ASSERT_EQ(kSize, ReadData(corrupted_entry, 0, 0, buffer.get(), kSize));
3454 corrupted_entry->Close(); 3458 corrupted_entry->Close();
3455 3459
3456 EXPECT_TRUE(disk_cache::simple_util::CreateCorruptFileForTests( 3460 EXPECT_TRUE(disk_cache::simple_util::CreateCorruptFileForTests(
3457 key, cache_path_)); 3461 key, cache_path_));
3458 EXPECT_EQ(key_pool.size() + 1, 3462 EXPECT_EQ(key_pool.size() + 1,
3459 implicit_cast<size_t>(cache_->GetEntryCount())); 3463 implicit_cast<size_t>(cache_->GetEntryCount()));
3460 3464
3461 // Check that enumeration returns all entries but the corrupt one. 3465 // Check that enumeration returns all entries but the corrupt one.
3462 std::set<std::string> keys_to_match(key_pool); 3466 std::set<std::string> keys_to_match(key_pool);
3463 scoped_ptr<TestIterator> iter = CreateIterator(); 3467 void* iter = NULL;
3464 size_t count = 0; 3468 size_t count = 0;
3465 ASSERT_TRUE(EnumerateAndMatchKeys(-1, iter.get(), &keys_to_match, &count)); 3469 ASSERT_TRUE(EnumerateAndMatchKeys(-1, &iter, &keys_to_match, &count));
3466 iter.reset(); 3470 cache_->EndEnumeration(&iter);
3467 3471
3468 EXPECT_EQ(key_pool.size(), count); 3472 EXPECT_EQ(key_pool.size(), count);
3469 EXPECT_TRUE(keys_to_match.empty()); 3473 EXPECT_TRUE(keys_to_match.empty());
3470 } 3474 }
3471 3475
3472 // Tests that enumerations don't leak memory when the backend is destructed 3476 // Tests that enumerations don't leak memory when the backend is destructed
3473 // mid-enumeration. 3477 // mid-enumeration.
3474 TEST_F(DiskCacheBackendTest, SimpleCacheEnumerationDestruction) { 3478 TEST_F(DiskCacheBackendTest, SimpleCacheEnumerationDestruction) {
3475 SetSimpleCacheMode(); 3479 SetSimpleCacheMode();
3476 InitCache(); 3480 InitCache();
3477 std::set<std::string> key_pool; 3481 std::set<std::string> key_pool;
3478 ASSERT_TRUE(CreateSetOfRandomEntries(&key_pool)); 3482 ASSERT_TRUE(CreateSetOfRandomEntries(&key_pool));
3479 3483
3480 scoped_ptr<TestIterator> iter = CreateIterator(); 3484 void* iter = NULL;
3481 disk_cache::Entry* entry = NULL; 3485 disk_cache::Entry* entry = NULL;
3482 ASSERT_EQ(net::OK, iter->OpenNextEntry(&entry)); 3486 ASSERT_EQ(net::OK, OpenNextEntry(&iter, &entry));
3483 EXPECT_TRUE(entry); 3487 EXPECT_TRUE(entry);
3484 disk_cache::ScopedEntryPtr entry_closer(entry); 3488 disk_cache::ScopedEntryPtr entry_closer(entry);
3485 3489
3486 cache_.reset(); 3490 cache_.reset();
3487 // This test passes if we don't leak memory. 3491 // This test passes if we don't leak memory.
3488 } 3492 }
3489 3493
3490 #endif // defined(OS_POSIX) 3494 #endif // defined(OS_POSIX)
OLDNEW
« no previous file with comments | « content/browser/service_worker/service_worker_cache.cc ('k') | net/disk_cache/blockfile/backend_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698