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

Unified Diff: net/disk_cache/backend_unittest.cc

Issue 165030: Disk Cache: Don't depend on the backend being enabled to... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 11 years, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | net/disk_cache/entry_impl.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/disk_cache/backend_unittest.cc
===================================================================
--- net/disk_cache/backend_unittest.cc (revision 22579)
+++ net/disk_cache/backend_unittest.cc (working copy)
@@ -67,6 +67,7 @@
void BackendDisable();
void BackendDisable2();
void BackendDisable3();
+ void BackendDisable4();
};
void DiskCacheBackendTest::BackendBasics() {
@@ -1324,6 +1325,71 @@
BackendDisable3();
}
+// If we disable the cache, already open entries should work as far as possible.
+void DiskCacheBackendTest::BackendDisable4() {
+ disk_cache::Entry *entry1, *entry2, *entry3, *entry4;
+ void* iter = NULL;
+ ASSERT_TRUE(cache_->OpenNextEntry(&iter, &entry1));
+
+ char key2[2000];
+ char key3[20000];
+ CacheTestFillBuffer(key2, sizeof(key2), true);
+ CacheTestFillBuffer(key3, sizeof(key3), true);
+ key2[sizeof(key2) - 1] = '\0';
+ key3[sizeof(key3) - 1] = '\0';
+ ASSERT_TRUE(cache_->CreateEntry(key2, &entry2));
+ ASSERT_TRUE(cache_->CreateEntry(key3, &entry3));
+
+ const int kBufSize = 20000;
+ scoped_refptr<net::IOBuffer> buf = new net::IOBuffer(kBufSize);
+ memset(buf->data(), 0, kBufSize);
+ EXPECT_EQ(100, entry2->WriteData(0, 0, buf, 100, NULL, false));
+ EXPECT_EQ(kBufSize, entry3->WriteData(0, 0, buf, kBufSize, NULL, false));
+
+ // This line should disable the cache but not delete it.
+ EXPECT_FALSE(cache_->OpenNextEntry(&iter, &entry4));
+ EXPECT_EQ(4, cache_->GetEntryCount());
+
+ EXPECT_FALSE(cache_->CreateEntry("cache is disabled", &entry4));
+
+ EXPECT_EQ(100, entry2->ReadData(0, 0, buf, 100, NULL));
+ EXPECT_EQ(100, entry2->WriteData(0, 0, buf, 100, NULL, false));
+ EXPECT_EQ(100, entry2->WriteData(1, 0, buf, 100, NULL, false));
+
+ EXPECT_EQ(kBufSize, entry3->ReadData(0, 0, buf, kBufSize, NULL));
+ EXPECT_EQ(kBufSize, entry3->WriteData(0, 0, buf, kBufSize, NULL, false));
+ EXPECT_EQ(kBufSize, entry3->WriteData(1, 0, buf, kBufSize, NULL, false));
+
+ std::string key = entry2->GetKey();
+ EXPECT_EQ(sizeof(key2) - 1, key.size());
+ key = entry3->GetKey();
+ EXPECT_EQ(sizeof(key3) - 1, key.size());
+
+ entry1->Close();
+ entry2->Close();
+ entry3->Close();
+ MessageLoop::current()->RunAllPending();
+
+ EXPECT_EQ(0, cache_->GetEntryCount());
+}
+
+TEST_F(DiskCacheBackendTest, DisableSuccess4) {
+ ASSERT_TRUE(CopyTestCache(L"bad_rankings"));
+ DisableFirstCleanup();
+ SetDirectMode();
+ InitCache();
+ BackendDisable4();
+}
+
+TEST_F(DiskCacheBackendTest, NewEvictionDisableSuccess4) {
+ ASSERT_TRUE(CopyTestCache(L"bad_rankings"));
+ DisableFirstCleanup();
+ SetDirectMode();
+ SetNewEviction();
+ InitCache();
+ BackendDisable4();
+}
+
TEST_F(DiskCacheTest, Backend_UsageStats) {
MessageLoopHelper helper;
« no previous file with comments | « no previous file | net/disk_cache/entry_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698