| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/basictypes.h" | 5 #include "base/basictypes.h" |
| 6 #include "base/file_util.h" | 6 #include "base/file_util.h" |
| 7 #include "base/string_util.h" | 7 #include "base/string_util.h" |
| 8 #include "base/stringprintf.h" | 8 #include "base/stringprintf.h" |
| 9 #include "base/third_party/dynamic_annotations/dynamic_annotations.h" | 9 #include "base/third_party/dynamic_annotations/dynamic_annotations.h" |
| 10 #include "base/threading/platform_thread.h" | 10 #include "base/threading/platform_thread.h" |
| (...skipping 631 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 642 BackendChain(); | 642 BackendChain(); |
| 643 } | 643 } |
| 644 | 644 |
| 645 TEST_F(DiskCacheBackendTest, NewEvictionTrim) { | 645 TEST_F(DiskCacheBackendTest, NewEvictionTrim) { |
| 646 SetNewEviction(); | 646 SetNewEviction(); |
| 647 SetDirectMode(); | 647 SetDirectMode(); |
| 648 InitCache(); | 648 InitCache(); |
| 649 | 649 |
| 650 disk_cache::Entry* entry; | 650 disk_cache::Entry* entry; |
| 651 for (int i = 0; i < 100; i++) { | 651 for (int i = 0; i < 100; i++) { |
| 652 std::string name(StringPrintf("Key %d", i)); | 652 std::string name(base::StringPrintf("Key %d", i)); |
| 653 ASSERT_EQ(net::OK, CreateEntry(name, &entry)); | 653 ASSERT_EQ(net::OK, CreateEntry(name, &entry)); |
| 654 entry->Close(); | 654 entry->Close(); |
| 655 if (i < 90) { | 655 if (i < 90) { |
| 656 // Entries 0 to 89 are in list 1; 90 to 99 are in list 0. | 656 // Entries 0 to 89 are in list 1; 90 to 99 are in list 0. |
| 657 ASSERT_EQ(net::OK, OpenEntry(name, &entry)); | 657 ASSERT_EQ(net::OK, OpenEntry(name, &entry)); |
| 658 entry->Close(); | 658 entry->Close(); |
| 659 } | 659 } |
| 660 } | 660 } |
| 661 | 661 |
| 662 // The first eviction must come from list 1 (10% limit), the second must come | 662 // The first eviction must come from list 1 (10% limit), the second must come |
| (...skipping 1982 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2645 EXPECT_TRUE(disk_cache::DeleteCacheFile(name)); | 2645 EXPECT_TRUE(disk_cache::DeleteCacheFile(name)); |
| 2646 } | 2646 } |
| 2647 | 2647 |
| 2648 TEST_F(DiskCacheBackendTest, UpdateRankForExternalCacheHit) { | 2648 TEST_F(DiskCacheBackendTest, UpdateRankForExternalCacheHit) { |
| 2649 SetDirectMode(); | 2649 SetDirectMode(); |
| 2650 InitCache(); | 2650 InitCache(); |
| 2651 | 2651 |
| 2652 disk_cache::Entry* entry; | 2652 disk_cache::Entry* entry; |
| 2653 | 2653 |
| 2654 for (int i = 0; i < 2; ++i) { | 2654 for (int i = 0; i < 2; ++i) { |
| 2655 std::string key = StringPrintf("key%d", i); | 2655 std::string key = base::StringPrintf("key%d", i); |
| 2656 ASSERT_EQ(net::OK, CreateEntry(key, &entry)); | 2656 ASSERT_EQ(net::OK, CreateEntry(key, &entry)); |
| 2657 entry->Close(); | 2657 entry->Close(); |
| 2658 } | 2658 } |
| 2659 | 2659 |
| 2660 // Ping the oldest entry. | 2660 // Ping the oldest entry. |
| 2661 cache_->OnExternalCacheHit("key0"); | 2661 cache_->OnExternalCacheHit("key0"); |
| 2662 | 2662 |
| 2663 TrimForTest(false); | 2663 TrimForTest(false); |
| 2664 | 2664 |
| 2665 // Make sure the older key remains. | 2665 // Make sure the older key remains. |
| 2666 EXPECT_EQ(1, cache_->GetEntryCount()); | 2666 EXPECT_EQ(1, cache_->GetEntryCount()); |
| 2667 ASSERT_EQ(net::OK, OpenEntry("key0", &entry)); | 2667 ASSERT_EQ(net::OK, OpenEntry("key0", &entry)); |
| 2668 entry->Close(); | 2668 entry->Close(); |
| 2669 } | 2669 } |
| 2670 | 2670 |
| 2671 TEST_F(DiskCacheBackendTest, ShaderCacheUpdateRankForExternalCacheHit) { | 2671 TEST_F(DiskCacheBackendTest, ShaderCacheUpdateRankForExternalCacheHit) { |
| 2672 SetCacheType(net::SHADER_CACHE); | 2672 SetCacheType(net::SHADER_CACHE); |
| 2673 SetDirectMode(); | 2673 SetDirectMode(); |
| 2674 InitCache(); | 2674 InitCache(); |
| 2675 | 2675 |
| 2676 disk_cache::Entry* entry; | 2676 disk_cache::Entry* entry; |
| 2677 | 2677 |
| 2678 for (int i = 0; i < 2; ++i) { | 2678 for (int i = 0; i < 2; ++i) { |
| 2679 std::string key = StringPrintf("key%d", i); | 2679 std::string key = base::StringPrintf("key%d", i); |
| 2680 ASSERT_EQ(net::OK, CreateEntry(key, &entry)); | 2680 ASSERT_EQ(net::OK, CreateEntry(key, &entry)); |
| 2681 entry->Close(); | 2681 entry->Close(); |
| 2682 } | 2682 } |
| 2683 | 2683 |
| 2684 // Ping the oldest entry. | 2684 // Ping the oldest entry. |
| 2685 cache_->OnExternalCacheHit("key0"); | 2685 cache_->OnExternalCacheHit("key0"); |
| 2686 | 2686 |
| 2687 TrimForTest(false); | 2687 TrimForTest(false); |
| 2688 | 2688 |
| 2689 // Make sure the older key remains. | 2689 // Make sure the older key remains. |
| 2690 EXPECT_EQ(1, cache_->GetEntryCount()); | 2690 EXPECT_EQ(1, cache_->GetEntryCount()); |
| 2691 ASSERT_EQ(net::OK, OpenEntry("key0", &entry)); | 2691 ASSERT_EQ(net::OK, OpenEntry("key0", &entry)); |
| 2692 entry->Close(); | 2692 entry->Close(); |
| 2693 } | 2693 } |
| OLD | NEW |