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

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