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

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

Issue 6967006: Disk cache: Make sure the list of unused entries is not (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Fix stupid gcc warning Created 9 years, 7 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 | « no previous file | net/disk_cache/disk_cache_test_base.h » ('j') | net/disk_cache/eviction.h » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 476 matching lines...) Expand 10 before | Expand all | Expand 10 after
487 } 487 }
488 488
489 TEST_F(DiskCacheBackendTest, AppCacheLoad) { 489 TEST_F(DiskCacheBackendTest, AppCacheLoad) {
490 SetCacheType(net::APP_CACHE); 490 SetCacheType(net::APP_CACHE);
491 // Work with a tiny index table (16 entries) 491 // Work with a tiny index table (16 entries)
492 SetMask(0xf); 492 SetMask(0xf);
493 SetMaxSize(0x100000); 493 SetMaxSize(0x100000);
494 BackendLoad(); 494 BackendLoad();
495 } 495 }
496 496
497 TEST_F(DiskCacheBackendTest, NewEvictionTrim) {
498 SetNewEviction();
499 SetDirectMode();
500 InitCache();
501
502 disk_cache::Entry* entry;
503 for (int i = 0; i < 100; i++) {
504 std::string name(StringPrintf("Key %d", i));
505 ASSERT_EQ(net::OK, CreateEntry(name, &entry));
506 entry->Close();
507 if (i < 90) {
508 // Entries 0 to 89 are in list 1; 90 to 99 are in list 0.
509 ASSERT_EQ(net::OK, OpenEntry(name, &entry));
510 entry->Close();
511 }
512 }
513
514 // The first eviction must come from list 1 (10% limit), the second must come
515 // from list 0.
516 TrimForTest(false);
517 EXPECT_NE(net::OK, OpenEntry("Key 0", &entry));
518 TrimForTest(false);
519 EXPECT_NE(net::OK, OpenEntry("Key 90", &entry));
520
521 // Double check that we still have the list tails.
522 ASSERT_EQ(net::OK, OpenEntry("Key 1", &entry));
523 entry->Close();
524 ASSERT_EQ(net::OK, OpenEntry("Key 91", &entry));
525 entry->Close();
526 }
527
497 // Before looking for invalid entries, let's check a valid entry. 528 // Before looking for invalid entries, let's check a valid entry.
498 void DiskCacheBackendTest::BackendValidEntry() { 529 void DiskCacheBackendTest::BackendValidEntry() {
499 SetDirectMode(); 530 SetDirectMode();
500 InitCache(); 531 InitCache();
501 532
502 std::string key("Some key"); 533 std::string key("Some key");
503 disk_cache::Entry* entry; 534 disk_cache::Entry* entry;
504 ASSERT_EQ(net::OK, CreateEntry(key, &entry)); 535 ASSERT_EQ(net::OK, CreateEntry(key, &entry));
505 536
506 const int kSize = 50; 537 const int kSize = 50;
(...skipping 1570 matching lines...) Expand 10 before | Expand all | Expand 10 after
2077 char buffer1[kSize]; 2108 char buffer1[kSize];
2078 char buffer2[kSize]; 2109 char buffer2[kSize];
2079 memset(buffer1, 't', kSize); 2110 memset(buffer1, 't', kSize);
2080 memset(buffer2, 0, kSize); 2111 memset(buffer2, 0, kSize);
2081 EXPECT_TRUE(file->Write(buffer1, kSize, 0)); 2112 EXPECT_TRUE(file->Write(buffer1, kSize, 0));
2082 EXPECT_TRUE(file->Read(buffer2, kSize, 0)); 2113 EXPECT_TRUE(file->Read(buffer2, kSize, 0));
2083 EXPECT_EQ(0, memcmp(buffer1, buffer2, kSize)); 2114 EXPECT_EQ(0, memcmp(buffer1, buffer2, kSize));
2084 2115
2085 EXPECT_TRUE(disk_cache::DeleteCacheFile(name)); 2116 EXPECT_TRUE(disk_cache::DeleteCacheFile(name));
2086 } 2117 }
OLDNEW
« no previous file with comments | « no previous file | net/disk_cache/disk_cache_test_base.h » ('j') | net/disk_cache/eviction.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698