Chromium Code Reviews| Index: net/disk_cache/backend_unittest.cc |
| diff --git a/net/disk_cache/backend_unittest.cc b/net/disk_cache/backend_unittest.cc |
| index fbf8689d29b997403ea8d7bfd63ab11dc4f32922..c20aca646bf1c9389ad56667a2598839f0ea9f36 100644 |
| --- a/net/disk_cache/backend_unittest.cc |
| +++ b/net/disk_cache/backend_unittest.cc |
| @@ -106,6 +106,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 of approximate size. This rounds the exact |
|
pasko
2017/06/29 16:31:49
nit: "tracks size approximately"?
gavinp
2017/08/04 18:42:54
How about: "The Simple Backend only tracks the app
Maks Orlovich
2017/08/23 19:29:05
Done.
|
| + // size appropriately. |
| + int GetRoundedSize(int exact_size); |
| + |
| // Actual tests: |
| void BackendBasics(); |
| void BackendKeying(); |
| @@ -319,6 +323,13 @@ int DiskCacheBackendTest::GetEntryMetadataSize(std::string key) { |
| sizeof(disk_cache::SimpleFileEOF) + key.size()); |
| } |
| +int DiskCacheBackendTest::GetRoundedSize(int exact_size) { |
|
pasko
2017/06/29 16:31:49
should this be a method of cache backend? can be w
Maks Orlovich
2017/08/23 19:29:05
Hmm, maybe. Feels better wrt to abstraction bounda
|
| + if (!simple_cache_mode_) |
| + return exact_size; |
| + |
| + return (exact_size + 255) & 0xFFFFFF00; |
| +} |
| + |
| void DiskCacheBackendTest::BackendBasics() { |
| InitCache(); |
| disk_cache::Entry *entry1 = NULL, *entry2 = NULL; |
| @@ -1879,6 +1890,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); |
| @@ -1890,15 +1902,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. |
| @@ -1915,7 +1924,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(); |
| @@ -1969,9 +1980,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(), |