Chromium Code Reviews| 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 <stdint.h> | 5 #include <stdint.h> |
| 6 | 6 |
| 7 #include "base/files/file_util.h" | 7 #include "base/files/file_util.h" |
| 8 #include "base/metrics/field_trial.h" | 8 #include "base/metrics/field_trial.h" |
| 9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
| 10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
| (...skipping 2929 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2940 } | 2940 } |
| 2941 | 2941 |
| 2942 TEST_F(DiskCacheBackendTest, MemoryOnlyBackendEviction) { | 2942 TEST_F(DiskCacheBackendTest, MemoryOnlyBackendEviction) { |
| 2943 SetMemoryOnlyMode(); | 2943 SetMemoryOnlyMode(); |
| 2944 BackendEviction(); | 2944 BackendEviction(); |
| 2945 } | 2945 } |
| 2946 | 2946 |
| 2947 // TODO(gavinp): Enable BackendEviction test for simple cache after performance | 2947 // TODO(gavinp): Enable BackendEviction test for simple cache after performance |
| 2948 // problems are addressed. See crbug.com/588184 for more information. | 2948 // problems are addressed. See crbug.com/588184 for more information. |
| 2949 | 2949 |
| 2950 // This overly specific looking test is a regression test aimed at | |
| 2951 // crbug.com/589186. | |
| 2952 TEST_F(DiskCacheBackendTest, MemoryOnlyUseAfterFree) { | |
|
gavinp
2016/02/25 15:55:32
The rename of the test makes it way more consisten
| |
| 2953 SetMemoryOnlyMode(); | |
| 2954 | |
| 2955 const int kMaxSize = 200 * 1024; | |
| 2956 const int kMaxEntryCount = 20; | |
| 2957 const int kWriteSize = kMaxSize / kMaxEntryCount; | |
| 2958 | |
| 2959 SetMaxSize(kMaxSize); | |
| 2960 InitCache(); | |
| 2961 | |
| 2962 scoped_refptr<net::IOBuffer> buffer(new net::IOBuffer(kWriteSize)); | |
| 2963 CacheTestFillBuffer(buffer->data(), kWriteSize, false); | |
| 2964 | |
| 2965 // Create an entry to be our sparse entry that gets written later. | |
| 2966 disk_cache::Entry* entry; | |
| 2967 ASSERT_EQ(net::OK, CreateEntry("first parent", &entry)); | |
| 2968 disk_cache::ScopedEntryPtr first_parent(entry); | |
| 2969 | |
| 2970 // Create a ton of entries, and keep them open, to put the cache well above | |
| 2971 // its eviction threshhold. | |
| 2972 const int kTooManyEntriesCount = kMaxEntryCount * 2; | |
| 2973 std::list<disk_cache::ScopedEntryPtr> open_entries; | |
| 2974 std::string key_prefix("prefix"); | |
| 2975 for (int i = 0; i < kTooManyEntriesCount; ++i) { | |
| 2976 ASSERT_EQ(net::OK, CreateEntry(key_prefix + base::IntToString(i), &entry)); | |
| 2977 EXPECT_EQ(kWriteSize, | |
| 2978 WriteData(entry, 1, 0, buffer.get(), kWriteSize, false)); | |
| 2979 open_entries.push_back(disk_cache::ScopedEntryPtr(entry)); | |
| 2980 } | |
| 2981 EXPECT_LT(kMaxSize, CalculateSizeOfAllEntries()); | |
| 2982 | |
| 2983 // Writing this sparse data should not crash. | |
| 2984 EXPECT_EQ(1024, first_parent->WriteSparseData(32768, buffer.get(), 1024, | |
| 2985 net::CompletionCallback())); | |
| 2986 } | |
| 2987 | |
| 2950 TEST_F(DiskCacheTest, Backend_UsageStatsTimer) { | 2988 TEST_F(DiskCacheTest, Backend_UsageStatsTimer) { |
| 2951 MessageLoopHelper helper; | 2989 MessageLoopHelper helper; |
| 2952 | 2990 |
| 2953 ASSERT_TRUE(CleanupCacheDir()); | 2991 ASSERT_TRUE(CleanupCacheDir()); |
| 2954 scoped_ptr<disk_cache::BackendImpl> cache; | 2992 scoped_ptr<disk_cache::BackendImpl> cache; |
| 2955 cache.reset(new disk_cache::BackendImpl( | 2993 cache.reset(new disk_cache::BackendImpl( |
| 2956 cache_path_, base::ThreadTaskRunnerHandle::Get(), NULL)); | 2994 cache_path_, base::ThreadTaskRunnerHandle::Get(), NULL)); |
| 2957 ASSERT_TRUE(NULL != cache.get()); | 2995 ASSERT_TRUE(NULL != cache.get()); |
| 2958 cache->SetUnitTestMode(); | 2996 cache->SetUnitTestMode(); |
| 2959 ASSERT_EQ(net::OK, cache->SyncInit()); | 2997 ASSERT_EQ(net::OK, cache->SyncInit()); |
| (...skipping 743 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3703 // after closing. | 3741 // after closing. |
| 3704 // NOTE: IF THIS TEST IS FLAKY THEN IT IS FAILING. See https://crbug.com/416940 | 3742 // NOTE: IF THIS TEST IS FLAKY THEN IT IS FAILING. See https://crbug.com/416940 |
| 3705 TEST_F(DiskCacheBackendTest, SimpleCacheDeleteQuickly) { | 3743 TEST_F(DiskCacheBackendTest, SimpleCacheDeleteQuickly) { |
| 3706 SetSimpleCacheMode(); | 3744 SetSimpleCacheMode(); |
| 3707 for (int i = 0; i < 100; ++i) { | 3745 for (int i = 0; i < 100; ++i) { |
| 3708 InitCache(); | 3746 InitCache(); |
| 3709 cache_.reset(); | 3747 cache_.reset(); |
| 3710 EXPECT_TRUE(CleanupCacheDir()); | 3748 EXPECT_TRUE(CleanupCacheDir()); |
| 3711 } | 3749 } |
| 3712 } | 3750 } |
| OLD | NEW |