OLD | NEW |
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 "base/basictypes.h" | 5 #include "base/basictypes.h" |
6 #include "base/bind.h" | 6 #include "base/bind.h" |
7 #include "base/bind_helpers.h" | 7 #include "base/bind_helpers.h" |
8 #include "base/files/file.h" | 8 #include "base/files/file.h" |
9 #include "base/files/file_util.h" | 9 #include "base/files/file_util.h" |
10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
(...skipping 1599 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1610 0, buf.get(), kSize, net::CompletionCallback())); | 1610 0, buf.get(), kSize, net::CompletionCallback())); |
1611 | 1611 |
1612 // This write creates a child entry and writes to it. | 1612 // This write creates a child entry and writes to it. |
1613 EXPECT_EQ(kSize, | 1613 EXPECT_EQ(kSize, |
1614 parent_entry->WriteSparseData( | 1614 parent_entry->WriteSparseData( |
1615 8192, buf.get(), kSize, net::CompletionCallback())); | 1615 8192, buf.get(), kSize, net::CompletionCallback())); |
1616 | 1616 |
1617 parent_entry->Close(); | 1617 parent_entry->Close(); |
1618 | 1618 |
1619 // Perform the enumerations. | 1619 // Perform the enumerations. |
1620 void* iter = NULL; | 1620 scoped_ptr<TestIterator> iter = CreateIterator(); |
1621 disk_cache::Entry* entry = NULL; | 1621 disk_cache::Entry* entry = NULL; |
1622 int count = 0; | 1622 int count = 0; |
1623 while (OpenNextEntry(&iter, &entry) == net::OK) { | 1623 while (iter->OpenNextEntry(&entry) == net::OK) { |
1624 ASSERT_TRUE(entry != NULL); | 1624 ASSERT_TRUE(entry != NULL); |
1625 ++count; | 1625 ++count; |
1626 disk_cache::MemEntryImpl* mem_entry = | 1626 disk_cache::MemEntryImpl* mem_entry = |
1627 reinterpret_cast<disk_cache::MemEntryImpl*>(entry); | 1627 reinterpret_cast<disk_cache::MemEntryImpl*>(entry); |
1628 EXPECT_EQ(disk_cache::MemEntryImpl::kParentEntry, mem_entry->type()); | 1628 EXPECT_EQ(disk_cache::MemEntryImpl::kParentEntry, mem_entry->type()); |
1629 mem_entry->Close(); | 1629 mem_entry->Close(); |
1630 } | 1630 } |
1631 EXPECT_EQ(1, count); | 1631 EXPECT_EQ(1, count); |
1632 } | 1632 } |
1633 | 1633 |
(...skipping 576 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2210 scoped_refptr<net::IOBuffer> buf1(new net::IOBuffer(kSize)); | 2210 scoped_refptr<net::IOBuffer> buf1(new net::IOBuffer(kSize)); |
2211 CacheTestFillBuffer(buf1->data(), kSize, false); | 2211 CacheTestFillBuffer(buf1->data(), kSize, false); |
2212 | 2212 |
2213 const int k1Meg = 1024 * 1024; | 2213 const int k1Meg = 1024 * 1024; |
2214 EXPECT_EQ(kSize, WriteSparseData(entry, 8192, buf1.get(), kSize)); | 2214 EXPECT_EQ(kSize, WriteSparseData(entry, 8192, buf1.get(), kSize)); |
2215 EXPECT_EQ(kSize, WriteSparseData(entry, k1Meg + 8192, buf1.get(), kSize)); | 2215 EXPECT_EQ(kSize, WriteSparseData(entry, k1Meg + 8192, buf1.get(), kSize)); |
2216 EXPECT_EQ(kSize, WriteSparseData(entry, 2 * k1Meg + 8192, buf1.get(), kSize)); | 2216 EXPECT_EQ(kSize, WriteSparseData(entry, 2 * k1Meg + 8192, buf1.get(), kSize)); |
2217 entry->Close(); | 2217 entry->Close(); |
2218 EXPECT_EQ(4, cache_->GetEntryCount()); | 2218 EXPECT_EQ(4, cache_->GetEntryCount()); |
2219 | 2219 |
2220 void* iter = NULL; | 2220 scoped_ptr<TestIterator> iter = CreateIterator(); |
2221 int count = 0; | 2221 int count = 0; |
2222 std::string child_key[2]; | 2222 std::string child_key[2]; |
2223 while (OpenNextEntry(&iter, &entry) == net::OK) { | 2223 while (iter->OpenNextEntry(&entry) == net::OK) { |
2224 ASSERT_TRUE(entry != NULL); | 2224 ASSERT_TRUE(entry != NULL); |
2225 // Writing to an entry will alter the LRU list and invalidate the iterator. | 2225 // Writing to an entry will alter the LRU list and invalidate the iterator. |
2226 if (entry->GetKey() != key && count < 2) | 2226 if (entry->GetKey() != key && count < 2) |
2227 child_key[count++] = entry->GetKey(); | 2227 child_key[count++] = entry->GetKey(); |
2228 entry->Close(); | 2228 entry->Close(); |
2229 } | 2229 } |
2230 for (int i = 0; i < 2; i++) { | 2230 for (int i = 0; i < 2; i++) { |
2231 ASSERT_EQ(net::OK, OpenEntry(child_key[i], &entry)); | 2231 ASSERT_EQ(net::OK, OpenEntry(child_key[i], &entry)); |
2232 // Overwrite the header's magic and signature. | 2232 // Overwrite the header's magic and signature. |
2233 EXPECT_EQ(12, WriteData(entry, 2, 0, buf1.get(), 12, false)); | 2233 EXPECT_EQ(12, WriteData(entry, 2, 0, buf1.get(), 12, false)); |
(...skipping 1824 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4058 EXPECT_EQ(kSize, callback.GetResult(ret)); | 4058 EXPECT_EQ(kSize, callback.GetResult(ret)); |
4059 | 4059 |
4060 // Make sure the first range was removed when the second was written. | 4060 // Make sure the first range was removed when the second was written. |
4061 ret = entry->ReadSparseData(0, buffer.get(), kSize, callback.callback()); | 4061 ret = entry->ReadSparseData(0, buffer.get(), kSize, callback.callback()); |
4062 EXPECT_EQ(0, callback.GetResult(ret)); | 4062 EXPECT_EQ(0, callback.GetResult(ret)); |
4063 | 4063 |
4064 entry->Close(); | 4064 entry->Close(); |
4065 } | 4065 } |
4066 | 4066 |
4067 #endif // defined(OS_POSIX) | 4067 #endif // defined(OS_POSIX) |
OLD | NEW |