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

Side by Side 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: 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « net/disk_cache/backend_impl.cc ('k') | net/disk_cache/entry_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 TEST_F(DiskCacheBackendTest, MemoryOnlyBasics) { 131 TEST_F(DiskCacheBackendTest, MemoryOnlyBasics) {
132 SetMemoryOnlyMode(); 132 SetMemoryOnlyMode();
133 BackendBasics(); 133 BackendBasics();
134 } 134 }
135 135
136 TEST_F(DiskCacheBackendTest, AppCacheBasics) { 136 TEST_F(DiskCacheBackendTest, AppCacheBasics) {
137 SetCacheType(net::APP_CACHE); 137 SetCacheType(net::APP_CACHE);
138 BackendBasics(); 138 BackendBasics();
139 } 139 }
140 140
141 TEST_F(DiskCacheBackendTest, ShaderCacheBasics) {
142 SetCacheType(net::SHADER_CACHE);
143 BackendBasics();
144 }
145
141 void DiskCacheBackendTest::BackendKeying() { 146 void DiskCacheBackendTest::BackendKeying() {
142 InitCache(); 147 InitCache();
143 const char* kName1 = "the first key"; 148 const char* kName1 = "the first key";
144 const char* kName2 = "the first Key"; 149 const char* kName2 = "the first Key";
145 disk_cache::Entry *entry1, *entry2; 150 disk_cache::Entry *entry1, *entry2;
146 ASSERT_EQ(net::OK, CreateEntry(kName1, &entry1)); 151 ASSERT_EQ(net::OK, CreateEntry(kName1, &entry1));
147 152
148 ASSERT_EQ(net::OK, CreateEntry(kName2, &entry2)); 153 ASSERT_EQ(net::OK, CreateEntry(kName2, &entry2));
149 EXPECT_TRUE(entry1 != entry2) << "Case sensitive"; 154 EXPECT_TRUE(entry1 != entry2) << "Case sensitive";
150 entry2->Close(); 155 entry2->Close();
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 TEST_F(DiskCacheBackendTest, MemoryOnlyKeying) { 196 TEST_F(DiskCacheBackendTest, MemoryOnlyKeying) {
192 SetMemoryOnlyMode(); 197 SetMemoryOnlyMode();
193 BackendKeying(); 198 BackendKeying();
194 } 199 }
195 200
196 TEST_F(DiskCacheBackendTest, AppCacheKeying) { 201 TEST_F(DiskCacheBackendTest, AppCacheKeying) {
197 SetCacheType(net::APP_CACHE); 202 SetCacheType(net::APP_CACHE);
198 BackendKeying(); 203 BackendKeying();
199 } 204 }
200 205
206 TEST_F(DiskCacheBackendTest, ShaderCacheKeying) {
207 SetCacheType(net::SHADER_CACHE);
208 BackendKeying();
209 }
210
201 TEST_F(DiskCacheTest, CreateBackend) { 211 TEST_F(DiskCacheTest, CreateBackend) {
202 net::TestCompletionCallback cb; 212 net::TestCompletionCallback cb;
203 213
204 { 214 {
205 ASSERT_TRUE(CleanupCacheDir()); 215 ASSERT_TRUE(CleanupCacheDir());
206 base::Thread cache_thread("CacheThread"); 216 base::Thread cache_thread("CacheThread");
207 ASSERT_TRUE(cache_thread.StartWithOptions( 217 ASSERT_TRUE(cache_thread.StartWithOptions(
208 base::Thread::Options(MessageLoop::TYPE_IO, 0))); 218 base::Thread::Options(MessageLoop::TYPE_IO, 0)));
209 219
210 // Test the private factory methods. 220 // Test the private factory methods.
(...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after
584 } 594 }
585 595
586 TEST_F(DiskCacheBackendTest, AppCacheLoad) { 596 TEST_F(DiskCacheBackendTest, AppCacheLoad) {
587 SetCacheType(net::APP_CACHE); 597 SetCacheType(net::APP_CACHE);
588 // Work with a tiny index table (16 entries) 598 // Work with a tiny index table (16 entries)
589 SetMask(0xf); 599 SetMask(0xf);
590 SetMaxSize(0x100000); 600 SetMaxSize(0x100000);
591 BackendLoad(); 601 BackendLoad();
592 } 602 }
593 603
604 TEST_F(DiskCacheBackendTest, ShaderCacheLoad) {
605 SetCacheType(net::SHADER_CACHE);
606 // Work with a tiny index table (16 entries)
607 SetMask(0xf);
608 SetMaxSize(0x100000);
609 BackendLoad();
610 }
611
594 // Tests the chaining of an entry to the current head. 612 // Tests the chaining of an entry to the current head.
595 void DiskCacheBackendTest::BackendChain() { 613 void DiskCacheBackendTest::BackendChain() {
596 SetMask(0x1); // 2-entry table. 614 SetMask(0x1); // 2-entry table.
597 SetMaxSize(0x3000); // 12 kB. 615 SetMaxSize(0x3000); // 12 kB.
598 InitCache(); 616 InitCache();
599 617
600 disk_cache::Entry* entry; 618 disk_cache::Entry* entry;
601 ASSERT_EQ(net::OK, CreateEntry("The first key", &entry)); 619 ASSERT_EQ(net::OK, CreateEntry("The first key", &entry));
602 entry->Close(); 620 entry->Close();
603 ASSERT_EQ(net::OK, CreateEntry("The Second key", &entry)); 621 ASSERT_EQ(net::OK, CreateEntry("The Second key", &entry));
604 entry->Close(); 622 entry->Close();
605 } 623 }
606 624
607 TEST_F(DiskCacheBackendTest, Chain) { 625 TEST_F(DiskCacheBackendTest, Chain) {
608 BackendChain(); 626 BackendChain();
609 } 627 }
610 628
611 TEST_F(DiskCacheBackendTest, NewEvictionChain) { 629 TEST_F(DiskCacheBackendTest, NewEvictionChain) {
612 SetNewEviction(); 630 SetNewEviction();
613 BackendChain(); 631 BackendChain();
614 } 632 }
615 633
616 TEST_F(DiskCacheBackendTest, AppCacheChain) { 634 TEST_F(DiskCacheBackendTest, AppCacheChain) {
617 SetCacheType(net::APP_CACHE); 635 SetCacheType(net::APP_CACHE);
618 BackendChain(); 636 BackendChain();
619 } 637 }
620 638
639 TEST_F(DiskCacheBackendTest, ShaderCacheChain) {
640 SetCacheType(net::SHADER_CACHE);
641 BackendChain();
642 }
643
621 TEST_F(DiskCacheBackendTest, NewEvictionTrim) { 644 TEST_F(DiskCacheBackendTest, NewEvictionTrim) {
622 SetNewEviction(); 645 SetNewEviction();
623 SetDirectMode(); 646 SetDirectMode();
624 InitCache(); 647 InitCache();
625 648
626 disk_cache::Entry* entry; 649 disk_cache::Entry* entry;
627 for (int i = 0; i < 100; i++) { 650 for (int i = 0; i < 100; i++) {
628 std::string name(StringPrintf("Key %d", i)); 651 std::string name(StringPrintf("Key %d", i));
629 ASSERT_EQ(net::OK, CreateEntry(name, &entry)); 652 ASSERT_EQ(net::OK, CreateEntry(name, &entry));
630 entry->Close(); 653 entry->Close();
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
721 SetNewEviction(); 744 SetNewEviction();
722 BackendInvalidEntry(); 745 BackendInvalidEntry();
723 } 746 }
724 747
725 // We'll be leaking memory from this test. 748 // We'll be leaking memory from this test.
726 TEST_F(DiskCacheBackendTest, AppCacheInvalidEntry) { 749 TEST_F(DiskCacheBackendTest, AppCacheInvalidEntry) {
727 SetCacheType(net::APP_CACHE); 750 SetCacheType(net::APP_CACHE);
728 BackendInvalidEntry(); 751 BackendInvalidEntry();
729 } 752 }
730 753
754 // We'll be leaking memory from this test.
755 TEST_F(DiskCacheBackendTest, ShaderCacheInvalidEntry) {
756 SetCacheType(net::SHADER_CACHE);
757 BackendInvalidEntry();
758 }
759
731 // Almost the same test, but this time crash the cache after reading an entry. 760 // Almost the same test, but this time crash the cache after reading an entry.
732 // We'll be leaking memory from this test. 761 // We'll be leaking memory from this test.
733 void DiskCacheBackendTest::BackendInvalidEntryRead() { 762 void DiskCacheBackendTest::BackendInvalidEntryRead() {
734 // Use the implementation directly... we need to simulate a crash. 763 // Use the implementation directly... we need to simulate a crash.
735 SetDirectMode(); 764 SetDirectMode();
736 InitCache(); 765 InitCache();
737 766
738 std::string key("Some key"); 767 std::string key("Some key");
739 disk_cache::Entry* entry; 768 disk_cache::Entry* entry;
740 ASSERT_EQ(net::OK, CreateEntry(key, &entry)); 769 ASSERT_EQ(net::OK, CreateEntry(key, &entry));
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
772 BackendInvalidEntryRead(); 801 BackendInvalidEntryRead();
773 } 802 }
774 803
775 // We'll be leaking memory from this test. 804 // We'll be leaking memory from this test.
776 TEST_F(DiskCacheBackendTest, AppCacheInvalidEntryRead) { 805 TEST_F(DiskCacheBackendTest, AppCacheInvalidEntryRead) {
777 SetCacheType(net::APP_CACHE); 806 SetCacheType(net::APP_CACHE);
778 BackendInvalidEntryRead(); 807 BackendInvalidEntryRead();
779 } 808 }
780 809
781 // We'll be leaking memory from this test. 810 // We'll be leaking memory from this test.
811 TEST_F(DiskCacheBackendTest, ShaderCacheInvalidEntryRead) {
812 SetCacheType(net::SHADER_CACHE);
813 BackendInvalidEntryRead();
814 }
815
816 // We'll be leaking memory from this test.
782 void DiskCacheBackendTest::BackendInvalidEntryWithLoad() { 817 void DiskCacheBackendTest::BackendInvalidEntryWithLoad() {
783 // Work with a tiny index table (16 entries) 818 // Work with a tiny index table (16 entries)
784 SetMask(0xf); 819 SetMask(0xf);
785 SetMaxSize(0x100000); 820 SetMaxSize(0x100000);
786 InitCache(); 821 InitCache();
787 822
788 int seed = static_cast<int>(Time::Now().ToInternalValue()); 823 int seed = static_cast<int>(Time::Now().ToInternalValue());
789 srand(seed); 824 srand(seed);
790 825
791 const int kNumEntries = 100; 826 const int kNumEntries = 100;
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
838 BackendInvalidEntryWithLoad(); 873 BackendInvalidEntryWithLoad();
839 } 874 }
840 875
841 // We'll be leaking memory from this test. 876 // We'll be leaking memory from this test.
842 TEST_F(DiskCacheBackendTest, AppCacheInvalidEntryWithLoad) { 877 TEST_F(DiskCacheBackendTest, AppCacheInvalidEntryWithLoad) {
843 SetCacheType(net::APP_CACHE); 878 SetCacheType(net::APP_CACHE);
844 BackendInvalidEntryWithLoad(); 879 BackendInvalidEntryWithLoad();
845 } 880 }
846 881
847 // We'll be leaking memory from this test. 882 // We'll be leaking memory from this test.
883 TEST_F(DiskCacheBackendTest, ShaderCacheInvalidEntryWithLoad) {
884 SetCacheType(net::SHADER_CACHE);
885 BackendInvalidEntryWithLoad();
886 }
887
888 // We'll be leaking memory from this test.
848 void DiskCacheBackendTest::BackendTrimInvalidEntry() { 889 void DiskCacheBackendTest::BackendTrimInvalidEntry() {
849 // Use the implementation directly... we need to simulate a crash. 890 // Use the implementation directly... we need to simulate a crash.
850 SetDirectMode(); 891 SetDirectMode();
851 892
852 const int kSize = 0x3000; // 12 kB 893 const int kSize = 0x3000; // 12 kB
853 SetMaxSize(kSize * 10); 894 SetMaxSize(kSize * 10);
854 InitCache(); 895 InitCache();
855 896
856 std::string first("some key"); 897 std::string first("some key");
857 std::string second("something else"); 898 std::string second("something else");
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
1020 TEST_F(DiskCacheBackendTest, NewEvictionEnumerations) { 1061 TEST_F(DiskCacheBackendTest, NewEvictionEnumerations) {
1021 SetNewEviction(); 1062 SetNewEviction();
1022 BackendEnumerations(); 1063 BackendEnumerations();
1023 } 1064 }
1024 1065
1025 TEST_F(DiskCacheBackendTest, MemoryOnlyEnumerations) { 1066 TEST_F(DiskCacheBackendTest, MemoryOnlyEnumerations) {
1026 SetMemoryOnlyMode(); 1067 SetMemoryOnlyMode();
1027 BackendEnumerations(); 1068 BackendEnumerations();
1028 } 1069 }
1029 1070
1071 TEST_F(DiskCacheBackendTest, ShaderCacheEnumerations) {
1072 SetCacheType(net::SHADER_CACHE);
1073 BackendEnumerations();
1074 }
1075
1030 TEST_F(DiskCacheBackendTest, AppCacheEnumerations) { 1076 TEST_F(DiskCacheBackendTest, AppCacheEnumerations) {
1031 SetCacheType(net::APP_CACHE); 1077 SetCacheType(net::APP_CACHE);
1032 BackendEnumerations(); 1078 BackendEnumerations();
1033 } 1079 }
1034 1080
1035 // Verifies enumerations while entries are open. 1081 // Verifies enumerations while entries are open.
1036 void DiskCacheBackendTest::BackendEnumerations2() { 1082 void DiskCacheBackendTest::BackendEnumerations2() {
1037 InitCache(); 1083 InitCache();
1038 const std::string first("first"); 1084 const std::string first("first");
1039 const std::string second("second"); 1085 const std::string second("second");
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
1089 TEST_F(DiskCacheBackendTest, MemoryOnlyEnumerations2) { 1135 TEST_F(DiskCacheBackendTest, MemoryOnlyEnumerations2) {
1090 SetMemoryOnlyMode(); 1136 SetMemoryOnlyMode();
1091 BackendEnumerations2(); 1137 BackendEnumerations2();
1092 } 1138 }
1093 1139
1094 TEST_F(DiskCacheBackendTest, AppCacheEnumerations2) { 1140 TEST_F(DiskCacheBackendTest, AppCacheEnumerations2) {
1095 SetCacheType(net::APP_CACHE); 1141 SetCacheType(net::APP_CACHE);
1096 BackendEnumerations2(); 1142 BackendEnumerations2();
1097 } 1143 }
1098 1144
1145 TEST_F(DiskCacheBackendTest, ShaderCacheEnumerations2) {
1146 SetCacheType(net::SHADER_CACHE);
1147 BackendEnumerations2();
1148 }
1149
1150 // Verify that ReadData calls do not update the LRU cache
1151 // when using the SHADER_CACHE type.
1152 TEST_F(DiskCacheBackendTest, ShaderCacheEnumerationReadData) {
1153 SetCacheType(net::SHADER_CACHE);
1154 InitCache();
1155 const std::string first("first");
1156 const std::string second("second");
1157 disk_cache::Entry *entry1, *entry2;
1158 const int kSize = 50;
1159 scoped_refptr<net::IOBuffer> buffer1(new net::IOBuffer(kSize));
1160
1161 ASSERT_EQ(net::OK, CreateEntry(first, &entry1));
1162 memset(buffer1->data(), 0, kSize);
1163 base::strlcpy(buffer1->data(), "And the data to save", kSize);
1164 EXPECT_EQ(kSize, WriteData(entry1, 0, 0, buffer1, kSize, false));
1165
1166 ASSERT_EQ(net::OK, CreateEntry(second, &entry2));
1167 entry2->Close();
1168
1169 FlushQueueForTest();
1170
1171 // Make sure that the timestamp is not the same.
1172 AddDelay();
1173
1174 // Make entry2 the first item in the cache.
1175 ASSERT_EQ(net::OK, OpenEntry(second, &entry2));
rvargas (doing something else) 2013/02/11 23:12:47 entry2 was already the first entry on the list...
dsinclair 2013/02/12 16:05:50 Doh, I was thinking the Open would kick in and upd
1176 entry2->Close();
1177
1178 // Read from the last item in the LRU.
1179 EXPECT_EQ(kSize, ReadData(entry1, 0, 0, buffer1, kSize));
1180 entry1->Close();
1181
1182 void* iter = NULL;
1183 ASSERT_EQ(net::OK, OpenNextEntry(&iter, &entry2));
1184 EXPECT_EQ(entry2->GetKey(), second);
1185 entry2->Close();
1186 cache_->EndEnumeration(&iter);
1187 }
1188
1099 // Verify handling of invalid entries while doing enumerations. 1189 // Verify handling of invalid entries while doing enumerations.
1100 // We'll be leaking memory from this test. 1190 // We'll be leaking memory from this test.
1101 void DiskCacheBackendTest::BackendInvalidEntryEnumeration() { 1191 void DiskCacheBackendTest::BackendInvalidEntryEnumeration() {
1102 // Use the implementation directly... we need to simulate a crash. 1192 // Use the implementation directly... we need to simulate a crash.
1103 SetDirectMode(); 1193 SetDirectMode();
1104 InitCache(); 1194 InitCache();
1105 1195
1106 std::string key("Some key"); 1196 std::string key("Some key");
1107 disk_cache::Entry *entry, *entry1, *entry2; 1197 disk_cache::Entry *entry, *entry1, *entry2;
1108 ASSERT_EQ(net::OK, CreateEntry(key, &entry1)); 1198 ASSERT_EQ(net::OK, CreateEntry(key, &entry1));
(...skipping 1208 matching lines...) Expand 10 before | Expand all | Expand 10 after
2317 TEST_F(DiskCacheBackendTest, MemoryOnlyDoomAll) { 2407 TEST_F(DiskCacheBackendTest, MemoryOnlyDoomAll) {
2318 SetMemoryOnlyMode(); 2408 SetMemoryOnlyMode();
2319 BackendDoomAll(); 2409 BackendDoomAll();
2320 } 2410 }
2321 2411
2322 TEST_F(DiskCacheBackendTest, AppCacheOnlyDoomAll) { 2412 TEST_F(DiskCacheBackendTest, AppCacheOnlyDoomAll) {
2323 SetCacheType(net::APP_CACHE); 2413 SetCacheType(net::APP_CACHE);
2324 BackendDoomAll(); 2414 BackendDoomAll();
2325 } 2415 }
2326 2416
2417 TEST_F(DiskCacheBackendTest, ShaderCacheOnlyDoomAll) {
2418 SetCacheType(net::SHADER_CACHE);
2419 BackendDoomAll();
2420 }
2421
2327 // If the index size changes when we doom the cache, we should not crash. 2422 // If the index size changes when we doom the cache, we should not crash.
2328 void DiskCacheBackendTest::BackendDoomAll2() { 2423 void DiskCacheBackendTest::BackendDoomAll2() {
2329 EXPECT_EQ(2, cache_->GetEntryCount()); 2424 EXPECT_EQ(2, cache_->GetEntryCount());
2330 EXPECT_EQ(net::OK, DoomAllEntries()); 2425 EXPECT_EQ(net::OK, DoomAllEntries());
2331 2426
2332 disk_cache::Entry* entry; 2427 disk_cache::Entry* entry;
2333 ASSERT_EQ(net::OK, CreateEntry("Something new", &entry)); 2428 ASSERT_EQ(net::OK, CreateEntry("Something new", &entry));
2334 entry->Close(); 2429 entry->Close();
2335 2430
2336 EXPECT_EQ(1, cache_->GetEntryCount()); 2431 EXPECT_EQ(1, cache_->GetEntryCount());
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
2568 // Ping the oldest entry. 2663 // Ping the oldest entry.
2569 cache_->OnExternalCacheHit("key0"); 2664 cache_->OnExternalCacheHit("key0");
2570 2665
2571 TrimForTest(false); 2666 TrimForTest(false);
2572 2667
2573 // Make sure the older key remains. 2668 // Make sure the older key remains.
2574 EXPECT_EQ(1, cache_->GetEntryCount()); 2669 EXPECT_EQ(1, cache_->GetEntryCount());
2575 ASSERT_EQ(net::OK, OpenEntry("key0", &entry)); 2670 ASSERT_EQ(net::OK, OpenEntry("key0", &entry));
2576 entry->Close(); 2671 entry->Close();
2577 } 2672 }
OLDNEW
« 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