OLD | NEW |
1 // Copyright (c) 2006-2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2010 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 "net/disk_cache/disk_cache_test_base.h" | 5 #include "net/disk_cache/disk_cache_test_base.h" |
6 | 6 |
7 #include "net/base/test_completion_callback.h" | 7 #include "net/base/test_completion_callback.h" |
8 #include "net/disk_cache/backend_impl.h" | 8 #include "net/disk_cache/backend_impl.h" |
9 #include "net/disk_cache/disk_cache_test_util.h" | 9 #include "net/disk_cache/disk_cache_test_util.h" |
10 #include "net/disk_cache/mem_backend_impl.h" | 10 #include "net/disk_cache/mem_backend_impl.h" |
(...skipping 20 matching lines...) Expand all Loading... |
31 else | 31 else |
32 InitDiskCache(); | 32 InitDiskCache(); |
33 | 33 |
34 ASSERT_TRUE(NULL != cache_); | 34 ASSERT_TRUE(NULL != cache_); |
35 if (first_cleanup_) | 35 if (first_cleanup_) |
36 ASSERT_EQ(0, cache_->GetEntryCount()); | 36 ASSERT_EQ(0, cache_->GetEntryCount()); |
37 } | 37 } |
38 | 38 |
39 void DiskCacheTestWithCache::InitMemoryCache() { | 39 void DiskCacheTestWithCache::InitMemoryCache() { |
40 if (!implementation_) { | 40 if (!implementation_) { |
41 cache_ = disk_cache::CreateInMemoryCacheBackend(size_); | 41 cache_ = disk_cache::MemBackendImpl::CreateBackend(size_); |
42 return; | 42 return; |
43 } | 43 } |
44 | 44 |
45 mem_cache_ = new disk_cache::MemBackendImpl(); | 45 mem_cache_ = new disk_cache::MemBackendImpl(); |
46 cache_ = mem_cache_; | 46 cache_ = mem_cache_; |
47 ASSERT_TRUE(NULL != cache_); | 47 ASSERT_TRUE(NULL != cache_); |
48 | 48 |
49 if (size_) | 49 if (size_) |
50 EXPECT_TRUE(mem_cache_->SetMaxSize(size_)); | 50 EXPECT_TRUE(mem_cache_->SetMaxSize(size_)); |
51 | 51 |
52 ASSERT_TRUE(mem_cache_->Init()); | 52 ASSERT_TRUE(mem_cache_->Init()); |
53 } | 53 } |
54 | 54 |
55 void DiskCacheTestWithCache::InitDiskCache() { | 55 void DiskCacheTestWithCache::InitDiskCache() { |
56 FilePath path = GetCacheFilePath(); | 56 FilePath path = GetCacheFilePath(); |
57 if (first_cleanup_) | 57 if (first_cleanup_) |
58 ASSERT_TRUE(DeleteCache(path)); | 58 ASSERT_TRUE(DeleteCache(path)); |
59 | 59 |
| 60 if (!cache_thread_.IsRunning()) { |
| 61 EXPECT_TRUE(cache_thread_.StartWithOptions( |
| 62 base::Thread::Options(MessageLoop::TYPE_IO, 0))); |
| 63 } |
| 64 ASSERT_TRUE(cache_thread_.message_loop() != NULL); |
| 65 |
60 if (implementation_) | 66 if (implementation_) |
61 return InitDiskCacheImpl(path); | 67 return InitDiskCacheImpl(path); |
62 | 68 |
63 cache_ = disk_cache::BackendImpl::CreateBackend(path, force_creation_, size_, | 69 TestCompletionCallback cb; |
64 net::DISK_CACHE, | 70 int rv = disk_cache::BackendImpl::CreateBackend( |
65 disk_cache::kNoRandom); | 71 path, force_creation_, size_, net::DISK_CACHE, |
| 72 disk_cache::kNoRandom, cache_thread_.message_loop_proxy(), |
| 73 &cache_, &cb); |
| 74 ASSERT_EQ(net::OK, cb.GetResult(rv)); |
66 } | 75 } |
67 | 76 |
68 void DiskCacheTestWithCache::InitDiskCacheImpl(const FilePath& path) { | 77 void DiskCacheTestWithCache::InitDiskCacheImpl(const FilePath& path) { |
69 if (mask_) | 78 if (mask_) |
70 cache_impl_ = new disk_cache::BackendImpl(path, mask_); | 79 cache_impl_ = new disk_cache::BackendImpl( |
| 80 path, mask_, cache_thread_.message_loop_proxy()); |
71 else | 81 else |
72 cache_impl_ = new disk_cache::BackendImpl(path); | 82 cache_impl_ = new disk_cache::BackendImpl( |
| 83 path, cache_thread_.message_loop_proxy()); |
73 | 84 |
74 cache_ = cache_impl_; | 85 cache_ = cache_impl_; |
75 ASSERT_TRUE(NULL != cache_); | 86 ASSERT_TRUE(NULL != cache_); |
76 | 87 |
77 if (size_) | 88 if (size_) |
78 EXPECT_TRUE(cache_impl_->SetMaxSize(size_)); | 89 EXPECT_TRUE(cache_impl_->SetMaxSize(size_)); |
79 | 90 |
80 if (new_eviction_) | 91 if (new_eviction_) |
81 cache_impl_->SetNewEviction(); | 92 cache_impl_->SetNewEviction(); |
82 | 93 |
83 cache_impl_->SetFlags(disk_cache::kNoRandom); | 94 cache_impl_->SetFlags(disk_cache::kNoRandom); |
84 ASSERT_TRUE(cache_impl_->Init()); | 95 ASSERT_TRUE(cache_impl_->Init()); |
85 } | 96 } |
86 | 97 |
87 void DiskCacheTestWithCache::TearDown() { | 98 void DiskCacheTestWithCache::TearDown() { |
88 MessageLoop::current()->RunAllPending(); | 99 MessageLoop::current()->RunAllPending(); |
89 delete cache_; | 100 delete cache_; |
| 101 if (cache_thread_.IsRunning()) |
| 102 cache_thread_.Stop(); |
90 | 103 |
91 if (!memory_only_ && integrity_) { | 104 if (!memory_only_ && integrity_) { |
92 FilePath path = GetCacheFilePath(); | 105 FilePath path = GetCacheFilePath(); |
93 EXPECT_TRUE(CheckCacheIntegrity(path, new_eviction_)); | 106 EXPECT_TRUE(CheckCacheIntegrity(path, new_eviction_)); |
94 } | 107 } |
95 | 108 |
96 PlatformTest::TearDown(); | 109 PlatformTest::TearDown(); |
97 } | 110 } |
98 | 111 |
99 // We are expected to leak memory when simulating crashes. | 112 // We are expected to leak memory when simulating crashes. |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 int rv = cache_->DoomEntriesSince(initial_time, &cb); | 164 int rv = cache_->DoomEntriesSince(initial_time, &cb); |
152 return cb.GetResult(rv); | 165 return cb.GetResult(rv); |
153 } | 166 } |
154 | 167 |
155 int DiskCacheTestWithCache::OpenNextEntry(void** iter, | 168 int DiskCacheTestWithCache::OpenNextEntry(void** iter, |
156 disk_cache::Entry** next_entry) { | 169 disk_cache::Entry** next_entry) { |
157 TestCompletionCallback cb; | 170 TestCompletionCallback cb; |
158 int rv = cache_->OpenNextEntry(iter, next_entry, &cb); | 171 int rv = cache_->OpenNextEntry(iter, next_entry, &cb); |
159 return cb.GetResult(rv); | 172 return cb.GetResult(rv); |
160 } | 173 } |
OLD | NEW |