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 3 sparse entries. |doomed_start| and |doomed_end| if not NULL, | |
| 55 // will be filled with times, used by DoomEntriesSince and DoomEntriesBetween | |
| 56 // to doom last two entries. | |
| 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 InitCache(); | |
| 1357 | |
| 1358 const int kSize = 50; | |
| 1359 // This must be greater then MemEntryImpl::kMaxSparseEntrySize. | |
| 1360 const int kOffset = 10 + 1024 * 1024; | |
| 1361 | |
| 1362 disk_cache::Entry* entry0 = NULL; | |
| 1363 disk_cache::Entry* entry1 = NULL; | |
| 1364 disk_cache::Entry* entry2 = NULL; | |
| 1365 | |
| 1366 scoped_refptr<net::IOBuffer> buffer(new net::IOBuffer(kSize)); | |
| 1367 CacheTestFillBuffer(buffer->data(), kSize, false); | |
| 1368 | |
| 1369 // entry0 is the only entry whish left after | |
| 1370 // DoomEntriesSince and DoomEntriesBetween. | |
| 1371 ASSERT_EQ(net::OK, CreateEntry("zeroth", &entry0)); | |
| 1372 ASSERT_EQ(kSize, WriteSparseData(entry0, 0, buffer.get(), kSize)); | |
| 1373 ASSERT_EQ(kSize, | |
| 1374 WriteSparseData(entry0, kOffset + kSize, buffer.get(), kSize)); | |
| 1375 entry0->Close(); | |
| 1376 | |
| 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 // Order in rankings list: | |
| 1396 // third_part1, fourth_part1, third_part2, fourth_part2 | |
|
rvargas (doing something else)
2013/03/21 22:01:57
The second time stamp should be somewhere in the m
Slava Chigrin
2013/03/22 13:45:02
Done.
| |
| 1397 disk_cache::Entry* entry3 = NULL; | |
| 1398 disk_cache::Entry* entry4 = NULL; | |
| 1399 ASSERT_EQ(net::OK, CreateEntry("third", &entry3)); | |
| 1400 ASSERT_EQ(kSize, WriteSparseData(entry3, 0, buffer.get(), kSize)); | |
| 1401 ASSERT_EQ(net::OK, CreateEntry("fourth", &entry4)); | |
| 1402 ASSERT_EQ(kSize, WriteSparseData(entry4, 0, buffer.get(), kSize)); | |
| 1403 ASSERT_EQ(kSize, | |
| 1404 WriteSparseData(entry3, kOffset + kSize, buffer.get(), kSize)); | |
| 1405 ASSERT_EQ(kSize, | |
| 1406 WriteSparseData(entry4, kOffset + kSize, buffer.get(), kSize)); | |
| 1407 entry3->Close(); | |
| 1408 entry4->Close(); | |
| 1409 | |
| 1410 AddDelay(); | |
| 1411 if (doomed_end) | |
| 1412 *doomed_end = base::Time::Now(); | |
| 1413 } | |
| 1414 | |
| 1415 TEST_F(DiskCacheBackendTest, MemoryOnlyDoomEntriesSinceSparse) { | |
|
rvargas (doing something else)
2013/03/21 22:01:57
It would be nice to also add tests for the regular
Slava Chigrin
2013/03/22 13:45:02
I have added tests for BackendImpl here. I noticed
rvargas (doing something else)
2013/03/23 02:08:31
yes... the disk backend allows enumeration (and in
| |
| 1416 SetMemoryOnlyMode(); | |
| 1417 base::Time start; | |
| 1418 InitSparseCache(&start, NULL); | |
| 1419 DoomEntriesSince(start); | |
| 1420 EXPECT_EQ(1, cache_->GetEntryCount()); | |
| 1421 } | |
| 1422 | |
| 1423 TEST_F(DiskCacheBackendTest, MemoryOnlyDoomAllSparse) { | |
| 1424 SetMemoryOnlyMode(); | |
| 1425 InitSparseCache(NULL, NULL); | |
| 1426 EXPECT_EQ(net::OK, DoomAllEntries()); | |
| 1427 EXPECT_EQ(0, cache_->GetEntryCount()); | |
| 1428 } | |
| 1429 | |
| 1348 void DiskCacheBackendTest::BackendDoomBetween() { | 1430 void DiskCacheBackendTest::BackendDoomBetween() { |
| 1349 InitCache(); | 1431 InitCache(); |
| 1350 | 1432 |
| 1351 disk_cache::Entry *entry; | 1433 disk_cache::Entry *entry; |
| 1352 ASSERT_EQ(net::OK, CreateEntry("first", &entry)); | 1434 ASSERT_EQ(net::OK, CreateEntry("first", &entry)); |
| 1353 entry->Close(); | 1435 entry->Close(); |
| 1354 FlushQueueForTest(); | 1436 FlushQueueForTest(); |
| 1355 | 1437 |
| 1356 AddDelay(); | 1438 AddDelay(); |
| 1357 Time middle_start = Time::Now(); | 1439 Time middle_start = Time::Now(); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1395 TEST_F(DiskCacheBackendTest, NewEvictionDoomBetween) { | 1477 TEST_F(DiskCacheBackendTest, NewEvictionDoomBetween) { |
| 1396 SetNewEviction(); | 1478 SetNewEviction(); |
| 1397 BackendDoomBetween(); | 1479 BackendDoomBetween(); |
| 1398 } | 1480 } |
| 1399 | 1481 |
| 1400 TEST_F(DiskCacheBackendTest, MemoryOnlyDoomBetween) { | 1482 TEST_F(DiskCacheBackendTest, MemoryOnlyDoomBetween) { |
| 1401 SetMemoryOnlyMode(); | 1483 SetMemoryOnlyMode(); |
| 1402 BackendDoomBetween(); | 1484 BackendDoomBetween(); |
| 1403 } | 1485 } |
| 1404 | 1486 |
| 1487 TEST_F(DiskCacheBackendTest, MemoryOnlyDoomEntriesBetweenSparse) { | |
| 1488 SetMemoryOnlyMode(); | |
| 1489 base::Time start, end; | |
| 1490 InitSparseCache(&start, &end); | |
| 1491 DoomEntriesBetween(start, end); | |
| 1492 EXPECT_EQ(1, cache_->GetEntryCount()); | |
| 1493 } | |
| 1494 | |
| 1405 void DiskCacheBackendTest::BackendTransaction(const std::string& name, | 1495 void DiskCacheBackendTest::BackendTransaction(const std::string& name, |
| 1406 int num_entries, bool load) { | 1496 int num_entries, bool load) { |
| 1407 success_ = false; | 1497 success_ = false; |
| 1408 ASSERT_TRUE(CopyTestCache(name)); | 1498 ASSERT_TRUE(CopyTestCache(name)); |
| 1409 DisableFirstCleanup(); | 1499 DisableFirstCleanup(); |
| 1410 | 1500 |
| 1411 uint32 mask; | 1501 uint32 mask; |
| 1412 if (load) { | 1502 if (load) { |
| 1413 mask = 0xf; | 1503 mask = 0xf; |
| 1414 SetMaxSize(0x100000); | 1504 SetMaxSize(0x100000); |
| (...skipping 1269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2684 // Ping the oldest entry. | 2774 // Ping the oldest entry. |
| 2685 cache_->OnExternalCacheHit("key0"); | 2775 cache_->OnExternalCacheHit("key0"); |
| 2686 | 2776 |
| 2687 TrimForTest(false); | 2777 TrimForTest(false); |
| 2688 | 2778 |
| 2689 // Make sure the older key remains. | 2779 // Make sure the older key remains. |
| 2690 EXPECT_EQ(1, cache_->GetEntryCount()); | 2780 EXPECT_EQ(1, cache_->GetEntryCount()); |
| 2691 ASSERT_EQ(net::OK, OpenEntry("key0", &entry)); | 2781 ASSERT_EQ(net::OK, OpenEntry("key0", &entry)); |
| 2692 entry->Close(); | 2782 entry->Close(); |
| 2693 } | 2783 } |
| OLD | NEW |