summaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authorrvargas@google.com <rvargas@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2010-03-18 23:58:17 +0000
committerrvargas@google.com <rvargas@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2010-03-18 23:58:17 +0000
commitbc4fb8e849ccfd850680d3d402ed18765df7fe11 (patch)
treeebd43e81798813cef227fa0f31356aba9185f92b /net
parenta2495a45f4bc8861261238c20944767a8de8d11e (diff)
downloadchromium_src-bc4fb8e849ccfd850680d3d402ed18765df7fe11.zip
chromium_src-bc4fb8e849ccfd850680d3d402ed18765df7fe11.tar.gz
chromium_src-bc4fb8e849ccfd850680d3d402ed18765df7fe11.tar.bz2
Disk cache" Convert some of the unit tests to the new
disk cache interface (async) BUG=26730 TEST=unit tests Review URL: http://codereview.chromium.org/1135002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@42031 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net')
-rw-r--r--net/disk_cache/backend_unittest.cc229
-rw-r--r--net/disk_cache/disk_cache_test_base.cc49
-rw-r--r--net/disk_cache/disk_cache_test_base.h14
-rw-r--r--net/disk_cache/entry_unittest.cc110
4 files changed, 231 insertions, 171 deletions
diff --git a/net/disk_cache/backend_unittest.cc b/net/disk_cache/backend_unittest.cc
index 07d9735..01cd2fd 100644
--- a/net/disk_cache/backend_unittest.cc
+++ b/net/disk_cache/backend_unittest.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
+// Copyright (c) 2006-2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -74,45 +74,45 @@ class DiskCacheBackendTest : public DiskCacheTestWithCache {
void DiskCacheBackendTest::BackendBasics() {
InitCache();
disk_cache::Entry *entry1 = NULL, *entry2 = NULL;
- EXPECT_FALSE(cache_->OpenEntry("the first key", &entry1));
- ASSERT_TRUE(cache_->CreateEntry("the first key", &entry1));
+ EXPECT_NE(net::OK, OpenEntry("the first key", &entry1));
+ ASSERT_EQ(net::OK, CreateEntry("the first key", &entry1));
ASSERT_TRUE(NULL != entry1);
entry1->Close();
entry1 = NULL;
- ASSERT_TRUE(cache_->OpenEntry("the first key", &entry1));
+ ASSERT_EQ(net::OK, OpenEntry("the first key", &entry1));
ASSERT_TRUE(NULL != entry1);
entry1->Close();
entry1 = NULL;
- EXPECT_FALSE(cache_->CreateEntry("the first key", &entry1));
- ASSERT_TRUE(cache_->OpenEntry("the first key", &entry1));
- EXPECT_FALSE(cache_->OpenEntry("some other key", &entry2));
- ASSERT_TRUE(cache_->CreateEntry("some other key", &entry2));
+ EXPECT_NE(net::OK, CreateEntry("the first key", &entry1));
+ ASSERT_EQ(net::OK, OpenEntry("the first key", &entry1));
+ EXPECT_NE(net::OK, OpenEntry("some other key", &entry2));
+ ASSERT_EQ(net::OK, CreateEntry("some other key", &entry2));
ASSERT_TRUE(NULL != entry1);
ASSERT_TRUE(NULL != entry2);
EXPECT_EQ(2, cache_->GetEntryCount());
disk_cache::Entry* entry3 = NULL;
- ASSERT_TRUE(cache_->OpenEntry("some other key", &entry3));
+ ASSERT_EQ(net::OK, OpenEntry("some other key", &entry3));
ASSERT_TRUE(NULL != entry3);
EXPECT_TRUE(entry2 == entry3);
EXPECT_EQ(2, cache_->GetEntryCount());
- EXPECT_TRUE(cache_->DoomEntry("some other key"));
+ EXPECT_EQ(net::OK, DoomEntry("some other key"));
EXPECT_EQ(1, cache_->GetEntryCount());
entry1->Close();
entry2->Close();
entry3->Close();
- EXPECT_TRUE(cache_->DoomEntry("the first key"));
+ EXPECT_EQ(net::OK, DoomEntry("the first key"));
EXPECT_EQ(0, cache_->GetEntryCount());
- ASSERT_TRUE(cache_->CreateEntry("the first key", &entry1));
- ASSERT_TRUE(cache_->CreateEntry("some other key", &entry2));
+ ASSERT_EQ(net::OK, CreateEntry("the first key", &entry1));
+ ASSERT_EQ(net::OK, CreateEntry("some other key", &entry2));
entry1->Doom();
entry1->Close();
- EXPECT_TRUE(cache_->DoomEntry("some other key"));
+ EXPECT_EQ(net::OK, DoomEntry("some other key"));
EXPECT_EQ(0, cache_->GetEntryCount());
entry2->Close();
}
@@ -136,25 +136,25 @@ void DiskCacheBackendTest::BackendKeying() {
const char* kName1 = "the first key";
const char* kName2 = "the first Key";
disk_cache::Entry *entry1, *entry2;
- ASSERT_TRUE(cache_->CreateEntry(kName1, &entry1));
+ ASSERT_EQ(net::OK, CreateEntry(kName1, &entry1));
- ASSERT_TRUE(cache_->CreateEntry(kName2, &entry2));
+ ASSERT_EQ(net::OK, CreateEntry(kName2, &entry2));
EXPECT_TRUE(entry1 != entry2) << "Case sensitive";
entry2->Close();
char buffer[30];
base::strlcpy(buffer, kName1, arraysize(buffer));
- ASSERT_TRUE(cache_->OpenEntry(buffer, &entry2));
+ ASSERT_EQ(net::OK, OpenEntry(buffer, &entry2));
EXPECT_TRUE(entry1 == entry2);
entry2->Close();
base::strlcpy(buffer + 1, kName1, arraysize(buffer) - 1);
- ASSERT_TRUE(cache_->OpenEntry(buffer + 1, &entry2));
+ ASSERT_EQ(net::OK, OpenEntry(buffer + 1, &entry2));
EXPECT_TRUE(entry1 == entry2);
entry2->Close();
base::strlcpy(buffer + 3, kName1, arraysize(buffer) - 3);
- ASSERT_TRUE(cache_->OpenEntry(buffer + 3, &entry2));
+ ASSERT_EQ(net::OK, OpenEntry(buffer + 3, &entry2));
EXPECT_TRUE(entry1 == entry2);
entry2->Close();
@@ -162,12 +162,12 @@ void DiskCacheBackendTest::BackendKeying() {
char buffer2[20000];
memset(buffer2, 's', sizeof(buffer2));
buffer2[1023] = '\0';
- ASSERT_TRUE(cache_->CreateEntry(buffer2, &entry2)) << "key on block file";
+ ASSERT_EQ(net::OK, CreateEntry(buffer2, &entry2)) << "key on block file";
entry2->Close();
buffer2[1023] = 'g';
buffer2[19999] = '\0';
- ASSERT_TRUE(cache_->CreateEntry(buffer2, &entry2)) << "key on external file";
+ ASSERT_EQ(net::OK, CreateEntry(buffer2, &entry2)) << "key on external file";
entry2->Close();
entry1->Close();
}
@@ -198,7 +198,7 @@ TEST_F(DiskCacheBackendTest, ExternalFiles) {
// Now let's create a file with the cache.
disk_cache::Entry* entry;
- ASSERT_TRUE(cache_->CreateEntry("key", &entry));
+ ASSERT_EQ(net::OK, CreateEntry("key", &entry));
ASSERT_EQ(0, entry->WriteData(0, 20000, buffer1, 0, NULL, false));
entry->Close();
@@ -250,7 +250,7 @@ void DiskCacheBackendTest::BackendSetSize() {
std::string first("some key");
std::string second("something else");
disk_cache::Entry* entry;
- ASSERT_TRUE(cache_->CreateEntry(first, &entry));
+ ASSERT_EQ(net::OK, CreateEntry(first, &entry));
scoped_refptr<net::IOBuffer> buffer = new net::IOBuffer(cache_size);
memset(buffer->data(), 0, cache_size);
@@ -275,13 +275,13 @@ void DiskCacheBackendTest::BackendSetSize() {
// The cache is 95% full.
- ASSERT_TRUE(cache_->CreateEntry(second, &entry));
+ ASSERT_EQ(net::OK, CreateEntry(second, &entry));
EXPECT_EQ(cache_size / 10, entry->WriteData(0, 0, buffer, cache_size / 10,
NULL, false)) << "trim the cache";
entry->Close();
- EXPECT_FALSE(cache_->OpenEntry(first, &entry));
- ASSERT_TRUE(cache_->OpenEntry(second, &entry));
+ EXPECT_NE(net::OK, OpenEntry(first, &entry));
+ ASSERT_EQ(net::OK, OpenEntry(second, &entry));
EXPECT_EQ(cache_size / 10, entry->GetDataSize(0));
entry->Close();
}
@@ -308,7 +308,7 @@ void DiskCacheBackendTest::BackendLoad() {
disk_cache::Entry* entries[100];
for (int i = 0; i < 100; i++) {
std::string key = GenerateKey(true);
- ASSERT_TRUE(cache_->CreateEntry(key, &entries[i]));
+ ASSERT_EQ(net::OK, CreateEntry(key, &entries[i]));
}
EXPECT_EQ(100, cache_->GetEntryCount());
@@ -322,7 +322,7 @@ void DiskCacheBackendTest::BackendLoad() {
for (int i = 0; i < 100; i++) {
disk_cache::Entry* entry;
- ASSERT_TRUE(cache_->OpenEntry(entries[i]->GetKey(), &entry));
+ ASSERT_EQ(net::OK, OpenEntry(entries[i]->GetKey(), &entry));
EXPECT_TRUE(entry == entries[i]);
entry->Close();
entries[i]->Doom();
@@ -360,7 +360,7 @@ void DiskCacheBackendTest::BackendValidEntry() {
std::string key("Some key");
disk_cache::Entry* entry1;
- ASSERT_TRUE(cache_->CreateEntry(key, &entry1));
+ ASSERT_EQ(net::OK, CreateEntry(key, &entry1));
const int kSize = 50;
scoped_refptr<net::IOBuffer> buffer1 = new net::IOBuffer(kSize);
@@ -370,7 +370,7 @@ void DiskCacheBackendTest::BackendValidEntry() {
entry1->Close();
SimulateCrash();
- ASSERT_TRUE(cache_->OpenEntry(key, &entry1));
+ ASSERT_EQ(net::OK, OpenEntry(key, &entry1));
scoped_refptr<net::IOBuffer> buffer2 = new net::IOBuffer(kSize);
memset(buffer2->data(), 0, kSize);
@@ -398,7 +398,7 @@ void DiskCacheBackendTest::BackendInvalidEntry() {
std::string key("Some key");
disk_cache::Entry* entry1;
- ASSERT_TRUE(cache_->CreateEntry(key, &entry1));
+ ASSERT_EQ(net::OK, CreateEntry(key, &entry1));
const int kSize = 50;
scoped_refptr<net::IOBuffer> buffer1 = new net::IOBuffer(kSize);
@@ -407,7 +407,7 @@ void DiskCacheBackendTest::BackendInvalidEntry() {
EXPECT_EQ(kSize, entry1->WriteData(0, 0, buffer1, kSize, NULL, false));
SimulateCrash();
- EXPECT_FALSE(cache_->OpenEntry(key, &entry1));
+ EXPECT_NE(net::OK, OpenEntry(key, &entry1));
EXPECT_EQ(0, cache_->GetEntryCount());
}
@@ -436,7 +436,7 @@ void DiskCacheBackendTest::BackendInvalidEntryRead() {
std::string key("Some key");
disk_cache::Entry* entry1;
- ASSERT_TRUE(cache_->CreateEntry(key, &entry1));
+ ASSERT_EQ(net::OK, CreateEntry(key, &entry1));
const int kSize = 50;
scoped_refptr<net::IOBuffer> buffer1 = new net::IOBuffer(kSize);
@@ -444,12 +444,12 @@ void DiskCacheBackendTest::BackendInvalidEntryRead() {
base::strlcpy(buffer1->data(), "And the data to save", kSize);
EXPECT_EQ(kSize, entry1->WriteData(0, 0, buffer1, kSize, NULL, false));
entry1->Close();
- ASSERT_TRUE(cache_->OpenEntry(key, &entry1));
+ ASSERT_EQ(net::OK, OpenEntry(key, &entry1));
EXPECT_EQ(kSize, entry1->ReadData(0, 0, buffer1, kSize, NULL));
SimulateCrash();
- EXPECT_FALSE(cache_->OpenEntry(key, &entry1));
+ EXPECT_NE(net::OK, OpenEntry(key, &entry1));
EXPECT_EQ(0, cache_->GetEntryCount());
}
@@ -478,7 +478,7 @@ void DiskCacheBackendTest::BackendInvalidEntryWithLoad() {
disk_cache::Entry* entries[kNumEntries];
for (int i = 0; i < kNumEntries; i++) {
std::string key = GenerateKey(true);
- ASSERT_TRUE(cache_->CreateEntry(key, &entries[i]));
+ ASSERT_EQ(net::OK, CreateEntry(key, &entries[i]));
}
EXPECT_EQ(kNumEntries, cache_->GetEntryCount());
@@ -501,12 +501,12 @@ void DiskCacheBackendTest::BackendInvalidEntryWithLoad() {
for (int i = kNumEntries / 2; i < kNumEntries; i++) {
disk_cache::Entry* entry;
- EXPECT_FALSE(cache_->OpenEntry(keys[i], &entry));
+ EXPECT_NE(net::OK, OpenEntry(keys[i], &entry));
}
for (int i = 0; i < kNumEntries / 2; i++) {
disk_cache::Entry* entry;
- EXPECT_TRUE(cache_->OpenEntry(keys[i], &entry));
+ EXPECT_EQ(net::OK, OpenEntry(keys[i], &entry));
entry->Close();
}
@@ -536,7 +536,7 @@ void DiskCacheBackendTest::BackendTrimInvalidEntry() {
std::string first("some key");
std::string second("something else");
disk_cache::Entry* entry;
- ASSERT_TRUE(cache_->CreateEntry(first, &entry));
+ ASSERT_EQ(net::OK, CreateEntry(first, &entry));
scoped_refptr<net::IOBuffer> buffer = new net::IOBuffer(kSize);
memset(buffer->data(), 0, kSize);
@@ -545,7 +545,7 @@ void DiskCacheBackendTest::BackendTrimInvalidEntry() {
// Simulate a crash.
SimulateCrash();
- ASSERT_TRUE(cache_->CreateEntry(second, &entry));
+ ASSERT_EQ(net::OK, CreateEntry(second, &entry));
EXPECT_EQ(kSize, entry->WriteData(0, 0, buffer, kSize, NULL, false));
EXPECT_EQ(2, cache_->GetEntryCount());
@@ -557,7 +557,7 @@ void DiskCacheBackendTest::BackendTrimInvalidEntry() {
// entry too.
MessageLoop::current()->RunAllPending();
EXPECT_GE(1, cache_->GetEntryCount());
- EXPECT_FALSE(cache_->OpenEntry(first, &entry));
+ EXPECT_NE(net::OK, OpenEntry(first, &entry));
}
// We'll be leaking memory from this test.
@@ -588,17 +588,17 @@ void DiskCacheBackendTest::BackendTrimInvalidEntry2() {
// Writing 32 entries to this cache chains most of them.
for (int i = 0; i < 32; i++) {
std::string key(StringPrintf("some key %d", i));
- ASSERT_TRUE(cache_->CreateEntry(key, &entry));
+ ASSERT_EQ(net::OK, CreateEntry(key, &entry));
EXPECT_EQ(kSize, entry->WriteData(0, 0, buffer, kSize, NULL, false));
entry->Close();
- ASSERT_TRUE(cache_->OpenEntry(key, &entry));
+ ASSERT_EQ(net::OK, OpenEntry(key, &entry));
// Note that we are not closing the entries.
}
// Simulate a crash.
SimulateCrash();
- ASSERT_TRUE(cache_->CreateEntry("Something else", &entry));
+ ASSERT_EQ(net::OK, CreateEntry("Something else", &entry));
EXPECT_EQ(kSize, entry->WriteData(0, 0, buffer, kSize, NULL, false));
EXPECT_EQ(33, cache_->GetEntryCount());
@@ -606,8 +606,9 @@ void DiskCacheBackendTest::BackendTrimInvalidEntry2() {
// For the new eviction code, all corrupt entries are on the second list so
// they are not going away that easy.
- if (new_eviction_)
- cache_->DoomAllEntries();
+ if (new_eviction_) {
+ EXPECT_EQ(net::OK, DoomAllEntries());
+ }
entry->Close(); // Trim the cache.
@@ -637,7 +638,7 @@ void DiskCacheBackendTest::BackendEnumerations() {
for (int i = 0; i < kNumEntries; i++) {
std::string key = GenerateKey(true);
disk_cache::Entry* entry;
- ASSERT_TRUE(cache_->CreateEntry(key, &entry));
+ ASSERT_EQ(net::OK, CreateEntry(key, &entry));
entry->Close();
}
EXPECT_EQ(kNumEntries, cache_->GetEntryCount());
@@ -648,7 +649,7 @@ void DiskCacheBackendTest::BackendEnumerations() {
int count = 0;
Time last_modified[kNumEntries];
Time last_used[kNumEntries];
- while (cache_->OpenNextEntry(&iter, &entry)) {
+ while (OpenNextEntry(&iter, &entry) == net::OK) {
ASSERT_TRUE(NULL != entry);
if (count < kNumEntries) {
last_modified[count] = entry->GetLastModified();
@@ -665,7 +666,7 @@ void DiskCacheBackendTest::BackendEnumerations() {
iter = NULL;
count = 0;
// The previous enumeration should not have changed the timestamps.
- while (cache_->OpenNextEntry(&iter, &entry)) {
+ while (OpenNextEntry(&iter, &entry) == net::OK) {
ASSERT_TRUE(NULL != entry);
if (count < kNumEntries) {
EXPECT_TRUE(last_modified[count] == entry->GetLastModified());
@@ -697,24 +698,24 @@ void DiskCacheBackendTest::BackendEnumerations2() {
const std::string first("first");
const std::string second("second");
disk_cache::Entry *entry1, *entry2;
- ASSERT_TRUE(cache_->CreateEntry(first, &entry1));
+ ASSERT_EQ(net::OK, CreateEntry(first, &entry1));
entry1->Close();
- ASSERT_TRUE(cache_->CreateEntry(second, &entry2));
+ ASSERT_EQ(net::OK, CreateEntry(second, &entry2));
entry2->Close();
// Make sure that the timestamp is not the same.
PlatformThread::Sleep(20);
- ASSERT_TRUE(cache_->OpenEntry(second, &entry1));
+ ASSERT_EQ(net::OK, OpenEntry(second, &entry1));
void* iter = NULL;
- ASSERT_TRUE(cache_->OpenNextEntry(&iter, &entry2));
+ ASSERT_EQ(net::OK, OpenNextEntry(&iter, &entry2));
ASSERT_EQ(entry2->GetKey(), second);
// Two entries and the iterator pointing at "first".
entry1->Close();
entry2->Close();
- // The iterator should still be valid, se we should not crash.
- ASSERT_TRUE(cache_->OpenNextEntry(&iter, &entry2));
+ // The iterator should still be valid, so we should not crash.
+ ASSERT_EQ(net::OK, OpenNextEntry(&iter, &entry2));
ASSERT_EQ(entry2->GetKey(), first);
entry2->Close();
cache_->EndEnumeration(&iter);
@@ -744,7 +745,7 @@ void DiskCacheBackendTest::BackendInvalidEntryEnumeration() {
std::string key("Some key");
disk_cache::Entry *entry, *entry1, *entry2;
- ASSERT_TRUE(cache_->CreateEntry(key, &entry1));
+ ASSERT_EQ(net::OK, CreateEntry(key, &entry1));
const int kSize = 50;
scoped_refptr<net::IOBuffer> buffer1 = new net::IOBuffer(kSize);
@@ -752,11 +753,11 @@ void DiskCacheBackendTest::BackendInvalidEntryEnumeration() {
base::strlcpy(buffer1->data(), "And the data to save", kSize);
EXPECT_EQ(kSize, entry1->WriteData(0, 0, buffer1, kSize, NULL, false));
entry1->Close();
- ASSERT_TRUE(cache_->OpenEntry(key, &entry1));
+ ASSERT_EQ(net::OK, OpenEntry(key, &entry1));
EXPECT_EQ(kSize, entry1->ReadData(0, 0, buffer1, kSize, NULL));
std::string key2("Another key");
- ASSERT_TRUE(cache_->CreateEntry(key2, &entry2));
+ ASSERT_EQ(net::OK, CreateEntry(key2, &entry2));
entry2->Close();
ASSERT_EQ(2, cache_->GetEntryCount());
@@ -764,7 +765,7 @@ void DiskCacheBackendTest::BackendInvalidEntryEnumeration() {
void* iter = NULL;
int count = 0;
- while (cache_->OpenNextEntry(&iter, &entry)) {
+ while (OpenNextEntry(&iter, &entry) == net::OK) {
ASSERT_TRUE(NULL != entry);
EXPECT_EQ(key2, entry->GetKey());
entry->Close();
@@ -797,7 +798,7 @@ void DiskCacheBackendTest::BackendFixEnumerators() {
for (int i = 0; i < kNumEntries; i++) {
std::string key = GenerateKey(true);
disk_cache::Entry* entry;
- ASSERT_TRUE(cache_->CreateEntry(key, &entry));
+ ASSERT_EQ(net::OK, CreateEntry(key, &entry));
entry->Close();
}
EXPECT_EQ(kNumEntries, cache_->GetEntryCount());
@@ -805,7 +806,7 @@ void DiskCacheBackendTest::BackendFixEnumerators() {
disk_cache::Entry *entry1, *entry2;
void* iter1 = NULL;
void* iter2 = NULL;
- ASSERT_TRUE(cache_->OpenNextEntry(&iter1, &entry1));
+ ASSERT_EQ(net::OK, OpenNextEntry(&iter1, &entry1));
ASSERT_TRUE(NULL != entry1);
entry1->Close();
entry1 = NULL;
@@ -814,17 +815,17 @@ void DiskCacheBackendTest::BackendFixEnumerators() {
for (int i = 0; i < kNumEntries / 2; i++) {
if (entry1)
entry1->Close();
- ASSERT_TRUE(cache_->OpenNextEntry(&iter1, &entry1));
+ ASSERT_EQ(net::OK, OpenNextEntry(&iter1, &entry1));
ASSERT_TRUE(NULL != entry1);
- ASSERT_TRUE(cache_->OpenNextEntry(&iter2, &entry2));
+ ASSERT_EQ(net::OK, OpenNextEntry(&iter2, &entry2));
ASSERT_TRUE(NULL != entry2);
entry2->Close();
}
// Messing up with entry1 will modify entry2->next.
entry1->Doom();
- ASSERT_TRUE(cache_->OpenNextEntry(&iter2, &entry2));
+ ASSERT_EQ(net::OK, OpenNextEntry(&iter2, &entry2));
ASSERT_TRUE(NULL != entry2);
// The link entry2->entry1 should be broken.
@@ -833,7 +834,7 @@ void DiskCacheBackendTest::BackendFixEnumerators() {
entry2->Close();
// And the second iterator should keep working.
- ASSERT_TRUE(cache_->OpenNextEntry(&iter2, &entry2));
+ ASSERT_EQ(net::OK, OpenNextEntry(&iter2, &entry2));
ASSERT_TRUE(NULL != entry2);
entry2->Close();
@@ -855,30 +856,30 @@ void DiskCacheBackendTest::BackendDoomRecent() {
Time initial = Time::Now();
disk_cache::Entry *entry;
- ASSERT_TRUE(cache_->CreateEntry("first", &entry));
+ ASSERT_EQ(net::OK, CreateEntry("first", &entry));
entry->Close();
- ASSERT_TRUE(cache_->CreateEntry("second", &entry));
+ ASSERT_EQ(net::OK, CreateEntry("second", &entry));
entry->Close();
PlatformThread::Sleep(20);
Time middle = Time::Now();
- ASSERT_TRUE(cache_->CreateEntry("third", &entry));
+ ASSERT_EQ(net::OK, CreateEntry("third", &entry));
entry->Close();
- ASSERT_TRUE(cache_->CreateEntry("fourth", &entry));
+ ASSERT_EQ(net::OK, CreateEntry("fourth", &entry));
entry->Close();
PlatformThread::Sleep(20);
Time final = Time::Now();
ASSERT_EQ(4, cache_->GetEntryCount());
- EXPECT_TRUE(cache_->DoomEntriesSince(final));
+ EXPECT_EQ(net::OK, DoomEntriesSince(final));
ASSERT_EQ(4, cache_->GetEntryCount());
- EXPECT_TRUE(cache_->DoomEntriesSince(middle));
+ EXPECT_EQ(net::OK, DoomEntriesSince(middle));
ASSERT_EQ(2, cache_->GetEntryCount());
- ASSERT_TRUE(cache_->OpenEntry("second", &entry));
+ ASSERT_EQ(net::OK, OpenEntry("second", &entry));
entry->Close();
}
@@ -901,39 +902,39 @@ void DiskCacheBackendTest::BackendDoomBetween() {
Time initial = Time::Now();
disk_cache::Entry *entry;
- ASSERT_TRUE(cache_->CreateEntry("first", &entry));
+ ASSERT_EQ(net::OK, CreateEntry("first", &entry));
entry->Close();
PlatformThread::Sleep(20);
Time middle_start = Time::Now();
- ASSERT_TRUE(cache_->CreateEntry("second", &entry));
+ ASSERT_EQ(net::OK, CreateEntry("second", &entry));
entry->Close();
- ASSERT_TRUE(cache_->CreateEntry("third", &entry));
+ ASSERT_EQ(net::OK, CreateEntry("third", &entry));
entry->Close();
PlatformThread::Sleep(20);
Time middle_end = Time::Now();
- ASSERT_TRUE(cache_->CreateEntry("fourth", &entry));
+ ASSERT_EQ(net::OK, CreateEntry("fourth", &entry));
entry->Close();
- ASSERT_TRUE(cache_->OpenEntry("fourth", &entry));
+ ASSERT_EQ(net::OK, OpenEntry("fourth", &entry));
entry->Close();
PlatformThread::Sleep(20);
Time final = Time::Now();
ASSERT_EQ(4, cache_->GetEntryCount());
- EXPECT_TRUE(cache_->DoomEntriesBetween(middle_start, middle_end));
+ EXPECT_EQ(net::OK, DoomEntriesBetween(middle_start, middle_end));
ASSERT_EQ(2, cache_->GetEntryCount());
- ASSERT_TRUE(cache_->OpenEntry("fourth", &entry));
+ ASSERT_EQ(net::OK, OpenEntry("fourth", &entry));
entry->Close();
- EXPECT_TRUE(cache_->DoomEntriesBetween(middle_start, final));
+ EXPECT_EQ(net::OK, DoomEntriesBetween(middle_start, final));
ASSERT_EQ(1, cache_->GetEntryCount());
- ASSERT_TRUE(cache_->OpenEntry("first", &entry));
+ ASSERT_EQ(net::OK, OpenEntry("first", &entry));
entry->Close();
}
@@ -1097,8 +1098,8 @@ void DiskCacheBackendTest::BackendInvalidEntry2() {
InitCache();
disk_cache::Entry *entry1, *entry2;
- ASSERT_TRUE(cache_->OpenEntry("the first key", &entry1));
- EXPECT_FALSE(cache_->OpenEntry("some other key", &entry2));
+ ASSERT_EQ(net::OK, OpenEntry("the first key", &entry1));
+ EXPECT_NE(net::OK, OpenEntry("some other key", &entry2));
entry1->Close();
// CheckCacheIntegrity will fail at this point.
@@ -1121,8 +1122,8 @@ void DiskCacheBackendTest::BackendNotMarkedButDirty(const std::wstring& name) {
InitCache();
disk_cache::Entry *entry1, *entry2;
- ASSERT_TRUE(cache_->OpenEntry("the first key", &entry1));
- EXPECT_FALSE(cache_->OpenEntry("some other key", &entry2));
+ ASSERT_EQ(net::OK, OpenEntry("the first key", &entry1));
+ EXPECT_NE(net::OK, OpenEntry("some other key", &entry2));
entry1->Close();
}
@@ -1152,8 +1153,8 @@ void DiskCacheBackendTest::BackendInvalidRankings2() {
InitCache();
disk_cache::Entry *entry1, *entry2;
- EXPECT_FALSE(cache_->OpenEntry("the first key", &entry1));
- ASSERT_TRUE(cache_->OpenEntry("some other key", &entry2));
+ EXPECT_NE(net::OK, OpenEntry("the first key", &entry1));
+ ASSERT_EQ(net::OK, OpenEntry("some other key", &entry2));
entry2->Close();
// CheckCacheIntegrity will fail at this point.
@@ -1173,11 +1174,11 @@ TEST_F(DiskCacheBackendTest, NewEvictionInvalidRankings2) {
void DiskCacheBackendTest::BackendInvalidRankings() {
disk_cache::Entry* entry;
void* iter = NULL;
- ASSERT_TRUE(cache_->OpenNextEntry(&iter, &entry));
+ ASSERT_EQ(net::OK, OpenNextEntry(&iter, &entry));
entry->Close();
EXPECT_EQ(2, cache_->GetEntryCount());
- EXPECT_FALSE(cache_->OpenNextEntry(&iter, &entry));
+ EXPECT_NE(net::OK, OpenNextEntry(&iter, &entry));
MessageLoop::current()->RunAllPending();
EXPECT_EQ(0, cache_->GetEntryCount());
}
@@ -1222,11 +1223,11 @@ TEST_F(DiskCacheBackendTest, NewEvictionInvalidRankingsFailure) {
void DiskCacheBackendTest::BackendDisable() {
disk_cache::Entry *entry1, *entry2;
void* iter = NULL;
- ASSERT_TRUE(cache_->OpenNextEntry(&iter, &entry1));
+ ASSERT_EQ(net::OK, OpenNextEntry(&iter, &entry1));
- EXPECT_FALSE(cache_->OpenNextEntry(&iter, &entry2));
+ EXPECT_NE(net::OK, OpenNextEntry(&iter, &entry2));
EXPECT_EQ(2, cache_->GetEntryCount());
- EXPECT_FALSE(cache_->CreateEntry("Something new", &entry2));
+ EXPECT_NE(net::OK, CreateEntry("Something new", &entry2));
entry1->Close();
MessageLoop::current()->RunAllPending();
@@ -1277,7 +1278,7 @@ void DiskCacheBackendTest::BackendDisable2() {
disk_cache::Entry* entry;
void* iter = NULL;
int count = 0;
- while (cache_->OpenNextEntry(&iter, &entry)) {
+ while (OpenNextEntry(&iter, &entry) == net::OK) {
ASSERT_TRUE(NULL != entry);
entry->Close();
count++;
@@ -1329,13 +1330,13 @@ void DiskCacheBackendTest::BackendDisable3() {
disk_cache::Entry *entry1, *entry2;
void* iter = NULL;
EXPECT_EQ(2, cache_->GetEntryCount());
- ASSERT_TRUE(cache_->OpenNextEntry(&iter, &entry1));
+ ASSERT_EQ(net::OK, OpenNextEntry(&iter, &entry1));
entry1->Close();
- EXPECT_FALSE(cache_->OpenNextEntry(&iter, &entry2));
+ EXPECT_NE(net::OK, OpenNextEntry(&iter, &entry2));
MessageLoop::current()->RunAllPending();
- ASSERT_TRUE(cache_->CreateEntry("Something new", &entry2));
+ ASSERT_EQ(net::OK, CreateEntry("Something new", &entry2));
entry2->Close();
EXPECT_EQ(1, cache_->GetEntryCount());
@@ -1362,7 +1363,7 @@ TEST_F(DiskCacheBackendTest, NewEvictionDisableSuccess3) {
void DiskCacheBackendTest::BackendDisable4() {
disk_cache::Entry *entry1, *entry2, *entry3, *entry4;
void* iter = NULL;
- ASSERT_TRUE(cache_->OpenNextEntry(&iter, &entry1));
+ ASSERT_EQ(net::OK, OpenNextEntry(&iter, &entry1));
char key2[2000];
char key3[20000];
@@ -1370,8 +1371,8 @@ void DiskCacheBackendTest::BackendDisable4() {
CacheTestFillBuffer(key3, sizeof(key3), true);
key2[sizeof(key2) - 1] = '\0';
key3[sizeof(key3) - 1] = '\0';
- ASSERT_TRUE(cache_->CreateEntry(key2, &entry2));
- ASSERT_TRUE(cache_->CreateEntry(key3, &entry3));
+ ASSERT_EQ(net::OK, CreateEntry(key2, &entry2));
+ ASSERT_EQ(net::OK, CreateEntry(key3, &entry3));
const int kBufSize = 20000;
scoped_refptr<net::IOBuffer> buf = new net::IOBuffer(kBufSize);
@@ -1380,10 +1381,10 @@ void DiskCacheBackendTest::BackendDisable4() {
EXPECT_EQ(kBufSize, entry3->WriteData(0, 0, buf, kBufSize, NULL, false));
// This line should disable the cache but not delete it.
- EXPECT_FALSE(cache_->OpenNextEntry(&iter, &entry4));
+ EXPECT_NE(net::OK, OpenNextEntry(&iter, &entry4));
EXPECT_EQ(4, cache_->GetEntryCount());
- EXPECT_FALSE(cache_->CreateEntry("cache is disabled", &entry4));
+ EXPECT_NE(net::OK, CreateEntry("cache is disabled", &entry4));
EXPECT_EQ(100, entry2->ReadData(0, 0, buf, 100, NULL));
EXPECT_EQ(100, entry2->WriteData(0, 0, buf, 100, NULL, false));
@@ -1446,26 +1447,26 @@ void DiskCacheBackendTest::BackendDoomAll() {
Time initial = Time::Now();
disk_cache::Entry *entry1, *entry2;
- ASSERT_TRUE(cache_->CreateEntry("first", &entry1));
- ASSERT_TRUE(cache_->CreateEntry("second", &entry2));
+ ASSERT_EQ(net::OK, CreateEntry("first", &entry1));
+ ASSERT_EQ(net::OK, CreateEntry("second", &entry2));
entry1->Close();
entry2->Close();
- ASSERT_TRUE(cache_->CreateEntry("third", &entry1));
- ASSERT_TRUE(cache_->CreateEntry("fourth", &entry2));
+ ASSERT_EQ(net::OK, CreateEntry("third", &entry1));
+ ASSERT_EQ(net::OK, CreateEntry("fourth", &entry2));
ASSERT_EQ(4, cache_->GetEntryCount());
- EXPECT_TRUE(cache_->DoomAllEntries());
+ EXPECT_EQ(net::OK, DoomAllEntries());
ASSERT_EQ(0, cache_->GetEntryCount());
// We should stop posting tasks at some point (if we post any).
MessageLoop::current()->RunAllPending();
disk_cache::Entry *entry3, *entry4;
- ASSERT_TRUE(cache_->CreateEntry("third", &entry3));
- ASSERT_TRUE(cache_->CreateEntry("fourth", &entry4));
+ ASSERT_EQ(net::OK, CreateEntry("third", &entry3));
+ ASSERT_EQ(net::OK, CreateEntry("fourth", &entry4));
- EXPECT_TRUE(cache_->DoomAllEntries());
+ EXPECT_EQ(net::OK, DoomAllEntries());
ASSERT_EQ(0, cache_->GetEntryCount());
entry1->Close();
@@ -1475,13 +1476,13 @@ void DiskCacheBackendTest::BackendDoomAll() {
entry4->Close();
// Now try with all references released.
- ASSERT_TRUE(cache_->CreateEntry("third", &entry1));
- ASSERT_TRUE(cache_->CreateEntry("fourth", &entry2));
+ ASSERT_EQ(net::OK, CreateEntry("third", &entry1));
+ ASSERT_EQ(net::OK, CreateEntry("fourth", &entry2));
entry1->Close();
entry2->Close();
ASSERT_EQ(2, cache_->GetEntryCount());
- EXPECT_TRUE(cache_->DoomAllEntries());
+ EXPECT_EQ(net::OK, DoomAllEntries());
ASSERT_EQ(0, cache_->GetEntryCount());
}
@@ -1502,10 +1503,10 @@ TEST_F(DiskCacheBackendTest, MemoryOnlyDoomAll) {
// If the index size changes when we doom the cache, we should not crash.
void DiskCacheBackendTest::BackendDoomAll2() {
EXPECT_EQ(2, cache_->GetEntryCount());
- EXPECT_TRUE(cache_->DoomAllEntries());
+ EXPECT_EQ(net::OK, DoomAllEntries());
disk_cache::Entry* entry;
- ASSERT_TRUE(cache_->CreateEntry("Something new", &entry));
+ ASSERT_EQ(net::OK, CreateEntry("Something new", &entry));
entry->Close();
EXPECT_EQ(1, cache_->GetEntryCount());
diff --git a/net/disk_cache/disk_cache_test_base.cc b/net/disk_cache/disk_cache_test_base.cc
index 21352a2..2738674 100644
--- a/net/disk_cache/disk_cache_test_base.cc
+++ b/net/disk_cache/disk_cache_test_base.cc
@@ -1,9 +1,10 @@
-// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
+// Copyright (c) 2006-2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "net/disk_cache/disk_cache_test_base.h"
+#include "net/base/test_completion_callback.h"
#include "net/disk_cache/backend_impl.h"
#include "net/disk_cache/disk_cache_test_util.h"
#include "net/disk_cache/mem_backend_impl.h"
@@ -111,3 +112,49 @@ void DiskCacheTestWithCache::SetTestMode() {
ASSERT_TRUE(implementation_ && !memory_only_);
cache_impl_->SetUnitTestMode();
}
+
+int DiskCacheTestWithCache::OpenEntry(const std::string& key,
+ disk_cache::Entry** entry) {
+ TestCompletionCallback cb;
+ int rv = cache_->OpenEntry(key, entry, &cb);
+ return cb.GetResult(rv);
+}
+
+int DiskCacheTestWithCache::CreateEntry(const std::string& key,
+ disk_cache::Entry** entry) {
+ TestCompletionCallback cb;
+ int rv = cache_->CreateEntry(key, entry, &cb);
+ return cb.GetResult(rv);
+}
+
+int DiskCacheTestWithCache::DoomEntry(const std::string& key) {
+ TestCompletionCallback cb;
+ int rv = cache_->DoomEntry(key, &cb);
+ return cb.GetResult(rv);
+}
+
+int DiskCacheTestWithCache::DoomAllEntries() {
+ TestCompletionCallback cb;
+ int rv = cache_->DoomAllEntries(&cb);
+ return cb.GetResult(rv);
+}
+
+int DiskCacheTestWithCache::DoomEntriesBetween(const base::Time initial_time,
+ const base::Time end_time) {
+ TestCompletionCallback cb;
+ int rv = cache_->DoomEntriesBetween(initial_time, end_time, &cb);
+ return cb.GetResult(rv);
+}
+
+int DiskCacheTestWithCache::DoomEntriesSince(const base::Time initial_time) {
+ TestCompletionCallback cb;
+ int rv = cache_->DoomEntriesSince(initial_time, &cb);
+ return cb.GetResult(rv);
+}
+
+int DiskCacheTestWithCache::OpenNextEntry(void** iter,
+ disk_cache::Entry** next_entry) {
+ TestCompletionCallback cb;
+ int rv = cache_->OpenNextEntry(iter, next_entry, &cb);
+ return cb.GetResult(rv);
+}
diff --git a/net/disk_cache/disk_cache_test_base.h b/net/disk_cache/disk_cache_test_base.h
index c198e22..0878a38 100644
--- a/net/disk_cache/disk_cache_test_base.h
+++ b/net/disk_cache/disk_cache_test_base.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
+// Copyright (c) 2006-2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -6,6 +6,7 @@
#define NET_DISK_CACHE_DISK_CACHE_TEST_BASE_H_
#include "base/basictypes.h"
+#include "base/time.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "testing/platform_test.h"
@@ -15,6 +16,7 @@ namespace disk_cache {
class Backend;
class BackendImpl;
+class Entry;
class MemBackendImpl;
} // namespace disk_cache
@@ -72,6 +74,16 @@ class DiskCacheTestWithCache : public DiskCacheTest {
integrity_ = false;
}
+ // Utility methods to access the cache and wait for each operation to finish.
+ int OpenEntry(const std::string& key, disk_cache::Entry** entry);
+ int CreateEntry(const std::string& key, disk_cache::Entry** entry);
+ int DoomEntry(const std::string& key);
+ int DoomAllEntries();
+ int DoomEntriesBetween(const base::Time initial_time,
+ const base::Time end_time);
+ int DoomEntriesSince(const base::Time initial_time);
+ int OpenNextEntry(void** iter, disk_cache::Entry** next_entry);
+
// cache_ will always have a valid object, regardless of how the cache was
// initialized. The implementation pointers can be NULL.
disk_cache::Backend* cache_;
diff --git a/net/disk_cache/entry_unittest.cc b/net/disk_cache/entry_unittest.cc
index e60a3da..c96469a 100644
--- a/net/disk_cache/entry_unittest.cc
+++ b/net/disk_cache/entry_unittest.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2006-2009 The Chromium Authors. All rights reserved.
+// Copyright (c) 2006-2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -34,7 +34,7 @@ class DiskCacheEntryTest : public DiskCacheTestWithCache {
void ZeroLengthIO();
void ReuseEntry(int size);
void InvalidData();
- void DoomEntry();
+ void DoomNormalEntry();
void DoomedEntry();
void BasicSparseIO(bool async);
void HugeSparseIO(bool async);
@@ -45,7 +45,7 @@ class DiskCacheEntryTest : public DiskCacheTestWithCache {
void DiskCacheEntryTest::InternalSyncIO() {
disk_cache::Entry *entry1 = NULL;
- ASSERT_TRUE(cache_->CreateEntry("the first key", &entry1));
+ ASSERT_EQ(net::OK, CreateEntry("the first key", &entry1));
ASSERT_TRUE(NULL != entry1);
const int kSize1 = 10;
@@ -97,7 +97,7 @@ TEST_F(DiskCacheEntryTest, MemoryOnlyInternalSyncIO) {
void DiskCacheEntryTest::InternalAsyncIO() {
disk_cache::Entry *entry1 = NULL;
- ASSERT_TRUE(cache_->CreateEntry("the first key", &entry1));
+ ASSERT_EQ(net::OK, CreateEntry("the first key", &entry1));
ASSERT_TRUE(NULL != entry1);
// Avoid using internal buffers for the test. We have to write something to
@@ -108,7 +108,7 @@ void DiskCacheEntryTest::InternalAsyncIO() {
EXPECT_EQ(0, entry1->WriteData(0, 15 * 1024, NULL, 0, NULL, false));
EXPECT_EQ(0, entry1->WriteData(1, 15 * 1024, NULL, 0, NULL, false));
entry1->Close();
- ASSERT_TRUE(cache_->OpenEntry("the first key", &entry1));
+ ASSERT_EQ(net::OK, OpenEntry("the first key", &entry1));
// Let's verify that each IO goes to the right callback object.
CallbackTest callback1(false);
@@ -238,7 +238,7 @@ TEST_F(DiskCacheEntryTest, MemoryOnlyInternalAsyncIO) {
void DiskCacheEntryTest::ExternalSyncIO() {
disk_cache::Entry *entry1;
- ASSERT_TRUE(cache_->CreateEntry("the first key", &entry1));
+ ASSERT_EQ(net::OK, CreateEntry("the first key", &entry1));
const int kSize1 = 17000;
const int kSize2 = 25000;
@@ -284,7 +284,7 @@ TEST_F(DiskCacheEntryTest, MemoryOnlyExternalSyncIO) {
void DiskCacheEntryTest::ExternalAsyncIO() {
disk_cache::Entry *entry1;
- ASSERT_TRUE(cache_->CreateEntry("the first key", &entry1));
+ ASSERT_EQ(net::OK, CreateEntry("the first key", &entry1));
// Let's verify that each IO goes to the right callback object.
CallbackTest callback1(false);
@@ -391,7 +391,7 @@ TEST_F(DiskCacheEntryTest, MemoryOnlyExternalAsyncIO) {
void DiskCacheEntryTest::StreamAccess() {
disk_cache::Entry *entry = NULL;
- ASSERT_TRUE(cache_->CreateEntry("the first key", &entry));
+ ASSERT_EQ(net::OK, CreateEntry("the first key", &entry));
ASSERT_TRUE(NULL != entry);
const int kBufferSize = 1024;
@@ -427,7 +427,7 @@ TEST_F(DiskCacheEntryTest, MemoryOnlyStreamAccess) {
void DiskCacheEntryTest::GetKey() {
std::string key1("the first key");
disk_cache::Entry *entry1;
- ASSERT_TRUE(cache_->CreateEntry(key1, &entry1));
+ ASSERT_EQ(net::OK, CreateEntry(key1, &entry1));
EXPECT_EQ(key1, entry1->GetKey()) << "short key";
entry1->Close();
@@ -439,14 +439,14 @@ void DiskCacheEntryTest::GetKey() {
key_buffer[1000] = '\0';
key1 = key_buffer;
- ASSERT_TRUE(cache_->CreateEntry(key1, &entry1));
+ ASSERT_EQ(net::OK, CreateEntry(key1, &entry1));
EXPECT_TRUE(key1 == entry1->GetKey()) << "1000 bytes key";
entry1->Close();
key_buffer[1000] = 'p';
key_buffer[3000] = '\0';
key1 = key_buffer;
- ASSERT_TRUE(cache_->CreateEntry(key1, &entry1));
+ ASSERT_EQ(net::OK, CreateEntry(key1, &entry1));
EXPECT_TRUE(key1 == entry1->GetKey()) << "medium size key";
entry1->Close();
@@ -454,7 +454,7 @@ void DiskCacheEntryTest::GetKey() {
key_buffer[19999] = '\0';
key1 = key_buffer;
- ASSERT_TRUE(cache_->CreateEntry(key1, &entry1));
+ ASSERT_EQ(net::OK, CreateEntry(key1, &entry1));
EXPECT_TRUE(key1 == entry1->GetKey()) << "long key";
entry1->Close();
}
@@ -473,7 +473,7 @@ TEST_F(DiskCacheEntryTest, MemoryOnlyGetKey) {
void DiskCacheEntryTest::GrowData() {
std::string key1("the first key");
disk_cache::Entry *entry1, *entry2;
- ASSERT_TRUE(cache_->CreateEntry(key1, &entry1));
+ ASSERT_EQ(net::OK, CreateEntry(key1, &entry1));
const int kSize = 20000;
scoped_refptr<net::IOBuffer> buffer1 = new net::IOBuffer(kSize);
@@ -499,13 +499,13 @@ void DiskCacheEntryTest::GrowData() {
entry1->Close();
memset(buffer2->data(), 0, kSize);
- ASSERT_TRUE(cache_->CreateEntry("Second key", &entry2));
+ ASSERT_EQ(net::OK, CreateEntry("Second key", &entry2));
EXPECT_EQ(10, entry2->WriteData(0, 0, buffer1, 10, NULL, false));
EXPECT_EQ(10, entry2->GetDataSize(0));
entry2->Close();
// Go from an internal address to a bigger block size.
- ASSERT_TRUE(cache_->OpenEntry("Second key", &entry2));
+ ASSERT_EQ(net::OK, OpenEntry("Second key", &entry2));
EXPECT_EQ(2000, entry2->WriteData(0, 0, buffer1, 2000, NULL, false));
EXPECT_EQ(2000, entry2->GetDataSize(0));
EXPECT_EQ(2000, entry2->ReadData(0, 0, buffer2, 2000, NULL));
@@ -514,7 +514,7 @@ void DiskCacheEntryTest::GrowData() {
memset(buffer2->data(), 0, kSize);
// Go from an internal address to an external one.
- ASSERT_TRUE(cache_->OpenEntry("Second key", &entry2));
+ ASSERT_EQ(net::OK, OpenEntry("Second key", &entry2));
EXPECT_EQ(20000, entry2->WriteData(0, 0, buffer1, kSize, NULL, false));
EXPECT_EQ(20000, entry2->GetDataSize(0));
EXPECT_EQ(20000, entry2->ReadData(0, 0, buffer2, kSize, NULL));
@@ -536,7 +536,7 @@ TEST_F(DiskCacheEntryTest, MemoryOnlyGrowData) {
void DiskCacheEntryTest::TruncateData() {
std::string key1("the first key");
disk_cache::Entry *entry1;
- ASSERT_TRUE(cache_->CreateEntry(key1, &entry1));
+ ASSERT_EQ(net::OK, CreateEntry(key1, &entry1));
const int kSize1 = 20000;
const int kSize2 = 20000;
@@ -558,7 +558,7 @@ void DiskCacheEntryTest::TruncateData() {
EXPECT_EQ(0, entry1->WriteData(0, 0, buffer1, 0, NULL, true));
EXPECT_EQ(0, entry1->GetDataSize(0));
entry1->Close();
- ASSERT_TRUE(cache_->OpenEntry(key1, &entry1));
+ ASSERT_EQ(net::OK, OpenEntry(key1, &entry1));
// Go to an external file.
EXPECT_EQ(20000, entry1->WriteData(0, 0, buffer1, 20000, NULL, true));
@@ -612,7 +612,7 @@ TEST_F(DiskCacheEntryTest, MemoryOnlyTruncateData) {
void DiskCacheEntryTest::ZeroLengthIO() {
std::string key1("the first key");
disk_cache::Entry *entry1;
- ASSERT_TRUE(cache_->CreateEntry(key1, &entry1));
+ ASSERT_EQ(net::OK, CreateEntry(key1, &entry1));
EXPECT_EQ(0, entry1->ReadData(0, 0, NULL, 0, NULL));
EXPECT_EQ(0, entry1->WriteData(0, 0, NULL, 0, NULL, false));
@@ -641,11 +641,11 @@ TEST_F(DiskCacheEntryTest, MemoryOnlyZeroLengthIO) {
void DiskCacheEntryTest::ReuseEntry(int size) {
std::string key1("the first key");
disk_cache::Entry *entry;
- ASSERT_TRUE(cache_->CreateEntry(key1, &entry));
+ ASSERT_EQ(net::OK, CreateEntry(key1, &entry));
entry->Close();
std::string key2("the second key");
- ASSERT_TRUE(cache_->CreateEntry(key2, &entry));
+ ASSERT_EQ(net::OK, CreateEntry(key2, &entry));
scoped_refptr<net::IOBuffer> buffer = new net::IOBuffer(size);
CacheTestFillBuffer(buffer->data(), size, false);
@@ -654,11 +654,11 @@ void DiskCacheEntryTest::ReuseEntry(int size) {
EXPECT_EQ(0, entry->WriteData(0, 0, buffer, 0, NULL, true));
EXPECT_EQ(size, entry->WriteData(0, 0, buffer, size, NULL, false));
entry->Close();
- ASSERT_TRUE(cache_->OpenEntry(key2, &entry));
+ ASSERT_EQ(net::OK, OpenEntry(key2, &entry));
}
entry->Close();
- ASSERT_TRUE(cache_->OpenEntry(key1, &entry)) << "have not evicted this entry";
+ ASSERT_EQ(net::OK, OpenEntry(key1, &entry)) << "have not evicted this entry";
entry->Close();
}
@@ -696,7 +696,7 @@ TEST_F(DiskCacheEntryTest, MemoryOnlyReuseInternalEntry) {
void DiskCacheEntryTest::InvalidData() {
std::string key1("the first key");
disk_cache::Entry *entry1;
- ASSERT_TRUE(cache_->CreateEntry(key1, &entry1));
+ ASSERT_EQ(net::OK, CreateEntry(key1, &entry1));
const int kSize1 = 20000;
const int kSize2 = 20000;
@@ -714,7 +714,7 @@ void DiskCacheEntryTest::InvalidData() {
EXPECT_EQ(100, entry1->ReadData(0, 300, buffer3, 100, NULL));
EXPECT_TRUE(!memcmp(buffer3->data(), buffer2->data(), 100));
entry1->Close();
- ASSERT_TRUE(cache_->OpenEntry(key1, &entry1));
+ ASSERT_EQ(net::OK, OpenEntry(key1, &entry1));
// The entry is now on disk. Load it and extend it.
EXPECT_EQ(200, entry1->WriteData(0, 800, buffer1, 200, NULL, false));
@@ -722,7 +722,7 @@ void DiskCacheEntryTest::InvalidData() {
EXPECT_EQ(100, entry1->ReadData(0, 700, buffer3, 100, NULL));
EXPECT_TRUE(!memcmp(buffer3->data(), buffer2->data(), 100));
entry1->Close();
- ASSERT_TRUE(cache_->OpenEntry(key1, &entry1));
+ ASSERT_EQ(net::OK, OpenEntry(key1, &entry1));
// This time using truncate.
EXPECT_EQ(200, entry1->WriteData(0, 1800, buffer1, 200, NULL, true));
@@ -768,10 +768,10 @@ TEST_F(DiskCacheEntryTest, MemoryOnlyInvalidData) {
InvalidData();
}
-void DiskCacheEntryTest::DoomEntry() {
+void DiskCacheEntryTest::DoomNormalEntry() {
std::string key1("the first key");
disk_cache::Entry *entry1;
- ASSERT_TRUE(cache_->CreateEntry(key1, &entry1));
+ ASSERT_EQ(net::OK, CreateEntry(key1, &entry1));
entry1->Doom();
entry1->Close();
@@ -781,7 +781,7 @@ void DiskCacheEntryTest::DoomEntry() {
buffer->data()[19999] = '\0';
key1 = buffer->data();
- ASSERT_TRUE(cache_->CreateEntry(key1, &entry1));
+ ASSERT_EQ(net::OK, CreateEntry(key1, &entry1));
EXPECT_EQ(20000, entry1->WriteData(0, 0, buffer, kSize, NULL, false));
EXPECT_EQ(20000, entry1->WriteData(1, 0, buffer, kSize, NULL, false));
entry1->Doom();
@@ -792,20 +792,20 @@ void DiskCacheEntryTest::DoomEntry() {
TEST_F(DiskCacheEntryTest, DoomEntry) {
InitCache();
- DoomEntry();
+ DoomNormalEntry();
}
TEST_F(DiskCacheEntryTest, MemoryOnlyDoomEntry) {
SetMemoryOnlyMode();
InitCache();
- DoomEntry();
+ DoomNormalEntry();
}
// Verify that basic operations work as expected with doomed entries.
void DiskCacheEntryTest::DoomedEntry() {
std::string key("the first key");
disk_cache::Entry *entry;
- ASSERT_TRUE(cache_->CreateEntry(key, &entry));
+ ASSERT_EQ(net::OK, CreateEntry(key, &entry));
entry->Doom();
EXPECT_EQ(0, cache_->GetEntryCount());
@@ -831,13 +831,13 @@ void DiskCacheEntryTest::DoomedEntry() {
TEST_F(DiskCacheEntryTest, DoomedEntry) {
InitCache();
- DoomEntry();
+ DoomedEntry();
}
TEST_F(DiskCacheEntryTest, MemoryOnlyDoomedEntry) {
SetMemoryOnlyMode();
InitCache();
- DoomEntry();
+ DoomedEntry();
}
// Test that child entries in a memory cache backend are not visible from
@@ -852,7 +852,7 @@ TEST_F(DiskCacheEntryTest, MemoryOnlyEnumerationWithSparseEntries) {
std::string key("the first key");
disk_cache::Entry* parent_entry;
- ASSERT_TRUE(cache_->CreateEntry(key, &parent_entry));
+ ASSERT_EQ(net::OK, CreateEntry(key, &parent_entry));
// Writes to the parent entry.
EXPECT_EQ(kSize, parent_entry->WriteSparseData(0, buf, kSize, NULL));
@@ -866,7 +866,7 @@ TEST_F(DiskCacheEntryTest, MemoryOnlyEnumerationWithSparseEntries) {
void* iter = NULL;
disk_cache::Entry* entry = NULL;
int count = 0;
- while (cache_->OpenNextEntry(&iter, &entry)) {
+ while (OpenNextEntry(&iter, &entry) == net::OK) {
ASSERT_TRUE(entry != NULL);
++count;
disk_cache::MemEntryImpl* mem_entry =
@@ -919,7 +919,7 @@ void VerifyContentSparseIO(disk_cache::Entry* entry, int64 offset, char* buffer,
void DiskCacheEntryTest::BasicSparseIO(bool async) {
std::string key("the first key");
disk_cache::Entry* entry;
- ASSERT_TRUE(cache_->CreateEntry(key, &entry));
+ ASSERT_EQ(net::OK, CreateEntry(key, &entry));
const int kSize = 2048;
scoped_refptr<net::IOBuffer> buf_1 = new net::IOBuffer(kSize);
@@ -938,7 +938,7 @@ void DiskCacheEntryTest::BasicSparseIO(bool async) {
entry->Close();
// Check everything again.
- ASSERT_TRUE(cache_->OpenEntry(key, &entry));
+ ASSERT_EQ(net::OK, OpenEntry(key, &entry));
VerifyContentSparseIO(entry, 0, buf_1->data(), kSize, async);
VerifyContentSparseIO(entry, 0x400000, buf_1->data(), kSize, async);
VerifyContentSparseIO(entry, 0x800000000LL, buf_1->data(), kSize, async);
@@ -970,7 +970,7 @@ TEST_F(DiskCacheEntryTest, MemoryOnlyBasicSparseAsyncIO) {
void DiskCacheEntryTest::HugeSparseIO(bool async) {
std::string key("the first key");
disk_cache::Entry* entry;
- ASSERT_TRUE(cache_->CreateEntry(key, &entry));
+ ASSERT_EQ(net::OK, CreateEntry(key, &entry));
// Write 1.2 MB so that we cover multiple entries.
const int kSize = 1200 * 1024;
@@ -983,7 +983,7 @@ void DiskCacheEntryTest::HugeSparseIO(bool async) {
entry->Close();
// Check it again.
- ASSERT_TRUE(cache_->OpenEntry(key, &entry));
+ ASSERT_EQ(net::OK, OpenEntry(key, &entry));
VerifyContentSparseIO(entry, 0x20F0000, buf_1->data(), kSize, async);
entry->Close();
}
@@ -1013,7 +1013,7 @@ TEST_F(DiskCacheEntryTest, MemoryOnlyHugeSparseAsyncIO) {
void DiskCacheEntryTest::GetAvailableRange() {
std::string key("the first key");
disk_cache::Entry* entry;
- ASSERT_TRUE(cache_->CreateEntry(key, &entry));
+ ASSERT_EQ(net::OK, CreateEntry(key, &entry));
const int kSize = 16 * 1024;
scoped_refptr<net::IOBuffer> buf = new net::IOBuffer(kSize);
@@ -1074,7 +1074,7 @@ TEST_F(DiskCacheEntryTest, MemoryOnlyMisalignedSparseIO) {
std::string key("the first key");
disk_cache::Entry* entry;
- ASSERT_TRUE(cache_->CreateEntry(key, &entry));
+ ASSERT_EQ(net::OK, CreateEntry(key, &entry));
// This loop writes back to back starting from offset 0 and 9000.
for (int i = 0; i < kSize; i += 1024) {
@@ -1104,7 +1104,7 @@ TEST_F(DiskCacheEntryTest, MemoryOnlyMisalignedGetAvailableRange) {
disk_cache::Entry* entry;
std::string key("the first key");
- ASSERT_TRUE(cache_->CreateEntry(key, &entry));
+ ASSERT_EQ(net::OK, CreateEntry(key, &entry));
// Writes in the middle of an entry.
EXPECT_EQ(1024, entry->WriteSparseData(0, buf, 1024, NULL));
@@ -1149,8 +1149,8 @@ void DiskCacheEntryTest::DoomSparseEntry() {
std::string key1("the first key");
std::string key2("the second key");
disk_cache::Entry *entry1, *entry2;
- ASSERT_TRUE(cache_->CreateEntry(key1, &entry1));
- ASSERT_TRUE(cache_->CreateEntry(key2, &entry2));
+ ASSERT_EQ(net::OK, CreateEntry(key1, &entry1));
+ ASSERT_EQ(net::OK, CreateEntry(key2, &entry2));
const int kSize = 4 * 1024;
scoped_refptr<net::IOBuffer> buf = new net::IOBuffer(kSize);
@@ -1177,7 +1177,7 @@ void DiskCacheEntryTest::DoomSparseEntry() {
entry2->Close();
// Doom the second entry after it's fully saved.
- EXPECT_TRUE(cache_->DoomEntry(key2));
+ EXPECT_EQ(net::OK, DoomEntry(key2));
// Make sure we do all needed work. This may fail for entry2 if between Close
// and DoomEntry the system decides to remove all traces of the file from the
@@ -1212,7 +1212,7 @@ TEST_F(DiskCacheEntryTest, MemoryOnlyDoomSparseEntry) {
void DiskCacheEntryTest::PartialSparseEntry() {
std::string key("the first key");
disk_cache::Entry* entry;
- ASSERT_TRUE(cache_->CreateEntry(key, &entry));
+ ASSERT_EQ(net::OK, CreateEntry(key, &entry));
// We should be able to deal with IO that is not aligned to the block size
// of a sparse entry, at least to write a big range without leaving holes.
@@ -1229,7 +1229,7 @@ void DiskCacheEntryTest::PartialSparseEntry() {
EXPECT_EQ(kSmallSize,
entry->WriteSparseData(1080321, buf1, kSmallSize, NULL));
entry->Close();
- ASSERT_TRUE(cache_->OpenEntry(key, &entry));
+ ASSERT_EQ(net::OK, OpenEntry(key, &entry));
scoped_refptr<net::IOBuffer> buf2 = new net::IOBuffer(kSize);
memset(buf2->data(), 0, kSize);
@@ -1294,13 +1294,13 @@ TEST_F(DiskCacheEntryTest, MemoryPartialSparseEntry) {
PartialSparseEntry();
}
+// Tests that corrupt sparse children are removed automatically.
TEST_F(DiskCacheEntryTest, CleanupSparseEntry) {
InitCache();
std::string key("the first key");
disk_cache::Entry* entry;
- ASSERT_TRUE(cache_->CreateEntry(key, &entry));
+ ASSERT_EQ(net::OK, CreateEntry(key, &entry));
- // Corrupt sparse children should be removed automatically.
const int kSize = 4 * 1024;
scoped_refptr<net::IOBuffer> buf1 = new net::IOBuffer(kSize);
CacheTestFillBuffer(buf1->data(), kSize, false);
@@ -1315,7 +1315,7 @@ TEST_F(DiskCacheEntryTest, CleanupSparseEntry) {
void* iter = NULL;
int count = 0;
std::string child_key[2];
- while (cache_->OpenNextEntry(&iter, &entry)) {
+ while (OpenNextEntry(&iter, &entry) == net::OK) {
ASSERT_TRUE(entry != NULL);
// Writing to an entry will alter the LRU list and invalidate the iterator.
if (entry->GetKey() != key && count < 2)
@@ -1323,14 +1323,14 @@ TEST_F(DiskCacheEntryTest, CleanupSparseEntry) {
entry->Close();
}
for (int i = 0; i < 2; i++) {
- ASSERT_TRUE(cache_->OpenEntry(child_key[i], &entry));
+ ASSERT_EQ(net::OK, OpenEntry(child_key[i], &entry));
// Overwrite the header's magic and signature.
EXPECT_EQ(12, entry->WriteData(2, 0, buf1, 12, NULL, false));
entry->Close();
}
EXPECT_EQ(4, cache_->GetEntryCount());
- ASSERT_TRUE(cache_->OpenEntry(key, &entry));
+ ASSERT_EQ(net::OK, OpenEntry(key, &entry));
// Two children should be gone. One while reading and one while writing.
EXPECT_EQ(0, entry->ReadSparseData(2 * k1Meg + 8192, buf1, kSize, NULL));
@@ -1349,7 +1349,7 @@ TEST_F(DiskCacheEntryTest, CancelSparseIO) {
InitCache();
std::string key("the first key");
disk_cache::Entry* entry;
- ASSERT_TRUE(cache_->CreateEntry(key, &entry));
+ ASSERT_EQ(net::OK, CreateEntry(key, &entry));
const int kSize = 40 * 1024;
scoped_refptr<net::IOBuffer> buf = new net::IOBuffer(kSize);
@@ -1358,7 +1358,7 @@ TEST_F(DiskCacheEntryTest, CancelSparseIO) {
TestCompletionCallback cb1, cb2, cb3, cb4;
int64 offset = 0;
int tries = 0;
- const int maxtries = 100; // Avoid hang on infinitely fast disks
+ const int maxtries = 100; // Avoid hang on infinitely fast disks.
for (int ret = 0; ret != net::ERR_IO_PENDING; offset += kSize * 4) {
ret = entry->WriteSparseData(offset, buf, kSize, &cb1);
if (++tries > maxtries) {