summaryrefslogtreecommitdiffstats
path: root/net/disk_cache/entry_unittest.cc
diff options
context:
space:
mode:
Diffstat (limited to 'net/disk_cache/entry_unittest.cc')
-rw-r--r--net/disk_cache/entry_unittest.cc41
1 files changed, 41 insertions, 0 deletions
diff --git a/net/disk_cache/entry_unittest.cc b/net/disk_cache/entry_unittest.cc
index d2eea79..b61c657 100644
--- a/net/disk_cache/entry_unittest.cc
+++ b/net/disk_cache/entry_unittest.cc
@@ -48,6 +48,7 @@ class DiskCacheEntryTest : public DiskCacheTestBase {
void GetKey();
void GrowData();
void TruncateData();
+ void ReuseEntry();
void InvalidData();
void DoomEntry();
void DoomedEntry();
@@ -571,6 +572,46 @@ TEST_F(DiskCacheEntryTest, MemoryOnlyTruncateData) {
TruncateData();
}
+// Write more than the total cache capacity but to a single entry.
+void DiskCacheEntryTest::ReuseEntry() {
+ std::string key1("the first key");
+ disk_cache::Entry *entry;
+ ASSERT_TRUE(cache_->CreateEntry(key1, &entry));
+
+ entry->Close();
+ std::string key2("the second key");
+ ASSERT_TRUE(cache_->CreateEntry(key2, &entry));
+
+ char buffer[20000];
+ CacheTestFillBuffer(buffer, sizeof(buffer), false);
+
+ for (int i = 0; i < 15; i++) {
+ EXPECT_EQ(0, entry->WriteData(0, 0, buffer, 0, NULL, true));
+ EXPECT_EQ(20000, entry->WriteData(0, 0, buffer, 20000, NULL, false));
+ entry->Close();
+ ASSERT_TRUE(cache_->OpenEntry(key2, &entry));
+ }
+
+ entry->Close();
+ ASSERT_TRUE(cache_->OpenEntry(key1, &entry)) << "have not evicted this entry";
+ entry->Close();
+}
+
+TEST_F(DiskCacheEntryTest, ReuseEntry) {
+ SetDirectMode();
+ SetMaxSize(200 * 1024);
+ InitCache();
+ ReuseEntry();
+}
+
+TEST_F(DiskCacheEntryTest, MemoryOnlyReuseEntry) {
+ SetDirectMode();
+ SetMemoryOnlyMode();
+ SetMaxSize(200 * 1024);
+ InitCache();
+ ReuseEntry();
+}
+
// Reading somewhere that was not written should return zeros.
void DiskCacheEntryTest::InvalidData() {
std::string key1("the first key");