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

Unified Diff: net/disk_cache/simple/simple_index_file_unittest.cc

Issue 17265007: Unlink corrupt SimpleCache index files immediately after load. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: narrowest! Created 7 years, 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/disk_cache/simple/simple_index_file.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/disk_cache/simple/simple_index_file_unittest.cc
diff --git a/net/disk_cache/simple/simple_index_file_unittest.cc b/net/disk_cache/simple/simple_index_file_unittest.cc
index 76ecd91726c99f90d3091d1da0897d74e228ff34..caf3f402bb944a83726360f5df7611f9ac5b91d7 100644
--- a/net/disk_cache/simple/simple_index_file_unittest.cc
+++ b/net/disk_cache/simple/simple_index_file_unittest.cc
@@ -149,6 +149,58 @@ TEST_F(SimpleIndexFileTest, IsIndexFileStale) {
EXPECT_TRUE(SimpleIndexFile::IsIndexFileStale(index_path));
}
+TEST_F(SimpleIndexFileTest, WriteThenLoadIndex) {
+ base::ScopedTempDir temp_dir;
+ ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
+
+ const base::FilePath index_path =
+ temp_dir.path().AppendASCII(SimpleIndexFile::kIndexFileName);
+ EXPECT_TRUE(SimpleIndexFile::IsIndexFileStale(index_path));
+
+ SimpleIndex::EntrySet entries;
+ static const uint64 kHashes[] = { 11, 22, 33 };
+ static const size_t kNumHashes = arraysize(kHashes);
+ EntryMetadata metadata_entries[kNumHashes];
+ for (size_t i = 0; i < kNumHashes; ++i) {
+ uint64 hash = kHashes[i];
+ metadata_entries[i] =
+ EntryMetadata(Time::FromInternalValue(hash), hash);
+ SimpleIndex::InsertInEntrySet(hash, metadata_entries[i], &entries);
+ }
+
+ const uint64 kCacheSize = 456U;
+ {
+ SimpleIndexFile simple_index_file(base::MessageLoopProxy::current(),
+ base::MessageLoopProxy::current(),
+ temp_dir.path());
+ simple_index_file.WriteToDisk(entries, kCacheSize,
+ base::TimeTicks(), false);
+ base::RunLoop().RunUntilIdle();
+ EXPECT_TRUE(file_util::PathExists(index_path));
+ }
+
+ SimpleIndexFile simple_index_file(base::MessageLoopProxy::current(),
+ base::MessageLoopProxy::current(),
+ temp_dir.path());
+ SimpleIndexFile::IndexCompletionCallback callback =
+ base::Bind(&SimpleIndexFileTest::IndexCompletionCallback,
+ base::Unretained(this));
+ simple_index_file.LoadIndexEntries(base::MessageLoopProxy::current(),
+ callback);
+ base::RunLoop().RunUntilIdle();
+
+ EXPECT_TRUE(file_util::PathExists(index_path));
+ ASSERT_TRUE(callback_result());
+ EXPECT_FALSE(callback_result()->force_index_flush);
+ const SimpleIndex::EntrySet* read_entries =
+ callback_result()->index_file_entries.get();
+ ASSERT_TRUE(read_entries);
+
+ EXPECT_EQ(kNumHashes, read_entries->size());
+ for (size_t i = 0; i < kNumHashes; ++i)
+ EXPECT_EQ(1U, read_entries->count(kHashes[i]));
+}
+
TEST_F(SimpleIndexFileTest, IsIndexFileCorrupt) {
base::ScopedTempDir temp_dir;
ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
@@ -175,6 +227,7 @@ TEST_F(SimpleIndexFileTest, IsIndexFileCorrupt) {
callback);
base::RunLoop().RunUntilIdle();
+ EXPECT_FALSE(file_util::PathExists(index_path));
ASSERT_TRUE(callback_result());
EXPECT_TRUE(callback_result()->index_file_entries);
EXPECT_TRUE(callback_result()->force_index_flush);
« no previous file with comments | « net/disk_cache/simple/simple_index_file.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698