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

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

Issue 12794003: Initialize the simple cache backend at runtime. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: . Created 7 years, 9 months 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
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" 5 #include "base/basictypes.h"
6 #include "base/file_util.h" 6 #include "base/file_util.h"
7 #include "base/string_util.h" 7 #include "base/string_util.h"
8 #include "base/stringprintf.h" 8 #include "base/stringprintf.h"
9 #include "base/third_party/dynamic_annotations/dynamic_annotations.h" 9 #include "base/third_party/dynamic_annotations/dynamic_annotations.h"
10 #include "base/threading/platform_thread.h" 10 #include "base/threading/platform_thread.h"
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 210
211 TEST_F(DiskCacheTest, CreateBackend) { 211 TEST_F(DiskCacheTest, CreateBackend) {
212 net::TestCompletionCallback cb; 212 net::TestCompletionCallback cb;
213 213
214 { 214 {
215 ASSERT_TRUE(CleanupCacheDir()); 215 ASSERT_TRUE(CleanupCacheDir());
216 base::Thread cache_thread("CacheThread"); 216 base::Thread cache_thread("CacheThread");
217 ASSERT_TRUE(cache_thread.StartWithOptions( 217 ASSERT_TRUE(cache_thread.StartWithOptions(
218 base::Thread::Options(MessageLoop::TYPE_IO, 0))); 218 base::Thread::Options(MessageLoop::TYPE_IO, 0)));
219 219
220 // Test the private factory methods. 220 // Test the private factory methods.
rvargas (doing something else) 2013/03/13 19:36:01 If there's no private factory method, this part of
pasko-google - do not use 2013/03/18 15:47:07 Done.
221 disk_cache::Backend* cache = NULL; 221 disk_cache::Backend* cache = NULL;
222 int rv = disk_cache::BackendImpl::CreateBackend( 222 int rv = disk_cache::CreateCacheBackend(net::DISK_CACHE, cache_path_,
223 cache_path_, false, 0, net::DISK_CACHE, disk_cache::kNoRandom, 223 0, false, cache_thread.message_loop_proxy(), NULL, &cache,
224 cache_thread.message_loop_proxy(), NULL, &cache, cb.callback()); 224 cb.callback());
225 ASSERT_EQ(net::OK, cb.GetResult(rv)); 225 ASSERT_EQ(net::OK, cb.GetResult(rv));
226 ASSERT_TRUE(cache); 226 ASSERT_TRUE(cache);
227 delete cache; 227 delete cache;
228 228
229 cache = disk_cache::MemBackendImpl::CreateBackend(0, NULL); 229 cache = disk_cache::MemBackendImpl::CreateBackend(0, NULL);
230 ASSERT_TRUE(cache); 230 ASSERT_TRUE(cache);
231 delete cache; 231 delete cache;
232 cache = NULL; 232 cache = NULL;
233 233
234 // Now test the public API. 234 // Now test the public API.
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
294 { 294 {
295 ASSERT_TRUE(CleanupCacheDir()); 295 ASSERT_TRUE(CleanupCacheDir());
296 base::Thread cache_thread("CacheThread"); 296 base::Thread cache_thread("CacheThread");
297 ASSERT_TRUE(cache_thread.StartWithOptions( 297 ASSERT_TRUE(cache_thread.StartWithOptions(
298 base::Thread::Options(MessageLoop::TYPE_IO, 0))); 298 base::Thread::Options(MessageLoop::TYPE_IO, 0)));
299 299
300 disk_cache::Backend* cache; 300 disk_cache::Backend* cache;
301 uint32 flags = disk_cache::kNoBuffering; 301 uint32 flags = disk_cache::kNoBuffering;
302 if (!fast) 302 if (!fast)
303 flags |= disk_cache::kNoRandom; 303 flags |= disk_cache::kNoRandom;
304 rv = disk_cache::BackendImpl::CreateBackend( 304 rv = disk_cache::CreateCacheBackendWithFlags(
305 cache_path_, false, 0, net::DISK_CACHE, flags, 305 net::DISK_CACHE, cache_path_, 0, false, flags,
306 base::MessageLoopProxy::current(), NULL, 306 base::MessageLoopProxy::current(), NULL,
307 &cache, cb.callback()); 307 &cache, cb.callback());
308 ASSERT_EQ(net::OK, cb.GetResult(rv)); 308 ASSERT_EQ(net::OK, cb.GetResult(rv));
309 309
310 disk_cache::EntryImpl* entry; 310 disk_cache::EntryImpl* entry;
311 rv = cache->CreateEntry( 311 rv = cache->CreateEntry(
312 "some key", reinterpret_cast<disk_cache::Entry**>(&entry), 312 "some key", reinterpret_cast<disk_cache::Entry**>(&entry),
313 cb.callback()); 313 cb.callback());
314 ASSERT_EQ(net::OK, cb.GetResult(rv)); 314 ASSERT_EQ(net::OK, cb.GetResult(rv));
315 315
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
372 { 372 {
373 ASSERT_TRUE(CleanupCacheDir()); 373 ASSERT_TRUE(CleanupCacheDir());
374 base::Thread cache_thread("CacheThread"); 374 base::Thread cache_thread("CacheThread");
375 ASSERT_TRUE(cache_thread.StartWithOptions( 375 ASSERT_TRUE(cache_thread.StartWithOptions(
376 base::Thread::Options(MessageLoop::TYPE_IO, 0))); 376 base::Thread::Options(MessageLoop::TYPE_IO, 0)));
377 377
378 disk_cache::Backend* cache; 378 disk_cache::Backend* cache;
379 uint32 flags = disk_cache::kNoBuffering; 379 uint32 flags = disk_cache::kNoBuffering;
380 if (!fast) 380 if (!fast)
381 flags |= disk_cache::kNoRandom; 381 flags |= disk_cache::kNoRandom;
382 int rv = disk_cache::BackendImpl::CreateBackend( 382 int rv = disk_cache::CreateCacheBackendWithFlags(
383 cache_path_, false, 0, net::DISK_CACHE, flags, 383 net::DISK_CACHE, cache_path_, 0, false, flags,
384 cache_thread.message_loop_proxy(), NULL, &cache, cb.callback()); 384 cache_thread.message_loop_proxy(), NULL, &cache, cb.callback());
385 ASSERT_EQ(net::OK, cb.GetResult(rv)); 385 ASSERT_EQ(net::OK, cb.GetResult(rv));
386 386
387 disk_cache::Entry* entry; 387 disk_cache::Entry* entry;
388 rv = cache->CreateEntry("some key", &entry, cb.callback()); 388 rv = cache->CreateEntry("some key", &entry, cb.callback());
389 ASSERT_EQ(net::OK, cb.GetResult(rv)); 389 ASSERT_EQ(net::OK, cb.GetResult(rv));
390 390
391 entry->Close(); 391 entry->Close();
392 392
393 // The cache destructor will see one pending operation here. 393 // The cache destructor will see one pending operation here.
(...skipping 21 matching lines...) Expand all
415 415
416 { 416 {
417 ASSERT_TRUE(CleanupCacheDir()); 417 ASSERT_TRUE(CleanupCacheDir());
418 base::Thread cache_thread("CacheThread"); 418 base::Thread cache_thread("CacheThread");
419 ASSERT_TRUE(cache_thread.StartWithOptions( 419 ASSERT_TRUE(cache_thread.StartWithOptions(
420 base::Thread::Options(MessageLoop::TYPE_IO, 0))); 420 base::Thread::Options(MessageLoop::TYPE_IO, 0)));
421 421
422 disk_cache::Backend* cache; 422 disk_cache::Backend* cache;
423 disk_cache::BackendFlags flags = 423 disk_cache::BackendFlags flags =
424 fast ? disk_cache::kNone : disk_cache::kNoRandom; 424 fast ? disk_cache::kNone : disk_cache::kNoRandom;
425 int rv = disk_cache::BackendImpl::CreateBackend( 425 int rv = disk_cache::CreateCacheBackendWithFlags(
426 cache_path_, false, 0, net::DISK_CACHE, flags, 426 net::DISK_CACHE, cache_path_, 0, false, flags,
427 cache_thread.message_loop_proxy(), NULL, &cache, cb.callback()); 427 cache_thread.message_loop_proxy(), NULL, &cache, cb.callback());
428 ASSERT_EQ(net::OK, cb.GetResult(rv)); 428 ASSERT_EQ(net::OK, cb.GetResult(rv));
429 429
430 disk_cache::Entry* entry; 430 disk_cache::Entry* entry;
431 rv = cache->CreateEntry("some key", &entry, cb.callback()); 431 rv = cache->CreateEntry("some key", &entry, cb.callback());
432 ASSERT_EQ(net::ERR_IO_PENDING, rv); 432 ASSERT_EQ(net::ERR_IO_PENDING, rv);
433 433
434 delete cache; 434 delete cache;
435 EXPECT_FALSE(cb.have_result()); 435 EXPECT_FALSE(cb.have_result());
436 } 436 }
(...skipping 17 matching lines...) Expand all
454 ASSERT_TRUE(CleanupCacheDir()); 454 ASSERT_TRUE(CleanupCacheDir());
455 base::FilePath index = cache_path_.AppendASCII("index"); 455 base::FilePath index = cache_path_.AppendASCII("index");
456 ASSERT_EQ(5, file_util::WriteFile(index, "hello", 5)); 456 ASSERT_EQ(5, file_util::WriteFile(index, "hello", 5));
457 457
458 base::Thread cache_thread("CacheThread"); 458 base::Thread cache_thread("CacheThread");
459 ASSERT_TRUE(cache_thread.StartWithOptions( 459 ASSERT_TRUE(cache_thread.StartWithOptions(
460 base::Thread::Options(MessageLoop::TYPE_IO, 0))); 460 base::Thread::Options(MessageLoop::TYPE_IO, 0)));
461 net::TestCompletionCallback cb; 461 net::TestCompletionCallback cb;
462 462
463 disk_cache::Backend* backend = NULL; 463 disk_cache::Backend* backend = NULL;
464 int rv = disk_cache::BackendImpl::CreateBackend( 464 int rv = disk_cache::CreateCacheBackend(
465 cache_path_, false, 0, net::DISK_CACHE, disk_cache::kNone, 465 net::DISK_CACHE, cache_path_, 0, false,
466 cache_thread.message_loop_proxy(), NULL, &backend, cb.callback()); 466 cache_thread.message_loop_proxy(), NULL, &backend, cb.callback());
467 ASSERT_NE(net::OK, cb.GetResult(rv)); 467 ASSERT_NE(net::OK, cb.GetResult(rv));
468 468
469 ASSERT_TRUE(backend == NULL); 469 ASSERT_TRUE(backend == NULL);
470 delete backend; 470 delete backend;
471 } 471 }
472 472
473 void DiskCacheBackendTest::BackendSetSize() { 473 void DiskCacheBackendTest::BackendSetSize() {
474 SetDirectMode(); 474 SetDirectMode();
475 const int cache_size = 0x10000; // 64 kB 475 const int cache_size = 0x10000; // 64 kB
(...skipping 1072 matching lines...) Expand 10 before | Expand all | Expand 10 after
1548 1548
1549 // Tests dealing with cache files that cannot be recovered. 1549 // Tests dealing with cache files that cannot be recovered.
1550 TEST_F(DiskCacheTest, DeleteOld) { 1550 TEST_F(DiskCacheTest, DeleteOld) {
1551 ASSERT_TRUE(CopyTestCache("wrong_version")); 1551 ASSERT_TRUE(CopyTestCache("wrong_version"));
1552 base::Thread cache_thread("CacheThread"); 1552 base::Thread cache_thread("CacheThread");
1553 ASSERT_TRUE(cache_thread.StartWithOptions( 1553 ASSERT_TRUE(cache_thread.StartWithOptions(
1554 base::Thread::Options(MessageLoop::TYPE_IO, 0))); 1554 base::Thread::Options(MessageLoop::TYPE_IO, 0)));
1555 net::TestCompletionCallback cb; 1555 net::TestCompletionCallback cb;
1556 1556
1557 disk_cache::Backend* cache; 1557 disk_cache::Backend* cache;
1558 int rv = disk_cache::BackendImpl::CreateBackend( 1558 int rv = disk_cache::CreateCacheBackendWithFlags(
1559 cache_path_, true, 0, net::DISK_CACHE, disk_cache::kNoRandom, 1559 net::DISK_CACHE, cache_path_, 0, true, disk_cache::kNoRandom,
1560 cache_thread.message_loop_proxy(), NULL, &cache, cb.callback()); 1560 cache_thread.message_loop_proxy(), NULL, &cache, cb.callback());
1561 ASSERT_EQ(net::OK, cb.GetResult(rv)); 1561 ASSERT_EQ(net::OK, cb.GetResult(rv));
1562 1562
1563 MessageLoopHelper helper; 1563 MessageLoopHelper helper;
1564 1564
1565 ASSERT_TRUE(NULL != cache); 1565 ASSERT_TRUE(NULL != cache);
1566 ASSERT_EQ(0, cache->GetEntryCount()); 1566 ASSERT_EQ(0, cache->GetEntryCount());
1567 1567
1568 delete cache; 1568 delete cache;
1569 } 1569 }
(...skipping 883 matching lines...) Expand 10 before | Expand all | Expand 10 after
2453 ASSERT_TRUE(store2.CreateUniqueTempDir()); 2453 ASSERT_TRUE(store2.CreateUniqueTempDir());
2454 2454
2455 base::Thread cache_thread("CacheThread"); 2455 base::Thread cache_thread("CacheThread");
2456 ASSERT_TRUE(cache_thread.StartWithOptions( 2456 ASSERT_TRUE(cache_thread.StartWithOptions(
2457 base::Thread::Options(MessageLoop::TYPE_IO, 0))); 2457 base::Thread::Options(MessageLoop::TYPE_IO, 0)));
2458 net::TestCompletionCallback cb; 2458 net::TestCompletionCallback cb;
2459 2459
2460 const int kNumberOfCaches = 2; 2460 const int kNumberOfCaches = 2;
2461 disk_cache::Backend* cache[kNumberOfCaches]; 2461 disk_cache::Backend* cache[kNumberOfCaches];
2462 2462
2463 int rv = disk_cache::BackendImpl::CreateBackend( 2463 int rv = disk_cache::CreateCacheBackend(
2464 store1.path(), false, 0, net::DISK_CACHE, disk_cache::kNone, 2464 net::DISK_CACHE, store1.path(), 0, false,
2465 cache_thread.message_loop_proxy(), NULL, &cache[0], cb.callback()); 2465 cache_thread.message_loop_proxy(), NULL, &cache[0], cb.callback());
2466 ASSERT_EQ(net::OK, cb.GetResult(rv)); 2466 ASSERT_EQ(net::OK, cb.GetResult(rv));
2467 rv = disk_cache::BackendImpl::CreateBackend( 2467 rv = disk_cache::CreateCacheBackend(
2468 store2.path(), false, 0, net::MEDIA_CACHE, disk_cache::kNone, 2468 net::MEDIA_CACHE, store2.path(), 0, false,
2469 cache_thread.message_loop_proxy(), NULL, &cache[1], cb.callback()); 2469 cache_thread.message_loop_proxy(), NULL, &cache[1], cb.callback());
2470 ASSERT_EQ(net::OK, cb.GetResult(rv)); 2470 ASSERT_EQ(net::OK, cb.GetResult(rv));
2471 2471
2472 ASSERT_TRUE(cache[0] != NULL && cache[1] != NULL); 2472 ASSERT_TRUE(cache[0] != NULL && cache[1] != NULL);
2473 2473
2474 std::string key("the first key"); 2474 std::string key("the first key");
2475 disk_cache::Entry* entry; 2475 disk_cache::Entry* entry;
2476 for (int i = 0; i < kNumberOfCaches; i++) { 2476 for (int i = 0; i < kNumberOfCaches; i++) {
2477 rv = cache[i]->CreateEntry(key, &entry, cb.callback()); 2477 rv = cache[i]->CreateEntry(key, &entry, cb.callback());
2478 ASSERT_EQ(net::OK, cb.GetResult(rv)); 2478 ASSERT_EQ(net::OK, cb.GetResult(rv));
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
2684 // Ping the oldest entry. 2684 // Ping the oldest entry.
2685 cache_->OnExternalCacheHit("key0"); 2685 cache_->OnExternalCacheHit("key0");
2686 2686
2687 TrimForTest(false); 2687 TrimForTest(false);
2688 2688
2689 // Make sure the older key remains. 2689 // Make sure the older key remains.
2690 EXPECT_EQ(1, cache_->GetEntryCount()); 2690 EXPECT_EQ(1, cache_->GetEntryCount());
2691 ASSERT_EQ(net::OK, OpenEntry("key0", &entry)); 2691 ASSERT_EQ(net::OK, OpenEntry("key0", &entry));
2692 entry->Close(); 2692 entry->Close();
2693 } 2693 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698