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..b4b1bca751f076faa3daa9c2995952f9ce68af93 100644 |
| --- a/net/disk_cache/backend_unittest.cc |
| +++ b/net/disk_cache/backend_unittest.cc |
| @@ -1679,12 +1679,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. |
| @@ -1697,10 +1692,15 @@ void DiskCacheBackendTest::BackendCalculateSizeOfAllEntries() { |
| 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. |
| + // we are not taking just the first stream into account. For convenience, |
| + // the last written stream should be 0. This is because writing to |
| + // the stream 1 in simple cache triggers a write to the stream 0 as well. |
|
pasko
2015/10/09 15:52:03
This is subtle. Will the stream 0 contain the chec
msramek
2015/10/13 09:45:06
So, I observed that writing to stream 1 triggers t
|
| + // This will happen asynchronously and possibly later than our call to |
| + // |CalculateSizeOfAllEntries|. |
| 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, (count + 1) % 2, 0, buffer.get(), count, true)); |
| entry->Close(); |
| ++count; |
| @@ -1708,16 +1708,20 @@ 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) |
| + int total_key_size = 0; |
| + for (std::string key : key_pool) { |
| + if (!simple_cache_mode_) { |
| total_key_size += key.size(); |
| - |
| - EXPECT_EQ((count - 1) * count / 2 + total_key_size, result); |
| + } else { |
| + // In the case of simple cache, we must count the key size together with |
| + // the file headers, and that for each of the streams. |
| + total_key_size += disk_cache::kSimpleEntryStreamCount * ( |
| + sizeof(disk_cache::SimpleFileHeader) + |
| + sizeof(disk_cache::SimpleFileEOF) + |
| + key.size()); |
| + } |
| } |
| + EXPECT_EQ((count - 1) * count / 2 + total_key_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,9 +1738,15 @@ 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); |
| + if (simple_cache_mode_) { |
| + EXPECT_EQ( |
| + result + |
| + last_entry_size + |
| + static_cast<int>(disk_cache::kSimpleEntryStreamCount * ( |
| + sizeof(disk_cache::SimpleFileHeader) + |
| + sizeof(disk_cache::SimpleFileEOF) + |
| + key.size())), |
| + new_result); |
| } else { |
| EXPECT_EQ(result + last_entry_size + static_cast<int>(key.size()), |
| new_result); |
| @@ -1744,22 +1754,12 @@ void DiskCacheBackendTest::BackendCalculateSizeOfAllEntries() { |
| 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) { |