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

Unified Diff: net/disk_cache/backend_unittest.cc

Issue 2957133002: Implement in-memory byte hints in SimpleCache (Closed)
Patch Set: Adjust to the interface's naming change. Created 3 years, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | net/disk_cache/simple/simple_backend_impl.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/disk_cache/backend_unittest.cc
diff --git a/net/disk_cache/backend_unittest.cc b/net/disk_cache/backend_unittest.cc
index 8beb1d76cbf59ffb3afd1a7353ded9d70afa8393..27594e2172b145b832bc99286d783703d37c2f39 100644
--- a/net/disk_cache/backend_unittest.cc
+++ b/net/disk_cache/backend_unittest.cc
@@ -109,6 +109,10 @@ class DiskCacheBackendTest : public DiskCacheTestWithCache {
// the actual data stored. This depends only on the entry's |key| size.
int GetEntryMetadataSize(std::string key);
+ // The Simple Backend only tracks the approximate sizes of entries. This
+ // rounds the exact size appropriately.
+ int GetRoundedSize(int exact_size);
+
// Actual tests:
void BackendBasics();
void BackendKeying();
@@ -322,6 +326,13 @@ int DiskCacheBackendTest::GetEntryMetadataSize(std::string key) {
sizeof(disk_cache::SimpleFileEOF) + key.size());
}
+int DiskCacheBackendTest::GetRoundedSize(int exact_size) {
+ if (!simple_cache_mode_)
+ return exact_size;
+
+ return (exact_size + 255) & 0xFFFFFF00;
+}
+
void DiskCacheBackendTest::BackendBasics() {
InitCache();
disk_cache::Entry *entry1 = NULL, *entry2 = NULL;
@@ -2009,6 +2020,7 @@ void DiskCacheBackendTest::BackendCalculateSizeOfAllEntries() {
CreateSetOfRandomEntries(&key_pool);
int count = 0;
+ int total_size = 0;
for (std::string key : key_pool) {
std::string data(count, ' ');
scoped_refptr<net::StringIOBuffer> buffer = new net::StringIOBuffer(data);
@@ -2020,15 +2032,12 @@ void DiskCacheBackendTest::BackendCalculateSizeOfAllEntries() {
ASSERT_EQ(count, WriteData(entry, count % 2, 0, buffer.get(), count, true));
entry->Close();
+ total_size += GetRoundedSize(count + GetEntryMetadataSize(key));
++count;
}
- // The resulting size should be (0 + 1 + ... + count - 1) plus keys.
int result = CalculateSizeOfAllEntries();
- int total_metadata_size = 0;
- for (std::string key : key_pool)
- total_metadata_size += GetEntryMetadataSize(key);
- EXPECT_EQ((count - 1) * count / 2 + total_metadata_size, result);
+ EXPECT_EQ(total_size, result);
// Add another entry and test if the size is updated. Then remove it and test
// if the size is back to original value.
@@ -2045,7 +2054,9 @@ void DiskCacheBackendTest::BackendCalculateSizeOfAllEntries() {
entry->Close();
int new_result = CalculateSizeOfAllEntries();
- EXPECT_EQ(result + last_entry_size + GetEntryMetadataSize(key), new_result);
+ EXPECT_EQ(
+ result + GetRoundedSize(last_entry_size + GetEntryMetadataSize(key)),
+ new_result);
DoomEntry(key);
new_result = CalculateSizeOfAllEntries();
@@ -2099,9 +2110,9 @@ void DiskCacheBackendTest::BackendCalculateSizeOfEntriesBetween() {
AddDelay();
Time end = Time::Now();
- int size_1 = GetEntryMetadataSize("first");
- int size_2 = GetEntryMetadataSize("second");
- int size_3 = GetEntryMetadataSize("third_entry");
+ int size_1 = GetRoundedSize(GetEntryMetadataSize("first"));
+ int size_2 = GetRoundedSize(GetEntryMetadataSize("second"));
+ int size_3 = GetRoundedSize(GetEntryMetadataSize("third_entry"));
ASSERT_EQ(3, cache_->GetEntryCount());
ASSERT_EQ(CalculateSizeOfAllEntries(),
« no previous file with comments | « no previous file | net/disk_cache/simple/simple_backend_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698