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/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" |
11 #include "base/threading/thread_restrictions.h" | 11 #include "base/threading/thread_restrictions.h" |
12 #include "net/base/io_buffer.h" | 12 #include "net/base/io_buffer.h" |
13 #include "net/base/net_errors.h" | 13 #include "net/base/net_errors.h" |
14 #include "net/base/test_completion_callback.h" | 14 #include "net/base/test_completion_callback.h" |
15 #include "net/disk_cache/backend_impl.h" | 15 #include "net/disk_cache/backend_impl.h" |
16 #include "net/disk_cache/cache_util.h" | 16 #include "net/disk_cache/cache_util.h" |
17 #include "net/disk_cache/disk_cache_test_base.h" | 17 #include "net/disk_cache/disk_cache_test_base.h" |
18 #include "net/disk_cache/disk_cache_test_util.h" | 18 #include "net/disk_cache/disk_cache_test_util.h" |
19 #include "net/disk_cache/entry_impl.h" | 19 #include "net/disk_cache/entry_impl.h" |
20 #include "net/disk_cache/histogram_macros.h" | 20 #include "net/disk_cache/histogram_macros.h" |
21 #include "net/disk_cache/mapped_file.h" | 21 #include "net/disk_cache/mapped_file.h" |
22 #include "net/disk_cache/mem_backend_impl.h" | 22 #include "net/disk_cache/mem_backend_impl.h" |
| 23 #include "net/disk_cache/tracing_cache_backend.h" |
23 #include "testing/gtest/include/gtest/gtest.h" | 24 #include "testing/gtest/include/gtest/gtest.h" |
24 | 25 |
25 #if defined(OS_WIN) | 26 #if defined(OS_WIN) |
26 #include "base/win/scoped_handle.h" | 27 #include "base/win/scoped_handle.h" |
27 #endif | 28 #endif |
28 | 29 |
29 using base::Time; | 30 using base::Time; |
30 | 31 |
31 // Tests that can run with different types of caches. | 32 // Tests that can run with different types of caches. |
32 class DiskCacheBackendTest : public DiskCacheTestWithCache { | 33 class DiskCacheBackendTest : public DiskCacheTestWithCache { |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 void BackendInvalidEntry11(bool eviction); | 65 void BackendInvalidEntry11(bool eviction); |
65 void BackendTrimInvalidEntry12(); | 66 void BackendTrimInvalidEntry12(); |
66 void BackendDoomAll(); | 67 void BackendDoomAll(); |
67 void BackendDoomAll2(); | 68 void BackendDoomAll2(); |
68 void BackendInvalidRankings(); | 69 void BackendInvalidRankings(); |
69 void BackendInvalidRankings2(); | 70 void BackendInvalidRankings2(); |
70 void BackendDisable(); | 71 void BackendDisable(); |
71 void BackendDisable2(); | 72 void BackendDisable2(); |
72 void BackendDisable3(); | 73 void BackendDisable3(); |
73 void BackendDisable4(); | 74 void BackendDisable4(); |
| 75 void TracingBackendBasics(); |
74 }; | 76 }; |
75 | 77 |
76 void DiskCacheBackendTest::BackendBasics() { | 78 void DiskCacheBackendTest::BackendBasics() { |
77 InitCache(); | 79 InitCache(); |
78 disk_cache::Entry *entry1 = NULL, *entry2 = NULL; | 80 disk_cache::Entry *entry1 = NULL, *entry2 = NULL; |
79 EXPECT_NE(net::OK, OpenEntry("the first key", &entry1)); | 81 EXPECT_NE(net::OK, OpenEntry("the first key", &entry1)); |
80 ASSERT_EQ(net::OK, CreateEntry("the first key", &entry1)); | 82 ASSERT_EQ(net::OK, CreateEntry("the first key", &entry1)); |
81 ASSERT_TRUE(NULL != entry1); | 83 ASSERT_TRUE(NULL != entry1); |
82 entry1->Close(); | 84 entry1->Close(); |
83 entry1 = NULL; | 85 entry1 = NULL; |
(...skipping 2572 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2656 // Ping the oldest entry. | 2658 // Ping the oldest entry. |
2657 cache_->OnExternalCacheHit("key0"); | 2659 cache_->OnExternalCacheHit("key0"); |
2658 | 2660 |
2659 TrimForTest(false); | 2661 TrimForTest(false); |
2660 | 2662 |
2661 // Make sure the older key remains. | 2663 // Make sure the older key remains. |
2662 EXPECT_EQ(1, cache_->GetEntryCount()); | 2664 EXPECT_EQ(1, cache_->GetEntryCount()); |
2663 ASSERT_EQ(net::OK, OpenEntry("key0", &entry)); | 2665 ASSERT_EQ(net::OK, OpenEntry("key0", &entry)); |
2664 entry->Close(); | 2666 entry->Close(); |
2665 } | 2667 } |
| 2668 |
| 2669 void DiskCacheBackendTest::TracingBackendBasics() { |
| 2670 InitCache(); |
| 2671 cache_ = new disk_cache::TracingCacheBackend(cache_); |
| 2672 cache_impl_ = NULL; |
| 2673 EXPECT_EQ(net::DISK_CACHE, cache_->GetCacheType()); |
| 2674 if (!simple_cache_mode_) { |
| 2675 EXPECT_EQ(0, cache_->GetEntryCount()); |
| 2676 } |
| 2677 |
| 2678 net::TestCompletionCallback cb; |
| 2679 disk_cache::Entry* entry = NULL; |
| 2680 EXPECT_NE(net::OK, OpenEntry("key", &entry)); |
| 2681 EXPECT_TRUE(NULL == entry); |
| 2682 |
| 2683 ASSERT_EQ(net::OK, CreateEntry("key", &entry)); |
| 2684 EXPECT_TRUE(NULL != entry); |
| 2685 |
| 2686 disk_cache::Entry* same_entry = NULL; |
| 2687 ASSERT_EQ(net::OK, OpenEntry("key", &same_entry)); |
| 2688 EXPECT_TRUE(NULL != same_entry); |
| 2689 |
| 2690 if (!simple_cache_mode_) { |
| 2691 EXPECT_EQ(1, cache_->GetEntryCount()); |
| 2692 } |
| 2693 entry->Close(); |
| 2694 entry = NULL; |
| 2695 same_entry->Close(); |
| 2696 same_entry = NULL; |
| 2697 } |
| 2698 |
| 2699 TEST_F(DiskCacheBackendTest, TracingBackendBasicsWithBackendImpl) { |
| 2700 TracingBackendBasics(); |
| 2701 } |
| 2702 |
| 2703 // File renaming is flaky on Windows, disable all Simple Backend Tests there. |
| 2704 #ifdef OS_WIN |
| 2705 #define TEST_SIMPLECACHE_F(c, t) TEST_F(c, DISABLED_##t) |
| 2706 #else |
| 2707 #define TEST_SIMPLECACHE_F(c, t) TEST_F(c, t) |
| 2708 #endif |
| 2709 |
| 2710 TEST_SIMPLECACHE_F(DiskCacheBackendTest, |
| 2711 TracingBackendBasicsWithSimpleBackend) { |
| 2712 SetSimpleCacheMode(); |
| 2713 TracingBackendBasics(); |
| 2714 // TODO(pasko): implement integrity checking on the Simple Backend. |
| 2715 DisableIntegrityCheck(); |
| 2716 } |
OLD | NEW |