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

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

Issue 1535363003: Switch to standard integer types in net/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: stddef Created 5 years 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_test_util.cc ('k') | net/disk_cache/memory/mem_backend_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 "base/basictypes.h"
6 #include "base/bind.h" 5 #include "base/bind.h"
7 #include "base/bind_helpers.h" 6 #include "base/bind_helpers.h"
8 #include "base/files/file.h" 7 #include "base/files/file.h"
9 #include "base/files/file_util.h" 8 #include "base/files/file_util.h"
9 #include "base/macros.h"
10 #include "base/strings/string_number_conversions.h" 10 #include "base/strings/string_number_conversions.h"
11 #include "base/strings/string_util.h" 11 #include "base/strings/string_util.h"
12 #include "base/threading/platform_thread.h" 12 #include "base/threading/platform_thread.h"
13 #include "net/base/completion_callback.h" 13 #include "net/base/completion_callback.h"
14 #include "net/base/io_buffer.h" 14 #include "net/base/io_buffer.h"
15 #include "net/base/net_errors.h" 15 #include "net/base/net_errors.h"
16 #include "net/base/test_completion_callback.h" 16 #include "net/base/test_completion_callback.h"
17 #include "net/disk_cache/blockfile/backend_impl.h" 17 #include "net/disk_cache/blockfile/backend_impl.h"
18 #include "net/disk_cache/blockfile/entry_impl.h" 18 #include "net/disk_cache/blockfile/entry_impl.h"
19 #include "net/disk_cache/disk_cache_test_base.h" 19 #include "net/disk_cache/disk_cache_test_base.h"
(...skipping 1611 matching lines...) Expand 10 before | Expand all | Expand 10 after
1631 ++count; 1631 ++count;
1632 disk_cache::MemEntryImpl* mem_entry = 1632 disk_cache::MemEntryImpl* mem_entry =
1633 reinterpret_cast<disk_cache::MemEntryImpl*>(entry); 1633 reinterpret_cast<disk_cache::MemEntryImpl*>(entry);
1634 EXPECT_EQ(disk_cache::MemEntryImpl::kParentEntry, mem_entry->type()); 1634 EXPECT_EQ(disk_cache::MemEntryImpl::kParentEntry, mem_entry->type());
1635 mem_entry->Close(); 1635 mem_entry->Close();
1636 } 1636 }
1637 EXPECT_EQ(1, count); 1637 EXPECT_EQ(1, count);
1638 } 1638 }
1639 1639
1640 // Writes |buf_1| to offset and reads it back as |buf_2|. 1640 // Writes |buf_1| to offset and reads it back as |buf_2|.
1641 void VerifySparseIO(disk_cache::Entry* entry, int64 offset, 1641 void VerifySparseIO(disk_cache::Entry* entry,
1642 net::IOBuffer* buf_1, int size, net::IOBuffer* buf_2) { 1642 int64_t offset,
1643 net::IOBuffer* buf_1,
1644 int size,
1645 net::IOBuffer* buf_2) {
1643 net::TestCompletionCallback cb; 1646 net::TestCompletionCallback cb;
1644 1647
1645 memset(buf_2->data(), 0, size); 1648 memset(buf_2->data(), 0, size);
1646 int ret = entry->ReadSparseData(offset, buf_2, size, cb.callback()); 1649 int ret = entry->ReadSparseData(offset, buf_2, size, cb.callback());
1647 EXPECT_EQ(0, cb.GetResult(ret)); 1650 EXPECT_EQ(0, cb.GetResult(ret));
1648 1651
1649 ret = entry->WriteSparseData(offset, buf_1, size, cb.callback()); 1652 ret = entry->WriteSparseData(offset, buf_1, size, cb.callback());
1650 EXPECT_EQ(size, cb.GetResult(ret)); 1653 EXPECT_EQ(size, cb.GetResult(ret));
1651 1654
1652 ret = entry->ReadSparseData(offset, buf_2, size, cb.callback()); 1655 ret = entry->ReadSparseData(offset, buf_2, size, cb.callback());
1653 EXPECT_EQ(size, cb.GetResult(ret)); 1656 EXPECT_EQ(size, cb.GetResult(ret));
1654 1657
1655 EXPECT_EQ(0, memcmp(buf_1->data(), buf_2->data(), size)); 1658 EXPECT_EQ(0, memcmp(buf_1->data(), buf_2->data(), size));
1656 } 1659 }
1657 1660
1658 // Reads |size| bytes from |entry| at |offset| and verifies that they are the 1661 // Reads |size| bytes from |entry| at |offset| and verifies that they are the
1659 // same as the content of the provided |buffer|. 1662 // same as the content of the provided |buffer|.
1660 void VerifyContentSparseIO(disk_cache::Entry* entry, int64 offset, char* buffer, 1663 void VerifyContentSparseIO(disk_cache::Entry* entry,
1664 int64_t offset,
1665 char* buffer,
1661 int size) { 1666 int size) {
1662 net::TestCompletionCallback cb; 1667 net::TestCompletionCallback cb;
1663 1668
1664 scoped_refptr<net::IOBuffer> buf_1(new net::IOBuffer(size)); 1669 scoped_refptr<net::IOBuffer> buf_1(new net::IOBuffer(size));
1665 memset(buf_1->data(), 0, size); 1670 memset(buf_1->data(), 0, size);
1666 int ret = entry->ReadSparseData(offset, buf_1.get(), size, cb.callback()); 1671 int ret = entry->ReadSparseData(offset, buf_1.get(), size, cb.callback());
1667 EXPECT_EQ(size, cb.GetResult(ret)); 1672 EXPECT_EQ(size, cb.GetResult(ret));
1668 EXPECT_EQ(0, memcmp(buf_1->data(), buffer, size)); 1673 EXPECT_EQ(0, memcmp(buf_1->data(), buffer, size));
1669 } 1674 }
1670 1675
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
1747 1752
1748 const int kSize = 16 * 1024; 1753 const int kSize = 16 * 1024;
1749 scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(kSize)); 1754 scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(kSize));
1750 CacheTestFillBuffer(buf->data(), kSize, false); 1755 CacheTestFillBuffer(buf->data(), kSize, false);
1751 1756
1752 // Write at offset 0x20F0000 (33 MB - 64 KB), and 0x20F4400 (33 MB - 47 KB). 1757 // Write at offset 0x20F0000 (33 MB - 64 KB), and 0x20F4400 (33 MB - 47 KB).
1753 EXPECT_EQ(kSize, WriteSparseData(entry, 0x20F0000, buf.get(), kSize)); 1758 EXPECT_EQ(kSize, WriteSparseData(entry, 0x20F0000, buf.get(), kSize));
1754 EXPECT_EQ(kSize, WriteSparseData(entry, 0x20F4400, buf.get(), kSize)); 1759 EXPECT_EQ(kSize, WriteSparseData(entry, 0x20F4400, buf.get(), kSize));
1755 1760
1756 // We stop at the first empty block. 1761 // We stop at the first empty block.
1757 int64 start; 1762 int64_t start;
1758 net::TestCompletionCallback cb; 1763 net::TestCompletionCallback cb;
1759 int rv = entry->GetAvailableRange( 1764 int rv = entry->GetAvailableRange(
1760 0x20F0000, kSize * 2, &start, cb.callback()); 1765 0x20F0000, kSize * 2, &start, cb.callback());
1761 EXPECT_EQ(kSize, cb.GetResult(rv)); 1766 EXPECT_EQ(kSize, cb.GetResult(rv));
1762 EXPECT_EQ(0x20F0000, start); 1767 EXPECT_EQ(0x20F0000, start);
1763 1768
1764 start = 0; 1769 start = 0;
1765 rv = entry->GetAvailableRange(0, kSize, &start, cb.callback()); 1770 rv = entry->GetAvailableRange(0, kSize, &start, cb.callback());
1766 EXPECT_EQ(0, cb.GetResult(rv)); 1771 EXPECT_EQ(0, cb.GetResult(rv));
1767 rv = entry->GetAvailableRange( 1772 rv = entry->GetAvailableRange(
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
1826 scoped_refptr<net::IOBuffer> buf_1(new net::IOBuffer(kSize)); 1831 scoped_refptr<net::IOBuffer> buf_1(new net::IOBuffer(kSize));
1827 scoped_refptr<net::IOBuffer> buf_2(new net::IOBuffer(kSize)); 1832 scoped_refptr<net::IOBuffer> buf_2(new net::IOBuffer(kSize));
1828 CacheTestFillBuffer(buf_1->data(), kSize, false); 1833 CacheTestFillBuffer(buf_1->data(), kSize, false);
1829 1834
1830 // Do small writes (180 bytes) that get increasingly close to a 1024-byte 1835 // Do small writes (180 bytes) that get increasingly close to a 1024-byte
1831 // boundary. All data should be dropped until a boundary is crossed, at which 1836 // boundary. All data should be dropped until a boundary is crossed, at which
1832 // point the data after the boundary is saved (at least for a while). 1837 // point the data after the boundary is saved (at least for a while).
1833 int offset = 1024 - 500; 1838 int offset = 1024 - 500;
1834 int rv = 0; 1839 int rv = 0;
1835 net::TestCompletionCallback cb; 1840 net::TestCompletionCallback cb;
1836 int64 start; 1841 int64_t start;
1837 for (int i = 0; i < 5; i++) { 1842 for (int i = 0; i < 5; i++) {
1838 // Check result of last GetAvailableRange. 1843 // Check result of last GetAvailableRange.
1839 EXPECT_EQ(0, rv); 1844 EXPECT_EQ(0, rv);
1840 1845
1841 rv = entry->WriteSparseData(offset, buf_1.get(), kSize, cb.callback()); 1846 rv = entry->WriteSparseData(offset, buf_1.get(), kSize, cb.callback());
1842 EXPECT_EQ(kSize, cb.GetResult(rv)); 1847 EXPECT_EQ(kSize, cb.GetResult(rv));
1843 1848
1844 rv = entry->GetAvailableRange(offset - 100, kSize, &start, cb.callback()); 1849 rv = entry->GetAvailableRange(offset - 100, kSize, &start, cb.callback());
1845 EXPECT_EQ(0, cb.GetResult(rv)); 1850 EXPECT_EQ(0, cb.GetResult(rv));
1846 1851
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
1880 ASSERT_EQ(net::OK, CreateEntry(key, &entry)); 1885 ASSERT_EQ(net::OK, CreateEntry(key, &entry));
1881 1886
1882 const int kSize = 180; 1887 const int kSize = 180;
1883 scoped_refptr<net::IOBuffer> buf_1(new net::IOBuffer(kSize)); 1888 scoped_refptr<net::IOBuffer> buf_1(new net::IOBuffer(kSize));
1884 scoped_refptr<net::IOBuffer> buf_2(new net::IOBuffer(kSize)); 1889 scoped_refptr<net::IOBuffer> buf_2(new net::IOBuffer(kSize));
1885 CacheTestFillBuffer(buf_1->data(), kSize, false); 1890 CacheTestFillBuffer(buf_1->data(), kSize, false);
1886 1891
1887 // Any starting offset is fine as long as it is 1024-bytes aligned. 1892 // Any starting offset is fine as long as it is 1024-bytes aligned.
1888 int rv = 0; 1893 int rv = 0;
1889 net::TestCompletionCallback cb; 1894 net::TestCompletionCallback cb;
1890 int64 start; 1895 int64_t start;
1891 int64 offset = 1024 * 11; 1896 int64_t offset = 1024 * 11;
1892 for (; offset < 20000; offset += kSize) { 1897 for (; offset < 20000; offset += kSize) {
1893 rv = entry->WriteSparseData(offset, buf_1.get(), kSize, cb.callback()); 1898 rv = entry->WriteSparseData(offset, buf_1.get(), kSize, cb.callback());
1894 EXPECT_EQ(kSize, cb.GetResult(rv)); 1899 EXPECT_EQ(kSize, cb.GetResult(rv));
1895 1900
1896 rv = entry->GetAvailableRange(offset, kSize, &start, cb.callback()); 1901 rv = entry->GetAvailableRange(offset, kSize, &start, cb.callback());
1897 EXPECT_EQ(kSize, cb.GetResult(rv)); 1902 EXPECT_EQ(kSize, cb.GetResult(rv));
1898 EXPECT_EQ(offset, start); 1903 EXPECT_EQ(offset, start);
1899 1904
1900 rv = entry->ReadSparseData(offset, buf_2.get(), kSize, cb.callback()); 1905 rv = entry->ReadSparseData(offset, buf_2.get(), kSize, cb.callback());
1901 EXPECT_EQ(kSize, cb.GetResult(rv)); 1906 EXPECT_EQ(kSize, cb.GetResult(rv));
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
2018 entry->WriteSparseData(5120, buf.get(), 1024, net::CompletionCallback())); 2023 entry->WriteSparseData(5120, buf.get(), 1024, net::CompletionCallback()));
2019 EXPECT_EQ(1024, 2024 EXPECT_EQ(1024,
2020 entry->WriteSparseData( 2025 entry->WriteSparseData(
2021 10000, buf.get(), 1024, net::CompletionCallback())); 2026 10000, buf.get(), 1024, net::CompletionCallback()));
2022 2027
2023 // Writes in the middle of an entry and spans 2 child entries. 2028 // Writes in the middle of an entry and spans 2 child entries.
2024 EXPECT_EQ(8192, 2029 EXPECT_EQ(8192,
2025 entry->WriteSparseData( 2030 entry->WriteSparseData(
2026 50000, buf.get(), 8192, net::CompletionCallback())); 2031 50000, buf.get(), 8192, net::CompletionCallback()));
2027 2032
2028 int64 start; 2033 int64_t start;
2029 net::TestCompletionCallback cb; 2034 net::TestCompletionCallback cb;
2030 // Test that we stop at a discontinuous child at the second block. 2035 // Test that we stop at a discontinuous child at the second block.
2031 int rv = entry->GetAvailableRange(0, 10000, &start, cb.callback()); 2036 int rv = entry->GetAvailableRange(0, 10000, &start, cb.callback());
2032 EXPECT_EQ(1024, cb.GetResult(rv)); 2037 EXPECT_EQ(1024, cb.GetResult(rv));
2033 EXPECT_EQ(0, start); 2038 EXPECT_EQ(0, start);
2034 2039
2035 // Test that number of bytes is reported correctly when we start from the 2040 // Test that number of bytes is reported correctly when we start from the
2036 // middle of a filled region. 2041 // middle of a filled region.
2037 rv = entry->GetAvailableRange(512, 10000, &start, cb.callback()); 2042 rv = entry->GetAvailableRange(512, 10000, &start, cb.callback());
2038 EXPECT_EQ(512, cb.GetResult(rv)); 2043 EXPECT_EQ(512, cb.GetResult(rv));
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
2110 std::string key1("the first key"); 2115 std::string key1("the first key");
2111 std::string key2("the second key"); 2116 std::string key2("the second key");
2112 disk_cache::Entry *entry1, *entry2; 2117 disk_cache::Entry *entry1, *entry2;
2113 ASSERT_EQ(net::OK, CreateEntry(key1, &entry1)); 2118 ASSERT_EQ(net::OK, CreateEntry(key1, &entry1));
2114 ASSERT_EQ(net::OK, CreateEntry(key2, &entry2)); 2119 ASSERT_EQ(net::OK, CreateEntry(key2, &entry2));
2115 2120
2116 const int kSize = 4 * 1024; 2121 const int kSize = 4 * 1024;
2117 scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(kSize)); 2122 scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(kSize));
2118 CacheTestFillBuffer(buf->data(), kSize, false); 2123 CacheTestFillBuffer(buf->data(), kSize, false);
2119 2124
2120 int64 offset = 1024; 2125 int64_t offset = 1024;
2121 // Write to a bunch of ranges. 2126 // Write to a bunch of ranges.
2122 for (int i = 0; i < 12; i++) { 2127 for (int i = 0; i < 12; i++) {
2123 EXPECT_EQ(kSize, WriteSparseData(entry1, offset, buf.get(), kSize)); 2128 EXPECT_EQ(kSize, WriteSparseData(entry1, offset, buf.get(), kSize));
2124 // Keep the second map under the default size. 2129 // Keep the second map under the default size.
2125 if (i < 9) 2130 if (i < 9)
2126 EXPECT_EQ(kSize, WriteSparseData(entry2, offset, buf.get(), kSize)); 2131 EXPECT_EQ(kSize, WriteSparseData(entry2, offset, buf.get(), kSize));
2127 2132
2128 offset *= 4; 2133 offset *= 4;
2129 } 2134 }
2130 2135
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
2198 UseCurrentThread(); 2203 UseCurrentThread();
2199 InitCache(); 2204 InitCache();
2200 std::string key("the key"); 2205 std::string key("the key");
2201 disk_cache::Entry* entry; 2206 disk_cache::Entry* entry;
2202 ASSERT_EQ(net::OK, CreateEntry(key, &entry)); 2207 ASSERT_EQ(net::OK, CreateEntry(key, &entry));
2203 2208
2204 const int kSize = 4 * 1024; 2209 const int kSize = 4 * 1024;
2205 scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(kSize)); 2210 scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(kSize));
2206 CacheTestFillBuffer(buf->data(), kSize, false); 2211 CacheTestFillBuffer(buf->data(), kSize, false);
2207 2212
2208 int64 offset = 1024; 2213 int64_t offset = 1024;
2209 // Write to a bunch of ranges. 2214 // Write to a bunch of ranges.
2210 for (int i = 0; i < 12; i++) { 2215 for (int i = 0; i < 12; i++) {
2211 EXPECT_EQ(kSize, 2216 EXPECT_EQ(kSize,
2212 entry->WriteSparseData( 2217 entry->WriteSparseData(
2213 offset, buf.get(), kSize, net::CompletionCallback())); 2218 offset, buf.get(), kSize, net::CompletionCallback()));
2214 offset *= 4; 2219 offset *= 4;
2215 } 2220 }
2216 EXPECT_EQ(9, cache_->GetEntryCount()); 2221 EXPECT_EQ(9, cache_->GetEntryCount());
2217 2222
2218 entry->Close(); 2223 entry->Close();
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
2256 // This read should not change anything. 2261 // This read should not change anything.
2257 if (memory_only_ || simple_cache_mode_) 2262 if (memory_only_ || simple_cache_mode_)
2258 EXPECT_EQ(96, ReadSparseData(entry, 24000, buf2.get(), kSize)); 2263 EXPECT_EQ(96, ReadSparseData(entry, 24000, buf2.get(), kSize));
2259 else 2264 else
2260 EXPECT_EQ(0, ReadSparseData(entry, 24000, buf2.get(), kSize)); 2265 EXPECT_EQ(0, ReadSparseData(entry, 24000, buf2.get(), kSize));
2261 2266
2262 EXPECT_EQ(500, ReadSparseData(entry, kSize, buf2.get(), kSize)); 2267 EXPECT_EQ(500, ReadSparseData(entry, kSize, buf2.get(), kSize));
2263 EXPECT_EQ(0, ReadSparseData(entry, 99, buf2.get(), kSize)); 2268 EXPECT_EQ(0, ReadSparseData(entry, 99, buf2.get(), kSize));
2264 2269
2265 int rv; 2270 int rv;
2266 int64 start; 2271 int64_t start;
2267 net::TestCompletionCallback cb; 2272 net::TestCompletionCallback cb;
2268 if (memory_only_ || simple_cache_mode_) { 2273 if (memory_only_ || simple_cache_mode_) {
2269 rv = entry->GetAvailableRange(0, 600, &start, cb.callback()); 2274 rv = entry->GetAvailableRange(0, 600, &start, cb.callback());
2270 EXPECT_EQ(100, cb.GetResult(rv)); 2275 EXPECT_EQ(100, cb.GetResult(rv));
2271 EXPECT_EQ(500, start); 2276 EXPECT_EQ(500, start);
2272 } else { 2277 } else {
2273 rv = entry->GetAvailableRange(0, 2048, &start, cb.callback()); 2278 rv = entry->GetAvailableRange(0, 2048, &start, cb.callback());
2274 EXPECT_EQ(1024, cb.GetResult(rv)); 2279 EXPECT_EQ(1024, cb.GetResult(rv));
2275 EXPECT_EQ(1024, start); 2280 EXPECT_EQ(1024, start);
2276 } 2281 }
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
2388 const int kSize = 40 * 1024; 2393 const int kSize = 40 * 1024;
2389 scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(kSize)); 2394 scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(kSize));
2390 CacheTestFillBuffer(buf->data(), kSize, false); 2395 CacheTestFillBuffer(buf->data(), kSize, false);
2391 2396
2392 // This will open and write two "real" entries. 2397 // This will open and write two "real" entries.
2393 net::TestCompletionCallback cb1, cb2, cb3, cb4, cb5; 2398 net::TestCompletionCallback cb1, cb2, cb3, cb4, cb5;
2394 int rv = entry->WriteSparseData( 2399 int rv = entry->WriteSparseData(
2395 1024 * 1024 - 4096, buf.get(), kSize, cb1.callback()); 2400 1024 * 1024 - 4096, buf.get(), kSize, cb1.callback());
2396 EXPECT_EQ(net::ERR_IO_PENDING, rv); 2401 EXPECT_EQ(net::ERR_IO_PENDING, rv);
2397 2402
2398 int64 offset = 0; 2403 int64_t offset = 0;
2399 rv = entry->GetAvailableRange(offset, kSize, &offset, cb5.callback()); 2404 rv = entry->GetAvailableRange(offset, kSize, &offset, cb5.callback());
2400 rv = cb5.GetResult(rv); 2405 rv = cb5.GetResult(rv);
2401 if (!cb1.have_result()) { 2406 if (!cb1.have_result()) {
2402 // We may or may not have finished writing to the entry. If we have not, 2407 // We may or may not have finished writing to the entry. If we have not,
2403 // we cannot start another operation at this time. 2408 // we cannot start another operation at this time.
2404 EXPECT_EQ(net::ERR_CACHE_OPERATION_NOT_SUPPORTED, rv); 2409 EXPECT_EQ(net::ERR_CACHE_OPERATION_NOT_SUPPORTED, rv);
2405 } 2410 }
2406 2411
2407 // We cancel the pending operation, and register multiple notifications. 2412 // We cancel the pending operation, and register multiple notifications.
2408 entry->CancelSparseIO(); 2413 entry->CancelSparseIO();
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
2630 entry = NULL; 2635 entry = NULL;
2631 2636
2632 // Corrupt the last byte of the data. 2637 // Corrupt the last byte of the data.
2633 base::FilePath entry_file0_path = cache_path_.AppendASCII( 2638 base::FilePath entry_file0_path = cache_path_.AppendASCII(
2634 disk_cache::simple_util::GetFilenameFromKeyAndFileIndex(key, 0)); 2639 disk_cache::simple_util::GetFilenameFromKeyAndFileIndex(key, 0));
2635 base::File entry_file0(entry_file0_path, 2640 base::File entry_file0(entry_file0_path,
2636 base::File::FLAG_WRITE | base::File::FLAG_OPEN); 2641 base::File::FLAG_WRITE | base::File::FLAG_OPEN);
2637 if (!entry_file0.IsValid()) 2642 if (!entry_file0.IsValid())
2638 return false; 2643 return false;
2639 2644
2640 int64 file_offset = 2645 int64_t file_offset =
2641 sizeof(disk_cache::SimpleFileHeader) + key.size() + kDataSize - 2; 2646 sizeof(disk_cache::SimpleFileHeader) + key.size() + kDataSize - 2;
2642 EXPECT_EQ(1, entry_file0.Write(file_offset, "X", 1)); 2647 EXPECT_EQ(1, entry_file0.Write(file_offset, "X", 1));
2643 *data_size = kDataSize; 2648 *data_size = kDataSize;
2644 return true; 2649 return true;
2645 } 2650 }
2646 2651
2647 // Tests that the simple cache can detect entries that have bad data. 2652 // Tests that the simple cache can detect entries that have bad data.
2648 TEST_F(DiskCacheEntryTest, SimpleCacheBadChecksum) { 2653 TEST_F(DiskCacheEntryTest, SimpleCacheBadChecksum) {
2649 SetSimpleCacheMode(); 2654 SetSimpleCacheMode();
2650 InitCache(); 2655 InitCache();
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
2683 2688
2684 const int kReadBufferSize = 200; 2689 const int kReadBufferSize = 200;
2685 EXPECT_GE(kReadBufferSize, entry->GetDataSize(1)); 2690 EXPECT_GE(kReadBufferSize, entry->GetDataSize(1));
2686 scoped_refptr<net::IOBuffer> read_buffer(new net::IOBuffer(kReadBufferSize)); 2691 scoped_refptr<net::IOBuffer> read_buffer(new net::IOBuffer(kReadBufferSize));
2687 EXPECT_EQ(net::ERR_CACHE_CHECKSUM_MISMATCH, 2692 EXPECT_EQ(net::ERR_CACHE_CHECKSUM_MISMATCH,
2688 ReadData(entry, 1, 0, read_buffer.get(), kReadBufferSize)); 2693 ReadData(entry, 1, 0, read_buffer.get(), kReadBufferSize));
2689 2694
2690 entry->Doom(); // Should not crash. 2695 entry->Doom(); // Should not crash.
2691 } 2696 }
2692 2697
2693 bool TruncatePath(const base::FilePath& file_path, int64 length) { 2698 bool TruncatePath(const base::FilePath& file_path, int64_t length) {
2694 base::File file(file_path, base::File::FLAG_WRITE | base::File::FLAG_OPEN); 2699 base::File file(file_path, base::File::FLAG_WRITE | base::File::FLAG_OPEN);
2695 if (!file.IsValid()) 2700 if (!file.IsValid())
2696 return false; 2701 return false;
2697 return file.SetLength(length); 2702 return file.SetLength(length);
2698 } 2703 }
2699 2704
2700 TEST_F(DiskCacheEntryTest, SimpleCacheNoEOF) { 2705 TEST_F(DiskCacheEntryTest, SimpleCacheNoEOF) {
2701 SetSimpleCacheMode(); 2706 SetSimpleCacheMode();
2702 InitCache(); 2707 InitCache();
2703 2708
(...skipping 10 matching lines...) Expand all
2714 // succed. 2719 // succed.
2715 ASSERT_EQ(net::OK, OpenEntry(key, &entry)); 2720 ASSERT_EQ(net::OK, OpenEntry(key, &entry));
2716 entry->Close(); 2721 entry->Close();
2717 entry = NULL; 2722 entry = NULL;
2718 2723
2719 // Truncate the file such that the length isn't sufficient to have an EOF 2724 // Truncate the file such that the length isn't sufficient to have an EOF
2720 // record. 2725 // record.
2721 int kTruncationBytes = -static_cast<int>(sizeof(disk_cache::SimpleFileEOF)); 2726 int kTruncationBytes = -static_cast<int>(sizeof(disk_cache::SimpleFileEOF));
2722 const base::FilePath entry_path = cache_path_.AppendASCII( 2727 const base::FilePath entry_path = cache_path_.AppendASCII(
2723 disk_cache::simple_util::GetFilenameFromKeyAndFileIndex(key, 0)); 2728 disk_cache::simple_util::GetFilenameFromKeyAndFileIndex(key, 0));
2724 const int64 invalid_size = 2729 const int64_t invalid_size =
2725 disk_cache::simple_util::GetFileSizeFromKeyAndDataSize(key, 2730 disk_cache::simple_util::GetFileSizeFromKeyAndDataSize(key,
2726 kTruncationBytes); 2731 kTruncationBytes);
2727 EXPECT_TRUE(TruncatePath(entry_path, invalid_size)); 2732 EXPECT_TRUE(TruncatePath(entry_path, invalid_size));
2728 EXPECT_EQ(net::ERR_FAILED, OpenEntry(key, &entry)); 2733 EXPECT_EQ(net::ERR_FAILED, OpenEntry(key, &entry));
2729 DisableIntegrityCheck(); 2734 DisableIntegrityCheck();
2730 } 2735 }
2731 2736
2732 TEST_F(DiskCacheEntryTest, SimpleCacheNonOptimisticOperationsBasic) { 2737 TEST_F(DiskCacheEntryTest, SimpleCacheNonOptimisticOperationsBasic) {
2733 // Test sequence: 2738 // Test sequence:
2734 // Create, Write, Read, Close. 2739 // Create, Write, Read, Close.
(...skipping 1416 matching lines...) Expand 10 before | Expand all | Expand 10 after
4151 ASSERT_EQ(net::OK, OpenEntry(key, &entry)); 4156 ASSERT_EQ(net::OK, OpenEntry(key, &entry));
4152 4157
4153 ret = entry->ReadSparseData(0, buffer.get(), kSize, callback.callback()); 4158 ret = entry->ReadSparseData(0, buffer.get(), kSize, callback.callback());
4154 EXPECT_EQ(0, callback.GetResult(ret)); 4159 EXPECT_EQ(0, callback.GetResult(ret));
4155 4160
4156 ret = entry->ReadSparseData(kSize, buffer.get(), kSize, callback.callback()); 4161 ret = entry->ReadSparseData(kSize, buffer.get(), kSize, callback.callback());
4157 EXPECT_EQ(kSize, callback.GetResult(ret)); 4162 EXPECT_EQ(kSize, callback.GetResult(ret));
4158 4163
4159 entry->Close(); 4164 entry->Close();
4160 } 4165 }
OLDNEW
« no previous file with comments | « net/disk_cache/disk_cache_test_util.cc ('k') | net/disk_cache/memory/mem_backend_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698