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

Unified Diff: net/disk_cache/backend_unittest.cc

Issue 2556363003: Refactor cache counting into a separate helper class (Closed)
Patch Set: extract cache_test_util and fixes Created 4 years 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
Index: net/disk_cache/backend_unittest.cc
diff --git a/net/disk_cache/backend_unittest.cc b/net/disk_cache/backend_unittest.cc
index e92dd9b2f59ce8d07ee293ce6e536c16402ec1ce..6c0ad6cc7b2c90ed0d250b9568672e26d4c3c888 100644
--- a/net/disk_cache/backend_unittest.cc
+++ b/net/disk_cache/backend_unittest.cc
@@ -1805,6 +1805,9 @@ void DiskCacheBackendTest::BackendCalculateSizeOfAllEntries() {
// sizes 0, 1, ..., count - 1 bytes.
std::set<std::string> key_pool;
CreateSetOfRandomEntries(&key_pool);
+ // Keep track of the sum of the individual entry sizes and check that it is
+ // consistent with CalculateSizeOfAllEntries().
+ int64_t sum_entry_size = 0;
int count = 0;
for (std::string key : key_pool) {
@@ -1816,6 +1819,7 @@ void DiskCacheBackendTest::BackendCalculateSizeOfAllEntries() {
disk_cache::Entry* entry;
ASSERT_THAT(OpenEntry(key, &entry), IsOk());
ASSERT_EQ(count, WriteData(entry, count % 2, 0, buffer.get(), count, true));
+ sum_entry_size += entry->GetEntrySize();
entry->Close();
++count;
@@ -1827,6 +1831,7 @@ void DiskCacheBackendTest::BackendCalculateSizeOfAllEntries() {
for (std::string key : key_pool)
total_metadata_size += GetEntryMetadataSize(key);
EXPECT_EQ((count - 1) * count / 2 + total_metadata_size, result);
+ EXPECT_EQ(sum_entry_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.
@@ -1840,6 +1845,8 @@ void DiskCacheBackendTest::BackendCalculateSizeOfAllEntries() {
ASSERT_THAT(CreateEntry(key, &entry), IsOk());
ASSERT_EQ(last_entry_size,
WriteData(entry, 0, 0, buffer.get(), last_entry_size, true));
+ ASSERT_EQ(last_entry_size + GetEntryMetadataSize(key),
+ entry->GetEntrySize());
entry->Close();
int new_result = CalculateSizeOfAllEntries();
@@ -1848,6 +1855,7 @@ void DiskCacheBackendTest::BackendCalculateSizeOfAllEntries() {
DoomEntry(key);
new_result = CalculateSizeOfAllEntries();
EXPECT_EQ(result, new_result);
+ EXPECT_EQ(sum_entry_size, new_result);
}
// After dooming the entries, the size should be back to zero.

Powered by Google App Engine
This is Rietveld 408576698