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

Side by Side Diff: net/disk_cache/backend_unittest.cc

Issue 15203004: Disk cache: Reference CL for the implementation of file format version 3. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 7 years, 6 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/block_files.h » ('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/port.h" 7 #include "base/port.h"
8 #include "base/string_util.h" 8 #include "base/string_util.h"
9 #include "base/stringprintf.h" 9 #include "base/stringprintf.h"
10 #include "base/third_party/dynamic_annotations/dynamic_annotations.h" 10 #include "base/third_party/dynamic_annotations/dynamic_annotations.h"
(...skipping 27 matching lines...) Expand all
38 class DiskCacheBackendTest : public DiskCacheTestWithCache { 38 class DiskCacheBackendTest : public DiskCacheTestWithCache {
39 protected: 39 protected:
40 void BackendBasics(); 40 void BackendBasics();
41 void BackendKeying(); 41 void BackendKeying();
42 void BackendShutdownWithPendingFileIO(bool fast); 42 void BackendShutdownWithPendingFileIO(bool fast);
43 void BackendShutdownWithPendingIO(bool fast); 43 void BackendShutdownWithPendingIO(bool fast);
44 void BackendShutdownWithPendingCreate(bool fast); 44 void BackendShutdownWithPendingCreate(bool fast);
45 void BackendSetSize(); 45 void BackendSetSize();
46 void BackendLoad(); 46 void BackendLoad();
47 void BackendChain(); 47 void BackendChain();
48 void BucketUse();
49 void BackendNewEvictionTrim();
48 void BackendValidEntry(); 50 void BackendValidEntry();
49 void BackendInvalidEntry(); 51 void BackendInvalidEntry();
50 void BackendInvalidEntryRead(); 52 void BackendInvalidEntryRead();
51 void BackendInvalidEntryWithLoad(); 53 void BackendInvalidEntryWithLoad();
52 void BackendTrimInvalidEntry(); 54 void BackendTrimInvalidEntry();
53 void BackendTrimInvalidEntry2(); 55 void BackendTrimInvalidEntry2();
54 void BackendEnumerations(); 56 void BackendEnumerations();
55 void BackendEnumerations2(); 57 void BackendEnumerations2();
56 void BackendInvalidEntryEnumeration(); 58 void BackendInvalidEntryEnumeration();
57 void BackendFixEnumerators(); 59 void BackendFixEnumerators();
(...skipping 18 matching lines...) Expand all
76 void BackendInvalidEntry11(bool eviction); 78 void BackendInvalidEntry11(bool eviction);
77 void BackendTrimInvalidEntry12(); 79 void BackendTrimInvalidEntry12();
78 void BackendDoomAll(); 80 void BackendDoomAll();
79 void BackendDoomAll2(); 81 void BackendDoomAll2();
80 void BackendInvalidRankings(); 82 void BackendInvalidRankings();
81 void BackendInvalidRankings2(); 83 void BackendInvalidRankings2();
82 void BackendDisable(); 84 void BackendDisable();
83 void BackendDisable2(); 85 void BackendDisable2();
84 void BackendDisable3(); 86 void BackendDisable3();
85 void BackendDisable4(); 87 void BackendDisable4();
88 void BackendTotalBuffersSize1();
89 void BackendTotalBuffersSize2();
90 void BackendUpdateRankForExternalCacheHit();
86 void TracingBackendBasics(); 91 void TracingBackendBasics();
87 }; 92 };
88 93
89 void DiskCacheBackendTest::BackendBasics() { 94 void DiskCacheBackendTest::BackendBasics() {
90 InitCache(); 95 InitCache();
91 disk_cache::Entry *entry1 = NULL, *entry2 = NULL; 96 disk_cache::Entry *entry1 = NULL, *entry2 = NULL;
92 EXPECT_NE(net::OK, OpenEntry("the first key", &entry1)); 97 EXPECT_NE(net::OK, OpenEntry("the first key", &entry1));
93 ASSERT_EQ(net::OK, CreateEntry("the first key", &entry1)); 98 ASSERT_EQ(net::OK, CreateEntry("the first key", &entry1));
94 ASSERT_TRUE(NULL != entry1); 99 ASSERT_TRUE(NULL != entry1);
95 entry1->Close(); 100 entry1->Close();
96 entry1 = NULL; 101 entry1 = NULL;
97 102
98 ASSERT_EQ(net::OK, OpenEntry("the first key", &entry1)); 103 ASSERT_EQ(net::OK, OpenEntry("the first key", &entry1));
99 ASSERT_TRUE(NULL != entry1); 104 ASSERT_TRUE(NULL != entry1);
100 entry1->Close(); 105 entry1->Close();
101 entry1 = NULL; 106 entry1 = NULL;
102 107
103 EXPECT_NE(net::OK, CreateEntry("the first key", &entry1)); 108 EXPECT_NE(net::OK, CreateEntry("the first key", &entry1));
104 ASSERT_EQ(net::OK, OpenEntry("the first key", &entry1)); 109 ASSERT_EQ(net::OK, OpenEntry("the first key", &entry1));
105 EXPECT_NE(net::OK, OpenEntry("some other key", &entry2)); 110 EXPECT_NE(net::OK, OpenEntry("some other key", &entry2));
106 ASSERT_EQ(net::OK, CreateEntry("some other key", &entry2)); 111 ASSERT_EQ(net::OK, CreateEntry("some other key", &entry2));
107 ASSERT_TRUE(NULL != entry1); 112 ASSERT_TRUE(NULL != entry1);
108 ASSERT_TRUE(NULL != entry2); 113 ASSERT_TRUE(NULL != entry2);
109 EXPECT_EQ(2, cache_->GetEntryCount()); 114 EXPECT_EQ(2, cache_->GetEntryCount());
110 115
111 disk_cache::Entry* entry3 = NULL; 116 disk_cache::Entry* entry3 = NULL;
112 ASSERT_EQ(net::OK, OpenEntry("some other key", &entry3)); 117 ASSERT_EQ(net::OK, OpenEntry("some other key", &entry3));
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 TEST_F(DiskCacheBackendTest, AppCacheBasics) { 154 TEST_F(DiskCacheBackendTest, AppCacheBasics) {
150 SetCacheType(net::APP_CACHE); 155 SetCacheType(net::APP_CACHE);
151 BackendBasics(); 156 BackendBasics();
152 } 157 }
153 158
154 TEST_F(DiskCacheBackendTest, ShaderCacheBasics) { 159 TEST_F(DiskCacheBackendTest, ShaderCacheBasics) {
155 SetCacheType(net::SHADER_CACHE); 160 SetCacheType(net::SHADER_CACHE);
156 BackendBasics(); 161 BackendBasics();
157 } 162 }
158 163
164 TEST_F(DiskCacheBackendTest, V3Basics) {
165 UseVersion3();
166 BackendBasics();
167 }
168
159 void DiskCacheBackendTest::BackendKeying() { 169 void DiskCacheBackendTest::BackendKeying() {
160 InitCache(); 170 InitCache();
161 const char* kName1 = "the first key"; 171 const char* kName1 = "the first key";
162 const char* kName2 = "the first Key"; 172 const char* kName2 = "the first Key";
163 disk_cache::Entry *entry1, *entry2; 173 disk_cache::Entry *entry1, *entry2;
164 ASSERT_EQ(net::OK, CreateEntry(kName1, &entry1)); 174 ASSERT_EQ(net::OK, CreateEntry(kName1, &entry1));
165 175
166 ASSERT_EQ(net::OK, CreateEntry(kName2, &entry2)); 176 ASSERT_EQ(net::OK, CreateEntry(kName2, &entry2));
167 EXPECT_TRUE(entry1 != entry2) << "Case sensitive"; 177 EXPECT_TRUE(entry1 != entry2) << "Case sensitive";
168 entry2->Close(); 178 entry2->Close();
(...skipping 25 matching lines...) Expand all
194 buffer2[19999] = '\0'; 204 buffer2[19999] = '\0';
195 ASSERT_EQ(net::OK, CreateEntry(buffer2, &entry2)) << "key on external file"; 205 ASSERT_EQ(net::OK, CreateEntry(buffer2, &entry2)) << "key on external file";
196 entry2->Close(); 206 entry2->Close();
197 entry1->Close(); 207 entry1->Close();
198 } 208 }
199 209
200 TEST_F(DiskCacheBackendTest, Keying) { 210 TEST_F(DiskCacheBackendTest, Keying) {
201 BackendKeying(); 211 BackendKeying();
202 } 212 }
203 213
214 TEST_F(DiskCacheBackendTest, V3Keying) {
215 UseVersion3();
216 BackendKeying();
217 }
218
204 TEST_F(DiskCacheBackendTest, NewEvictionKeying) { 219 TEST_F(DiskCacheBackendTest, NewEvictionKeying) {
205 SetNewEviction(); 220 SetNewEviction();
206 BackendKeying(); 221 BackendKeying();
207 } 222 }
208 223
224 TEST_F(DiskCacheBackendTest, V3NewEvictionKeying) {
225 UseVersion3();
226 SetNewEviction();
227 BackendKeying();
228 }
229
209 TEST_F(DiskCacheBackendTest, MemoryOnlyKeying) { 230 TEST_F(DiskCacheBackendTest, MemoryOnlyKeying) {
210 SetMemoryOnlyMode(); 231 SetMemoryOnlyMode();
211 BackendKeying(); 232 BackendKeying();
212 } 233 }
213 234
214 TEST_F(DiskCacheBackendTest, AppCacheKeying) { 235 TEST_F(DiskCacheBackendTest, AppCacheKeying) {
215 SetCacheType(net::APP_CACHE); 236 SetCacheType(net::APP_CACHE);
216 BackendKeying(); 237 BackendKeying();
217 } 238 }
218 239
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 void DiskCacheBackendTest::BackendShutdownWithPendingFileIO(bool fast) { 329 void DiskCacheBackendTest::BackendShutdownWithPendingFileIO(bool fast) {
309 net::TestCompletionCallback cb; 330 net::TestCompletionCallback cb;
310 int rv; 331 int rv;
311 332
312 { 333 {
313 ASSERT_TRUE(CleanupCacheDir()); 334 ASSERT_TRUE(CleanupCacheDir());
314 base::Thread cache_thread("CacheThread"); 335 base::Thread cache_thread("CacheThread");
315 ASSERT_TRUE(cache_thread.StartWithOptions( 336 ASSERT_TRUE(cache_thread.StartWithOptions(
316 base::Thread::Options(MessageLoop::TYPE_IO, 0))); 337 base::Thread::Options(MessageLoop::TYPE_IO, 0)));
317 338
318 uint32 flags = disk_cache::kNoBuffering; 339 if (fast)
319 if (!fast) 340 AvoidTestFlag();
320 flags |= disk_cache::kNoRandom;
321 341
322 UseCurrentThread(); 342 UseCurrentThread();
323 CreateBackend(flags, NULL); 343 CreateBackend(NULL);
344 SetNoBuffering();
324 345
325 disk_cache::EntryImpl* entry; 346 disk_cache::EntryImpl* entry;
326 rv = cache_->CreateEntry( 347 rv = cache_->CreateEntry(
327 "some key", reinterpret_cast<disk_cache::Entry**>(&entry), 348 "some key", reinterpret_cast<disk_cache::Entry**>(&entry),
328 cb.callback()); 349 cb.callback());
329 ASSERT_EQ(net::OK, cb.GetResult(rv)); 350 ASSERT_EQ(net::OK, cb.GetResult(rv));
330 351
331 const int kSize = 25000; 352 const int kSize = 25000;
332 scoped_refptr<net::IOBuffer> buffer(new net::IOBuffer(kSize)); 353 scoped_refptr<net::IOBuffer> buffer(new net::IOBuffer(kSize));
333 CacheTestFillBuffer(buffer->data(), kSize, false); 354 CacheTestFillBuffer(buffer->data(), kSize, false);
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
385 // Tests that we deal with background-thread pending operations. 406 // Tests that we deal with background-thread pending operations.
386 void DiskCacheBackendTest::BackendShutdownWithPendingIO(bool fast) { 407 void DiskCacheBackendTest::BackendShutdownWithPendingIO(bool fast) {
387 net::TestCompletionCallback cb; 408 net::TestCompletionCallback cb;
388 409
389 { 410 {
390 ASSERT_TRUE(CleanupCacheDir()); 411 ASSERT_TRUE(CleanupCacheDir());
391 base::Thread cache_thread("CacheThread"); 412 base::Thread cache_thread("CacheThread");
392 ASSERT_TRUE(cache_thread.StartWithOptions( 413 ASSERT_TRUE(cache_thread.StartWithOptions(
393 base::Thread::Options(MessageLoop::TYPE_IO, 0))); 414 base::Thread::Options(MessageLoop::TYPE_IO, 0)));
394 415
395 uint32 flags = disk_cache::kNoBuffering; 416 if (fast)
396 if (!fast) 417 AvoidTestFlag();
397 flags |= disk_cache::kNoRandom;
398 418
399 CreateBackend(flags, &cache_thread); 419 CreateBackend(&cache_thread);
420 SetNoBuffering();
400 421
401 disk_cache::Entry* entry; 422 disk_cache::Entry* entry;
402 int rv = cache_->CreateEntry("some key", &entry, cb.callback()); 423 int rv = cache_->CreateEntry("some key", &entry, cb.callback());
403 ASSERT_EQ(net::OK, cb.GetResult(rv)); 424 ASSERT_EQ(net::OK, cb.GetResult(rv));
404 425
405 entry->Close(); 426 entry->Close();
406 427
407 // The cache destructor will see one pending operation here. 428 // The cache destructor will see one pending operation here.
408 delete cache_; 429 delete cache_;
409 // Prevent the TearDown() to delete the backend again. 430 // Prevent the TearDown() to delete the backend again.
(...skipping 18 matching lines...) Expand all
428 // Tests that we deal with create-type pending operations. 449 // Tests that we deal with create-type pending operations.
429 void DiskCacheBackendTest::BackendShutdownWithPendingCreate(bool fast) { 450 void DiskCacheBackendTest::BackendShutdownWithPendingCreate(bool fast) {
430 net::TestCompletionCallback cb; 451 net::TestCompletionCallback cb;
431 452
432 { 453 {
433 ASSERT_TRUE(CleanupCacheDir()); 454 ASSERT_TRUE(CleanupCacheDir());
434 base::Thread cache_thread("CacheThread"); 455 base::Thread cache_thread("CacheThread");
435 ASSERT_TRUE(cache_thread.StartWithOptions( 456 ASSERT_TRUE(cache_thread.StartWithOptions(
436 base::Thread::Options(MessageLoop::TYPE_IO, 0))); 457 base::Thread::Options(MessageLoop::TYPE_IO, 0)));
437 458
438 disk_cache::BackendFlags flags = 459 if (fast)
439 fast ? disk_cache::kNone : disk_cache::kNoRandom; 460 AvoidTestFlag();
440 CreateBackend(flags, &cache_thread); 461 CreateBackend(&cache_thread);
441 462
442 disk_cache::Entry* entry; 463 disk_cache::Entry* entry;
443 int rv = cache_->CreateEntry("some key", &entry, cb.callback()); 464 int rv = cache_->CreateEntry("some key", &entry, cb.callback());
444 ASSERT_EQ(net::ERR_IO_PENDING, rv); 465 ASSERT_EQ(net::ERR_IO_PENDING, rv);
445 466
446 delete cache_; 467 delete cache_;
447 // Prevent the TearDown() to delete the backend again. 468 // Prevent the TearDown() to delete the backend again.
448 cache_ = NULL; 469 cache_ = NULL;
449 EXPECT_FALSE(cb.have_result()); 470 EXPECT_FALSE(cb.have_result());
450 } 471 }
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
516 537
517 SetMaxSize(cache_size); 538 SetMaxSize(cache_size);
518 539
519 // The cache is 95% full. 540 // The cache is 95% full.
520 541
521 ASSERT_EQ(net::OK, CreateEntry(second, &entry)); 542 ASSERT_EQ(net::OK, CreateEntry(second, &entry));
522 EXPECT_EQ(cache_size / 10, WriteData(entry, 0, 0, buffer, cache_size / 10, 543 EXPECT_EQ(cache_size / 10, WriteData(entry, 0, 0, buffer, cache_size / 10,
523 false)); 544 false));
524 545
525 disk_cache::Entry* entry2; 546 disk_cache::Entry* entry2;
526 ASSERT_EQ(net::OK, CreateEntry("an extra key", &entry2)); 547 std::string extra_key("an extra key");
548 ASSERT_EQ(net::OK, CreateEntry(extra_key, &entry2));
527 EXPECT_EQ(cache_size / 10, WriteData(entry2, 0, 0, buffer, cache_size / 10, 549 EXPECT_EQ(cache_size / 10, WriteData(entry2, 0, 0, buffer, cache_size / 10,
528 false)); 550 false));
529 entry2->Close(); // This will trigger the cache trim. 551 entry2->Close(); // This will trigger the cache trim.
530 552 WaitForEntryToClose(extra_key);
531 EXPECT_NE(net::OK, OpenEntry(first, &entry2));
532 553
533 FlushQueueForTest(); // Make sure that we are done trimming the cache. 554 FlushQueueForTest(); // Make sure that we are done trimming the cache.
534 FlushQueueForTest(); // We may have posted two tasks to evict stuff. 555 FlushQueueForTest(); // We may have posted two tasks to evict stuff.
535 556
536 entry->Close(); 557 entry->Close();
558 WaitForEntryToClose(second);
559
560 EXPECT_NE(net::OK, OpenEntry(first, &entry2));
537 ASSERT_EQ(net::OK, OpenEntry(second, &entry)); 561 ASSERT_EQ(net::OK, OpenEntry(second, &entry));
538 EXPECT_EQ(cache_size / 10, entry->GetDataSize(0)); 562 EXPECT_EQ(cache_size / 10, entry->GetDataSize(0));
539 entry->Close(); 563 entry->Close();
540 } 564 }
541 565
542 TEST_F(DiskCacheBackendTest, SetSize) { 566 TEST_F(DiskCacheBackendTest, SetSize) {
543 BackendSetSize(); 567 BackendSetSize();
544 } 568 }
545 569
570 TEST_F(DiskCacheBackendTest, V3SetSize) {
571 UseVersion3();
572 UseVersion3();
573 SetNewEviction();
574 BackendSetSize();
575 }
576
546 TEST_F(DiskCacheBackendTest, NewEvictionSetSize) { 577 TEST_F(DiskCacheBackendTest, NewEvictionSetSize) {
547 SetNewEviction(); 578 SetNewEviction();
548 BackendSetSize(); 579 BackendSetSize();
549 } 580 }
550 581
582 TEST_F(DiskCacheBackendTest, V3NewEvictionSetSize) {
583 UseVersion3();
584 SetNewEviction();
585 BackendSetSize();
586 }
587
551 TEST_F(DiskCacheBackendTest, MemoryOnlySetSize) { 588 TEST_F(DiskCacheBackendTest, MemoryOnlySetSize) {
552 SetMemoryOnlyMode(); 589 SetMemoryOnlyMode();
553 BackendSetSize(); 590 BackendSetSize();
554 } 591 }
555 592
556 void DiskCacheBackendTest::BackendLoad() { 593 void DiskCacheBackendTest::BackendLoad() {
557 InitCache(); 594 InitCache();
558 int seed = static_cast<int>(Time::Now().ToInternalValue()); 595 int seed = static_cast<int>(Time::Now().ToInternalValue());
559 srand(seed); 596 srand(seed);
560 597
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
647 TEST_F(DiskCacheBackendTest, AppCacheChain) { 684 TEST_F(DiskCacheBackendTest, AppCacheChain) {
648 SetCacheType(net::APP_CACHE); 685 SetCacheType(net::APP_CACHE);
649 BackendChain(); 686 BackendChain();
650 } 687 }
651 688
652 TEST_F(DiskCacheBackendTest, ShaderCacheChain) { 689 TEST_F(DiskCacheBackendTest, ShaderCacheChain) {
653 SetCacheType(net::SHADER_CACHE); 690 SetCacheType(net::SHADER_CACHE);
654 BackendChain(); 691 BackendChain();
655 } 692 }
656 693
657 TEST_F(DiskCacheBackendTest, NewEvictionTrim) { 694 // Tests the proper use of cell buckets while the index grow.
695 void DiskCacheBackendTest::BucketUse() {
696 UseVersion3();
697 InitCache();
698 const int kNumEntries = 20;
699 disk_cache::Entry* entries[kNumEntries];
700 std::string key("The first key");
701
702 // This generates kNumEntries collisions so the extra table has to be used.
703 // There are only 2 extra buckets on the test setup, so the index has to grow.
704 for (int i = 0; i < kNumEntries; i++) {
705 ASSERT_EQ(net::OK, CreateEntry(key, &entries[i]));
706 entries[i]->Doom();
707 FlushQueueForTest();
708 }
709
710 for (int i = 0; i < kNumEntries / 2; i++)
711 entries[i]->Close();
712
713 for (int i = 0; i < kNumEntries / 2; i++) {
714 ASSERT_EQ(net::OK, CreateEntry(key, &entries[i]));
715 entries[i]->Doom();
716 }
717
718 for (int i = 0; i < kNumEntries; i++)
719 entries[i]->Close();
720 }
721
722 TEST_F(DiskCacheBackendTest, V3BucketUse) {
723 BucketUse();
724 }
725
726 TEST_F(DiskCacheBackendTest, V3DoubleIndexBucketUse) {
727 PresetTestMode(); // Doubles the index instead of a slow growth.
728 BucketUse();
729 }
730
731 TEST_F(DiskCacheBackendTest, V3DoubleIndex) {
732 UseVersion3();
733 PresetTestMode();
734 InitCache();
735
736 disk_cache::Entry* entry;
737 const int kNumEntries = 200;
738 for (int i = 0; i < kNumEntries; i++) {
739 std::string name(base::StringPrintf("Key %d", i));
740 ASSERT_EQ(net::OK, CreateEntry(name, &entry));
741 entry->Close();
742 FlushQueueForTest();
743 }
744
745 // Generate enough collisions to force growing the extra table (and with it,
746 // the index).
747 const int kNumSavedEntries = 5;
748 disk_cache::Entry* entries[kNumSavedEntries];
749 std::string key("The first key");
750 for (int i = 0; i < kNumSavedEntries; i++) {
751 ASSERT_EQ(net::OK, CreateEntry(key, &entries[i]));
752 entries[i]->Doom();
753 FlushQueueForTest();
754 }
755
756 for (int i = 0; i < kNumSavedEntries; i++)
757 entries[i]->Close();
758
759 // Verify that all entries are there.
760 for (int i = 0; i < kNumEntries; i++) {
761 std::string name(base::StringPrintf("Key %d", i));
762 ASSERT_EQ(net::OK, OpenEntry(name, &entry));
763 entry->Close();
764 }
765 }
766
767 void DiskCacheBackendTest::BackendNewEvictionTrim() {
658 SetNewEviction(); 768 SetNewEviction();
659 InitCache(); 769 InitCache();
660 770
661 disk_cache::Entry* entry; 771 disk_cache::Entry* entry;
662 for (int i = 0; i < 100; i++) { 772 for (int i = 0; i < 100; i++) {
663 std::string name(base::StringPrintf("Key %d", i)); 773 std::string name(base::StringPrintf("Key %d", i));
664 ASSERT_EQ(net::OK, CreateEntry(name, &entry)); 774 ASSERT_EQ(net::OK, CreateEntry(name, &entry));
665 entry->Close(); 775 entry->Close();
666 if (i < 90) { 776 if (i < 90) {
667 // Entries 0 to 89 are in list 1; 90 to 99 are in list 0. 777 // Entries 0 to 89 are in list 1; 90 to 99 are in list 0.
668 ASSERT_EQ(net::OK, OpenEntry(name, &entry)); 778 ASSERT_EQ(net::OK, OpenEntry(name, &entry));
669 entry->Close(); 779 entry->Close();
670 } 780 }
781 if (!(i % 10))
782 FlushQueueForTest();
783
784 if (i == 0 || i == 90) {
785 WaitForEntryToClose(name);
786 AddDelayForTest(70);
787 }
671 } 788 }
672 789
673 // The first eviction must come from list 1 (10% limit), the second must come 790 // The first eviction must come from list 1 (10% limit), the second must come
674 // from list 0. 791 // from list 0.
675 TrimForTest(false); 792 TrimForTest(false);
676 EXPECT_NE(net::OK, OpenEntry("Key 0", &entry)); 793 EXPECT_NE(net::OK, OpenEntry("Key 0", &entry));
677 TrimForTest(false); 794 TrimForTest(false);
678 EXPECT_NE(net::OK, OpenEntry("Key 90", &entry)); 795 EXPECT_NE(net::OK, OpenEntry("Key 90", &entry));
679 796
680 // Double check that we still have the list tails. 797 // Double check that we still have the list tails.
681 ASSERT_EQ(net::OK, OpenEntry("Key 1", &entry)); 798 ASSERT_EQ(net::OK, OpenEntry("Key 1", &entry));
682 entry->Close(); 799 entry->Close();
683 ASSERT_EQ(net::OK, OpenEntry("Key 91", &entry)); 800 ASSERT_EQ(net::OK, OpenEntry("Key 91", &entry));
684 entry->Close(); 801 entry->Close();
685 } 802 }
686 803
804 TEST_F(DiskCacheBackendTest, NewEvictionTrim) {
805 BackendNewEvictionTrim();
806 }
807
808 TEST_F(DiskCacheBackendTest, V3NewEvictionTrim) {
809 UseVersion3();
810 BackendNewEvictionTrim();
811 }
812
687 // Before looking for invalid entries, let's check a valid entry. 813 // Before looking for invalid entries, let's check a valid entry.
688 void DiskCacheBackendTest::BackendValidEntry() { 814 void DiskCacheBackendTest::BackendValidEntry() {
689 InitCache(); 815 InitCache();
690 816
691 std::string key("Some key"); 817 std::string key("Some key");
692 disk_cache::Entry* entry; 818 disk_cache::Entry* entry;
693 ASSERT_EQ(net::OK, CreateEntry(key, &entry)); 819 ASSERT_EQ(net::OK, CreateEntry(key, &entry));
694 820
695 const int kSize = 50; 821 const int kSize = 50;
696 scoped_refptr<net::IOBuffer> buffer1(new net::IOBuffer(kSize)); 822 scoped_refptr<net::IOBuffer> buffer1(new net::IOBuffer(kSize));
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after
1011 Time initial = Time::Now(); 1137 Time initial = Time::Now();
1012 int seed = static_cast<int>(initial.ToInternalValue()); 1138 int seed = static_cast<int>(initial.ToInternalValue());
1013 srand(seed); 1139 srand(seed);
1014 1140
1015 const int kNumEntries = 100; 1141 const int kNumEntries = 100;
1016 for (int i = 0; i < kNumEntries; i++) { 1142 for (int i = 0; i < kNumEntries; i++) {
1017 std::string key = GenerateKey(true); 1143 std::string key = GenerateKey(true);
1018 disk_cache::Entry* entry; 1144 disk_cache::Entry* entry;
1019 ASSERT_EQ(net::OK, CreateEntry(key, &entry)); 1145 ASSERT_EQ(net::OK, CreateEntry(key, &entry));
1020 entry->Close(); 1146 entry->Close();
1147 if (!(i % 10))
1148 FlushQueueForTest();
1021 } 1149 }
1022 EXPECT_EQ(kNumEntries, cache_->GetEntryCount()); 1150 EXPECT_EQ(kNumEntries, cache_->GetEntryCount());
1023 Time final = Time::Now(); 1151 Time final = Time::Now();
1024 1152
1025 disk_cache::Entry* entry; 1153 disk_cache::Entry* entry;
1026 void* iter = NULL; 1154 void* iter = NULL;
1027 int count = 0; 1155 int count = 0;
1028 Time last_modified[kNumEntries]; 1156 Time last_modified[kNumEntries];
1029 Time last_used[kNumEntries]; 1157 Time last_used[kNumEntries];
1030 while (OpenNextEntry(&iter, &entry) == net::OK) { 1158 while (OpenNextEntry(&iter, &entry) == net::OK) {
(...skipping 22 matching lines...) Expand all
1053 entry->Close(); 1181 entry->Close();
1054 count++; 1182 count++;
1055 }; 1183 };
1056 EXPECT_EQ(kNumEntries, count); 1184 EXPECT_EQ(kNumEntries, count);
1057 } 1185 }
1058 1186
1059 TEST_F(DiskCacheBackendTest, Enumerations) { 1187 TEST_F(DiskCacheBackendTest, Enumerations) {
1060 BackendEnumerations(); 1188 BackendEnumerations();
1061 } 1189 }
1062 1190
1191 TEST_F(DiskCacheBackendTest, V3Enumerations) {
1192 UseVersion3();
1193 BackendEnumerations();
1194 }
1195
1063 TEST_F(DiskCacheBackendTest, NewEvictionEnumerations) { 1196 TEST_F(DiskCacheBackendTest, NewEvictionEnumerations) {
1064 SetNewEviction(); 1197 SetNewEviction();
1065 BackendEnumerations(); 1198 BackendEnumerations();
1066 } 1199 }
1067 1200
1201 TEST_F(DiskCacheBackendTest, V3NewEvictionEnumerations) {
1202 UseVersion3();
1203 SetNewEviction();
1204 BackendEnumerations();
1205 }
1206
1068 TEST_F(DiskCacheBackendTest, MemoryOnlyEnumerations) { 1207 TEST_F(DiskCacheBackendTest, MemoryOnlyEnumerations) {
1069 SetMemoryOnlyMode(); 1208 SetMemoryOnlyMode();
1070 BackendEnumerations(); 1209 BackendEnumerations();
1071 } 1210 }
1072 1211
1073 TEST_F(DiskCacheBackendTest, ShaderCacheEnumerations) { 1212 TEST_F(DiskCacheBackendTest, ShaderCacheEnumerations) {
1074 SetCacheType(net::SHADER_CACHE); 1213 SetCacheType(net::SHADER_CACHE);
1075 BackendEnumerations(); 1214 BackendEnumerations();
1076 } 1215 }
1077 1216
1078 TEST_F(DiskCacheBackendTest, AppCacheEnumerations) { 1217 TEST_F(DiskCacheBackendTest, AppCacheEnumerations) {
1079 SetCacheType(net::APP_CACHE); 1218 SetCacheType(net::APP_CACHE);
1080 BackendEnumerations(); 1219 BackendEnumerations();
1081 } 1220 }
1082 1221
1083 // Verifies enumerations while entries are open. 1222 // Verifies enumerations while entries are open.
1084 void DiskCacheBackendTest::BackendEnumerations2() { 1223 void DiskCacheBackendTest::BackendEnumerations2() {
1085 InitCache(); 1224 InitCache();
1086 const std::string first("first"); 1225 const std::string first("first");
1087 const std::string second("second"); 1226 const std::string second("second");
1088 disk_cache::Entry *entry1, *entry2; 1227 disk_cache::Entry *entry1, *entry2;
1089 ASSERT_EQ(net::OK, CreateEntry(first, &entry1)); 1228 ASSERT_EQ(net::OK, CreateEntry(first, &entry1));
1090 entry1->Close(); 1229 entry1->Close();
1091 ASSERT_EQ(net::OK, CreateEntry(second, &entry2)); 1230 ASSERT_EQ(net::OK, CreateEntry(second, &entry2));
1092 entry2->Close(); 1231 entry2->Close();
1093 FlushQueueForTest(); 1232 FlushQueueForTest();
1094 1233
1095 // Make sure that the timestamp is not the same. 1234 // Make sure that the timestamp is not the same.
1096 AddDelay(); 1235 AddDelayForTest(70);
1097 ASSERT_EQ(net::OK, OpenEntry(second, &entry1)); 1236 ASSERT_EQ(net::OK, OpenEntry(second, &entry1));
1098 void* iter = NULL; 1237 void* iter = NULL;
1099 ASSERT_EQ(net::OK, OpenNextEntry(&iter, &entry2)); 1238 ASSERT_EQ(net::OK, OpenNextEntry(&iter, &entry2));
1100 EXPECT_EQ(entry2->GetKey(), second); 1239 EXPECT_EQ(entry2->GetKey(), second);
1101 1240
1102 // Two entries and the iterator pointing at "first". 1241 // Two entries and the iterator pointing at "first".
1103 entry1->Close(); 1242 entry1->Close();
1104 entry2->Close(); 1243 entry2->Close();
1105 1244
1106 // The iterator should still be valid, so we should not crash. 1245 // The iterator should still be valid, so we should not crash.
(...skipping 15 matching lines...) Expand all
1122 1261
1123 entry1->Close(); 1262 entry1->Close();
1124 entry2->Close(); 1263 entry2->Close();
1125 cache_->EndEnumeration(&iter); 1264 cache_->EndEnumeration(&iter);
1126 } 1265 }
1127 1266
1128 TEST_F(DiskCacheBackendTest, Enumerations2) { 1267 TEST_F(DiskCacheBackendTest, Enumerations2) {
1129 BackendEnumerations2(); 1268 BackendEnumerations2();
1130 } 1269 }
1131 1270
1271 TEST_F(DiskCacheBackendTest, V3Enumerations2) {
1272 UseVersion3();
1273 BackendEnumerations2();
1274 }
1275
1132 TEST_F(DiskCacheBackendTest, NewEvictionEnumerations2) { 1276 TEST_F(DiskCacheBackendTest, NewEvictionEnumerations2) {
1133 SetNewEviction(); 1277 SetNewEviction();
1134 BackendEnumerations2(); 1278 BackendEnumerations2();
1135 } 1279 }
1136 1280
1281 TEST_F(DiskCacheBackendTest, V3NewEvictionEnumerations2) {
1282 UseVersion3();
1283 SetNewEviction();
1284 BackendEnumerations2();
1285 }
1286
1137 TEST_F(DiskCacheBackendTest, MemoryOnlyEnumerations2) { 1287 TEST_F(DiskCacheBackendTest, MemoryOnlyEnumerations2) {
1138 SetMemoryOnlyMode(); 1288 SetMemoryOnlyMode();
1139 BackendEnumerations2(); 1289 BackendEnumerations2();
1140 } 1290 }
1141 1291
1142 TEST_F(DiskCacheBackendTest, AppCacheEnumerations2) { 1292 TEST_F(DiskCacheBackendTest, AppCacheEnumerations2) {
1143 SetCacheType(net::APP_CACHE); 1293 SetCacheType(net::APP_CACHE);
1144 BackendEnumerations2(); 1294 BackendEnumerations2();
1145 } 1295 }
1146 1296
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
1300 void DiskCacheBackendTest::BackendDoomRecent() { 1450 void DiskCacheBackendTest::BackendDoomRecent() {
1301 InitCache(); 1451 InitCache();
1302 1452
1303 disk_cache::Entry *entry; 1453 disk_cache::Entry *entry;
1304 ASSERT_EQ(net::OK, CreateEntry("first", &entry)); 1454 ASSERT_EQ(net::OK, CreateEntry("first", &entry));
1305 entry->Close(); 1455 entry->Close();
1306 ASSERT_EQ(net::OK, CreateEntry("second", &entry)); 1456 ASSERT_EQ(net::OK, CreateEntry("second", &entry));
1307 entry->Close(); 1457 entry->Close();
1308 FlushQueueForTest(); 1458 FlushQueueForTest();
1309 1459
1310 AddDelay(); 1460 AddDelayForTest(70);
1311 Time middle = Time::Now(); 1461 Time middle = GetCurrentTime();
1312 1462
1313 ASSERT_EQ(net::OK, CreateEntry("third", &entry)); 1463 ASSERT_EQ(net::OK, CreateEntry("third", &entry));
1314 entry->Close(); 1464 entry->Close();
1315 ASSERT_EQ(net::OK, CreateEntry("fourth", &entry)); 1465 ASSERT_EQ(net::OK, CreateEntry("fourth", &entry));
1316 entry->Close(); 1466 entry->Close();
1317 FlushQueueForTest(); 1467 FlushQueueForTest();
1318 1468
1319 AddDelay(); 1469 AddDelayForTest(70);
1320 Time final = Time::Now(); 1470 Time final = GetCurrentTime();
1321 1471
1322 ASSERT_EQ(4, cache_->GetEntryCount()); 1472 ASSERT_EQ(4, cache_->GetEntryCount());
1323 EXPECT_EQ(net::OK, DoomEntriesSince(final)); 1473 EXPECT_EQ(net::OK, DoomEntriesSince(final));
1324 ASSERT_EQ(4, cache_->GetEntryCount()); 1474 ASSERT_EQ(4, cache_->GetEntryCount());
1325 1475
1326 EXPECT_EQ(net::OK, DoomEntriesSince(middle)); 1476 EXPECT_EQ(net::OK, DoomEntriesSince(middle));
1327 ASSERT_EQ(2, cache_->GetEntryCount()); 1477 ASSERT_EQ(2, cache_->GetEntryCount());
1328 1478
1329 ASSERT_EQ(net::OK, OpenEntry("second", &entry)); 1479 ASSERT_EQ(net::OK, OpenEntry("second", &entry));
1330 entry->Close(); 1480 entry->Close();
1331 } 1481 }
1332 1482
1333 TEST_F(DiskCacheBackendTest, DoomRecent) { 1483 TEST_F(DiskCacheBackendTest, DoomRecent) {
1334 BackendDoomRecent(); 1484 BackendDoomRecent();
1335 } 1485 }
1336 1486
1487 TEST_F(DiskCacheBackendTest, V3DoomRecent) {
1488 UseVersion3();
1489 BackendDoomRecent();
1490 }
1491
1337 TEST_F(DiskCacheBackendTest, NewEvictionDoomRecent) { 1492 TEST_F(DiskCacheBackendTest, NewEvictionDoomRecent) {
1338 SetNewEviction(); 1493 SetNewEviction();
1339 BackendDoomRecent(); 1494 BackendDoomRecent();
1340 } 1495 }
1341 1496
1497 TEST_F(DiskCacheBackendTest, V3NewEvictionDoomRecent) {
1498 UseVersion3();
1499 SetNewEviction();
1500 BackendDoomRecent();
1501 }
1502
1342 TEST_F(DiskCacheBackendTest, MemoryOnlyDoomRecent) { 1503 TEST_F(DiskCacheBackendTest, MemoryOnlyDoomRecent) {
1343 SetMemoryOnlyMode(); 1504 SetMemoryOnlyMode();
1344 BackendDoomRecent(); 1505 BackendDoomRecent();
1345 } 1506 }
1346 1507
1347 void DiskCacheBackendTest::InitSparseCache(base::Time* doomed_start, 1508 void DiskCacheBackendTest::InitSparseCache(base::Time* doomed_start,
1348 base::Time* doomed_end) { 1509 base::Time* doomed_end) {
1349 InitCache(); 1510 InitCache();
1350 1511
1351 const int kSize = 50; 1512 const int kSize = 50;
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
1419 TEST_F(DiskCacheBackendTest, DoomEntriesSinceSparse) { 1580 TEST_F(DiskCacheBackendTest, DoomEntriesSinceSparse) {
1420 base::Time start; 1581 base::Time start;
1421 InitSparseCache(&start, NULL); 1582 InitSparseCache(&start, NULL);
1422 DoomEntriesSince(start); 1583 DoomEntriesSince(start);
1423 // NOTE: BackendImpl counts child entries in its GetEntryCount(), while 1584 // NOTE: BackendImpl counts child entries in its GetEntryCount(), while
1424 // MemBackendImpl does not. Thats why expected value differs here from 1585 // MemBackendImpl does not. Thats why expected value differs here from
1425 // MemoryOnlyDoomEntriesSinceSparse. 1586 // MemoryOnlyDoomEntriesSinceSparse.
1426 EXPECT_EQ(3, cache_->GetEntryCount()); 1587 EXPECT_EQ(3, cache_->GetEntryCount());
1427 } 1588 }
1428 1589
1590 TEST_F(DiskCacheBackendTest, V3DoomEntriesSinceSparse) {
1591 base::Time start;
1592 UseVersion3();
1593 InitSparseCache(&start, NULL);
1594 DoomEntriesSince(start);
1595 // NOTE: BackendImpl counts child entries in its GetEntryCount(), while
1596 // MemBackendImpl does not. Thats why expected value differs here from
1597 // MemoryOnlyDoomEntriesSinceSparse.
1598 EXPECT_EQ(3, cache_->GetEntryCount());
1599 }
1600
1429 TEST_F(DiskCacheBackendTest, MemoryOnlyDoomAllSparse) { 1601 TEST_F(DiskCacheBackendTest, MemoryOnlyDoomAllSparse) {
1430 SetMemoryOnlyMode(); 1602 SetMemoryOnlyMode();
1431 InitSparseCache(NULL, NULL); 1603 InitSparseCache(NULL, NULL);
1432 EXPECT_EQ(net::OK, DoomAllEntries()); 1604 EXPECT_EQ(net::OK, DoomAllEntries());
1433 EXPECT_EQ(0, cache_->GetEntryCount()); 1605 EXPECT_EQ(0, cache_->GetEntryCount());
1434 } 1606 }
1435 1607
1436 TEST_F(DiskCacheBackendTest, DoomAllSparse) { 1608 TEST_F(DiskCacheBackendTest, DoomAllSparse) {
1437 InitSparseCache(NULL, NULL); 1609 InitSparseCache(NULL, NULL);
1438 EXPECT_EQ(net::OK, DoomAllEntries()); 1610 EXPECT_EQ(net::OK, DoomAllEntries());
1439 EXPECT_EQ(0, cache_->GetEntryCount()); 1611 EXPECT_EQ(0, cache_->GetEntryCount());
1440 } 1612 }
1441 1613
1614 TEST_F(DiskCacheBackendTest, V3DoomAllSparse) {
1615 UseVersion3();
1616 InitSparseCache(NULL, NULL);
1617 EXPECT_EQ(net::OK, DoomAllEntries());
1618 EXPECT_EQ(0, cache_->GetEntryCount());
1619 }
1620
1442 void DiskCacheBackendTest::BackendDoomBetween() { 1621 void DiskCacheBackendTest::BackendDoomBetween() {
1443 InitCache(); 1622 InitCache();
1444 1623
1445 disk_cache::Entry *entry; 1624 disk_cache::Entry *entry;
1446 ASSERT_EQ(net::OK, CreateEntry("first", &entry)); 1625 ASSERT_EQ(net::OK, CreateEntry("first", &entry));
1447 entry->Close(); 1626 entry->Close();
1448 FlushQueueForTest(); 1627 FlushQueueForTest();
1449 1628
1450 AddDelay(); 1629 AddDelay();
1451 Time middle_start = Time::Now(); 1630 Time middle_start = Time::Now();
(...skipping 27 matching lines...) Expand all
1479 ASSERT_EQ(1, cache_->GetEntryCount()); 1658 ASSERT_EQ(1, cache_->GetEntryCount());
1480 1659
1481 ASSERT_EQ(net::OK, OpenEntry("first", &entry)); 1660 ASSERT_EQ(net::OK, OpenEntry("first", &entry));
1482 entry->Close(); 1661 entry->Close();
1483 } 1662 }
1484 1663
1485 TEST_F(DiskCacheBackendTest, DoomBetween) { 1664 TEST_F(DiskCacheBackendTest, DoomBetween) {
1486 BackendDoomBetween(); 1665 BackendDoomBetween();
1487 } 1666 }
1488 1667
1668 TEST_F(DiskCacheBackendTest, V3DoomBetween) {
1669 UseVersion3();
1670 BackendDoomBetween();
1671 }
1672
1489 TEST_F(DiskCacheBackendTest, NewEvictionDoomBetween) { 1673 TEST_F(DiskCacheBackendTest, NewEvictionDoomBetween) {
1490 SetNewEviction(); 1674 SetNewEviction();
1491 BackendDoomBetween(); 1675 BackendDoomBetween();
1492 } 1676 }
1493 1677
1678 TEST_F(DiskCacheBackendTest, V3NewEvictionDoomBetween) {
1679 UseVersion3();
1680 SetNewEviction();
1681 BackendDoomBetween();
1682 }
1683
1494 TEST_F(DiskCacheBackendTest, MemoryOnlyDoomBetween) { 1684 TEST_F(DiskCacheBackendTest, MemoryOnlyDoomBetween) {
1495 SetMemoryOnlyMode(); 1685 SetMemoryOnlyMode();
1496 BackendDoomBetween(); 1686 BackendDoomBetween();
1497 } 1687 }
1498 1688
1499 TEST_F(DiskCacheBackendTest, MemoryOnlyDoomEntriesBetweenSparse) { 1689 TEST_F(DiskCacheBackendTest, MemoryOnlyDoomEntriesBetweenSparse) {
1500 SetMemoryOnlyMode(); 1690 SetMemoryOnlyMode();
1501 base::Time start, end; 1691 base::Time start, end;
1502 InitSparseCache(&start, &end); 1692 InitSparseCache(&start, &end);
1503 DoomEntriesBetween(start, end); 1693 DoomEntriesBetween(start, end);
(...skipping 10 matching lines...) Expand all
1514 InitSparseCache(&start, &end); 1704 InitSparseCache(&start, &end);
1515 DoomEntriesBetween(start, end); 1705 DoomEntriesBetween(start, end);
1516 EXPECT_EQ(9, cache_->GetEntryCount()); 1706 EXPECT_EQ(9, cache_->GetEntryCount());
1517 1707
1518 start = end; 1708 start = end;
1519 end = base::Time::Now(); 1709 end = base::Time::Now();
1520 DoomEntriesBetween(start, end); 1710 DoomEntriesBetween(start, end);
1521 EXPECT_EQ(3, cache_->GetEntryCount()); 1711 EXPECT_EQ(3, cache_->GetEntryCount());
1522 } 1712 }
1523 1713
1714 TEST_F(DiskCacheBackendTest, V3DoomEntriesBetweenSparse) {
1715 base::Time start, end;
1716 UseVersion3();
1717 InitSparseCache(&start, &end);
1718 DoomEntriesBetween(start, end);
1719 EXPECT_EQ(9, cache_->GetEntryCount());
1720
1721 start = end;
1722 end = base::Time::Now();
1723 DoomEntriesBetween(start, end);
1724 EXPECT_EQ(3, cache_->GetEntryCount());
1725 }
1726
1524 void DiskCacheBackendTest::BackendTransaction(const std::string& name, 1727 void DiskCacheBackendTest::BackendTransaction(const std::string& name,
1525 int num_entries, bool load) { 1728 int num_entries, bool load) {
1526 success_ = false; 1729 success_ = false;
1527 ASSERT_TRUE(CopyTestCache(name)); 1730 ASSERT_TRUE(CopyTestCache(name));
1528 DisableFirstCleanup(); 1731 DisableFirstCleanup();
1529 1732
1530 uint32 mask; 1733 uint32 mask;
1531 if (load) { 1734 if (load) {
1532 mask = 0xf; 1735 mask = 0xf;
1533 SetMaxSize(0x100000); 1736 SetMaxSize(0x100000);
(...skipping 973 matching lines...) Expand 10 before | Expand all | Expand 10 after
2507 EXPECT_EQ(net::OK, DoomAllEntries()); 2710 EXPECT_EQ(net::OK, DoomAllEntries());
2508 ASSERT_EQ(0, cache_->GetEntryCount()); 2711 ASSERT_EQ(0, cache_->GetEntryCount());
2509 2712
2510 EXPECT_EQ(net::OK, DoomAllEntries()); 2713 EXPECT_EQ(net::OK, DoomAllEntries());
2511 } 2714 }
2512 2715
2513 TEST_F(DiskCacheBackendTest, DoomAll) { 2716 TEST_F(DiskCacheBackendTest, DoomAll) {
2514 BackendDoomAll(); 2717 BackendDoomAll();
2515 } 2718 }
2516 2719
2720 TEST_F(DiskCacheBackendTest, V3DoomAll) {
2721 UseVersion3();
2722 BackendDoomAll();
2723 }
2724
2517 TEST_F(DiskCacheBackendTest, NewEvictionDoomAll) { 2725 TEST_F(DiskCacheBackendTest, NewEvictionDoomAll) {
2518 SetNewEviction(); 2726 SetNewEviction();
2519 BackendDoomAll(); 2727 BackendDoomAll();
2520 } 2728 }
2521 2729
2730 TEST_F(DiskCacheBackendTest, V3NewEvictionDoomAll) {
2731 UseVersion3();
2732 SetNewEviction();
2733 BackendDoomAll();
2734 }
2735
2522 TEST_F(DiskCacheBackendTest, MemoryOnlyDoomAll) { 2736 TEST_F(DiskCacheBackendTest, MemoryOnlyDoomAll) {
2523 SetMemoryOnlyMode(); 2737 SetMemoryOnlyMode();
2524 BackendDoomAll(); 2738 BackendDoomAll();
2525 } 2739 }
2526 2740
2527 TEST_F(DiskCacheBackendTest, AppCacheOnlyDoomAll) { 2741 TEST_F(DiskCacheBackendTest, AppCacheOnlyDoomAll) {
2528 SetCacheType(net::APP_CACHE); 2742 SetCacheType(net::APP_CACHE);
2529 BackendDoomAll(); 2743 BackendDoomAll();
2530 } 2744 }
2531 2745
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
2655 InitCache(); 2869 InitCache();
2656 disk_cache::BackendImpl* backend_ = cache_impl_; // Needed be the macro. 2870 disk_cache::BackendImpl* backend_ = cache_impl_; // Needed be the macro.
2657 2871
2658 for (int i = 1; i < 3; i++) { 2872 for (int i = 1; i < 3; i++) {
2659 CACHE_UMA(HOURS, "FillupTime", i, 28); 2873 CACHE_UMA(HOURS, "FillupTime", i, 28);
2660 } 2874 }
2661 } 2875 }
2662 2876
2663 // Make sure that we keep the total memory used by the internal buffers under 2877 // Make sure that we keep the total memory used by the internal buffers under
2664 // control. 2878 // control.
2665 TEST_F(DiskCacheBackendTest, TotalBuffersSize1) { 2879 void DiskCacheBackendTest::BackendTotalBuffersSize1() {
2666 InitCache(); 2880 InitCache();
2667 std::string key("the first key"); 2881 std::string key("the first key");
2668 disk_cache::Entry* entry; 2882 disk_cache::Entry* entry;
2669 ASSERT_EQ(net::OK, CreateEntry(key, &entry)); 2883 ASSERT_EQ(net::OK, CreateEntry(key, &entry));
2670 2884
2671 const int kSize = 200; 2885 const int kSize = 200;
2672 scoped_refptr<net::IOBuffer> buffer(new net::IOBuffer(kSize)); 2886 scoped_refptr<net::IOBuffer> buffer(new net::IOBuffer(kSize));
2673 CacheTestFillBuffer(buffer->data(), kSize, true); 2887 CacheTestFillBuffer(buffer->data(), kSize, true);
2674 2888
2675 for (int i = 0; i < 10; i++) { 2889 for (int i = 0; i < 10; i++) {
2676 SCOPED_TRACE(i); 2890 SCOPED_TRACE(i);
2677 // Allocate 2MB for this entry. 2891 // Allocate 2MB for this entry.
2678 EXPECT_EQ(kSize, WriteData(entry, 0, 0, buffer, kSize, true)); 2892 EXPECT_EQ(kSize, WriteData(entry, 0, 0, buffer, kSize, true));
2679 EXPECT_EQ(kSize, WriteData(entry, 1, 0, buffer, kSize, true)); 2893 EXPECT_EQ(kSize, WriteData(entry, 1, 0, buffer, kSize, true));
2680 EXPECT_EQ(kSize, WriteData(entry, 0, 1024 * 1024, buffer, kSize, false)); 2894 EXPECT_EQ(kSize, WriteData(entry, 0, 1024 * 1024, buffer, kSize, false));
2681 EXPECT_EQ(kSize, WriteData(entry, 1, 1024 * 1024, buffer, kSize, false)); 2895 EXPECT_EQ(kSize, WriteData(entry, 1, 1024 * 1024, buffer, kSize, false));
2682 2896
2683 // Delete one of the buffers and truncate the other. 2897 // Delete one of the buffers and truncate the other.
2684 EXPECT_EQ(0, WriteData(entry, 0, 0, buffer, 0, true)); 2898 EXPECT_EQ(0, WriteData(entry, 0, 0, buffer, 0, true));
2685 EXPECT_EQ(0, WriteData(entry, 1, 10, buffer, 0, true)); 2899 EXPECT_EQ(0, WriteData(entry, 1, 10, buffer, 0, true));
2686 2900
2687 // Delete the second buffer, writing 10 bytes to disk. 2901 // Delete the second buffer, writing 10 bytes to disk.
2688 entry->Close(); 2902 entry->Close();
2689 ASSERT_EQ(net::OK, OpenEntry(key, &entry)); 2903 ASSERT_EQ(net::OK, OpenEntry(key, &entry));
2690 } 2904 }
2691 2905
2692 entry->Close(); 2906 entry->Close();
2693 EXPECT_EQ(0, cache_impl_->GetTotalBuffersSize()); 2907 EXPECT_EQ(0, GetTotalBuffersSize());
2908 }
2909
2910 TEST_F(DiskCacheBackendTest, TotalBuffersSize1) {
2911 BackendTotalBuffersSize1();
2912 }
2913
2914 TEST_F(DiskCacheBackendTest, V3TotalBuffersSize1) {
2915 UseVersion3();
2916 BackendTotalBuffersSize1();
2694 } 2917 }
2695 2918
2696 // This test assumes at least 150MB of system memory. 2919 // This test assumes at least 150MB of system memory.
2697 TEST_F(DiskCacheBackendTest, TotalBuffersSize2) { 2920 void DiskCacheBackendTest::BackendTotalBuffersSize2() {
2698 InitCache(); 2921 InitCache();
2699 2922
2700 const int kOneMB = 1024 * 1024; 2923 const int kOneMB = 1024 * 1024;
2701 EXPECT_TRUE(cache_impl_->IsAllocAllowed(0, kOneMB)); 2924 EXPECT_TRUE(IsAllocAllowed(0, kOneMB));
2702 EXPECT_EQ(kOneMB, cache_impl_->GetTotalBuffersSize()); 2925 EXPECT_EQ(kOneMB, GetTotalBuffersSize());
2703 2926
2704 EXPECT_TRUE(cache_impl_->IsAllocAllowed(0, kOneMB)); 2927 EXPECT_TRUE(IsAllocAllowed(0, kOneMB));
2705 EXPECT_EQ(kOneMB * 2, cache_impl_->GetTotalBuffersSize()); 2928 EXPECT_EQ(kOneMB * 2, GetTotalBuffersSize());
2706 2929
2707 EXPECT_TRUE(cache_impl_->IsAllocAllowed(0, kOneMB)); 2930 EXPECT_TRUE(IsAllocAllowed(0, kOneMB));
2708 EXPECT_EQ(kOneMB * 3, cache_impl_->GetTotalBuffersSize()); 2931 EXPECT_EQ(kOneMB * 3, GetTotalBuffersSize());
2709 2932
2710 cache_impl_->BufferDeleted(kOneMB); 2933 BufferDeleted(kOneMB);
2711 EXPECT_EQ(kOneMB * 2, cache_impl_->GetTotalBuffersSize()); 2934 EXPECT_EQ(kOneMB * 2, GetTotalBuffersSize());
2712 2935
2713 // Check the upper limit. 2936 // Check the upper limit.
2714 EXPECT_FALSE(cache_impl_->IsAllocAllowed(0, 30 * kOneMB)); 2937 EXPECT_FALSE(IsAllocAllowed(0, 30 * kOneMB));
2715 2938
2716 for (int i = 0; i < 30; i++) 2939 for (int i = 0; i < 30; i++)
2717 cache_impl_->IsAllocAllowed(0, kOneMB); // Ignore the result. 2940 IsAllocAllowed(0, kOneMB); // Ignore the result.
2718 2941
2719 EXPECT_FALSE(cache_impl_->IsAllocAllowed(0, kOneMB)); 2942 EXPECT_FALSE(IsAllocAllowed(0, kOneMB));
2943 }
2944
2945 TEST_F(DiskCacheBackendTest, TotalBuffersSize2) {
2946 BackendTotalBuffersSize2();
2947 }
2948
2949 TEST_F(DiskCacheBackendTest, V3TotalBuffersSize2) {
2950 UseVersion3();
2951 BackendTotalBuffersSize2();
2720 } 2952 }
2721 2953
2722 // Tests that sharing of external files works and we are able to delete the 2954 // Tests that sharing of external files works and we are able to delete the
2723 // files when we need to. 2955 // files when we need to.
2724 TEST_F(DiskCacheBackendTest, FileSharing) { 2956 TEST_F(DiskCacheBackendTest, FileSharing) {
2725 InitCache(); 2957 InitCache();
2726 2958
2727 disk_cache::Addr address(0x80000001); 2959 disk_cache::Addr address(0x80000001);
2728 ASSERT_TRUE(cache_impl_->CreateExternalFile(&address)); 2960 ASSERT_TRUE(cache_impl_->CreateExternalFile(&address));
2729 base::FilePath name = cache_impl_->GetFileName(address); 2961 base::FilePath name = cache_impl_->GetFileName(address);
(...skipping 22 matching lines...) Expand all
2752 char buffer2[kSize]; 2984 char buffer2[kSize];
2753 memset(buffer1, 't', kSize); 2985 memset(buffer1, 't', kSize);
2754 memset(buffer2, 0, kSize); 2986 memset(buffer2, 0, kSize);
2755 EXPECT_TRUE(file->Write(buffer1, kSize, 0)); 2987 EXPECT_TRUE(file->Write(buffer1, kSize, 0));
2756 EXPECT_TRUE(file->Read(buffer2, kSize, 0)); 2988 EXPECT_TRUE(file->Read(buffer2, kSize, 0));
2757 EXPECT_EQ(0, memcmp(buffer1, buffer2, kSize)); 2989 EXPECT_EQ(0, memcmp(buffer1, buffer2, kSize));
2758 2990
2759 EXPECT_TRUE(disk_cache::DeleteCacheFile(name)); 2991 EXPECT_TRUE(disk_cache::DeleteCacheFile(name));
2760 } 2992 }
2761 2993
2762 TEST_F(DiskCacheBackendTest, UpdateRankForExternalCacheHit) { 2994 void DiskCacheBackendTest::BackendUpdateRankForExternalCacheHit() {
2763 InitCache(); 2995 InitCache();
2764 2996
2765 disk_cache::Entry* entry; 2997 disk_cache::Entry* entry;
2766 2998
2767 for (int i = 0; i < 2; ++i) { 2999 for (int i = 0; i < 2; ++i) {
2768 std::string key = base::StringPrintf("key%d", i); 3000 std::string key = base::StringPrintf("key%d", i);
2769 ASSERT_EQ(net::OK, CreateEntry(key, &entry)); 3001 ASSERT_EQ(net::OK, CreateEntry(key, &entry));
2770 entry->Close(); 3002 entry->Close();
3003 AddDelayForTest(70);
2771 } 3004 }
3005 FlushQueueForTest();
2772 3006
2773 // Ping the oldest entry. 3007 // Ping the oldest entry.
3008 SetTestMode();
2774 cache_->OnExternalCacheHit("key0"); 3009 cache_->OnExternalCacheHit("key0");
3010 FlushQueueForTest();
2775 3011
2776 TrimForTest(false); 3012 TrimForTest(false);
2777 3013
2778 // Make sure the older key remains. 3014 // Make sure the older key remains.
2779 EXPECT_EQ(1, cache_->GetEntryCount()); 3015 EXPECT_NE(net::OK, OpenEntry("key1", &entry));
2780 ASSERT_EQ(net::OK, OpenEntry("key0", &entry)); 3016 ASSERT_EQ(net::OK, OpenEntry("key0", &entry));
2781 entry->Close(); 3017 entry->Close();
2782 } 3018 }
2783 3019
3020 TEST_F(DiskCacheBackendTest, UpdateRankForExternalCacheHit) {
3021 BackendUpdateRankForExternalCacheHit();
3022 }
3023
3024 TEST_F(DiskCacheBackendTest, V3UpdateRankForExternalCacheHit) {
3025 UseVersion3();
3026 BackendUpdateRankForExternalCacheHit();
3027 }
3028
2784 TEST_F(DiskCacheBackendTest, ShaderCacheUpdateRankForExternalCacheHit) { 3029 TEST_F(DiskCacheBackendTest, ShaderCacheUpdateRankForExternalCacheHit) {
2785 SetCacheType(net::SHADER_CACHE); 3030 SetCacheType(net::SHADER_CACHE);
2786 InitCache(); 3031 BackendUpdateRankForExternalCacheHit();
3032 }
2787 3033
2788 disk_cache::Entry* entry; 3034 TEST_F(DiskCacheBackendTest, V3ShaderCacheUpdateRankForExternalCacheHit) {
2789 3035 UseVersion3();
2790 for (int i = 0; i < 2; ++i) { 3036 SetCacheType(net::SHADER_CACHE);
2791 std::string key = base::StringPrintf("key%d", i); 3037 BackendUpdateRankForExternalCacheHit();
2792 ASSERT_EQ(net::OK, CreateEntry(key, &entry));
2793 entry->Close();
2794 }
2795
2796 // Ping the oldest entry.
2797 cache_->OnExternalCacheHit("key0");
2798
2799 TrimForTest(false);
2800
2801 // Make sure the older key remains.
2802 EXPECT_EQ(1, cache_->GetEntryCount());
2803 ASSERT_EQ(net::OK, OpenEntry("key0", &entry));
2804 entry->Close();
2805 } 3038 }
2806 3039
2807 void DiskCacheBackendTest::TracingBackendBasics() { 3040 void DiskCacheBackendTest::TracingBackendBasics() {
2808 InitCache(); 3041 InitCache();
2809 cache_ = new disk_cache::TracingCacheBackend(cache_); 3042 cache_ = new disk_cache::TracingCacheBackend(cache_);
2810 cache_impl_ = NULL; 3043 cache_impl_ = NULL;
2811 EXPECT_EQ(net::DISK_CACHE, cache_->GetCacheType()); 3044 EXPECT_EQ(net::DISK_CACHE, cache_->GetCacheType());
2812 if (!simple_cache_mode_) { 3045 if (!simple_cache_mode_) {
2813 EXPECT_EQ(0, cache_->GetEntryCount()); 3046 EXPECT_EQ(0, cache_->GetEntryCount());
2814 } 3047 }
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
3020 NULL); 3253 NULL);
3021 cache->SetUnitTestMode(); 3254 cache->SetUnitTestMode();
3022 net::TestCompletionCallback cb; 3255 net::TestCompletionCallback cb;
3023 int rv = cache->Init(cb.callback()); 3256 int rv = cache->Init(cb.callback());
3024 EXPECT_NE(net::OK, cb.GetResult(rv)); 3257 EXPECT_NE(net::OK, cb.GetResult(rv));
3025 delete cache; 3258 delete cache;
3026 DisableIntegrityCheck(); 3259 DisableIntegrityCheck();
3027 } 3260 }
3028 3261
3029 #endif // !defined(OS_WIN) 3262 #endif // !defined(OS_WIN)
OLDNEW
« no previous file with comments | « net/disk_cache/backend_impl.cc ('k') | net/disk_cache/block_files.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698