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 8833729f6965ce3a78f837a9e08d97f08105d3a5..6a27e24da7d1ea43d721a4f662ed6a320510addd 100644 |
| --- a/net/disk_cache/backend_unittest.cc |
| +++ b/net/disk_cache/backend_unittest.cc |
| @@ -89,6 +89,10 @@ class DiskCacheBackendTest : public DiskCacheTestWithCache { |
| std::set<std::string>* keys_to_match, |
| size_t* count); |
| + // Computes the expected size of entry metadata, i.e. the total size without |
| + // the actual data stored. This depends only on the entry's |key| size. |
| + int GetEntryMetadataSize(std::string key); |
| + |
| // Actual tests: |
| void BackendBasics(); |
| void BackendKeying(); |
| @@ -282,6 +286,18 @@ bool DiskCacheBackendTest::EnumerateAndMatchKeys( |
| return true; |
| } |
| +int DiskCacheBackendTest::GetEntryMetadataSize(std::string key) { |
| + // For blockfile and memory backends, it is just the key size. |
| + if (!simple_cache_mode_) |
| + return key.size(); |
| + |
| + // For the simple cache, we must add the file header and EOF, and that for |
| + // every stream. |
| + return disk_cache::kSimpleEntryStreamCount * |
| + (sizeof(disk_cache::SimpleFileHeader) + |
| + sizeof(disk_cache::SimpleFileEOF) + key.size()); |
| +} |
| + |
| void DiskCacheBackendTest::BackendBasics() { |
| InitCache(); |
| disk_cache::Entry *entry1 = NULL, *entry2 = NULL; |
| @@ -1679,12 +1695,7 @@ void DiskCacheBackendTest::BackendCalculateSizeOfAllEntries() { |
| InitCache(); |
| // The cache is initially empty. |
| - if (memory_only_ || simple_cache_mode_) { |
| - // TODO(msramek): Implement. |
| - EXPECT_EQ(net::ERR_NOT_IMPLEMENTED, CalculateSizeOfAllEntries()); |
| - } else { |
| - EXPECT_EQ(0, CalculateSizeOfAllEntries()); |
| - } |
| + EXPECT_EQ(0, CalculateSizeOfAllEntries()); |
| // Generate random entries and populate them with data of respective |
| // sizes 0, 1, ..., count - 1 bytes. |
| @@ -1696,11 +1707,15 @@ void DiskCacheBackendTest::BackendCalculateSizeOfAllEntries() { |
| std::string data(count, ' '); |
| scoped_refptr<net::StringIOBuffer> buffer = new net::StringIOBuffer(data); |
| - // Alternate between writing to the first and second stream to test that |
| - // we are not taking just the first stream into account. |
| + // Write only to the stream 0. This is because writing to the stream 1 |
|
pasko
2015/10/15 11:55:54
I would prefer if we did not regress in our test c
msramek
2015/10/16 13:32:37
I spent some more time trying to find out if I can
pasko
2015/10/16 14:03:32
yay! Thanks a lot! I could not really find a ratio
pasko
2015/10/16 14:24:04
tiny correction: we actually measured that it's he
msramek
2015/10/16 14:35:15
Ok, then I can revert to Patchset 1 and just add S
pasko
2015/10/16 14:43:59
you would not loose any important coverage in size
|
| + // in simple cache triggers a write to the stream 0 as well. This will |
| + // happen asynchronously, because |DiskCacheTestWithCache::WriteData| |
| + // only waits for the callback from the first write operation, and possibly |
| + // later than our call to |CalculateSizeOfAllEntries|. |
| + // TODO(msramek): Investigate how to write synchronously to other streams. |
| disk_cache::Entry* entry; |
| ASSERT_EQ(net::OK, OpenEntry(key, &entry)); |
| - ASSERT_EQ(count, WriteData(entry, count % 2, 0, buffer.get(), count, true)); |
| + ASSERT_EQ(count, WriteData(entry, 0, 0, buffer.get(), count, true)); |
| entry->Close(); |
| ++count; |
| @@ -1708,16 +1723,10 @@ void DiskCacheBackendTest::BackendCalculateSizeOfAllEntries() { |
| // The resulting size should be (0 + 1 + ... + count - 1) plus keys. |
| int result = CalculateSizeOfAllEntries(); |
| - if (memory_only_ || simple_cache_mode_) { |
| - // TODO(msramek): Implement. |
| - EXPECT_EQ(net::ERR_NOT_IMPLEMENTED, result); |
| - } else { |
| - int total_key_size = 0; |
| - for (std::string key : key_pool) |
| - total_key_size += key.size(); |
| - |
| - EXPECT_EQ((count - 1) * count / 2 + total_key_size, result); |
| - } |
| + 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); |
| // Add another entry and test if the size is updated. Then remove it and test |
| // if the size is back to original value. |
| @@ -1734,32 +1743,16 @@ void DiskCacheBackendTest::BackendCalculateSizeOfAllEntries() { |
| entry->Close(); |
| int new_result = CalculateSizeOfAllEntries(); |
| - if (memory_only_ || simple_cache_mode_) { |
| - // TODO(msramek): Implement. |
| - EXPECT_EQ(net::ERR_NOT_IMPLEMENTED, new_result); |
| - } else { |
| - EXPECT_EQ(result + last_entry_size + static_cast<int>(key.size()), |
| - new_result); |
| - } |
| + EXPECT_EQ(result + last_entry_size + GetEntryMetadataSize(key), new_result); |
| DoomEntry(key); |
| new_result = CalculateSizeOfAllEntries(); |
| - if (memory_only_ || simple_cache_mode_) { |
| - // TODO(msramek): Implement. |
| - EXPECT_EQ(net::ERR_NOT_IMPLEMENTED, new_result); |
| - } else { |
| - EXPECT_EQ(result, new_result); |
| - } |
| + EXPECT_EQ(result, new_result); |
| } |
| // After dooming the entries, the size should be back to zero. |
| ASSERT_EQ(net::OK, DoomAllEntries()); |
| - if (memory_only_ || simple_cache_mode_) { |
| - // TODO(msramek): Implement. |
| - EXPECT_EQ(net::ERR_NOT_IMPLEMENTED, CalculateSizeOfAllEntries()); |
| - } else { |
| - EXPECT_EQ(0, CalculateSizeOfAllEntries()); |
| - } |
| + EXPECT_EQ(0, CalculateSizeOfAllEntries()); |
| } |
| TEST_F(DiskCacheBackendTest, CalculateSizeOfAllEntries) { |