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

Side by Side Diff: net/disk_cache/entry_unittest.cc

Issue 2591743002: Implement a method to get the total size of a cache entry (Closed)
Patch Set: rebase Created 3 years, 11 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 unified diff | Download patch
« no previous file with comments | « net/disk_cache/disk_cache.h ('k') | net/disk_cache/memory/mem_entry_impl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <utility> 5 #include <utility>
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/files/file.h" 9 #include "base/files/file.h"
10 #include "base/files/file_util.h" 10 #include "base/files/file_util.h"
(...skipping 3689 matching lines...) Expand 10 before | Expand all | Expand 10 after
3700 disk_cache::Entry* entry = NULL; 3700 disk_cache::Entry* entry = NULL;
3701 const std::string key("the key"); 3701 const std::string key("the key");
3702 const int kSize = 100; 3702 const int kSize = 100;
3703 scoped_refptr<net::IOBuffer> buffer(new net::IOBuffer(kSize)); 3703 scoped_refptr<net::IOBuffer> buffer(new net::IOBuffer(kSize));
3704 scoped_refptr<net::IOBuffer> buffer_read(new net::IOBuffer(kSize)); 3704 scoped_refptr<net::IOBuffer> buffer_read(new net::IOBuffer(kSize));
3705 CacheTestFillBuffer(buffer->data(), kSize, false); 3705 CacheTestFillBuffer(buffer->data(), kSize, false);
3706 3706
3707 ASSERT_THAT(CreateEntry(key, &entry), IsOk()); 3707 ASSERT_THAT(CreateEntry(key, &entry), IsOk());
3708 EXPECT_TRUE(entry); 3708 EXPECT_TRUE(entry);
3709 3709
3710 long initial_entry_size = entry->GetEntrySize();
3711 DCHECK_GE(initial_entry_size, static_cast<long>(key.size()));
3712
3710 // Write something into stream0. 3713 // Write something into stream0.
3711 EXPECT_EQ(kSize, WriteData(entry, 0, 0, buffer.get(), kSize, false)); 3714 EXPECT_EQ(kSize, WriteData(entry, 0, 0, buffer.get(), kSize, false));
3712 EXPECT_EQ(kSize, ReadData(entry, 0, 0, buffer_read.get(), kSize)); 3715 EXPECT_EQ(kSize, ReadData(entry, 0, 0, buffer_read.get(), kSize));
3713 EXPECT_EQ(0, memcmp(buffer->data(), buffer_read->data(), kSize)); 3716 EXPECT_EQ(0, memcmp(buffer->data(), buffer_read->data(), kSize));
3717 DCHECK_EQ(initial_entry_size + kSize, entry->GetEntrySize());
3714 entry->Close(); 3718 entry->Close();
3715 3719
3716 // Extend stream1. 3720 // Extend stream1.
3717 ASSERT_THAT(OpenEntry(key, &entry), IsOk()); 3721 ASSERT_THAT(OpenEntry(key, &entry), IsOk());
3718 int stream1_size = 100; 3722 int stream1_size = 100;
3719 EXPECT_EQ(0, WriteData(entry, 1, stream1_size, buffer.get(), 0, false)); 3723 EXPECT_EQ(0, WriteData(entry, 1, stream1_size, buffer.get(), 0, false));
3720 EXPECT_EQ(stream1_size, entry->GetDataSize(1)); 3724 EXPECT_EQ(stream1_size, entry->GetDataSize(1));
3725 DCHECK_EQ(initial_entry_size + kSize + stream1_size, entry->GetEntrySize());
3721 entry->Close(); 3726 entry->Close();
3722 3727
3723 // Check that stream0 data has not been modified and that the EOF record for 3728 // Check that stream0 data has not been modified and that the EOF record for
3724 // stream 0 contains a crc. 3729 // stream 0 contains a crc.
3725 // The entry needs to be reopened before checking the crc: Open will perform 3730 // The entry needs to be reopened before checking the crc: Open will perform
3726 // the synchronization with the previous Close. This ensures the EOF records 3731 // the synchronization with the previous Close. This ensures the EOF records
3727 // have been written to disk before we attempt to read them independently. 3732 // have been written to disk before we attempt to read them independently.
3728 ASSERT_THAT(OpenEntry(key, &entry), IsOk()); 3733 ASSERT_THAT(OpenEntry(key, &entry), IsOk());
3729 base::FilePath entry_file0_path = cache_path_.AppendASCII( 3734 base::FilePath entry_file0_path = cache_path_.AppendASCII(
3730 disk_cache::simple_util::GetFilenameFromKeyAndFileIndex(key, 0)); 3735 disk_cache::simple_util::GetFilenameFromKeyAndFileIndex(key, 0));
(...skipping 15 matching lines...) Expand all
3746 disk_cache::SimpleFileEOF::FLAG_HAS_CRC32); 3751 disk_cache::SimpleFileEOF::FLAG_HAS_CRC32);
3747 3752
3748 buffer_read = new net::IOBuffer(kSize); 3753 buffer_read = new net::IOBuffer(kSize);
3749 EXPECT_EQ(kSize, ReadData(entry, 0, 0, buffer_read.get(), kSize)); 3754 EXPECT_EQ(kSize, ReadData(entry, 0, 0, buffer_read.get(), kSize));
3750 EXPECT_EQ(0, memcmp(buffer->data(), buffer_read->data(), kSize)); 3755 EXPECT_EQ(0, memcmp(buffer->data(), buffer_read->data(), kSize));
3751 3756
3752 // Shrink stream1. 3757 // Shrink stream1.
3753 stream1_size = 50; 3758 stream1_size = 50;
3754 EXPECT_EQ(0, WriteData(entry, 1, stream1_size, buffer.get(), 0, true)); 3759 EXPECT_EQ(0, WriteData(entry, 1, stream1_size, buffer.get(), 0, true));
3755 EXPECT_EQ(stream1_size, entry->GetDataSize(1)); 3760 EXPECT_EQ(stream1_size, entry->GetDataSize(1));
3761 DCHECK_EQ(initial_entry_size + kSize + stream1_size, entry->GetEntrySize());
3756 entry->Close(); 3762 entry->Close();
3757 3763
3758 // Check that stream0 data has not been modified. 3764 // Check that stream0 data has not been modified.
3759 buffer_read = new net::IOBuffer(kSize); 3765 buffer_read = new net::IOBuffer(kSize);
3760 ASSERT_THAT(OpenEntry(key, &entry), IsOk()); 3766 ASSERT_THAT(OpenEntry(key, &entry), IsOk());
3761 EXPECT_EQ(kSize, ReadData(entry, 0, 0, buffer_read.get(), kSize)); 3767 EXPECT_EQ(kSize, ReadData(entry, 0, 0, buffer_read.get(), kSize));
3762 EXPECT_EQ(0, memcmp(buffer->data(), buffer_read->data(), kSize)); 3768 EXPECT_EQ(0, memcmp(buffer->data(), buffer_read->data(), kSize));
3763 entry->Close(); 3769 entry->Close();
3764 entry = NULL; 3770 entry = NULL;
3765 } 3771 }
(...skipping 519 matching lines...) Expand 10 before | Expand all | Expand 10 after
4285 entry->Close(); 4291 entry->Close();
4286 4292
4287 base::RunLoop().RunUntilIdle(); 4293 base::RunLoop().RunUntilIdle();
4288 disk_cache::SimpleBackendImpl::FlushWorkerPoolForTesting(); 4294 disk_cache::SimpleBackendImpl::FlushWorkerPoolForTesting();
4289 base::RunLoop().RunUntilIdle(); 4295 base::RunLoop().RunUntilIdle();
4290 4296
4291 EXPECT_TRUE( 4297 EXPECT_TRUE(
4292 disk_cache::simple_util::CorruptStream0LengthFromEntry(key, cache_path_)); 4298 disk_cache::simple_util::CorruptStream0LengthFromEntry(key, cache_path_));
4293 EXPECT_NE(net::OK, OpenEntry(key, &entry)); 4299 EXPECT_NE(net::OK, OpenEntry(key, &entry));
4294 } 4300 }
OLDNEW
« no previous file with comments | « net/disk_cache/disk_cache.h ('k') | net/disk_cache/memory/mem_entry_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698