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

Unified Diff: net/disk_cache/entry_unittest.cc

Issue 1977863003: SimpleCache: open with fewer seeks. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@open-speeder-macbetter
Patch Set: add unit tests Created 4 years, 7 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
Index: net/disk_cache/entry_unittest.cc
diff --git a/net/disk_cache/entry_unittest.cc b/net/disk_cache/entry_unittest.cc
index 3612fab63bfd632254448f65b20c6e242dbc77af..4260f81d403eb71943ae2e193bb3dc81d9b576ba 100644
--- a/net/disk_cache/entry_unittest.cc
+++ b/net/disk_cache/entry_unittest.cc
@@ -9,6 +9,7 @@
#include "base/files/file.h"
#include "base/files/file_util.h"
#include "base/macros.h"
+#include "base/run_loop.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
#include "base/threading/platform_thread.h"
@@ -21,6 +22,7 @@
#include "net/disk_cache/disk_cache_test_base.h"
#include "net/disk_cache/disk_cache_test_util.h"
#include "net/disk_cache/memory/mem_entry_impl.h"
+#include "net/disk_cache/simple/simple_backend_impl.h"
#include "net/disk_cache/simple/simple_entry_format.h"
#include "net/disk_cache/simple/simple_entry_impl.h"
#include "net/disk_cache/simple/simple_synchronous_entry.h"
@@ -2708,7 +2710,7 @@ TEST_F(DiskCacheEntryTest, SimpleCacheNoEOF) {
SetSimpleCacheMode();
InitCache();
- const char key[] = "the first key";
+ const std::string key("the first key");
disk_cache::Entry* entry = NULL;
ASSERT_EQ(net::OK, CreateEntry(key, &entry));
@@ -2728,9 +2730,8 @@ TEST_F(DiskCacheEntryTest, SimpleCacheNoEOF) {
int kTruncationBytes = -static_cast<int>(sizeof(disk_cache::SimpleFileEOF));
const base::FilePath entry_path = cache_path_.AppendASCII(
disk_cache::simple_util::GetFilenameFromKeyAndFileIndex(key, 0));
- const int64_t invalid_size =
- disk_cache::simple_util::GetFileSizeFromKeyAndDataSize(key,
- kTruncationBytes);
+ const int64_t invalid_size = disk_cache::simple_util::GetFileSizeFromDataSize(
+ key.size(), kTruncationBytes);
EXPECT_TRUE(TruncatePath(entry_path, invalid_size));
EXPECT_EQ(net::ERR_FAILED, OpenEntry(key, &entry));
DisableIntegrityCheck();
@@ -3688,7 +3689,7 @@ TEST_F(DiskCacheEntryTest, SimpleCacheStream1SizeChanges) {
SetSimpleCacheMode();
InitCache();
disk_cache::Entry* entry = NULL;
- const char key[] = "the key";
+ const std::string key("the key");
const int kSize = 100;
scoped_refptr<net::IOBuffer> buffer(new net::IOBuffer(kSize));
scoped_refptr<net::IOBuffer> buffer_read(new net::IOBuffer(kSize));
@@ -3726,7 +3727,7 @@ TEST_F(DiskCacheEntryTest, SimpleCacheStream1SizeChanges) {
int sparse_data_size = 0;
disk_cache::SimpleEntryStat entry_stat(
base::Time::Now(), base::Time::Now(), data_size, sparse_data_size);
- int eof_offset = entry_stat.GetEOFOffsetInFile(key, 0);
+ int eof_offset = entry_stat.GetEOFOffsetInFile(key.size(), 0);
disk_cache::SimpleFileEOF eof_record;
ASSERT_EQ(static_cast<int>(sizeof(eof_record)),
entry_file0.Read(eof_offset, reinterpret_cast<char*>(&eof_record),
@@ -4165,3 +4166,39 @@ TEST_F(DiskCacheEntryTest, SimpleCacheTruncateLargeSparseFile) {
entry->Close();
}
+
+TEST_F(DiskCacheEntryTest, SimpleCacheReadWithoutKeySHA256) {
+ // This test runs as APP_CACHE to make operations more synchronous.
+ SetCacheType(net::APP_CACHE);
+ SetSimpleCacheMode();
+ InitCache();
+ disk_cache::Entry* entry;
+ std::string key("a key");
+ ASSERT_EQ(net::OK, CreateEntry(key, &entry));
+ entry->Close();
+
+ disk_cache::SimpleBackendImpl::FlushWorkerPoolForTesting();
+ base::RunLoop().RunUntilIdle();
+
+ EXPECT_TRUE(
+ disk_cache::simple_util::RemoveKeySHA256FromEntry(key, cache_path_));
+ EXPECT_EQ(net::OK, OpenEntry(key, &entry));
Randy Smith (Not in Mondays) 2016/05/19 19:38:50 Confirm contents ok? (Probably need to write some
gavinp 2016/05/20 01:42:32 Done.
+}
+
+TEST_F(DiskCacheEntryTest, SimpleCacheReadCorruptKeySHA256) {
+ // This test runs as APP_CACHE to make operations more synchronous.
+ SetCacheType(net::APP_CACHE);
+ SetSimpleCacheMode();
+ InitCache();
+ disk_cache::Entry* entry;
+ std::string key("a key");
+ ASSERT_EQ(net::OK, CreateEntry(key, &entry));
+ entry->Close();
+
+ disk_cache::SimpleBackendImpl::FlushWorkerPoolForTesting();
+ base::RunLoop().RunUntilIdle();
+
+ EXPECT_TRUE(
+ disk_cache::simple_util::CorruptKeySHA256FromEntry(key, cache_path_));
+ EXPECT_NE(net::OK, OpenEntry(key, &entry));
+}

Powered by Google App Engine
This is Rietveld 408576698