Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/file_util.h" | 6 #include "base/file_util.h" |
| 7 #include "base/string_util.h" | 7 #include "base/string_util.h" |
| 8 #include "base/stringprintf.h" | 8 #include "base/stringprintf.h" |
| 9 #include "base/third_party/dynamic_annotations/dynamic_annotations.h" | 9 #include "base/third_party/dynamic_annotations/dynamic_annotations.h" |
| 10 #include "base/threading/platform_thread.h" | 10 #include "base/threading/platform_thread.h" |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 43 void BackendInvalidEntry(); | 43 void BackendInvalidEntry(); |
| 44 void BackendInvalidEntryRead(); | 44 void BackendInvalidEntryRead(); |
| 45 void BackendInvalidEntryWithLoad(); | 45 void BackendInvalidEntryWithLoad(); |
| 46 void BackendTrimInvalidEntry(); | 46 void BackendTrimInvalidEntry(); |
| 47 void BackendTrimInvalidEntry2(); | 47 void BackendTrimInvalidEntry2(); |
| 48 void BackendEnumerations(); | 48 void BackendEnumerations(); |
| 49 void BackendEnumerations2(); | 49 void BackendEnumerations2(); |
| 50 void BackendInvalidEntryEnumeration(); | 50 void BackendInvalidEntryEnumeration(); |
| 51 void BackendFixEnumerators(); | 51 void BackendFixEnumerators(); |
| 52 void BackendDoomRecent(); | 52 void BackendDoomRecent(); |
| 53 | |
| 54 // Adds 5 sparse entries. |doomed_start| and |doomed_end| if not NULL, | |
| 55 // will be filled with times, used by DoomEntriesSince and DoomEntriesBetween. | |
| 56 // There are 4 entries after doomed_start and 2 after doomed_end. | |
| 57 void InitSparseCache(base::Time* doomed_start, base::Time* doomed_end); | |
| 58 | |
| 53 void BackendDoomBetween(); | 59 void BackendDoomBetween(); |
| 54 void BackendTransaction(const std::string& name, int num_entries, bool load); | 60 void BackendTransaction(const std::string& name, int num_entries, bool load); |
| 55 void BackendRecoverInsert(); | 61 void BackendRecoverInsert(); |
| 56 void BackendRecoverRemove(); | 62 void BackendRecoverRemove(); |
| 57 void BackendRecoverWithEviction(); | 63 void BackendRecoverWithEviction(); |
| 58 void BackendInvalidEntry2(); | 64 void BackendInvalidEntry2(); |
| 59 void BackendInvalidEntry3(); | 65 void BackendInvalidEntry3(); |
| 60 void BackendInvalidEntry7(); | 66 void BackendInvalidEntry7(); |
| 61 void BackendInvalidEntry8(); | 67 void BackendInvalidEntry8(); |
| 62 void BackendInvalidEntry9(bool eviction); | 68 void BackendInvalidEntry9(bool eviction); |
| (...skipping 1275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1338 TEST_F(DiskCacheBackendTest, NewEvictionDoomRecent) { | 1344 TEST_F(DiskCacheBackendTest, NewEvictionDoomRecent) { |
| 1339 SetNewEviction(); | 1345 SetNewEviction(); |
| 1340 BackendDoomRecent(); | 1346 BackendDoomRecent(); |
| 1341 } | 1347 } |
| 1342 | 1348 |
| 1343 TEST_F(DiskCacheBackendTest, MemoryOnlyDoomRecent) { | 1349 TEST_F(DiskCacheBackendTest, MemoryOnlyDoomRecent) { |
| 1344 SetMemoryOnlyMode(); | 1350 SetMemoryOnlyMode(); |
| 1345 BackendDoomRecent(); | 1351 BackendDoomRecent(); |
| 1346 } | 1352 } |
| 1347 | 1353 |
| 1354 void DiskCacheBackendTest::InitSparseCache(base::Time* doomed_start, | |
| 1355 base::Time* doomed_end) { | |
| 1356 SetDirectMode(); | |
| 1357 InitCache(); | |
| 1358 | |
| 1359 const int kSize = 50; | |
| 1360 // This must be greater then MemEntryImpl::kMaxSparseEntrySize. | |
| 1361 const int kOffset = 10 + 1024 * 1024; | |
| 1362 | |
| 1363 disk_cache::Entry* entry0 = NULL; | |
| 1364 disk_cache::Entry* entry1 = NULL; | |
| 1365 disk_cache::Entry* entry2 = NULL; | |
| 1366 | |
| 1367 scoped_refptr<net::IOBuffer> buffer(new net::IOBuffer(kSize)); | |
| 1368 CacheTestFillBuffer(buffer->data(), kSize, false); | |
| 1369 | |
| 1370 ASSERT_EQ(net::OK, CreateEntry("zeroth", &entry0)); | |
| 1371 ASSERT_EQ(kSize, WriteSparseData(entry0, 0, buffer.get(), kSize)); | |
| 1372 ASSERT_EQ(kSize, | |
| 1373 WriteSparseData(entry0, kOffset + kSize, buffer.get(), kSize)); | |
| 1374 entry0->Close(); | |
| 1375 | |
| 1376 FlushQueueForTest(); | |
| 1377 AddDelay(); | |
| 1378 if (doomed_start) | |
| 1379 *doomed_start = base::Time::Now(); | |
| 1380 | |
| 1381 // Order in rankings list: | |
| 1382 // first_part1, first_part2, second_part1, second_part2 | |
| 1383 ASSERT_EQ(net::OK, CreateEntry("first", &entry1)); | |
| 1384 ASSERT_EQ(kSize, WriteSparseData(entry1, 0, buffer.get(), kSize)); | |
| 1385 ASSERT_EQ(kSize, | |
| 1386 WriteSparseData(entry1, kOffset + kSize, buffer.get(), kSize)); | |
| 1387 entry1->Close(); | |
| 1388 | |
| 1389 ASSERT_EQ(net::OK, CreateEntry("second", &entry2)); | |
| 1390 ASSERT_EQ(kSize, WriteSparseData(entry2, 0, buffer.get(), kSize)); | |
| 1391 ASSERT_EQ(kSize, | |
| 1392 WriteSparseData(entry2, kOffset + kSize, buffer.get(), kSize)); | |
| 1393 entry2->Close(); | |
| 1394 | |
| 1395 FlushQueueForTest(); | |
| 1396 AddDelay(); | |
| 1397 if (doomed_end) | |
| 1398 *doomed_end = base::Time::Now(); | |
| 1399 | |
| 1400 // Order in rankings list: | |
| 1401 // third_part1, fourth_part1, third_part2, fourth_part2 | |
| 1402 disk_cache::Entry* entry3 = NULL; | |
| 1403 disk_cache::Entry* entry4 = NULL; | |
| 1404 ASSERT_EQ(net::OK, CreateEntry("third", &entry3)); | |
| 1405 ASSERT_EQ(kSize, WriteSparseData(entry3, 0, buffer.get(), kSize)); | |
| 1406 ASSERT_EQ(net::OK, CreateEntry("fourth", &entry4)); | |
| 1407 ASSERT_EQ(kSize, WriteSparseData(entry4, 0, buffer.get(), kSize)); | |
| 1408 ASSERT_EQ(kSize, | |
| 1409 WriteSparseData(entry3, kOffset + kSize, buffer.get(), kSize)); | |
| 1410 ASSERT_EQ(kSize, | |
| 1411 WriteSparseData(entry4, kOffset + kSize, buffer.get(), kSize)); | |
| 1412 entry3->Close(); | |
| 1413 entry4->Close(); | |
| 1414 | |
| 1415 FlushQueueForTest(); | |
| 1416 AddDelay(); | |
|
rvargas (doing something else)
2013/03/28 00:31:59
nit: we shouldn't need an extra delay here.
| |
| 1417 } | |
| 1418 | |
| 1419 TEST_F(DiskCacheBackendTest, MemoryOnlyDoomEntriesSinceSparse) { | |
| 1420 SetMemoryOnlyMode(); | |
| 1421 base::Time start; | |
| 1422 InitSparseCache(&start, NULL); | |
| 1423 DoomEntriesSince(start); | |
| 1424 EXPECT_EQ(1, cache_->GetEntryCount()); | |
| 1425 } | |
| 1426 | |
| 1427 TEST_F(DiskCacheBackendTest, DoomEntriesSinceSparse) { | |
| 1428 base::Time start; | |
| 1429 InitSparseCache(&start, NULL); | |
| 1430 DoomEntriesSince(start); | |
| 1431 // NOTE: BackendImpl counts child entries in it GetEntryCount(), while | |
|
rvargas (doing something else)
2013/03/28 00:31:59
type: it -> its
Slava Chigrin
2013/03/28 13:56:19
Done.
| |
| 1432 // MemBackendImpl does not. Thats why expected value differs here from | |
| 1433 // MemoryOnlyDoomEntriesSinceSparse. | |
| 1434 EXPECT_EQ(3, cache_->GetEntryCount()); | |
| 1435 } | |
| 1436 | |
| 1437 TEST_F(DiskCacheBackendTest, MemoryOnlyDoomAllSparse) { | |
| 1438 SetMemoryOnlyMode(); | |
| 1439 InitSparseCache(NULL, NULL); | |
| 1440 EXPECT_EQ(net::OK, DoomAllEntries()); | |
| 1441 EXPECT_EQ(0, cache_->GetEntryCount()); | |
| 1442 } | |
| 1443 | |
| 1444 TEST_F(DiskCacheBackendTest, DoomAllSparse) { | |
| 1445 InitSparseCache(NULL, NULL); | |
| 1446 EXPECT_EQ(net::OK, DoomAllEntries()); | |
| 1447 EXPECT_EQ(0, cache_->GetEntryCount()); | |
| 1448 } | |
| 1449 | |
| 1348 void DiskCacheBackendTest::BackendDoomBetween() { | 1450 void DiskCacheBackendTest::BackendDoomBetween() { |
| 1349 InitCache(); | 1451 InitCache(); |
| 1350 | 1452 |
| 1351 disk_cache::Entry *entry; | 1453 disk_cache::Entry *entry; |
| 1352 ASSERT_EQ(net::OK, CreateEntry("first", &entry)); | 1454 ASSERT_EQ(net::OK, CreateEntry("first", &entry)); |
| 1353 entry->Close(); | 1455 entry->Close(); |
| 1354 FlushQueueForTest(); | 1456 FlushQueueForTest(); |
| 1355 | 1457 |
| 1356 AddDelay(); | 1458 AddDelay(); |
| 1357 Time middle_start = Time::Now(); | 1459 Time middle_start = Time::Now(); |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 1381 ASSERT_EQ(net::OK, OpenEntry("fourth", &entry)); | 1483 ASSERT_EQ(net::OK, OpenEntry("fourth", &entry)); |
| 1382 entry->Close(); | 1484 entry->Close(); |
| 1383 | 1485 |
| 1384 EXPECT_EQ(net::OK, DoomEntriesBetween(middle_start, final)); | 1486 EXPECT_EQ(net::OK, DoomEntriesBetween(middle_start, final)); |
| 1385 ASSERT_EQ(1, cache_->GetEntryCount()); | 1487 ASSERT_EQ(1, cache_->GetEntryCount()); |
| 1386 | 1488 |
| 1387 ASSERT_EQ(net::OK, OpenEntry("first", &entry)); | 1489 ASSERT_EQ(net::OK, OpenEntry("first", &entry)); |
| 1388 entry->Close(); | 1490 entry->Close(); |
| 1389 } | 1491 } |
| 1390 | 1492 |
| 1493 TEST_F(DiskCacheBackendTest, MemoryOnlyDoomBetween) { | |
|
rvargas (doing something else)
2013/03/28 00:31:59
nit: don't move this test. (avoid not needed chang
Slava Chigrin
2013/03/28 13:56:19
Done.
| |
| 1494 SetMemoryOnlyMode(); | |
| 1495 BackendDoomBetween(); | |
| 1496 } | |
| 1497 | |
| 1391 TEST_F(DiskCacheBackendTest, DoomBetween) { | 1498 TEST_F(DiskCacheBackendTest, DoomBetween) { |
| 1392 BackendDoomBetween(); | 1499 BackendDoomBetween(); |
| 1393 } | 1500 } |
| 1394 | 1501 |
| 1395 TEST_F(DiskCacheBackendTest, NewEvictionDoomBetween) { | 1502 TEST_F(DiskCacheBackendTest, NewEvictionDoomBetween) { |
| 1396 SetNewEviction(); | 1503 SetNewEviction(); |
| 1397 BackendDoomBetween(); | 1504 BackendDoomBetween(); |
| 1398 } | 1505 } |
| 1399 | 1506 |
| 1400 TEST_F(DiskCacheBackendTest, MemoryOnlyDoomBetween) { | 1507 TEST_F(DiskCacheBackendTest, MemoryOnlyDoomEntriesBetweenSparse) { |
| 1401 SetMemoryOnlyMode(); | 1508 SetMemoryOnlyMode(); |
| 1402 BackendDoomBetween(); | 1509 base::Time start, end; |
| 1510 InitSparseCache(&start, &end); | |
| 1511 DoomEntriesBetween(start, end); | |
| 1512 EXPECT_EQ(3, cache_->GetEntryCount()); | |
| 1513 | |
| 1514 start = end; | |
| 1515 end = base::Time::Now(); | |
|
rvargas (doing something else)
2013/03/28 00:31:59
ah, I see... OK then for the extra delay.
| |
| 1516 DoomEntriesBetween(start, end); | |
| 1517 EXPECT_EQ(1, cache_->GetEntryCount()); | |
| 1518 } | |
| 1519 | |
| 1520 TEST_F(DiskCacheBackendTest, DoomEntriesBetweenSparse) { | |
| 1521 base::Time start, end; | |
| 1522 InitSparseCache(&start, &end); | |
| 1523 DoomEntriesBetween(start, end); | |
| 1524 EXPECT_EQ(9, cache_->GetEntryCount()); | |
| 1525 | |
| 1526 start = end; | |
| 1527 end = base::Time::Now(); | |
| 1528 DoomEntriesBetween(start, end); | |
| 1529 EXPECT_EQ(3, cache_->GetEntryCount()); | |
| 1403 } | 1530 } |
| 1404 | 1531 |
| 1405 void DiskCacheBackendTest::BackendTransaction(const std::string& name, | 1532 void DiskCacheBackendTest::BackendTransaction(const std::string& name, |
| 1406 int num_entries, bool load) { | 1533 int num_entries, bool load) { |
| 1407 success_ = false; | 1534 success_ = false; |
| 1408 ASSERT_TRUE(CopyTestCache(name)); | 1535 ASSERT_TRUE(CopyTestCache(name)); |
| 1409 DisableFirstCleanup(); | 1536 DisableFirstCleanup(); |
| 1410 | 1537 |
| 1411 uint32 mask; | 1538 uint32 mask; |
| 1412 if (load) { | 1539 if (load) { |
| (...skipping 1271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2684 // Ping the oldest entry. | 2811 // Ping the oldest entry. |
| 2685 cache_->OnExternalCacheHit("key0"); | 2812 cache_->OnExternalCacheHit("key0"); |
| 2686 | 2813 |
| 2687 TrimForTest(false); | 2814 TrimForTest(false); |
| 2688 | 2815 |
| 2689 // Make sure the older key remains. | 2816 // Make sure the older key remains. |
| 2690 EXPECT_EQ(1, cache_->GetEntryCount()); | 2817 EXPECT_EQ(1, cache_->GetEntryCount()); |
| 2691 ASSERT_EQ(net::OK, OpenEntry("key0", &entry)); | 2818 ASSERT_EQ(net::OK, OpenEntry("key0", &entry)); |
| 2692 entry->Close(); | 2819 entry->Close(); |
| 2693 } | 2820 } |
| OLD | NEW |