OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/basictypes.h" | 5 #include "base/basictypes.h" |
6 #include "base/file_util.h" | 6 #include "base/file_util.h" |
7 #include "base/metrics/field_trial.h" | 7 #include "base/metrics/field_trial.h" |
8 #include "base/port.h" | 8 #include "base/port.h" |
9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
(...skipping 500 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
511 | 511 |
512 if (rv == net::ERR_IO_PENDING) { | 512 if (rv == net::ERR_IO_PENDING) { |
513 if (fast || simple_cache_mode_) | 513 if (fast || simple_cache_mode_) |
514 EXPECT_FALSE(cb.have_result()); | 514 EXPECT_FALSE(cb.have_result()); |
515 else | 515 else |
516 EXPECT_TRUE(cb.have_result()); | 516 EXPECT_TRUE(cb.have_result()); |
517 } | 517 } |
518 | 518 |
519 base::MessageLoop::current()->RunUntilIdle(); | 519 base::MessageLoop::current()->RunUntilIdle(); |
520 | 520 |
| 521 #if !defined(OS_IOS) |
521 // Wait for the actual operation to complete, or we'll keep a file handle that | 522 // Wait for the actual operation to complete, or we'll keep a file handle that |
522 // may cause issues later. | 523 // may cause issues later. Note that on iOS systems even though this test |
| 524 // uses a single thread, the actual IO is posted to a worker thread and the |
| 525 // cache destructor breaks the link to reach cb when the operation completes. |
523 rv = cb.GetResult(rv); | 526 rv = cb.GetResult(rv); |
| 527 #endif |
524 } | 528 } |
525 | 529 |
526 TEST_F(DiskCacheBackendTest, ShutdownWithPendingFileIO) { | 530 TEST_F(DiskCacheBackendTest, ShutdownWithPendingFileIO) { |
527 BackendShutdownWithPendingFileIO(false); | 531 BackendShutdownWithPendingFileIO(false); |
528 } | 532 } |
529 | 533 |
530 // Here and below, tests that simulate crashes are not compiled in LeakSanitizer | 534 // Here and below, tests that simulate crashes are not compiled in LeakSanitizer |
531 // builds because they contain a lot of intentional memory leaks. | 535 // builds because they contain a lot of intentional memory leaks. |
532 // The wrapper scripts used to run tests under Valgrind Memcheck and | 536 // The wrapper scripts used to run tests under Valgrind Memcheck and |
533 // Heapchecker will also disable these tests under those tools. See: | 537 // Heapchecker will also disable these tests under those tools. See: |
534 // tools/valgrind/gtest_exclude/net_unittests.gtest-memcheck.txt | 538 // tools/valgrind/gtest_exclude/net_unittests.gtest-memcheck.txt |
535 // tools/heapcheck/net_unittests.gtest-heapcheck.txt | 539 // tools/heapcheck/net_unittests.gtest-heapcheck.txt |
536 #if !defined(LEAK_SANITIZER) | 540 #if !defined(LEAK_SANITIZER) |
537 // We'll be leaking from this test. | 541 // We'll be leaking from this test. |
538 TEST_F(DiskCacheBackendTest, ShutdownWithPendingFileIO_Fast) { | 542 TEST_F(DiskCacheBackendTest, ShutdownWithPendingFileIO_Fast) { |
539 // The integrity test sets kNoRandom so there's a version mismatch if we don't | 543 // The integrity test sets kNoRandom so there's a version mismatch if we don't |
540 // force new eviction. | 544 // force new eviction. |
541 SetNewEviction(); | 545 SetNewEviction(); |
542 BackendShutdownWithPendingFileIO(true); | 546 BackendShutdownWithPendingFileIO(true); |
543 } | 547 } |
544 #endif | 548 #endif |
545 | 549 |
| 550 // See crbug.com/330074 |
| 551 #if !defined(OS_IOS) |
546 // Tests that one cache instance is not affected by another one going away. | 552 // Tests that one cache instance is not affected by another one going away. |
547 TEST_F(DiskCacheBackendTest, MultipleInstancesWithPendingFileIO) { | 553 TEST_F(DiskCacheBackendTest, MultipleInstancesWithPendingFileIO) { |
548 base::ScopedTempDir store; | 554 base::ScopedTempDir store; |
549 ASSERT_TRUE(store.CreateUniqueTempDir()); | 555 ASSERT_TRUE(store.CreateUniqueTempDir()); |
550 | 556 |
551 net::TestCompletionCallback cb; | 557 net::TestCompletionCallback cb; |
552 scoped_ptr<disk_cache::Backend> extra_cache; | 558 scoped_ptr<disk_cache::Backend> extra_cache; |
553 int rv = disk_cache::CreateCacheBackend( | 559 int rv = disk_cache::CreateCacheBackend( |
554 net::DISK_CACHE, net::CACHE_BACKEND_DEFAULT, store.path(), 0, | 560 net::DISK_CACHE, net::CACHE_BACKEND_DEFAULT, store.path(), 0, |
555 false, base::MessageLoopProxy::current().get(), NULL, | 561 false, base::MessageLoopProxy::current().get(), NULL, |
(...skipping 13 matching lines...) Expand all Loading... |
569 | 575 |
570 if (rv == net::ERR_IO_PENDING) | 576 if (rv == net::ERR_IO_PENDING) |
571 EXPECT_FALSE(cb.have_result()); | 577 EXPECT_FALSE(cb.have_result()); |
572 | 578 |
573 base::MessageLoop::current()->RunUntilIdle(); | 579 base::MessageLoop::current()->RunUntilIdle(); |
574 | 580 |
575 // Wait for the actual operation to complete, or we'll keep a file handle that | 581 // Wait for the actual operation to complete, or we'll keep a file handle that |
576 // may cause issues later. | 582 // may cause issues later. |
577 rv = cb.GetResult(rv); | 583 rv = cb.GetResult(rv); |
578 } | 584 } |
| 585 #endif |
579 | 586 |
580 // Tests that we deal with background-thread pending operations. | 587 // Tests that we deal with background-thread pending operations. |
581 void DiskCacheBackendTest::BackendShutdownWithPendingIO(bool fast) { | 588 void DiskCacheBackendTest::BackendShutdownWithPendingIO(bool fast) { |
582 net::TestCompletionCallback cb; | 589 net::TestCompletionCallback cb; |
583 | 590 |
584 { | 591 { |
585 ASSERT_TRUE(CleanupCacheDir()); | 592 ASSERT_TRUE(CleanupCacheDir()); |
586 base::Thread cache_thread("CacheThread"); | 593 base::Thread cache_thread("CacheThread"); |
587 ASSERT_TRUE(cache_thread.StartWithOptions( | 594 ASSERT_TRUE(cache_thread.StartWithOptions( |
588 base::Thread::Options(base::MessageLoop::TYPE_IO, 0))); | 595 base::Thread::Options(base::MessageLoop::TYPE_IO, 0))); |
(...skipping 2875 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3464 void* iter = NULL; | 3471 void* iter = NULL; |
3465 size_t count = 0; | 3472 size_t count = 0; |
3466 ASSERT_TRUE(EnumerateAndMatchKeys(-1, &iter, &keys_to_match, &count)); | 3473 ASSERT_TRUE(EnumerateAndMatchKeys(-1, &iter, &keys_to_match, &count)); |
3467 cache_->EndEnumeration(&iter); | 3474 cache_->EndEnumeration(&iter); |
3468 | 3475 |
3469 EXPECT_EQ(key_pool.size(), count); | 3476 EXPECT_EQ(key_pool.size(), count); |
3470 EXPECT_TRUE(keys_to_match.empty()); | 3477 EXPECT_TRUE(keys_to_match.empty()); |
3471 } | 3478 } |
3472 | 3479 |
3473 #endif // defined(OS_POSIX) | 3480 #endif // defined(OS_POSIX) |
OLD | NEW |