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 <string> | 5 #include <string> |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/file_path.h" | 8 #include "base/file_path.h" |
9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/perftimer.h" | 10 #include "base/perftimer.h" |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 | 162 |
163 base::Thread cache_thread("CacheThread"); | 163 base::Thread cache_thread("CacheThread"); |
164 ASSERT_TRUE(cache_thread.StartWithOptions( | 164 ASSERT_TRUE(cache_thread.StartWithOptions( |
165 base::Thread::Options(MessageLoop::TYPE_IO, 0))); | 165 base::Thread::Options(MessageLoop::TYPE_IO, 0))); |
166 | 166 |
167 ScopedTestCache test_cache; | 167 ScopedTestCache test_cache; |
168 TestCompletionCallback cb; | 168 TestCompletionCallback cb; |
169 disk_cache::Backend* cache; | 169 disk_cache::Backend* cache; |
170 int rv = disk_cache::CreateCacheBackend( | 170 int rv = disk_cache::CreateCacheBackend( |
171 net::DISK_CACHE, test_cache.path(), 0, false, | 171 net::DISK_CACHE, test_cache.path(), 0, false, |
172 cache_thread.message_loop_proxy(), NULL, &cache, &cb); | 172 cache_thread.message_loop_proxy(), &cache, &cb); |
173 | 173 |
174 ASSERT_EQ(net::OK, cb.GetResult(rv)); | 174 ASSERT_EQ(net::OK, cb.GetResult(rv)); |
175 | 175 |
176 int seed = static_cast<int>(Time::Now().ToInternalValue()); | 176 int seed = static_cast<int>(Time::Now().ToInternalValue()); |
177 srand(seed); | 177 srand(seed); |
178 | 178 |
179 TestEntries entries; | 179 TestEntries entries; |
180 int num_entries = 1000; | 180 int num_entries = 1000; |
181 | 181 |
182 int ret = TimeWrite(num_entries, cache, &entries); | 182 int ret = TimeWrite(num_entries, cache, &entries); |
183 EXPECT_EQ(ret, g_cache_tests_received); | 183 EXPECT_EQ(ret, g_cache_tests_received); |
184 | 184 |
185 MessageLoop::current()->RunAllPending(); | 185 MessageLoop::current()->RunAllPending(); |
186 delete cache; | 186 delete cache; |
187 | 187 |
188 ASSERT_TRUE(file_util::EvictFileFromSystemCache( | 188 ASSERT_TRUE(file_util::EvictFileFromSystemCache( |
189 test_cache.path().AppendASCII("index"))); | 189 test_cache.path().AppendASCII("index"))); |
190 ASSERT_TRUE(file_util::EvictFileFromSystemCache( | 190 ASSERT_TRUE(file_util::EvictFileFromSystemCache( |
191 test_cache.path().AppendASCII("data_0"))); | 191 test_cache.path().AppendASCII("data_0"))); |
192 ASSERT_TRUE(file_util::EvictFileFromSystemCache( | 192 ASSERT_TRUE(file_util::EvictFileFromSystemCache( |
193 test_cache.path().AppendASCII("data_1"))); | 193 test_cache.path().AppendASCII("data_1"))); |
194 ASSERT_TRUE(file_util::EvictFileFromSystemCache( | 194 ASSERT_TRUE(file_util::EvictFileFromSystemCache( |
195 test_cache.path().AppendASCII("data_2"))); | 195 test_cache.path().AppendASCII("data_2"))); |
196 ASSERT_TRUE(file_util::EvictFileFromSystemCache( | 196 ASSERT_TRUE(file_util::EvictFileFromSystemCache( |
197 test_cache.path().AppendASCII("data_3"))); | 197 test_cache.path().AppendASCII("data_3"))); |
198 | 198 |
199 rv = disk_cache::CreateCacheBackend(net::DISK_CACHE, test_cache.path(), 0, | 199 rv = disk_cache::CreateCacheBackend(net::DISK_CACHE, test_cache.path(), 0, |
200 false, cache_thread.message_loop_proxy(), | 200 false, cache_thread.message_loop_proxy(), |
201 NULL, &cache, &cb); | 201 &cache, &cb); |
202 ASSERT_EQ(net::OK, cb.GetResult(rv)); | 202 ASSERT_EQ(net::OK, cb.GetResult(rv)); |
203 | 203 |
204 ret = TimeRead(num_entries, cache, entries, true); | 204 ret = TimeRead(num_entries, cache, entries, true); |
205 EXPECT_EQ(ret, g_cache_tests_received); | 205 EXPECT_EQ(ret, g_cache_tests_received); |
206 | 206 |
207 ret = TimeRead(num_entries, cache, entries, false); | 207 ret = TimeRead(num_entries, cache, entries, false); |
208 EXPECT_EQ(ret, g_cache_tests_received); | 208 EXPECT_EQ(ret, g_cache_tests_received); |
209 | 209 |
210 MessageLoop::current()->RunAllPending(); | 210 MessageLoop::current()->RunAllPending(); |
211 delete cache; | 211 delete cache; |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
248 | 248 |
249 files.DeleteBlock(address[entry], false); | 249 files.DeleteBlock(address[entry], false); |
250 EXPECT_TRUE(files.CreateBlock(disk_cache::RANKINGS, BlockSize(), | 250 EXPECT_TRUE(files.CreateBlock(disk_cache::RANKINGS, BlockSize(), |
251 &address[entry])); | 251 &address[entry])); |
252 } | 252 } |
253 | 253 |
254 timer2.Done(); | 254 timer2.Done(); |
255 MessageLoop::current()->RunAllPending(); | 255 MessageLoop::current()->RunAllPending(); |
256 delete[] address; | 256 delete[] address; |
257 } | 257 } |
OLD | NEW |