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

Unified Diff: net/disk_cache/backend_unittest.cc

Issue 12224017: Create a new disk_cache type, SHADER_CACHE. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Better fix for OnExternalCacheHit Created 7 years, 10 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 | « net/disk_cache/backend_impl.cc ('k') | net/disk_cache/entry_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/disk_cache/backend_unittest.cc
diff --git a/net/disk_cache/backend_unittest.cc b/net/disk_cache/backend_unittest.cc
index 65cd3837aa842d7693fc1c850c4a8ce353a335dd..db33c8e6ae9d520f4a691e17b0cd90e1cf6e4fad 100644
--- a/net/disk_cache/backend_unittest.cc
+++ b/net/disk_cache/backend_unittest.cc
@@ -138,6 +138,11 @@ TEST_F(DiskCacheBackendTest, AppCacheBasics) {
BackendBasics();
}
+TEST_F(DiskCacheBackendTest, ShaderCacheBasics) {
+ SetCacheType(net::SHADER_CACHE);
+ BackendBasics();
+}
+
void DiskCacheBackendTest::BackendKeying() {
InitCache();
const char* kName1 = "the first key";
@@ -198,6 +203,11 @@ TEST_F(DiskCacheBackendTest, AppCacheKeying) {
BackendKeying();
}
+TEST_F(DiskCacheBackendTest, ShaderCacheKeying) {
+ SetCacheType(net::SHADER_CACHE);
+ BackendKeying();
+}
+
TEST_F(DiskCacheTest, CreateBackend) {
net::TestCompletionCallback cb;
@@ -592,6 +602,14 @@ TEST_F(DiskCacheBackendTest, AppCacheLoad) {
BackendLoad();
}
+TEST_F(DiskCacheBackendTest, ShaderCacheLoad) {
+ SetCacheType(net::SHADER_CACHE);
+ // Work with a tiny index table (16 entries)
+ SetMask(0xf);
+ SetMaxSize(0x100000);
+ BackendLoad();
+}
+
// Tests the chaining of an entry to the current head.
void DiskCacheBackendTest::BackendChain() {
SetMask(0x1); // 2-entry table.
@@ -619,6 +637,11 @@ TEST_F(DiskCacheBackendTest, AppCacheChain) {
BackendChain();
}
+TEST_F(DiskCacheBackendTest, ShaderCacheChain) {
+ SetCacheType(net::SHADER_CACHE);
+ BackendChain();
+}
+
TEST_F(DiskCacheBackendTest, NewEvictionTrim) {
SetNewEviction();
SetDirectMode();
@@ -729,6 +752,12 @@ TEST_F(DiskCacheBackendTest, AppCacheInvalidEntry) {
BackendInvalidEntry();
}
+// We'll be leaking memory from this test.
+TEST_F(DiskCacheBackendTest, ShaderCacheInvalidEntry) {
+ SetCacheType(net::SHADER_CACHE);
+ BackendInvalidEntry();
+}
+
// Almost the same test, but this time crash the cache after reading an entry.
// We'll be leaking memory from this test.
void DiskCacheBackendTest::BackendInvalidEntryRead() {
@@ -780,6 +809,12 @@ TEST_F(DiskCacheBackendTest, AppCacheInvalidEntryRead) {
}
// We'll be leaking memory from this test.
+TEST_F(DiskCacheBackendTest, ShaderCacheInvalidEntryRead) {
+ SetCacheType(net::SHADER_CACHE);
+ BackendInvalidEntryRead();
+}
+
+// We'll be leaking memory from this test.
void DiskCacheBackendTest::BackendInvalidEntryWithLoad() {
// Work with a tiny index table (16 entries)
SetMask(0xf);
@@ -846,6 +881,12 @@ TEST_F(DiskCacheBackendTest, AppCacheInvalidEntryWithLoad) {
}
// We'll be leaking memory from this test.
+TEST_F(DiskCacheBackendTest, ShaderCacheInvalidEntryWithLoad) {
+ SetCacheType(net::SHADER_CACHE);
+ BackendInvalidEntryWithLoad();
+}
+
+// We'll be leaking memory from this test.
void DiskCacheBackendTest::BackendTrimInvalidEntry() {
// Use the implementation directly... we need to simulate a crash.
SetDirectMode();
@@ -1028,6 +1069,11 @@ TEST_F(DiskCacheBackendTest, MemoryOnlyEnumerations) {
BackendEnumerations();
}
+TEST_F(DiskCacheBackendTest, ShaderCacheEnumerations) {
+ SetCacheType(net::SHADER_CACHE);
+ BackendEnumerations();
+}
+
TEST_F(DiskCacheBackendTest, AppCacheEnumerations) {
SetCacheType(net::APP_CACHE);
BackendEnumerations();
@@ -1097,6 +1143,46 @@ TEST_F(DiskCacheBackendTest, AppCacheEnumerations2) {
BackendEnumerations2();
}
+TEST_F(DiskCacheBackendTest, ShaderCacheEnumerations2) {
+ SetCacheType(net::SHADER_CACHE);
+ BackendEnumerations2();
+}
+
+// Verify that ReadData calls do not update the LRU cache
+// when using the SHADER_CACHE type.
+TEST_F(DiskCacheBackendTest, ShaderCacheEnumerationReadData) {
+ SetCacheType(net::SHADER_CACHE);
+ InitCache();
+ const std::string first("first");
+ const std::string second("second");
+ disk_cache::Entry *entry1, *entry2;
+ const int kSize = 50;
+ scoped_refptr<net::IOBuffer> buffer1(new net::IOBuffer(kSize));
+
+ ASSERT_EQ(net::OK, CreateEntry(first, &entry1));
+ memset(buffer1->data(), 0, kSize);
+ base::strlcpy(buffer1->data(), "And the data to save", kSize);
+ EXPECT_EQ(kSize, WriteData(entry1, 0, 0, buffer1, kSize, false));
+
+ ASSERT_EQ(net::OK, CreateEntry(second, &entry2));
+ entry2->Close();
+
+ FlushQueueForTest();
+
+ // Make sure that the timestamp is not the same.
+ AddDelay();
+
+ // Read from the last item in the LRU.
+ EXPECT_EQ(kSize, ReadData(entry1, 0, 0, buffer1, kSize));
+ entry1->Close();
+
+ void* iter = NULL;
+ ASSERT_EQ(net::OK, OpenNextEntry(&iter, &entry2));
+ EXPECT_EQ(entry2->GetKey(), second);
+ entry2->Close();
+ cache_->EndEnumeration(&iter);
+}
+
// Verify handling of invalid entries while doing enumerations.
// We'll be leaking memory from this test.
void DiskCacheBackendTest::BackendInvalidEntryEnumeration() {
@@ -2325,6 +2411,11 @@ TEST_F(DiskCacheBackendTest, AppCacheOnlyDoomAll) {
BackendDoomAll();
}
+TEST_F(DiskCacheBackendTest, ShaderCacheOnlyDoomAll) {
+ SetCacheType(net::SHADER_CACHE);
+ BackendDoomAll();
+}
+
// If the index size changes when we doom the cache, we should not crash.
void DiskCacheBackendTest::BackendDoomAll2() {
EXPECT_EQ(2, cache_->GetEntryCount());
@@ -2576,3 +2667,27 @@ TEST_F(DiskCacheBackendTest, UpdateRankForExternalCacheHit) {
ASSERT_EQ(net::OK, OpenEntry("key0", &entry));
entry->Close();
}
+
+TEST_F(DiskCacheBackendTest, ShaderCacheUpdateRankForExternalCacheHit) {
+ SetCacheType(net::SHADER_CACHE);
+ SetDirectMode();
+ InitCache();
+
+ disk_cache::Entry* entry;
+
+ for (int i = 0; i < 2; ++i) {
+ std::string key = StringPrintf("key%d", i);
+ ASSERT_EQ(net::OK, CreateEntry(key, &entry));
+ entry->Close();
+ }
+
+ // Ping the oldest entry.
+ cache_->OnExternalCacheHit("key0");
+
+ TrimForTest(false);
+
+ // Make sure the older key remains.
+ EXPECT_EQ(1, cache_->GetEntryCount());
+ ASSERT_EQ(net::OK, OpenEntry("key0", &entry));
+ entry->Close();
+}
« no previous file with comments | « net/disk_cache/backend_impl.cc ('k') | net/disk_cache/entry_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698