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

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: rebased to latest, auto-merged net.gyp Created 7 years, 8 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
« no previous file with comments | « net/disk_cache/backend_impl.cc ('k') | net/disk_cache/cache_creator.cc » ('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" 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 method(s).
221 disk_cache::Backend* cache = NULL; 221 disk_cache::Backend* cache = NULL;
222 int rv = disk_cache::BackendImpl::CreateBackend(
223 cache_path_, false, 0, net::DISK_CACHE, disk_cache::kNoRandom,
224 cache_thread.message_loop_proxy(), NULL, &cache, cb.callback());
225 ASSERT_EQ(net::OK, cb.GetResult(rv));
226 ASSERT_TRUE(cache);
227 delete cache;
228
229 cache = disk_cache::MemBackendImpl::CreateBackend(0, NULL); 222 cache = disk_cache::MemBackendImpl::CreateBackend(0, NULL);
230 ASSERT_TRUE(cache); 223 ASSERT_TRUE(cache);
231 delete cache; 224 delete cache;
232 cache = NULL; 225 cache = NULL;
233 226
234 // Now test the public API. 227 // Now test the public API.
235 rv = disk_cache::CreateCacheBackend(net::DISK_CACHE, cache_path_, 0, false, 228 int rv = disk_cache::CreateCacheBackend(net::DISK_CACHE, cache_path_, 0,
236 cache_thread.message_loop_proxy(), 229 false,
237 NULL, &cache, cb.callback()); 230 cache_thread.message_loop_proxy(),
231 NULL, &cache, cb.callback());
238 ASSERT_EQ(net::OK, cb.GetResult(rv)); 232 ASSERT_EQ(net::OK, cb.GetResult(rv));
239 ASSERT_TRUE(cache); 233 ASSERT_TRUE(cache);
240 delete cache; 234 delete cache;
241 cache = NULL; 235 cache = NULL;
242 236
243 rv = disk_cache::CreateCacheBackend(net::MEMORY_CACHE, base::FilePath(), 0, 237 rv = disk_cache::CreateCacheBackend(net::MEMORY_CACHE, base::FilePath(), 0,
244 false, NULL, NULL, &cache, 238 false, NULL, NULL, &cache,
245 cb.callback()); 239 cb.callback());
246 ASSERT_EQ(net::OK, cb.GetResult(rv)); 240 ASSERT_EQ(net::OK, cb.GetResult(rv));
247 ASSERT_TRUE(cache); 241 ASSERT_TRUE(cache);
248 delete cache; 242 delete cache;
249 } 243 }
250 244
251 MessageLoop::current()->RunUntilIdle(); 245 MessageLoop::current()->RunUntilIdle();
252 } 246 }
253 247
254 // Testst that re-creating the cache performs the expected cleanup. 248 // Testst that re-creating the cache performs the expected cleanup.
255 TEST_F(DiskCacheBackendTest, CreateBackend_MissingFile) { 249 TEST_F(DiskCacheBackendTest, CreateBackend_MissingFile) {
256 ASSERT_TRUE(CopyTestCache("bad_entry")); 250 ASSERT_TRUE(CopyTestCache("bad_entry"));
257 base::FilePath filename = cache_path_.AppendASCII("data_1"); 251 base::FilePath filename = cache_path_.AppendASCII("data_1");
258 file_util::Delete(filename, false); 252 file_util::Delete(filename, false);
259 DisableFirstCleanup(); 253 DisableFirstCleanup();
260 SetForceCreation(); 254 SetForceCreation();
261 255
262 bool prev = base::ThreadRestrictions::SetIOAllowed(false); 256 bool prev = base::ThreadRestrictions::SetIOAllowed(false);
263 InitCache(); 257 InitDefaultCacheViaCreator();
264 base::ThreadRestrictions::SetIOAllowed(prev); 258 base::ThreadRestrictions::SetIOAllowed(prev);
265 } 259 }
266 260
267 TEST_F(DiskCacheBackendTest, ExternalFiles) { 261 TEST_F(DiskCacheBackendTest, ExternalFiles) {
268 InitCache(); 262 InitCache();
269 // First, let's create a file on the folder. 263 // First, let's create a file on the folder.
270 base::FilePath filename = cache_path_.AppendASCII("f_000001"); 264 base::FilePath filename = cache_path_.AppendASCII("f_000001");
271 265
272 const int kSize = 50; 266 const int kSize = 50;
273 scoped_refptr<net::IOBuffer> buffer1(new net::IOBuffer(kSize)); 267 scoped_refptr<net::IOBuffer> buffer1(new net::IOBuffer(kSize));
(...skipping 16 matching lines...) Expand all
290 void DiskCacheBackendTest::BackendShutdownWithPendingFileIO(bool fast) { 284 void DiskCacheBackendTest::BackendShutdownWithPendingFileIO(bool fast) {
291 net::TestCompletionCallback cb; 285 net::TestCompletionCallback cb;
292 int rv; 286 int rv;
293 287
294 { 288 {
295 ASSERT_TRUE(CleanupCacheDir()); 289 ASSERT_TRUE(CleanupCacheDir());
296 base::Thread cache_thread("CacheThread"); 290 base::Thread cache_thread("CacheThread");
297 ASSERT_TRUE(cache_thread.StartWithOptions( 291 ASSERT_TRUE(cache_thread.StartWithOptions(
298 base::Thread::Options(MessageLoop::TYPE_IO, 0))); 292 base::Thread::Options(MessageLoop::TYPE_IO, 0)));
299 293
300 disk_cache::Backend* cache;
301 uint32 flags = disk_cache::kNoBuffering; 294 uint32 flags = disk_cache::kNoBuffering;
302 if (!fast) 295 if (!fast)
303 flags |= disk_cache::kNoRandom; 296 flags |= disk_cache::kNoRandom;
304 rv = disk_cache::BackendImpl::CreateBackend( 297
305 cache_path_, false, 0, net::DISK_CACHE, flags, 298 UseCurrentThread();
306 base::MessageLoopProxy::current(), NULL, 299 CreateBackend(flags, NULL);
307 &cache, cb.callback());
308 ASSERT_EQ(net::OK, cb.GetResult(rv));
309 300
310 disk_cache::EntryImpl* entry; 301 disk_cache::EntryImpl* entry;
311 rv = cache->CreateEntry( 302 rv = cache_->CreateEntry(
312 "some key", reinterpret_cast<disk_cache::Entry**>(&entry), 303 "some key", reinterpret_cast<disk_cache::Entry**>(&entry),
313 cb.callback()); 304 cb.callback());
314 ASSERT_EQ(net::OK, cb.GetResult(rv)); 305 ASSERT_EQ(net::OK, cb.GetResult(rv));
315 306
316 const int kSize = 25000; 307 const int kSize = 25000;
317 scoped_refptr<net::IOBuffer> buffer(new net::IOBuffer(kSize)); 308 scoped_refptr<net::IOBuffer> buffer(new net::IOBuffer(kSize));
318 CacheTestFillBuffer(buffer->data(), kSize, false); 309 CacheTestFillBuffer(buffer->data(), kSize, false);
319 310
320 for (int i = 0; i < 10 * 1024 * 1024; i += 64 * 1024) { 311 for (int i = 0; i < 10 * 1024 * 1024; i += 64 * 1024) {
321 // We are using the current thread as the cache thread because we want to 312 // We are using the current thread as the cache thread because we want to
322 // be able to call directly this method to make sure that the OS (instead 313 // be able to call directly this method to make sure that the OS (instead
323 // of us switching thread) is returning IO pending. 314 // of us switching thread) is returning IO pending.
324 rv = entry->WriteDataImpl(0, i, buffer, kSize, cb.callback(), false); 315 rv = entry->WriteDataImpl(0, i, buffer, kSize, cb.callback(), false);
325 if (rv == net::ERR_IO_PENDING) 316 if (rv == net::ERR_IO_PENDING)
326 break; 317 break;
327 EXPECT_EQ(kSize, rv); 318 EXPECT_EQ(kSize, rv);
328 } 319 }
329 320
330 // Don't call Close() to avoid going through the queue or we'll deadlock 321 // Don't call Close() to avoid going through the queue or we'll deadlock
331 // waiting for the operation to finish. 322 // waiting for the operation to finish.
332 entry->Release(); 323 entry->Release();
333 324
334 // The cache destructor will see one pending operation here. 325 // The cache destructor will see one pending operation here.
335 delete cache; 326 delete cache_;
327 // Prevent the TearDown() to delete the backend again.
328 cache_ = NULL;
336 329
337 if (rv == net::ERR_IO_PENDING) { 330 if (rv == net::ERR_IO_PENDING) {
338 if (fast) 331 if (fast)
339 EXPECT_FALSE(cb.have_result()); 332 EXPECT_FALSE(cb.have_result());
340 else 333 else
341 EXPECT_TRUE(cb.have_result()); 334 EXPECT_TRUE(cb.have_result());
342 } 335 }
343 } 336 }
344 337
345 MessageLoop::current()->RunUntilIdle(); 338 MessageLoop::current()->RunUntilIdle();
(...skipping 22 matching lines...) Expand all
368 // Tests that we deal with background-thread pending operations. 361 // Tests that we deal with background-thread pending operations.
369 void DiskCacheBackendTest::BackendShutdownWithPendingIO(bool fast) { 362 void DiskCacheBackendTest::BackendShutdownWithPendingIO(bool fast) {
370 net::TestCompletionCallback cb; 363 net::TestCompletionCallback cb;
371 364
372 { 365 {
373 ASSERT_TRUE(CleanupCacheDir()); 366 ASSERT_TRUE(CleanupCacheDir());
374 base::Thread cache_thread("CacheThread"); 367 base::Thread cache_thread("CacheThread");
375 ASSERT_TRUE(cache_thread.StartWithOptions( 368 ASSERT_TRUE(cache_thread.StartWithOptions(
376 base::Thread::Options(MessageLoop::TYPE_IO, 0))); 369 base::Thread::Options(MessageLoop::TYPE_IO, 0)));
377 370
378 disk_cache::Backend* cache;
379 uint32 flags = disk_cache::kNoBuffering; 371 uint32 flags = disk_cache::kNoBuffering;
380 if (!fast) 372 if (!fast)
381 flags |= disk_cache::kNoRandom; 373 flags |= disk_cache::kNoRandom;
382 int rv = disk_cache::BackendImpl::CreateBackend( 374
383 cache_path_, false, 0, net::DISK_CACHE, flags, 375 CreateBackend(flags, &cache_thread);
384 cache_thread.message_loop_proxy(), NULL, &cache, cb.callback());
385 ASSERT_EQ(net::OK, cb.GetResult(rv));
386 376
387 disk_cache::Entry* entry; 377 disk_cache::Entry* entry;
388 rv = cache->CreateEntry("some key", &entry, cb.callback()); 378 int rv = cache_->CreateEntry("some key", &entry, cb.callback());
389 ASSERT_EQ(net::OK, cb.GetResult(rv)); 379 ASSERT_EQ(net::OK, cb.GetResult(rv));
390 380
391 entry->Close(); 381 entry->Close();
392 382
393 // The cache destructor will see one pending operation here. 383 // The cache destructor will see one pending operation here.
394 delete cache; 384 delete cache_;
385 // Prevent the TearDown() to delete the backend again.
386 cache_ = NULL;
395 } 387 }
396 388
397 MessageLoop::current()->RunUntilIdle(); 389 MessageLoop::current()->RunUntilIdle();
398 } 390 }
399 391
400 TEST_F(DiskCacheBackendTest, ShutdownWithPendingIO) { 392 TEST_F(DiskCacheBackendTest, ShutdownWithPendingIO) {
401 BackendShutdownWithPendingIO(false); 393 BackendShutdownWithPendingIO(false);
402 } 394 }
403 395
404 // We'll be leaking from this test. 396 // We'll be leaking from this test.
405 TEST_F(DiskCacheBackendTest, ShutdownWithPendingIO_Fast) { 397 TEST_F(DiskCacheBackendTest, ShutdownWithPendingIO_Fast) {
406 // The integrity test sets kNoRandom so there's a version mismatch if we don't 398 // The integrity test sets kNoRandom so there's a version mismatch if we don't
407 // force new eviction. 399 // force new eviction.
408 SetNewEviction(); 400 SetNewEviction();
409 BackendShutdownWithPendingIO(true); 401 BackendShutdownWithPendingIO(true);
410 } 402 }
411 403
412 // Tests that we deal with create-type pending operations. 404 // Tests that we deal with create-type pending operations.
413 void DiskCacheBackendTest::BackendShutdownWithPendingCreate(bool fast) { 405 void DiskCacheBackendTest::BackendShutdownWithPendingCreate(bool fast) {
414 net::TestCompletionCallback cb; 406 net::TestCompletionCallback cb;
415 407
416 { 408 {
417 ASSERT_TRUE(CleanupCacheDir()); 409 ASSERT_TRUE(CleanupCacheDir());
418 base::Thread cache_thread("CacheThread"); 410 base::Thread cache_thread("CacheThread");
419 ASSERT_TRUE(cache_thread.StartWithOptions( 411 ASSERT_TRUE(cache_thread.StartWithOptions(
420 base::Thread::Options(MessageLoop::TYPE_IO, 0))); 412 base::Thread::Options(MessageLoop::TYPE_IO, 0)));
421 413
422 disk_cache::Backend* cache;
423 disk_cache::BackendFlags flags = 414 disk_cache::BackendFlags flags =
424 fast ? disk_cache::kNone : disk_cache::kNoRandom; 415 fast ? disk_cache::kNone : disk_cache::kNoRandom;
425 int rv = disk_cache::BackendImpl::CreateBackend( 416 CreateBackend(flags, &cache_thread);
426 cache_path_, false, 0, net::DISK_CACHE, flags,
427 cache_thread.message_loop_proxy(), NULL, &cache, cb.callback());
428 ASSERT_EQ(net::OK, cb.GetResult(rv));
429 417
430 disk_cache::Entry* entry; 418 disk_cache::Entry* entry;
431 rv = cache->CreateEntry("some key", &entry, cb.callback()); 419 int rv = cache_->CreateEntry("some key", &entry, cb.callback());
432 ASSERT_EQ(net::ERR_IO_PENDING, rv); 420 ASSERT_EQ(net::ERR_IO_PENDING, rv);
433 421
434 delete cache; 422 delete cache_;
423 // Prevent the TearDown() to delete the backend again.
424 cache_ = NULL;
435 EXPECT_FALSE(cb.have_result()); 425 EXPECT_FALSE(cb.have_result());
436 } 426 }
437 427
438 MessageLoop::current()->RunUntilIdle(); 428 MessageLoop::current()->RunUntilIdle();
439 } 429 }
440 430
441 TEST_F(DiskCacheBackendTest, ShutdownWithPendingCreate) { 431 TEST_F(DiskCacheBackendTest, ShutdownWithPendingCreate) {
442 BackendShutdownWithPendingCreate(false); 432 BackendShutdownWithPendingCreate(false);
443 } 433 }
444 434
445 // We'll be leaking an entry from this test. 435 // We'll be leaking an entry from this test.
446 TEST_F(DiskCacheBackendTest, ShutdownWithPendingCreate_Fast) { 436 TEST_F(DiskCacheBackendTest, ShutdownWithPendingCreate_Fast) {
447 // The integrity test sets kNoRandom so there's a version mismatch if we don't 437 // The integrity test sets kNoRandom so there's a version mismatch if we don't
448 // force new eviction. 438 // force new eviction.
449 SetNewEviction(); 439 SetNewEviction();
450 BackendShutdownWithPendingCreate(true); 440 BackendShutdownWithPendingCreate(true);
451 } 441 }
452 442
453 TEST_F(DiskCacheTest, TruncatedIndex) { 443 TEST_F(DiskCacheTest, TruncatedIndex) {
454 ASSERT_TRUE(CleanupCacheDir()); 444 ASSERT_TRUE(CleanupCacheDir());
455 base::FilePath index = cache_path_.AppendASCII("index"); 445 base::FilePath index = cache_path_.AppendASCII("index");
456 ASSERT_EQ(5, file_util::WriteFile(index, "hello", 5)); 446 ASSERT_EQ(5, file_util::WriteFile(index, "hello", 5));
457 447
458 base::Thread cache_thread("CacheThread"); 448 base::Thread cache_thread("CacheThread");
459 ASSERT_TRUE(cache_thread.StartWithOptions( 449 ASSERT_TRUE(cache_thread.StartWithOptions(
460 base::Thread::Options(MessageLoop::TYPE_IO, 0))); 450 base::Thread::Options(MessageLoop::TYPE_IO, 0)));
461 net::TestCompletionCallback cb; 451 net::TestCompletionCallback cb;
462 452
463 disk_cache::Backend* backend = NULL; 453 disk_cache::Backend* backend = NULL;
464 int rv = disk_cache::BackendImpl::CreateBackend( 454 int rv = disk_cache::CreateCacheBackend(
465 cache_path_, false, 0, net::DISK_CACHE, disk_cache::kNone, 455 net::DISK_CACHE, cache_path_, 0, false,
466 cache_thread.message_loop_proxy(), NULL, &backend, cb.callback()); 456 cache_thread.message_loop_proxy(), NULL, &backend, cb.callback());
467 ASSERT_NE(net::OK, cb.GetResult(rv)); 457 ASSERT_NE(net::OK, cb.GetResult(rv));
468 458
469 ASSERT_TRUE(backend == NULL); 459 ASSERT_TRUE(backend == NULL);
470 delete backend; 460 delete backend;
471 } 461 }
472 462
473 void DiskCacheBackendTest::BackendSetSize() { 463 void DiskCacheBackendTest::BackendSetSize() {
474 SetDirectMode();
475 const int cache_size = 0x10000; // 64 kB 464 const int cache_size = 0x10000; // 64 kB
476 SetMaxSize(cache_size); 465 SetMaxSize(cache_size);
477 InitCache(); 466 InitCache();
478 467
479 std::string first("some key"); 468 std::string first("some key");
480 std::string second("something else"); 469 std::string second("something else");
481 disk_cache::Entry* entry; 470 disk_cache::Entry* entry;
482 ASSERT_EQ(net::OK, CreateEntry(first, &entry)); 471 ASSERT_EQ(net::OK, CreateEntry(first, &entry));
483 472
484 scoped_refptr<net::IOBuffer> buffer(new net::IOBuffer(cache_size)); 473 scoped_refptr<net::IOBuffer> buffer(new net::IOBuffer(cache_size));
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
637 BackendChain(); 626 BackendChain();
638 } 627 }
639 628
640 TEST_F(DiskCacheBackendTest, ShaderCacheChain) { 629 TEST_F(DiskCacheBackendTest, ShaderCacheChain) {
641 SetCacheType(net::SHADER_CACHE); 630 SetCacheType(net::SHADER_CACHE);
642 BackendChain(); 631 BackendChain();
643 } 632 }
644 633
645 TEST_F(DiskCacheBackendTest, NewEvictionTrim) { 634 TEST_F(DiskCacheBackendTest, NewEvictionTrim) {
646 SetNewEviction(); 635 SetNewEviction();
647 SetDirectMode();
648 InitCache(); 636 InitCache();
649 637
650 disk_cache::Entry* entry; 638 disk_cache::Entry* entry;
651 for (int i = 0; i < 100; i++) { 639 for (int i = 0; i < 100; i++) {
652 std::string name(base::StringPrintf("Key %d", i)); 640 std::string name(base::StringPrintf("Key %d", i));
653 ASSERT_EQ(net::OK, CreateEntry(name, &entry)); 641 ASSERT_EQ(net::OK, CreateEntry(name, &entry));
654 entry->Close(); 642 entry->Close();
655 if (i < 90) { 643 if (i < 90) {
656 // Entries 0 to 89 are in list 1; 90 to 99 are in list 0. 644 // Entries 0 to 89 are in list 1; 90 to 99 are in list 0.
657 ASSERT_EQ(net::OK, OpenEntry(name, &entry)); 645 ASSERT_EQ(net::OK, OpenEntry(name, &entry));
(...skipping 10 matching lines...) Expand all
668 656
669 // Double check that we still have the list tails. 657 // Double check that we still have the list tails.
670 ASSERT_EQ(net::OK, OpenEntry("Key 1", &entry)); 658 ASSERT_EQ(net::OK, OpenEntry("Key 1", &entry));
671 entry->Close(); 659 entry->Close();
672 ASSERT_EQ(net::OK, OpenEntry("Key 91", &entry)); 660 ASSERT_EQ(net::OK, OpenEntry("Key 91", &entry));
673 entry->Close(); 661 entry->Close();
674 } 662 }
675 663
676 // Before looking for invalid entries, let's check a valid entry. 664 // Before looking for invalid entries, let's check a valid entry.
677 void DiskCacheBackendTest::BackendValidEntry() { 665 void DiskCacheBackendTest::BackendValidEntry() {
678 SetDirectMode();
679 InitCache(); 666 InitCache();
680 667
681 std::string key("Some key"); 668 std::string key("Some key");
682 disk_cache::Entry* entry; 669 disk_cache::Entry* entry;
683 ASSERT_EQ(net::OK, CreateEntry(key, &entry)); 670 ASSERT_EQ(net::OK, CreateEntry(key, &entry));
684 671
685 const int kSize = 50; 672 const int kSize = 50;
686 scoped_refptr<net::IOBuffer> buffer1(new net::IOBuffer(kSize)); 673 scoped_refptr<net::IOBuffer> buffer1(new net::IOBuffer(kSize));
687 memset(buffer1->data(), 0, kSize); 674 memset(buffer1->data(), 0, kSize);
688 base::strlcpy(buffer1->data(), "And the data to save", kSize); 675 base::strlcpy(buffer1->data(), "And the data to save", kSize);
(...skipping 16 matching lines...) Expand all
705 692
706 TEST_F(DiskCacheBackendTest, NewEvictionValidEntry) { 693 TEST_F(DiskCacheBackendTest, NewEvictionValidEntry) {
707 SetNewEviction(); 694 SetNewEviction();
708 BackendValidEntry(); 695 BackendValidEntry();
709 } 696 }
710 697
711 // The same logic of the previous test (ValidEntry), but this time force the 698 // The same logic of the previous test (ValidEntry), but this time force the
712 // entry to be invalid, simulating a crash in the middle. 699 // entry to be invalid, simulating a crash in the middle.
713 // We'll be leaking memory from this test. 700 // We'll be leaking memory from this test.
714 void DiskCacheBackendTest::BackendInvalidEntry() { 701 void DiskCacheBackendTest::BackendInvalidEntry() {
715 // Use the implementation directly... we need to simulate a crash.
716 SetDirectMode();
717 InitCache(); 702 InitCache();
718 703
719 std::string key("Some key"); 704 std::string key("Some key");
720 disk_cache::Entry* entry; 705 disk_cache::Entry* entry;
721 ASSERT_EQ(net::OK, CreateEntry(key, &entry)); 706 ASSERT_EQ(net::OK, CreateEntry(key, &entry));
722 707
723 const int kSize = 50; 708 const int kSize = 50;
724 scoped_refptr<net::IOBuffer> buffer(new net::IOBuffer(kSize)); 709 scoped_refptr<net::IOBuffer> buffer(new net::IOBuffer(kSize));
725 memset(buffer->data(), 0, kSize); 710 memset(buffer->data(), 0, kSize);
726 base::strlcpy(buffer->data(), "And the data to save", kSize); 711 base::strlcpy(buffer->data(), "And the data to save", kSize);
(...skipping 27 matching lines...) Expand all
754 739
755 // We'll be leaking memory from this test. 740 // We'll be leaking memory from this test.
756 TEST_F(DiskCacheBackendTest, ShaderCacheInvalidEntry) { 741 TEST_F(DiskCacheBackendTest, ShaderCacheInvalidEntry) {
757 SetCacheType(net::SHADER_CACHE); 742 SetCacheType(net::SHADER_CACHE);
758 BackendInvalidEntry(); 743 BackendInvalidEntry();
759 } 744 }
760 745
761 // Almost the same test, but this time crash the cache after reading an entry. 746 // Almost the same test, but this time crash the cache after reading an entry.
762 // We'll be leaking memory from this test. 747 // We'll be leaking memory from this test.
763 void DiskCacheBackendTest::BackendInvalidEntryRead() { 748 void DiskCacheBackendTest::BackendInvalidEntryRead() {
764 // Use the implementation directly... we need to simulate a crash.
765 SetDirectMode();
766 InitCache(); 749 InitCache();
767 750
768 std::string key("Some key"); 751 std::string key("Some key");
769 disk_cache::Entry* entry; 752 disk_cache::Entry* entry;
770 ASSERT_EQ(net::OK, CreateEntry(key, &entry)); 753 ASSERT_EQ(net::OK, CreateEntry(key, &entry));
771 754
772 const int kSize = 50; 755 const int kSize = 50;
773 scoped_refptr<net::IOBuffer> buffer(new net::IOBuffer(kSize)); 756 scoped_refptr<net::IOBuffer> buffer(new net::IOBuffer(kSize));
774 memset(buffer->data(), 0, kSize); 757 memset(buffer->data(), 0, kSize);
775 base::strlcpy(buffer->data(), "And the data to save", kSize); 758 base::strlcpy(buffer->data(), "And the data to save", kSize);
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
881 } 864 }
882 865
883 // We'll be leaking memory from this test. 866 // We'll be leaking memory from this test.
884 TEST_F(DiskCacheBackendTest, ShaderCacheInvalidEntryWithLoad) { 867 TEST_F(DiskCacheBackendTest, ShaderCacheInvalidEntryWithLoad) {
885 SetCacheType(net::SHADER_CACHE); 868 SetCacheType(net::SHADER_CACHE);
886 BackendInvalidEntryWithLoad(); 869 BackendInvalidEntryWithLoad();
887 } 870 }
888 871
889 // We'll be leaking memory from this test. 872 // We'll be leaking memory from this test.
890 void DiskCacheBackendTest::BackendTrimInvalidEntry() { 873 void DiskCacheBackendTest::BackendTrimInvalidEntry() {
891 // Use the implementation directly... we need to simulate a crash.
892 SetDirectMode();
893
894 const int kSize = 0x3000; // 12 kB 874 const int kSize = 0x3000; // 12 kB
895 SetMaxSize(kSize * 10); 875 SetMaxSize(kSize * 10);
896 InitCache(); 876 InitCache();
897 877
898 std::string first("some key"); 878 std::string first("some key");
899 std::string second("something else"); 879 std::string second("something else");
900 disk_cache::Entry* entry; 880 disk_cache::Entry* entry;
901 ASSERT_EQ(net::OK, CreateEntry(first, &entry)); 881 ASSERT_EQ(net::OK, CreateEntry(first, &entry));
902 882
903 scoped_refptr<net::IOBuffer> buffer(new net::IOBuffer(kSize)); 883 scoped_refptr<net::IOBuffer> buffer(new net::IOBuffer(kSize));
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
936 } 916 }
937 917
938 // We'll be leaking memory from this test. 918 // We'll be leaking memory from this test.
939 TEST_F(DiskCacheBackendTest, NewEvictionTrimInvalidEntry) { 919 TEST_F(DiskCacheBackendTest, NewEvictionTrimInvalidEntry) {
940 SetNewEviction(); 920 SetNewEviction();
941 BackendTrimInvalidEntry(); 921 BackendTrimInvalidEntry();
942 } 922 }
943 923
944 // We'll be leaking memory from this test. 924 // We'll be leaking memory from this test.
945 void DiskCacheBackendTest::BackendTrimInvalidEntry2() { 925 void DiskCacheBackendTest::BackendTrimInvalidEntry2() {
946 // Use the implementation directly... we need to simulate a crash.
947 SetDirectMode();
948 SetMask(0xf); // 16-entry table. 926 SetMask(0xf); // 16-entry table.
949 927
950 const int kSize = 0x3000; // 12 kB 928 const int kSize = 0x3000; // 12 kB
951 SetMaxSize(kSize * 40); 929 SetMaxSize(kSize * 40);
952 InitCache(); 930 InitCache();
953 931
954 scoped_refptr<net::IOBuffer> buffer(new net::IOBuffer(kSize)); 932 scoped_refptr<net::IOBuffer> buffer(new net::IOBuffer(kSize));
955 memset(buffer->data(), 0, kSize); 933 memset(buffer->data(), 0, kSize);
956 disk_cache::Entry* entry; 934 disk_cache::Entry* entry;
957 935
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
1179 void* iter = NULL; 1157 void* iter = NULL;
1180 ASSERT_EQ(net::OK, OpenNextEntry(&iter, &entry2)); 1158 ASSERT_EQ(net::OK, OpenNextEntry(&iter, &entry2));
1181 EXPECT_EQ(entry2->GetKey(), second); 1159 EXPECT_EQ(entry2->GetKey(), second);
1182 entry2->Close(); 1160 entry2->Close();
1183 cache_->EndEnumeration(&iter); 1161 cache_->EndEnumeration(&iter);
1184 } 1162 }
1185 1163
1186 // Verify handling of invalid entries while doing enumerations. 1164 // Verify handling of invalid entries while doing enumerations.
1187 // We'll be leaking memory from this test. 1165 // We'll be leaking memory from this test.
1188 void DiskCacheBackendTest::BackendInvalidEntryEnumeration() { 1166 void DiskCacheBackendTest::BackendInvalidEntryEnumeration() {
1189 // Use the implementation directly... we need to simulate a crash.
1190 SetDirectMode();
1191 InitCache(); 1167 InitCache();
1192 1168
1193 std::string key("Some key"); 1169 std::string key("Some key");
1194 disk_cache::Entry *entry, *entry1, *entry2; 1170 disk_cache::Entry *entry, *entry1, *entry2;
1195 ASSERT_EQ(net::OK, CreateEntry(key, &entry1)); 1171 ASSERT_EQ(net::OK, CreateEntry(key, &entry1));
1196 1172
1197 const int kSize = 50; 1173 const int kSize = 50;
1198 scoped_refptr<net::IOBuffer> buffer1(new net::IOBuffer(kSize)); 1174 scoped_refptr<net::IOBuffer> buffer1(new net::IOBuffer(kSize));
1199 memset(buffer1->data(), 0, kSize); 1175 memset(buffer1->data(), 0, kSize);
1200 base::strlcpy(buffer1->data(), "And the data to save", kSize); 1176 base::strlcpy(buffer1->data(), "And the data to save", kSize);
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after
1539 1515
1540 TEST_F(DiskCacheBackendTest, RecoverWithEviction) { 1516 TEST_F(DiskCacheBackendTest, RecoverWithEviction) {
1541 BackendRecoverWithEviction(); 1517 BackendRecoverWithEviction();
1542 } 1518 }
1543 1519
1544 TEST_F(DiskCacheBackendTest, NewEvictionRecoverWithEviction) { 1520 TEST_F(DiskCacheBackendTest, NewEvictionRecoverWithEviction) {
1545 SetNewEviction(); 1521 SetNewEviction();
1546 BackendRecoverWithEviction(); 1522 BackendRecoverWithEviction();
1547 } 1523 }
1548 1524
1549 // Tests dealing with cache files that cannot be recovered. 1525 // Tests that the |BackendImpl| fails to start with the wrong cache version.
1550 TEST_F(DiskCacheTest, DeleteOld) { 1526 TEST_F(DiskCacheTest, WrongVersion) {
1551 ASSERT_TRUE(CopyTestCache("wrong_version")); 1527 ASSERT_TRUE(CopyTestCache("wrong_version"));
1552 base::Thread cache_thread("CacheThread"); 1528 base::Thread cache_thread("CacheThread");
1553 ASSERT_TRUE(cache_thread.StartWithOptions( 1529 ASSERT_TRUE(cache_thread.StartWithOptions(
1554 base::Thread::Options(MessageLoop::TYPE_IO, 0))); 1530 base::Thread::Options(MessageLoop::TYPE_IO, 0)));
1555 net::TestCompletionCallback cb; 1531 net::TestCompletionCallback cb;
1556 1532
1557 disk_cache::Backend* cache; 1533 disk_cache::BackendImpl* cache = new disk_cache::BackendImpl(
1558 int rv = disk_cache::BackendImpl::CreateBackend( 1534 cache_path_, cache_thread.message_loop_proxy(), NULL);
1559 cache_path_, true, 0, net::DISK_CACHE, disk_cache::kNoRandom, 1535 int rv = cache->Init(cb.callback());
1560 cache_thread.message_loop_proxy(), NULL, &cache, cb.callback()); 1536 ASSERT_EQ(net::ERR_FAILED, cb.GetResult(rv));
1561 ASSERT_EQ(net::OK, cb.GetResult(rv));
1562
1563 MessageLoopHelper helper;
1564
1565 ASSERT_TRUE(NULL != cache);
1566 ASSERT_EQ(0, cache->GetEntryCount());
1567 1537
1568 delete cache; 1538 delete cache;
1569 } 1539 }
1570 1540
1541 // Tests that the cache is properly restarted on recovery error.
1542 TEST_F(DiskCacheBackendTest, DeleteOld) {
1543 ASSERT_TRUE(CopyTestCache("wrong_version"));
1544 InitDefaultCacheViaCreator();
1545 }
1546
1571 // We want to be able to deal with messed up entries on disk. 1547 // We want to be able to deal with messed up entries on disk.
1572 void DiskCacheBackendTest::BackendInvalidEntry2() { 1548 void DiskCacheBackendTest::BackendInvalidEntry2() {
1573 ASSERT_TRUE(CopyTestCache("bad_entry")); 1549 ASSERT_TRUE(CopyTestCache("bad_entry"));
1574 DisableFirstCleanup(); 1550 DisableFirstCleanup();
1575 InitCache(); 1551 InitCache();
1576 1552
1577 disk_cache::Entry *entry1, *entry2; 1553 disk_cache::Entry *entry1, *entry2;
1578 ASSERT_EQ(net::OK, OpenEntry("the first key", &entry1)); 1554 ASSERT_EQ(net::OK, OpenEntry("the first key", &entry1));
1579 EXPECT_NE(net::OK, OpenEntry("some other key", &entry2)); 1555 EXPECT_NE(net::OK, OpenEntry("some other key", &entry2));
1580 entry1->Close(); 1556 entry1->Close();
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
1712 FlushQueueForTest(); 1688 FlushQueueForTest();
1713 entry->Close(); 1689 entry->Close();
1714 1690
1715 ASSERT_EQ(net::OK, OpenEntry("some other key", &entry)); 1691 ASSERT_EQ(net::OK, OpenEntry("some other key", &entry));
1716 entry->Close(); 1692 entry->Close();
1717 } 1693 }
1718 1694
1719 // Tests handling of corrupt entries by keeping the rankings node around, with 1695 // Tests handling of corrupt entries by keeping the rankings node around, with
1720 // a fatal failure. 1696 // a fatal failure.
1721 void DiskCacheBackendTest::BackendInvalidEntry7() { 1697 void DiskCacheBackendTest::BackendInvalidEntry7() {
1722 SetDirectMode();
1723 const int kSize = 0x3000; // 12 kB. 1698 const int kSize = 0x3000; // 12 kB.
1724 SetMaxSize(kSize * 10); 1699 SetMaxSize(kSize * 10);
1725 InitCache(); 1700 InitCache();
1726 1701
1727 std::string first("some key"); 1702 std::string first("some key");
1728 std::string second("something else"); 1703 std::string second("something else");
1729 disk_cache::Entry* entry; 1704 disk_cache::Entry* entry;
1730 ASSERT_EQ(net::OK, CreateEntry(first, &entry)); 1705 ASSERT_EQ(net::OK, CreateEntry(first, &entry));
1731 entry->Close(); 1706 entry->Close();
1732 ASSERT_EQ(net::OK, CreateEntry(second, &entry)); 1707 ASSERT_EQ(net::OK, CreateEntry(second, &entry));
(...skipping 24 matching lines...) Expand all
1757 } 1732 }
1758 1733
1759 TEST_F(DiskCacheBackendTest, NewEvictionInvalidEntry7) { 1734 TEST_F(DiskCacheBackendTest, NewEvictionInvalidEntry7) {
1760 SetNewEviction(); 1735 SetNewEviction();
1761 BackendInvalidEntry7(); 1736 BackendInvalidEntry7();
1762 } 1737 }
1763 1738
1764 // Tests handling of corrupt entries by keeping the rankings node around, with 1739 // Tests handling of corrupt entries by keeping the rankings node around, with
1765 // a non fatal failure. 1740 // a non fatal failure.
1766 void DiskCacheBackendTest::BackendInvalidEntry8() { 1741 void DiskCacheBackendTest::BackendInvalidEntry8() {
1767 SetDirectMode();
1768 const int kSize = 0x3000; // 12 kB 1742 const int kSize = 0x3000; // 12 kB
1769 SetMaxSize(kSize * 10); 1743 SetMaxSize(kSize * 10);
1770 InitCache(); 1744 InitCache();
1771 1745
1772 std::string first("some key"); 1746 std::string first("some key");
1773 std::string second("something else"); 1747 std::string second("something else");
1774 disk_cache::Entry* entry; 1748 disk_cache::Entry* entry;
1775 ASSERT_EQ(net::OK, CreateEntry(first, &entry)); 1749 ASSERT_EQ(net::OK, CreateEntry(first, &entry));
1776 entry->Close(); 1750 entry->Close();
1777 ASSERT_EQ(net::OK, CreateEntry(second, &entry)); 1751 ASSERT_EQ(net::OK, CreateEntry(second, &entry));
(...skipping 27 matching lines...) Expand all
1805 TEST_F(DiskCacheBackendTest, NewEvictionInvalidEntry8) { 1779 TEST_F(DiskCacheBackendTest, NewEvictionInvalidEntry8) {
1806 SetNewEviction(); 1780 SetNewEviction();
1807 BackendInvalidEntry8(); 1781 BackendInvalidEntry8();
1808 } 1782 }
1809 1783
1810 // Tests handling of corrupt entries detected by enumerations. Note that these 1784 // Tests handling of corrupt entries detected by enumerations. Note that these
1811 // tests (xx9 to xx11) are basically just going though slightly different 1785 // tests (xx9 to xx11) are basically just going though slightly different
1812 // codepaths so they are tighlty coupled with the code, but that is better than 1786 // codepaths so they are tighlty coupled with the code, but that is better than
1813 // not testing error handling code. 1787 // not testing error handling code.
1814 void DiskCacheBackendTest::BackendInvalidEntry9(bool eviction) { 1788 void DiskCacheBackendTest::BackendInvalidEntry9(bool eviction) {
1815 SetDirectMode();
1816 const int kSize = 0x3000; // 12 kB. 1789 const int kSize = 0x3000; // 12 kB.
1817 SetMaxSize(kSize * 10); 1790 SetMaxSize(kSize * 10);
1818 InitCache(); 1791 InitCache();
1819 1792
1820 std::string first("some key"); 1793 std::string first("some key");
1821 std::string second("something else"); 1794 std::string second("something else");
1822 disk_cache::Entry* entry; 1795 disk_cache::Entry* entry;
1823 ASSERT_EQ(net::OK, CreateEntry(first, &entry)); 1796 ASSERT_EQ(net::OK, CreateEntry(first, &entry));
1824 entry->Close(); 1797 entry->Close();
1825 ASSERT_EQ(net::OK, CreateEntry(second, &entry)); 1798 ASSERT_EQ(net::OK, CreateEntry(second, &entry));
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
1870 BackendInvalidEntry9(true); 1843 BackendInvalidEntry9(true);
1871 } 1844 }
1872 1845
1873 TEST_F(DiskCacheBackendTest, NewEvictionTrimInvalidEntry9) { 1846 TEST_F(DiskCacheBackendTest, NewEvictionTrimInvalidEntry9) {
1874 SetNewEviction(); 1847 SetNewEviction();
1875 BackendInvalidEntry9(true); 1848 BackendInvalidEntry9(true);
1876 } 1849 }
1877 1850
1878 // Tests handling of corrupt entries detected by enumerations. 1851 // Tests handling of corrupt entries detected by enumerations.
1879 void DiskCacheBackendTest::BackendInvalidEntry10(bool eviction) { 1852 void DiskCacheBackendTest::BackendInvalidEntry10(bool eviction) {
1880 SetDirectMode();
1881 const int kSize = 0x3000; // 12 kB. 1853 const int kSize = 0x3000; // 12 kB.
1882 SetMaxSize(kSize * 10); 1854 SetMaxSize(kSize * 10);
1883 SetNewEviction(); 1855 SetNewEviction();
1884 InitCache(); 1856 InitCache();
1885 1857
1886 std::string first("some key"); 1858 std::string first("some key");
1887 std::string second("something else"); 1859 std::string second("something else");
1888 disk_cache::Entry* entry; 1860 disk_cache::Entry* entry;
1889 ASSERT_EQ(net::OK, CreateEntry(first, &entry)); 1861 ASSERT_EQ(net::OK, CreateEntry(first, &entry));
1890 entry->Close(); 1862 entry->Close();
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
1934 TEST_F(DiskCacheBackendTest, InvalidEntry10) { 1906 TEST_F(DiskCacheBackendTest, InvalidEntry10) {
1935 BackendInvalidEntry10(false); 1907 BackendInvalidEntry10(false);
1936 } 1908 }
1937 1909
1938 TEST_F(DiskCacheBackendTest, TrimInvalidEntry10) { 1910 TEST_F(DiskCacheBackendTest, TrimInvalidEntry10) {
1939 BackendInvalidEntry10(true); 1911 BackendInvalidEntry10(true);
1940 } 1912 }
1941 1913
1942 // Tests handling of corrupt entries detected by enumerations. 1914 // Tests handling of corrupt entries detected by enumerations.
1943 void DiskCacheBackendTest::BackendInvalidEntry11(bool eviction) { 1915 void DiskCacheBackendTest::BackendInvalidEntry11(bool eviction) {
1944 SetDirectMode();
1945 const int kSize = 0x3000; // 12 kB. 1916 const int kSize = 0x3000; // 12 kB.
1946 SetMaxSize(kSize * 10); 1917 SetMaxSize(kSize * 10);
1947 SetNewEviction(); 1918 SetNewEviction();
1948 InitCache(); 1919 InitCache();
1949 1920
1950 std::string first("some key"); 1921 std::string first("some key");
1951 std::string second("something else"); 1922 std::string second("something else");
1952 disk_cache::Entry* entry; 1923 disk_cache::Entry* entry;
1953 ASSERT_EQ(net::OK, CreateEntry(first, &entry)); 1924 ASSERT_EQ(net::OK, CreateEntry(first, &entry));
1954 entry->Close(); 1925 entry->Close();
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
2006 TEST_F(DiskCacheBackendTest, InvalidEntry11) { 1977 TEST_F(DiskCacheBackendTest, InvalidEntry11) {
2007 BackendInvalidEntry11(false); 1978 BackendInvalidEntry11(false);
2008 } 1979 }
2009 1980
2010 TEST_F(DiskCacheBackendTest, TrimInvalidEntry11) { 1981 TEST_F(DiskCacheBackendTest, TrimInvalidEntry11) {
2011 BackendInvalidEntry11(true); 1982 BackendInvalidEntry11(true);
2012 } 1983 }
2013 1984
2014 // Tests handling of corrupt entries in the middle of a long eviction run. 1985 // Tests handling of corrupt entries in the middle of a long eviction run.
2015 void DiskCacheBackendTest::BackendTrimInvalidEntry12() { 1986 void DiskCacheBackendTest::BackendTrimInvalidEntry12() {
2016 SetDirectMode();
2017 const int kSize = 0x3000; // 12 kB 1987 const int kSize = 0x3000; // 12 kB
2018 SetMaxSize(kSize * 10); 1988 SetMaxSize(kSize * 10);
2019 InitCache(); 1989 InitCache();
2020 1990
2021 std::string first("some key"); 1991 std::string first("some key");
2022 std::string second("something else"); 1992 std::string second("something else");
2023 disk_cache::Entry* entry; 1993 disk_cache::Entry* entry;
2024 ASSERT_EQ(net::OK, CreateEntry(first, &entry)); 1994 ASSERT_EQ(net::OK, CreateEntry(first, &entry));
2025 entry->Close(); 1995 entry->Close();
2026 ASSERT_EQ(net::OK, CreateEntry(second, &entry)); 1996 ASSERT_EQ(net::OK, CreateEntry(second, &entry));
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
2083 EXPECT_EQ(2, cache_->GetEntryCount()); 2053 EXPECT_EQ(2, cache_->GetEntryCount());
2084 2054
2085 EXPECT_NE(net::OK, OpenNextEntry(&iter, &entry)); 2055 EXPECT_NE(net::OK, OpenNextEntry(&iter, &entry));
2086 FlushQueueForTest(); // Allow the restart to finish. 2056 FlushQueueForTest(); // Allow the restart to finish.
2087 EXPECT_EQ(0, cache_->GetEntryCount()); 2057 EXPECT_EQ(0, cache_->GetEntryCount());
2088 } 2058 }
2089 2059
2090 TEST_F(DiskCacheBackendTest, InvalidRankingsSuccess) { 2060 TEST_F(DiskCacheBackendTest, InvalidRankingsSuccess) {
2091 ASSERT_TRUE(CopyTestCache("bad_rankings")); 2061 ASSERT_TRUE(CopyTestCache("bad_rankings"));
2092 DisableFirstCleanup(); 2062 DisableFirstCleanup();
2093 SetDirectMode();
2094 InitCache(); 2063 InitCache();
2095 BackendInvalidRankings(); 2064 BackendInvalidRankings();
2096 } 2065 }
2097 2066
2098 TEST_F(DiskCacheBackendTest, NewEvictionInvalidRankingsSuccess) { 2067 TEST_F(DiskCacheBackendTest, NewEvictionInvalidRankingsSuccess) {
2099 ASSERT_TRUE(CopyTestCache("bad_rankings")); 2068 ASSERT_TRUE(CopyTestCache("bad_rankings"));
2100 DisableFirstCleanup(); 2069 DisableFirstCleanup();
2101 SetDirectMode();
2102 SetNewEviction(); 2070 SetNewEviction();
2103 InitCache(); 2071 InitCache();
2104 BackendInvalidRankings(); 2072 BackendInvalidRankings();
2105 } 2073 }
2106 2074
2107 TEST_F(DiskCacheBackendTest, InvalidRankingsFailure) { 2075 TEST_F(DiskCacheBackendTest, InvalidRankingsFailure) {
2108 ASSERT_TRUE(CopyTestCache("bad_rankings")); 2076 ASSERT_TRUE(CopyTestCache("bad_rankings"));
2109 DisableFirstCleanup(); 2077 DisableFirstCleanup();
2110 SetDirectMode();
2111 InitCache(); 2078 InitCache();
2112 SetTestMode(); // Fail cache reinitialization. 2079 SetTestMode(); // Fail cache reinitialization.
2113 BackendInvalidRankings(); 2080 BackendInvalidRankings();
2114 } 2081 }
2115 2082
2116 TEST_F(DiskCacheBackendTest, NewEvictionInvalidRankingsFailure) { 2083 TEST_F(DiskCacheBackendTest, NewEvictionInvalidRankingsFailure) {
2117 ASSERT_TRUE(CopyTestCache("bad_rankings")); 2084 ASSERT_TRUE(CopyTestCache("bad_rankings"));
2118 DisableFirstCleanup(); 2085 DisableFirstCleanup();
2119 SetDirectMode();
2120 SetNewEviction(); 2086 SetNewEviction();
2121 InitCache(); 2087 InitCache();
2122 SetTestMode(); // Fail cache reinitialization. 2088 SetTestMode(); // Fail cache reinitialization.
2123 BackendInvalidRankings(); 2089 BackendInvalidRankings();
2124 } 2090 }
2125 2091
2126 // If the LRU is corrupt and we have open entries, we disable the cache. 2092 // If the LRU is corrupt and we have open entries, we disable the cache.
2127 void DiskCacheBackendTest::BackendDisable() { 2093 void DiskCacheBackendTest::BackendDisable() {
2128 disk_cache::Entry *entry1, *entry2; 2094 disk_cache::Entry *entry1, *entry2;
2129 void* iter = NULL; 2095 void* iter = NULL;
2130 ASSERT_EQ(net::OK, OpenNextEntry(&iter, &entry1)); 2096 ASSERT_EQ(net::OK, OpenNextEntry(&iter, &entry1));
2131 2097
2132 EXPECT_NE(net::OK, OpenNextEntry(&iter, &entry2)); 2098 EXPECT_NE(net::OK, OpenNextEntry(&iter, &entry2));
2133 EXPECT_EQ(0, cache_->GetEntryCount()); 2099 EXPECT_EQ(0, cache_->GetEntryCount());
2134 EXPECT_NE(net::OK, CreateEntry("Something new", &entry2)); 2100 EXPECT_NE(net::OK, CreateEntry("Something new", &entry2));
2135 2101
2136 entry1->Close(); 2102 entry1->Close();
2137 FlushQueueForTest(); // Flushing the Close posts a task to restart the cache. 2103 FlushQueueForTest(); // Flushing the Close posts a task to restart the cache.
2138 FlushQueueForTest(); // This one actually allows that task to complete. 2104 FlushQueueForTest(); // This one actually allows that task to complete.
2139 2105
2140 EXPECT_EQ(0, cache_->GetEntryCount()); 2106 EXPECT_EQ(0, cache_->GetEntryCount());
2141 } 2107 }
2142 2108
2143 TEST_F(DiskCacheBackendTest, DisableSuccess) { 2109 TEST_F(DiskCacheBackendTest, DisableSuccess) {
2144 ASSERT_TRUE(CopyTestCache("bad_rankings")); 2110 ASSERT_TRUE(CopyTestCache("bad_rankings"));
2145 DisableFirstCleanup(); 2111 DisableFirstCleanup();
2146 SetDirectMode();
2147 InitCache(); 2112 InitCache();
2148 BackendDisable(); 2113 BackendDisable();
2149 } 2114 }
2150 2115
2151 TEST_F(DiskCacheBackendTest, NewEvictionDisableSuccess) { 2116 TEST_F(DiskCacheBackendTest, NewEvictionDisableSuccess) {
2152 ASSERT_TRUE(CopyTestCache("bad_rankings")); 2117 ASSERT_TRUE(CopyTestCache("bad_rankings"));
2153 DisableFirstCleanup(); 2118 DisableFirstCleanup();
2154 SetDirectMode();
2155 SetNewEviction(); 2119 SetNewEviction();
2156 InitCache(); 2120 InitCache();
2157 BackendDisable(); 2121 BackendDisable();
2158 } 2122 }
2159 2123
2160 TEST_F(DiskCacheBackendTest, DisableFailure) { 2124 TEST_F(DiskCacheBackendTest, DisableFailure) {
2161 ASSERT_TRUE(CopyTestCache("bad_rankings")); 2125 ASSERT_TRUE(CopyTestCache("bad_rankings"));
2162 DisableFirstCleanup(); 2126 DisableFirstCleanup();
2163 SetDirectMode();
2164 InitCache(); 2127 InitCache();
2165 SetTestMode(); // Fail cache reinitialization. 2128 SetTestMode(); // Fail cache reinitialization.
2166 BackendDisable(); 2129 BackendDisable();
2167 } 2130 }
2168 2131
2169 TEST_F(DiskCacheBackendTest, NewEvictionDisableFailure) { 2132 TEST_F(DiskCacheBackendTest, NewEvictionDisableFailure) {
2170 ASSERT_TRUE(CopyTestCache("bad_rankings")); 2133 ASSERT_TRUE(CopyTestCache("bad_rankings"));
2171 DisableFirstCleanup(); 2134 DisableFirstCleanup();
2172 SetDirectMode();
2173 SetNewEviction(); 2135 SetNewEviction();
2174 InitCache(); 2136 InitCache();
2175 SetTestMode(); // Fail cache reinitialization. 2137 SetTestMode(); // Fail cache reinitialization.
2176 BackendDisable(); 2138 BackendDisable();
2177 } 2139 }
2178 2140
2179 // This is another type of corruption on the LRU; disable the cache. 2141 // This is another type of corruption on the LRU; disable the cache.
2180 void DiskCacheBackendTest::BackendDisable2() { 2142 void DiskCacheBackendTest::BackendDisable2() {
2181 EXPECT_EQ(8, cache_->GetEntryCount()); 2143 EXPECT_EQ(8, cache_->GetEntryCount());
2182 2144
2183 disk_cache::Entry* entry; 2145 disk_cache::Entry* entry;
2184 void* iter = NULL; 2146 void* iter = NULL;
2185 int count = 0; 2147 int count = 0;
2186 while (OpenNextEntry(&iter, &entry) == net::OK) { 2148 while (OpenNextEntry(&iter, &entry) == net::OK) {
2187 ASSERT_TRUE(NULL != entry); 2149 ASSERT_TRUE(NULL != entry);
2188 entry->Close(); 2150 entry->Close();
2189 count++; 2151 count++;
2190 ASSERT_LT(count, 9); 2152 ASSERT_LT(count, 9);
2191 }; 2153 };
2192 2154
2193 FlushQueueForTest(); 2155 FlushQueueForTest();
2194 EXPECT_EQ(0, cache_->GetEntryCount()); 2156 EXPECT_EQ(0, cache_->GetEntryCount());
2195 } 2157 }
2196 2158
2197 TEST_F(DiskCacheBackendTest, DisableSuccess2) { 2159 TEST_F(DiskCacheBackendTest, DisableSuccess2) {
2198 ASSERT_TRUE(CopyTestCache("list_loop")); 2160 ASSERT_TRUE(CopyTestCache("list_loop"));
2199 DisableFirstCleanup(); 2161 DisableFirstCleanup();
2200 SetDirectMode();
2201 InitCache(); 2162 InitCache();
2202 BackendDisable2(); 2163 BackendDisable2();
2203 } 2164 }
2204 2165
2205 TEST_F(DiskCacheBackendTest, NewEvictionDisableSuccess2) { 2166 TEST_F(DiskCacheBackendTest, NewEvictionDisableSuccess2) {
2206 ASSERT_TRUE(CopyTestCache("list_loop")); 2167 ASSERT_TRUE(CopyTestCache("list_loop"));
2207 DisableFirstCleanup(); 2168 DisableFirstCleanup();
2208 SetNewEviction(); 2169 SetNewEviction();
2209 SetDirectMode();
2210 InitCache(); 2170 InitCache();
2211 BackendDisable2(); 2171 BackendDisable2();
2212 } 2172 }
2213 2173
2214 TEST_F(DiskCacheBackendTest, DisableFailure2) { 2174 TEST_F(DiskCacheBackendTest, DisableFailure2) {
2215 ASSERT_TRUE(CopyTestCache("list_loop")); 2175 ASSERT_TRUE(CopyTestCache("list_loop"));
2216 DisableFirstCleanup(); 2176 DisableFirstCleanup();
2217 SetDirectMode();
2218 InitCache(); 2177 InitCache();
2219 SetTestMode(); // Fail cache reinitialization. 2178 SetTestMode(); // Fail cache reinitialization.
2220 BackendDisable2(); 2179 BackendDisable2();
2221 } 2180 }
2222 2181
2223 TEST_F(DiskCacheBackendTest, NewEvictionDisableFailure2) { 2182 TEST_F(DiskCacheBackendTest, NewEvictionDisableFailure2) {
2224 ASSERT_TRUE(CopyTestCache("list_loop")); 2183 ASSERT_TRUE(CopyTestCache("list_loop"));
2225 DisableFirstCleanup(); 2184 DisableFirstCleanup();
2226 SetDirectMode();
2227 SetNewEviction(); 2185 SetNewEviction();
2228 InitCache(); 2186 InitCache();
2229 SetTestMode(); // Fail cache reinitialization. 2187 SetTestMode(); // Fail cache reinitialization.
2230 BackendDisable2(); 2188 BackendDisable2();
2231 } 2189 }
2232 2190
2233 // If the index size changes when we disable the cache, we should not crash. 2191 // If the index size changes when we disable the cache, we should not crash.
2234 void DiskCacheBackendTest::BackendDisable3() { 2192 void DiskCacheBackendTest::BackendDisable3() {
2235 disk_cache::Entry *entry1, *entry2; 2193 disk_cache::Entry *entry1, *entry2;
2236 void* iter = NULL; 2194 void* iter = NULL;
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
2309 entry3->Close(); 2267 entry3->Close();
2310 FlushQueueForTest(); // Flushing the Close posts a task to restart the cache. 2268 FlushQueueForTest(); // Flushing the Close posts a task to restart the cache.
2311 FlushQueueForTest(); // This one actually allows that task to complete. 2269 FlushQueueForTest(); // This one actually allows that task to complete.
2312 2270
2313 EXPECT_EQ(0, cache_->GetEntryCount()); 2271 EXPECT_EQ(0, cache_->GetEntryCount());
2314 } 2272 }
2315 2273
2316 TEST_F(DiskCacheBackendTest, DisableSuccess4) { 2274 TEST_F(DiskCacheBackendTest, DisableSuccess4) {
2317 ASSERT_TRUE(CopyTestCache("bad_rankings")); 2275 ASSERT_TRUE(CopyTestCache("bad_rankings"));
2318 DisableFirstCleanup(); 2276 DisableFirstCleanup();
2319 SetDirectMode();
2320 InitCache(); 2277 InitCache();
2321 BackendDisable4(); 2278 BackendDisable4();
2322 } 2279 }
2323 2280
2324 TEST_F(DiskCacheBackendTest, NewEvictionDisableSuccess4) { 2281 TEST_F(DiskCacheBackendTest, NewEvictionDisableSuccess4) {
2325 ASSERT_TRUE(CopyTestCache("bad_rankings")); 2282 ASSERT_TRUE(CopyTestCache("bad_rankings"));
2326 DisableFirstCleanup(); 2283 DisableFirstCleanup();
2327 SetDirectMode();
2328 SetNewEviction(); 2284 SetNewEviction();
2329 InitCache(); 2285 InitCache();
2330 BackendDisable4(); 2286 BackendDisable4();
2331 } 2287 }
2332 2288
2333 TEST_F(DiskCacheTest, Backend_UsageStats) { 2289 TEST_F(DiskCacheTest, Backend_UsageStats) {
2334 MessageLoopHelper helper; 2290 MessageLoopHelper helper;
2335 2291
2336 ASSERT_TRUE(CleanupCacheDir()); 2292 ASSERT_TRUE(CleanupCacheDir());
2337 scoped_ptr<disk_cache::BackendImpl> cache; 2293 scoped_ptr<disk_cache::BackendImpl> cache;
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
2453 ASSERT_TRUE(store2.CreateUniqueTempDir()); 2409 ASSERT_TRUE(store2.CreateUniqueTempDir());
2454 2410
2455 base::Thread cache_thread("CacheThread"); 2411 base::Thread cache_thread("CacheThread");
2456 ASSERT_TRUE(cache_thread.StartWithOptions( 2412 ASSERT_TRUE(cache_thread.StartWithOptions(
2457 base::Thread::Options(MessageLoop::TYPE_IO, 0))); 2413 base::Thread::Options(MessageLoop::TYPE_IO, 0)));
2458 net::TestCompletionCallback cb; 2414 net::TestCompletionCallback cb;
2459 2415
2460 const int kNumberOfCaches = 2; 2416 const int kNumberOfCaches = 2;
2461 disk_cache::Backend* cache[kNumberOfCaches]; 2417 disk_cache::Backend* cache[kNumberOfCaches];
2462 2418
2463 int rv = disk_cache::BackendImpl::CreateBackend( 2419 int rv = disk_cache::CreateCacheBackend(
2464 store1.path(), false, 0, net::DISK_CACHE, disk_cache::kNone, 2420 net::DISK_CACHE, store1.path(), 0, false,
2465 cache_thread.message_loop_proxy(), NULL, &cache[0], cb.callback()); 2421 cache_thread.message_loop_proxy(), NULL, &cache[0], cb.callback());
2466 ASSERT_EQ(net::OK, cb.GetResult(rv)); 2422 ASSERT_EQ(net::OK, cb.GetResult(rv));
2467 rv = disk_cache::BackendImpl::CreateBackend( 2423 rv = disk_cache::CreateCacheBackend(
2468 store2.path(), false, 0, net::MEDIA_CACHE, disk_cache::kNone, 2424 net::MEDIA_CACHE, store2.path(), 0, false,
2469 cache_thread.message_loop_proxy(), NULL, &cache[1], cb.callback()); 2425 cache_thread.message_loop_proxy(), NULL, &cache[1], cb.callback());
2470 ASSERT_EQ(net::OK, cb.GetResult(rv)); 2426 ASSERT_EQ(net::OK, cb.GetResult(rv));
2471 2427
2472 ASSERT_TRUE(cache[0] != NULL && cache[1] != NULL); 2428 ASSERT_TRUE(cache[0] != NULL && cache[1] != NULL);
2473 2429
2474 std::string key("the first key"); 2430 std::string key("the first key");
2475 disk_cache::Entry* entry; 2431 disk_cache::Entry* entry;
2476 for (int i = 0; i < kNumberOfCaches; i++) { 2432 for (int i = 0; i < kNumberOfCaches; i++) {
2477 rv = cache[i]->CreateEntry(key, &entry, cb.callback()); 2433 rv = cache[i]->CreateEntry(key, &entry, cb.callback());
2478 ASSERT_EQ(net::OK, cb.GetResult(rv)); 2434 ASSERT_EQ(net::OK, cb.GetResult(rv));
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
2527 // Region 6: expected = kint32max 2483 // Region 6: expected = kint32max
2528 EXPECT_EQ(kint32max, 2484 EXPECT_EQ(kint32max,
2529 disk_cache::PreferedCacheSize(largest_size * 100)); 2485 disk_cache::PreferedCacheSize(largest_size * 100));
2530 EXPECT_EQ(kint32max, 2486 EXPECT_EQ(kint32max,
2531 disk_cache::PreferedCacheSize(largest_size * 10000)); 2487 disk_cache::PreferedCacheSize(largest_size * 10000));
2532 } 2488 }
2533 2489
2534 // Tests that we can "migrate" a running instance from one experiment group to 2490 // Tests that we can "migrate" a running instance from one experiment group to
2535 // another. 2491 // another.
2536 TEST_F(DiskCacheBackendTest, Histograms) { 2492 TEST_F(DiskCacheBackendTest, Histograms) {
2537 SetDirectMode();
2538 InitCache(); 2493 InitCache();
2539 disk_cache::BackendImpl* backend_ = cache_impl_; // Needed be the macro. 2494 disk_cache::BackendImpl* backend_ = cache_impl_; // Needed be the macro.
2540 2495
2541 for (int i = 1; i < 3; i++) { 2496 for (int i = 1; i < 3; i++) {
2542 CACHE_UMA(HOURS, "FillupTime", i, 28); 2497 CACHE_UMA(HOURS, "FillupTime", i, 28);
2543 } 2498 }
2544 } 2499 }
2545 2500
2546 // Make sure that we keep the total memory used by the internal buffers under 2501 // Make sure that we keep the total memory used by the internal buffers under
2547 // control. 2502 // control.
2548 TEST_F(DiskCacheBackendTest, TotalBuffersSize1) { 2503 TEST_F(DiskCacheBackendTest, TotalBuffersSize1) {
2549 SetDirectMode();
2550 InitCache(); 2504 InitCache();
2551 std::string key("the first key"); 2505 std::string key("the first key");
2552 disk_cache::Entry* entry; 2506 disk_cache::Entry* entry;
2553 ASSERT_EQ(net::OK, CreateEntry(key, &entry)); 2507 ASSERT_EQ(net::OK, CreateEntry(key, &entry));
2554 2508
2555 const int kSize = 200; 2509 const int kSize = 200;
2556 scoped_refptr<net::IOBuffer> buffer(new net::IOBuffer(kSize)); 2510 scoped_refptr<net::IOBuffer> buffer(new net::IOBuffer(kSize));
2557 CacheTestFillBuffer(buffer->data(), kSize, true); 2511 CacheTestFillBuffer(buffer->data(), kSize, true);
2558 2512
2559 for (int i = 0; i < 10; i++) { 2513 for (int i = 0; i < 10; i++) {
(...skipping 12 matching lines...) Expand all
2572 entry->Close(); 2526 entry->Close();
2573 ASSERT_EQ(net::OK, OpenEntry(key, &entry)); 2527 ASSERT_EQ(net::OK, OpenEntry(key, &entry));
2574 } 2528 }
2575 2529
2576 entry->Close(); 2530 entry->Close();
2577 EXPECT_EQ(0, cache_impl_->GetTotalBuffersSize()); 2531 EXPECT_EQ(0, cache_impl_->GetTotalBuffersSize());
2578 } 2532 }
2579 2533
2580 // This test assumes at least 150MB of system memory. 2534 // This test assumes at least 150MB of system memory.
2581 TEST_F(DiskCacheBackendTest, TotalBuffersSize2) { 2535 TEST_F(DiskCacheBackendTest, TotalBuffersSize2) {
2582 SetDirectMode();
2583 InitCache(); 2536 InitCache();
2584 2537
2585 const int kOneMB = 1024 * 1024; 2538 const int kOneMB = 1024 * 1024;
2586 EXPECT_TRUE(cache_impl_->IsAllocAllowed(0, kOneMB)); 2539 EXPECT_TRUE(cache_impl_->IsAllocAllowed(0, kOneMB));
2587 EXPECT_EQ(kOneMB, cache_impl_->GetTotalBuffersSize()); 2540 EXPECT_EQ(kOneMB, cache_impl_->GetTotalBuffersSize());
2588 2541
2589 EXPECT_TRUE(cache_impl_->IsAllocAllowed(0, kOneMB)); 2542 EXPECT_TRUE(cache_impl_->IsAllocAllowed(0, kOneMB));
2590 EXPECT_EQ(kOneMB * 2, cache_impl_->GetTotalBuffersSize()); 2543 EXPECT_EQ(kOneMB * 2, cache_impl_->GetTotalBuffersSize());
2591 2544
2592 EXPECT_TRUE(cache_impl_->IsAllocAllowed(0, kOneMB)); 2545 EXPECT_TRUE(cache_impl_->IsAllocAllowed(0, kOneMB));
2593 EXPECT_EQ(kOneMB * 3, cache_impl_->GetTotalBuffersSize()); 2546 EXPECT_EQ(kOneMB * 3, cache_impl_->GetTotalBuffersSize());
2594 2547
2595 cache_impl_->BufferDeleted(kOneMB); 2548 cache_impl_->BufferDeleted(kOneMB);
2596 EXPECT_EQ(kOneMB * 2, cache_impl_->GetTotalBuffersSize()); 2549 EXPECT_EQ(kOneMB * 2, cache_impl_->GetTotalBuffersSize());
2597 2550
2598 // Check the upper limit. 2551 // Check the upper limit.
2599 EXPECT_FALSE(cache_impl_->IsAllocAllowed(0, 30 * kOneMB)); 2552 EXPECT_FALSE(cache_impl_->IsAllocAllowed(0, 30 * kOneMB));
2600 2553
2601 for (int i = 0; i < 30; i++) 2554 for (int i = 0; i < 30; i++)
2602 cache_impl_->IsAllocAllowed(0, kOneMB); // Ignore the result. 2555 cache_impl_->IsAllocAllowed(0, kOneMB); // Ignore the result.
2603 2556
2604 EXPECT_FALSE(cache_impl_->IsAllocAllowed(0, kOneMB)); 2557 EXPECT_FALSE(cache_impl_->IsAllocAllowed(0, kOneMB));
2605 } 2558 }
2606 2559
2607 // Tests that sharing of external files works and we are able to delete the 2560 // Tests that sharing of external files works and we are able to delete the
2608 // files when we need to. 2561 // files when we need to.
2609 TEST_F(DiskCacheBackendTest, FileSharing) { 2562 TEST_F(DiskCacheBackendTest, FileSharing) {
2610 SetDirectMode();
2611 InitCache(); 2563 InitCache();
2612 2564
2613 disk_cache::Addr address(0x80000001); 2565 disk_cache::Addr address(0x80000001);
2614 ASSERT_TRUE(cache_impl_->CreateExternalFile(&address)); 2566 ASSERT_TRUE(cache_impl_->CreateExternalFile(&address));
2615 base::FilePath name = cache_impl_->GetFileName(address); 2567 base::FilePath name = cache_impl_->GetFileName(address);
2616 2568
2617 scoped_refptr<disk_cache::File> file(new disk_cache::File(false)); 2569 scoped_refptr<disk_cache::File> file(new disk_cache::File(false));
2618 file->Init(name); 2570 file->Init(name);
2619 2571
2620 #if defined(OS_WIN) 2572 #if defined(OS_WIN)
(...skipping 18 matching lines...) Expand all
2639 memset(buffer1, 't', kSize); 2591 memset(buffer1, 't', kSize);
2640 memset(buffer2, 0, kSize); 2592 memset(buffer2, 0, kSize);
2641 EXPECT_TRUE(file->Write(buffer1, kSize, 0)); 2593 EXPECT_TRUE(file->Write(buffer1, kSize, 0));
2642 EXPECT_TRUE(file->Read(buffer2, kSize, 0)); 2594 EXPECT_TRUE(file->Read(buffer2, kSize, 0));
2643 EXPECT_EQ(0, memcmp(buffer1, buffer2, kSize)); 2595 EXPECT_EQ(0, memcmp(buffer1, buffer2, kSize));
2644 2596
2645 EXPECT_TRUE(disk_cache::DeleteCacheFile(name)); 2597 EXPECT_TRUE(disk_cache::DeleteCacheFile(name));
2646 } 2598 }
2647 2599
2648 TEST_F(DiskCacheBackendTest, UpdateRankForExternalCacheHit) { 2600 TEST_F(DiskCacheBackendTest, UpdateRankForExternalCacheHit) {
2649 SetDirectMode();
2650 InitCache(); 2601 InitCache();
2651 2602
2652 disk_cache::Entry* entry; 2603 disk_cache::Entry* entry;
2653 2604
2654 for (int i = 0; i < 2; ++i) { 2605 for (int i = 0; i < 2; ++i) {
2655 std::string key = base::StringPrintf("key%d", i); 2606 std::string key = base::StringPrintf("key%d", i);
2656 ASSERT_EQ(net::OK, CreateEntry(key, &entry)); 2607 ASSERT_EQ(net::OK, CreateEntry(key, &entry));
2657 entry->Close(); 2608 entry->Close();
2658 } 2609 }
2659 2610
2660 // Ping the oldest entry. 2611 // Ping the oldest entry.
2661 cache_->OnExternalCacheHit("key0"); 2612 cache_->OnExternalCacheHit("key0");
2662 2613
2663 TrimForTest(false); 2614 TrimForTest(false);
2664 2615
2665 // Make sure the older key remains. 2616 // Make sure the older key remains.
2666 EXPECT_EQ(1, cache_->GetEntryCount()); 2617 EXPECT_EQ(1, cache_->GetEntryCount());
2667 ASSERT_EQ(net::OK, OpenEntry("key0", &entry)); 2618 ASSERT_EQ(net::OK, OpenEntry("key0", &entry));
2668 entry->Close(); 2619 entry->Close();
2669 } 2620 }
2670 2621
2671 TEST_F(DiskCacheBackendTest, ShaderCacheUpdateRankForExternalCacheHit) { 2622 TEST_F(DiskCacheBackendTest, ShaderCacheUpdateRankForExternalCacheHit) {
2672 SetCacheType(net::SHADER_CACHE); 2623 SetCacheType(net::SHADER_CACHE);
2673 SetDirectMode();
2674 InitCache(); 2624 InitCache();
2675 2625
2676 disk_cache::Entry* entry; 2626 disk_cache::Entry* entry;
2677 2627
2678 for (int i = 0; i < 2; ++i) { 2628 for (int i = 0; i < 2; ++i) {
2679 std::string key = base::StringPrintf("key%d", i); 2629 std::string key = base::StringPrintf("key%d", i);
2680 ASSERT_EQ(net::OK, CreateEntry(key, &entry)); 2630 ASSERT_EQ(net::OK, CreateEntry(key, &entry));
2681 entry->Close(); 2631 entry->Close();
2682 } 2632 }
2683 2633
2684 // Ping the oldest entry. 2634 // Ping the oldest entry.
2685 cache_->OnExternalCacheHit("key0"); 2635 cache_->OnExternalCacheHit("key0");
2686 2636
2687 TrimForTest(false); 2637 TrimForTest(false);
2688 2638
2689 // Make sure the older key remains. 2639 // Make sure the older key remains.
2690 EXPECT_EQ(1, cache_->GetEntryCount()); 2640 EXPECT_EQ(1, cache_->GetEntryCount());
2691 ASSERT_EQ(net::OK, OpenEntry("key0", &entry)); 2641 ASSERT_EQ(net::OK, OpenEntry("key0", &entry));
2692 entry->Close(); 2642 entry->Close();
2693 } 2643 }
OLDNEW
« no previous file with comments | « net/disk_cache/backend_impl.cc ('k') | net/disk_cache/cache_creator.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698