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/files/file_util.h" | 6 #include "base/files/file_util.h" |
7 #include "base/metrics/field_trial.h" | 7 #include "base/metrics/field_trial.h" |
8 #include "base/port.h" | 8 #include "base/port.h" |
9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
(...skipping 11 matching lines...) Expand all Loading... |
22 #include "net/disk_cache/blockfile/histogram_macros.h" | 22 #include "net/disk_cache/blockfile/histogram_macros.h" |
23 #include "net/disk_cache/blockfile/mapped_file.h" | 23 #include "net/disk_cache/blockfile/mapped_file.h" |
24 #include "net/disk_cache/cache_util.h" | 24 #include "net/disk_cache/cache_util.h" |
25 #include "net/disk_cache/disk_cache_test_base.h" | 25 #include "net/disk_cache/disk_cache_test_base.h" |
26 #include "net/disk_cache/disk_cache_test_util.h" | 26 #include "net/disk_cache/disk_cache_test_util.h" |
27 #include "net/disk_cache/memory/mem_backend_impl.h" | 27 #include "net/disk_cache/memory/mem_backend_impl.h" |
28 #include "net/disk_cache/simple/simple_backend_impl.h" | 28 #include "net/disk_cache/simple/simple_backend_impl.h" |
29 #include "net/disk_cache/simple/simple_entry_format.h" | 29 #include "net/disk_cache/simple/simple_entry_format.h" |
30 #include "net/disk_cache/simple/simple_test_util.h" | 30 #include "net/disk_cache/simple/simple_test_util.h" |
31 #include "net/disk_cache/simple/simple_util.h" | 31 #include "net/disk_cache/simple/simple_util.h" |
32 #include "net/disk_cache/tracing/tracing_cache_backend.h" | |
33 #include "testing/gtest/include/gtest/gtest.h" | 32 #include "testing/gtest/include/gtest/gtest.h" |
34 | 33 |
35 #if defined(OS_WIN) | 34 #if defined(OS_WIN) |
36 #include "base/win/scoped_handle.h" | 35 #include "base/win/scoped_handle.h" |
37 #endif | 36 #endif |
38 | 37 |
39 // Provide a BackendImpl object to macros from histogram_macros.h. | 38 // Provide a BackendImpl object to macros from histogram_macros.h. |
40 #define CACHE_UMA_BACKEND_IMPL_OBJ backend_ | 39 #define CACHE_UMA_BACKEND_IMPL_OBJ backend_ |
41 | 40 |
42 using base::Time; | 41 using base::Time; |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 void BackendInvalidEntry11(bool eviction); | 119 void BackendInvalidEntry11(bool eviction); |
121 void BackendTrimInvalidEntry12(); | 120 void BackendTrimInvalidEntry12(); |
122 void BackendDoomAll(); | 121 void BackendDoomAll(); |
123 void BackendDoomAll2(); | 122 void BackendDoomAll2(); |
124 void BackendInvalidRankings(); | 123 void BackendInvalidRankings(); |
125 void BackendInvalidRankings2(); | 124 void BackendInvalidRankings2(); |
126 void BackendDisable(); | 125 void BackendDisable(); |
127 void BackendDisable2(); | 126 void BackendDisable2(); |
128 void BackendDisable3(); | 127 void BackendDisable3(); |
129 void BackendDisable4(); | 128 void BackendDisable4(); |
130 void TracingBackendBasics(); | |
131 }; | 129 }; |
132 | 130 |
133 int DiskCacheBackendTest::GeneratePendingIO(net::TestCompletionCallback* cb) { | 131 int DiskCacheBackendTest::GeneratePendingIO(net::TestCompletionCallback* cb) { |
134 if (!use_current_thread_) { | 132 if (!use_current_thread_) { |
135 ADD_FAILURE(); | 133 ADD_FAILURE(); |
136 return net::ERR_FAILED; | 134 return net::ERR_FAILED; |
137 } | 135 } |
138 | 136 |
139 disk_cache::Entry* entry; | 137 disk_cache::Entry* entry; |
140 int rv = cache_->CreateEntry("some key", &entry, cb->callback()); | 138 int rv = cache_->CreateEntry("some key", &entry, cb->callback()); |
(...skipping 3002 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3143 cache_->OnExternalCacheHit("key0"); | 3141 cache_->OnExternalCacheHit("key0"); |
3144 | 3142 |
3145 TrimForTest(false); | 3143 TrimForTest(false); |
3146 | 3144 |
3147 // Make sure the older key remains. | 3145 // Make sure the older key remains. |
3148 EXPECT_EQ(1, cache_->GetEntryCount()); | 3146 EXPECT_EQ(1, cache_->GetEntryCount()); |
3149 ASSERT_EQ(net::OK, OpenEntry("key0", &entry)); | 3147 ASSERT_EQ(net::OK, OpenEntry("key0", &entry)); |
3150 entry->Close(); | 3148 entry->Close(); |
3151 } | 3149 } |
3152 | 3150 |
3153 void DiskCacheBackendTest::TracingBackendBasics() { | |
3154 InitCache(); | |
3155 cache_.reset(new disk_cache::TracingCacheBackend(cache_.Pass())); | |
3156 cache_impl_ = NULL; | |
3157 EXPECT_EQ(net::DISK_CACHE, cache_->GetCacheType()); | |
3158 if (!simple_cache_mode_) { | |
3159 EXPECT_EQ(0, cache_->GetEntryCount()); | |
3160 } | |
3161 | |
3162 net::TestCompletionCallback cb; | |
3163 disk_cache::Entry* entry = NULL; | |
3164 EXPECT_NE(net::OK, OpenEntry("key", &entry)); | |
3165 EXPECT_TRUE(NULL == entry); | |
3166 | |
3167 ASSERT_EQ(net::OK, CreateEntry("key", &entry)); | |
3168 EXPECT_TRUE(NULL != entry); | |
3169 | |
3170 disk_cache::Entry* same_entry = NULL; | |
3171 ASSERT_EQ(net::OK, OpenEntry("key", &same_entry)); | |
3172 EXPECT_TRUE(NULL != same_entry); | |
3173 | |
3174 if (!simple_cache_mode_) { | |
3175 EXPECT_EQ(1, cache_->GetEntryCount()); | |
3176 } | |
3177 entry->Close(); | |
3178 entry = NULL; | |
3179 same_entry->Close(); | |
3180 same_entry = NULL; | |
3181 } | |
3182 | |
3183 TEST_F(DiskCacheBackendTest, TracingBackendBasics) { | |
3184 TracingBackendBasics(); | |
3185 } | |
3186 | |
3187 // The Simple Cache backend requires a few guarantees from the filesystem like | 3151 // The Simple Cache backend requires a few guarantees from the filesystem like |
3188 // atomic renaming of recently open files. Those guarantees are not provided in | 3152 // atomic renaming of recently open files. Those guarantees are not provided in |
3189 // general on Windows. | 3153 // general on Windows. |
3190 #if defined(OS_POSIX) | 3154 #if defined(OS_POSIX) |
3191 | 3155 |
3192 TEST_F(DiskCacheBackendTest, SimpleCacheShutdownWithPendingCreate) { | 3156 TEST_F(DiskCacheBackendTest, SimpleCacheShutdownWithPendingCreate) { |
3193 SetCacheType(net::APP_CACHE); | 3157 SetCacheType(net::APP_CACHE); |
3194 SetSimpleCacheMode(); | 3158 SetSimpleCacheMode(); |
3195 BackendShutdownWithPendingCreate(false); | 3159 BackendShutdownWithPendingCreate(false); |
3196 } | 3160 } |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3264 SetSimpleCacheMode(); | 3228 SetSimpleCacheMode(); |
3265 BackendDoomAll(); | 3229 BackendDoomAll(); |
3266 } | 3230 } |
3267 | 3231 |
3268 TEST_F(DiskCacheBackendTest, SimpleCacheAppCacheOnlyDoomAll) { | 3232 TEST_F(DiskCacheBackendTest, SimpleCacheAppCacheOnlyDoomAll) { |
3269 SetCacheType(net::APP_CACHE); | 3233 SetCacheType(net::APP_CACHE); |
3270 SetSimpleCacheMode(); | 3234 SetSimpleCacheMode(); |
3271 BackendDoomAll(); | 3235 BackendDoomAll(); |
3272 } | 3236 } |
3273 | 3237 |
3274 TEST_F(DiskCacheBackendTest, SimpleCacheTracingBackendBasics) { | |
3275 SetSimpleCacheMode(); | |
3276 TracingBackendBasics(); | |
3277 // TODO(pasko): implement integrity checking on the Simple Backend. | |
3278 DisableIntegrityCheck(); | |
3279 } | |
3280 | |
3281 TEST_F(DiskCacheBackendTest, SimpleCacheOpenMissingFile) { | 3238 TEST_F(DiskCacheBackendTest, SimpleCacheOpenMissingFile) { |
3282 SetSimpleCacheMode(); | 3239 SetSimpleCacheMode(); |
3283 InitCache(); | 3240 InitCache(); |
3284 | 3241 |
3285 const char* key = "the first key"; | 3242 const char* key = "the first key"; |
3286 disk_cache::Entry* entry = NULL; | 3243 disk_cache::Entry* entry = NULL; |
3287 | 3244 |
3288 ASSERT_EQ(net::OK, CreateEntry(key, &entry)); | 3245 ASSERT_EQ(net::OK, CreateEntry(key, &entry)); |
3289 ASSERT_TRUE(entry != NULL); | 3246 ASSERT_TRUE(entry != NULL); |
3290 entry->Close(); | 3247 entry->Close(); |
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3510 void* iter = NULL; | 3467 void* iter = NULL; |
3511 size_t count = 0; | 3468 size_t count = 0; |
3512 ASSERT_TRUE(EnumerateAndMatchKeys(-1, &iter, &keys_to_match, &count)); | 3469 ASSERT_TRUE(EnumerateAndMatchKeys(-1, &iter, &keys_to_match, &count)); |
3513 cache_->EndEnumeration(&iter); | 3470 cache_->EndEnumeration(&iter); |
3514 | 3471 |
3515 EXPECT_EQ(key_pool.size(), count); | 3472 EXPECT_EQ(key_pool.size(), count); |
3516 EXPECT_TRUE(keys_to_match.empty()); | 3473 EXPECT_TRUE(keys_to_match.empty()); |
3517 } | 3474 } |
3518 | 3475 |
3519 #endif // defined(OS_POSIX) | 3476 #endif // defined(OS_POSIX) |
OLD | NEW |