| OLD | NEW |
| 1 // Copyright (c) 2006-2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2010 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/file_util.h" | 6 #include "base/file_util.h" |
| 7 #include "base/platform_thread.h" | 7 #include "base/platform_thread.h" |
| 8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
| 9 #include "base/stringprintf.h" |
| 9 #include "base/third_party/dynamic_annotations/dynamic_annotations.h" | 10 #include "base/third_party/dynamic_annotations/dynamic_annotations.h" |
| 10 #include "net/base/io_buffer.h" | 11 #include "net/base/io_buffer.h" |
| 11 #include "net/base/net_errors.h" | 12 #include "net/base/net_errors.h" |
| 12 #include "net/base/test_completion_callback.h" | 13 #include "net/base/test_completion_callback.h" |
| 13 #include "net/disk_cache/backend_impl.h" | 14 #include "net/disk_cache/backend_impl.h" |
| 14 #include "net/disk_cache/disk_cache_test_base.h" | 15 #include "net/disk_cache/disk_cache_test_base.h" |
| 15 #include "net/disk_cache/disk_cache_test_util.h" | 16 #include "net/disk_cache/disk_cache_test_util.h" |
| 16 #include "net/disk_cache/histogram_macros.h" | 17 #include "net/disk_cache/histogram_macros.h" |
| 17 #include "net/disk_cache/mapped_file.h" | 18 #include "net/disk_cache/mapped_file.h" |
| 18 #include "net/disk_cache/mem_backend_impl.h" | 19 #include "net/disk_cache/mem_backend_impl.h" |
| (...skipping 726 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 745 const int kSize = 0x3000; // 12 kB | 746 const int kSize = 0x3000; // 12 kB |
| 746 SetMaxSize(kSize * 40); | 747 SetMaxSize(kSize * 40); |
| 747 InitCache(); | 748 InitCache(); |
| 748 | 749 |
| 749 scoped_refptr<net::IOBuffer> buffer = new net::IOBuffer(kSize); | 750 scoped_refptr<net::IOBuffer> buffer = new net::IOBuffer(kSize); |
| 750 memset(buffer->data(), 0, kSize); | 751 memset(buffer->data(), 0, kSize); |
| 751 disk_cache::Entry* entry; | 752 disk_cache::Entry* entry; |
| 752 | 753 |
| 753 // Writing 32 entries to this cache chains most of them. | 754 // Writing 32 entries to this cache chains most of them. |
| 754 for (int i = 0; i < 32; i++) { | 755 for (int i = 0; i < 32; i++) { |
| 755 std::string key(StringPrintf("some key %d", i)); | 756 std::string key(base::StringPrintf("some key %d", i)); |
| 756 ASSERT_EQ(net::OK, CreateEntry(key, &entry)); | 757 ASSERT_EQ(net::OK, CreateEntry(key, &entry)); |
| 757 EXPECT_EQ(kSize, WriteData(entry, 0, 0, buffer, kSize, false)); | 758 EXPECT_EQ(kSize, WriteData(entry, 0, 0, buffer, kSize, false)); |
| 758 entry->Close(); | 759 entry->Close(); |
| 759 ASSERT_EQ(net::OK, OpenEntry(key, &entry)); | 760 ASSERT_EQ(net::OK, OpenEntry(key, &entry)); |
| 760 // Note that we are not closing the entries. | 761 // Note that we are not closing the entries. |
| 761 } | 762 } |
| 762 | 763 |
| 763 // Simulate a crash. | 764 // Simulate a crash. |
| 764 SimulateCrash(); | 765 SimulateCrash(); |
| 765 | 766 |
| (...skipping 1115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1881 EXPECT_EQ(kOneMB * 2, cache_impl_->GetTotalBuffersSize()); | 1882 EXPECT_EQ(kOneMB * 2, cache_impl_->GetTotalBuffersSize()); |
| 1882 | 1883 |
| 1883 // Check the upper limit. | 1884 // Check the upper limit. |
| 1884 EXPECT_FALSE(cache_impl_->IsAllocAllowed(0, 30 * kOneMB)); | 1885 EXPECT_FALSE(cache_impl_->IsAllocAllowed(0, 30 * kOneMB)); |
| 1885 | 1886 |
| 1886 for (int i = 0; i < 30; i++) | 1887 for (int i = 0; i < 30; i++) |
| 1887 cache_impl_->IsAllocAllowed(0, kOneMB); // Ignore the result. | 1888 cache_impl_->IsAllocAllowed(0, kOneMB); // Ignore the result. |
| 1888 | 1889 |
| 1889 EXPECT_FALSE(cache_impl_->IsAllocAllowed(0, kOneMB)); | 1890 EXPECT_FALSE(cache_impl_->IsAllocAllowed(0, kOneMB)); |
| 1890 } | 1891 } |
| OLD | NEW |