| 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();
|
| +}
|
|
|