diff options
Diffstat (limited to 'net/disk_cache/backend_unittest.cc')
-rw-r--r-- | net/disk_cache/backend_unittest.cc | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/net/disk_cache/backend_unittest.cc b/net/disk_cache/backend_unittest.cc index dd33d28..2fbcfa9 100644 --- a/net/disk_cache/backend_unittest.cc +++ b/net/disk_cache/backend_unittest.cc @@ -59,10 +59,12 @@ class DiskCacheBackendTest : public DiskCacheTestWithCache { void BackendInvalidEntry2(); void BackendNotMarkedButDirty(); void BackendDoomAll(); + void BackendDoomAll2(); void BackendInvalidRankings(); void BackendInvalidRankings2(); void BackendDisable(); void BackendDisable2(); + void BackendDisable3(); }; void DiskCacheBackendTest::BackendBasics() { @@ -1169,6 +1171,38 @@ TEST_F(DiskCacheBackendTest, NewEvictionDisableFailure2) { BackendDisable2(); } +// If the index size changes when we disable the cache, we should not crash. +void DiskCacheBackendTest::BackendDisable3() { + disk_cache::Entry *entry1, *entry2; + void* iter = NULL; + EXPECT_EQ(2, cache_->GetEntryCount()); + ASSERT_TRUE(cache_->OpenNextEntry(&iter, &entry1)); + entry1->Close(); + + EXPECT_FALSE(cache_->OpenNextEntry(&iter, &entry2)); + ASSERT_TRUE(cache_->CreateEntry("Something new", &entry2)); + entry2->Close(); + + EXPECT_EQ(1, cache_->GetEntryCount()); +} + +TEST_F(DiskCacheBackendTest, DisableSuccess3) { + ASSERT_TRUE(CopyTestCache(L"bad_rankings2")); + DisableFirstCleanup(); + SetMaxSize(20 * 1024 * 1024); + InitCache(); + BackendDisable3(); +} + +TEST_F(DiskCacheBackendTest, NewEvictionDisableSuccess3) { + ASSERT_TRUE(CopyTestCache(L"bad_rankings2")); + DisableFirstCleanup(); + SetMaxSize(20 * 1024 * 1024); + SetNewEviction(); + InitCache(); + BackendDisable3(); +} + TEST_F(DiskCacheTest, Backend_UsageStats) { MessageLoopHelper helper; @@ -1240,6 +1274,35 @@ TEST_F(DiskCacheBackendTest, MemoryOnlyDoomAll) { BackendDoomAll(); } +// If the index size changes when we doom the cache, we should not crash. +void DiskCacheBackendTest::BackendDoomAll2() { + EXPECT_EQ(2, cache_->GetEntryCount()); + EXPECT_TRUE(cache_->DoomAllEntries()); + + disk_cache::Entry* entry; + ASSERT_TRUE(cache_->CreateEntry("Something new", &entry)); + entry->Close(); + + EXPECT_EQ(1, cache_->GetEntryCount()); +} + +TEST_F(DiskCacheBackendTest, DoomAll2) { + ASSERT_TRUE(CopyTestCache(L"bad_rankings2")); + DisableFirstCleanup(); + SetMaxSize(20 * 1024 * 1024); + InitCache(); + BackendDoomAll2(); +} + +TEST_F(DiskCacheBackendTest, NewEvictionDoomAll2) { + ASSERT_TRUE(CopyTestCache(L"bad_rankings2")); + DisableFirstCleanup(); + SetMaxSize(20 * 1024 * 1024); + SetNewEviction(); + InitCache(); + BackendDoomAll2(); +} + // We should be able to create the same entry on multiple simultaneous instances // of the cache. TEST_F(DiskCacheTest, MultipleInstances) { |