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

Side by Side Diff: net/disk_cache/backend_unittest.cc

Issue 6005015: Revert 70618 - First pass at adding http/backend cache events to the NetLog. ... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years, 11 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 | Annotate | Revision Log
« no previous file with comments | « net/disk_cache/backend_impl.cc ('k') | net/disk_cache/disk_cache.h » ('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) 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 "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 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 FilePath path = GetCacheFilePath(); 188 FilePath path = GetCacheFilePath();
189 ASSERT_TRUE(DeleteCache(path)); 189 ASSERT_TRUE(DeleteCache(path));
190 base::Thread cache_thread("CacheThread"); 190 base::Thread cache_thread("CacheThread");
191 ASSERT_TRUE(cache_thread.StartWithOptions( 191 ASSERT_TRUE(cache_thread.StartWithOptions(
192 base::Thread::Options(MessageLoop::TYPE_IO, 0))); 192 base::Thread::Options(MessageLoop::TYPE_IO, 0)));
193 193
194 // Test the private factory methods. 194 // Test the private factory methods.
195 disk_cache::Backend* cache = NULL; 195 disk_cache::Backend* cache = NULL;
196 int rv = disk_cache::BackendImpl::CreateBackend( 196 int rv = disk_cache::BackendImpl::CreateBackend(
197 path, false, 0, net::DISK_CACHE, disk_cache::kNoRandom, 197 path, false, 0, net::DISK_CACHE, disk_cache::kNoRandom,
198 cache_thread.message_loop_proxy(), NULL, &cache, &cb); 198 cache_thread.message_loop_proxy(), &cache, &cb);
199 ASSERT_EQ(net::OK, cb.GetResult(rv)); 199 ASSERT_EQ(net::OK, cb.GetResult(rv));
200 ASSERT_TRUE(cache); 200 ASSERT_TRUE(cache);
201 delete cache; 201 delete cache;
202 202
203 cache = disk_cache::MemBackendImpl::CreateBackend(0); 203 cache = disk_cache::MemBackendImpl::CreateBackend(0);
204 ASSERT_TRUE(cache); 204 ASSERT_TRUE(cache);
205 delete cache; 205 delete cache;
206 cache = NULL; 206 cache = NULL;
207 207
208 // Now test the public API. 208 // Now test the public API.
209 rv = disk_cache::CreateCacheBackend(net::DISK_CACHE, path, 0, false, 209 rv = disk_cache::CreateCacheBackend(net::DISK_CACHE, path, 0, false,
210 cache_thread.message_loop_proxy(), 210 cache_thread.message_loop_proxy(),
211 NULL, &cache, &cb); 211 &cache, &cb);
212 ASSERT_EQ(net::OK, cb.GetResult(rv)); 212 ASSERT_EQ(net::OK, cb.GetResult(rv));
213 ASSERT_TRUE(cache); 213 ASSERT_TRUE(cache);
214 delete cache; 214 delete cache;
215 cache = NULL; 215 cache = NULL;
216 216
217 rv = disk_cache::CreateCacheBackend(net::MEMORY_CACHE, FilePath(), 0, false, 217 rv = disk_cache::CreateCacheBackend(net::MEMORY_CACHE, FilePath(), 0, false,
218 NULL, NULL, &cache, &cb); 218 NULL, &cache, &cb);
219 ASSERT_EQ(net::OK, cb.GetResult(rv)); 219 ASSERT_EQ(net::OK, cb.GetResult(rv));
220 ASSERT_TRUE(cache); 220 ASSERT_TRUE(cache);
221 delete cache; 221 delete cache;
222 } 222 }
223 223
224 MessageLoop::current()->RunAllPending(); 224 MessageLoop::current()->RunAllPending();
225 } 225 }
226 226
227 TEST_F(DiskCacheBackendTest, ExternalFiles) { 227 TEST_F(DiskCacheBackendTest, ExternalFiles) {
228 InitCache(); 228 InitCache();
(...skipping 24 matching lines...) Expand all
253 { 253 {
254 FilePath path = GetCacheFilePath(); 254 FilePath path = GetCacheFilePath();
255 ASSERT_TRUE(DeleteCache(path)); 255 ASSERT_TRUE(DeleteCache(path));
256 base::Thread cache_thread("CacheThread"); 256 base::Thread cache_thread("CacheThread");
257 ASSERT_TRUE(cache_thread.StartWithOptions( 257 ASSERT_TRUE(cache_thread.StartWithOptions(
258 base::Thread::Options(MessageLoop::TYPE_IO, 0))); 258 base::Thread::Options(MessageLoop::TYPE_IO, 0)));
259 259
260 disk_cache::Backend* cache; 260 disk_cache::Backend* cache;
261 int rv = disk_cache::BackendImpl::CreateBackend( 261 int rv = disk_cache::BackendImpl::CreateBackend(
262 path, false, 0, net::DISK_CACHE, disk_cache::kNoRandom, 262 path, false, 0, net::DISK_CACHE, disk_cache::kNoRandom,
263 base::MessageLoopProxy::CreateForCurrentThread(), NULL, 263 base::MessageLoopProxy::CreateForCurrentThread(), &cache, &cb);
264 &cache, &cb);
265 ASSERT_EQ(net::OK, cb.GetResult(rv)); 264 ASSERT_EQ(net::OK, cb.GetResult(rv));
266 265
267 disk_cache::EntryImpl* entry; 266 disk_cache::EntryImpl* entry;
268 rv = cache->CreateEntry("some key", 267 rv = cache->CreateEntry("some key",
269 reinterpret_cast<disk_cache::Entry**>(&entry), &cb); 268 reinterpret_cast<disk_cache::Entry**>(&entry), &cb);
270 ASSERT_EQ(net::OK, cb.GetResult(rv)); 269 ASSERT_EQ(net::OK, cb.GetResult(rv));
271 270
272 const int kSize = 25000; 271 const int kSize = 25000;
273 scoped_refptr<net::IOBuffer> buffer(new net::IOBuffer(kSize)); 272 scoped_refptr<net::IOBuffer> buffer(new net::IOBuffer(kSize));
274 CacheTestFillBuffer(buffer->data(), kSize, false); 273 CacheTestFillBuffer(buffer->data(), kSize, false);
(...skipping 30 matching lines...) Expand all
305 { 304 {
306 FilePath path = GetCacheFilePath(); 305 FilePath path = GetCacheFilePath();
307 ASSERT_TRUE(DeleteCache(path)); 306 ASSERT_TRUE(DeleteCache(path));
308 base::Thread cache_thread("CacheThread"); 307 base::Thread cache_thread("CacheThread");
309 ASSERT_TRUE(cache_thread.StartWithOptions( 308 ASSERT_TRUE(cache_thread.StartWithOptions(
310 base::Thread::Options(MessageLoop::TYPE_IO, 0))); 309 base::Thread::Options(MessageLoop::TYPE_IO, 0)));
311 310
312 disk_cache::Backend* cache; 311 disk_cache::Backend* cache;
313 int rv = disk_cache::BackendImpl::CreateBackend( 312 int rv = disk_cache::BackendImpl::CreateBackend(
314 path, false, 0, net::DISK_CACHE, disk_cache::kNoRandom, 313 path, false, 0, net::DISK_CACHE, disk_cache::kNoRandom,
315 cache_thread.message_loop_proxy(), NULL, &cache, &cb); 314 cache_thread.message_loop_proxy(), &cache, &cb);
316 ASSERT_EQ(net::OK, cb.GetResult(rv)); 315 ASSERT_EQ(net::OK, cb.GetResult(rv));
317 316
318 disk_cache::Entry* entry; 317 disk_cache::Entry* entry;
319 rv = cache->CreateEntry("some key", &entry, &cb); 318 rv = cache->CreateEntry("some key", &entry, &cb);
320 ASSERT_EQ(net::OK, cb.GetResult(rv)); 319 ASSERT_EQ(net::OK, cb.GetResult(rv));
321 320
322 const int kSize = 25000; 321 const int kSize = 25000;
323 scoped_refptr<net::IOBuffer> buffer(new net::IOBuffer(kSize)); 322 scoped_refptr<net::IOBuffer> buffer(new net::IOBuffer(kSize));
324 CacheTestFillBuffer(buffer->data(), kSize, false); 323 CacheTestFillBuffer(buffer->data(), kSize, false);
325 324
(...skipping 16 matching lines...) Expand all
342 ASSERT_EQ(5, file_util::WriteFile(index, "hello", 5)); 341 ASSERT_EQ(5, file_util::WriteFile(index, "hello", 5));
343 342
344 base::Thread cache_thread("CacheThread"); 343 base::Thread cache_thread("CacheThread");
345 ASSERT_TRUE(cache_thread.StartWithOptions( 344 ASSERT_TRUE(cache_thread.StartWithOptions(
346 base::Thread::Options(MessageLoop::TYPE_IO, 0))); 345 base::Thread::Options(MessageLoop::TYPE_IO, 0)));
347 TestCompletionCallback cb; 346 TestCompletionCallback cb;
348 347
349 disk_cache::Backend* backend = NULL; 348 disk_cache::Backend* backend = NULL;
350 int rv = disk_cache::BackendImpl::CreateBackend( 349 int rv = disk_cache::BackendImpl::CreateBackend(
351 path, false, 0, net::DISK_CACHE, disk_cache::kNone, 350 path, false, 0, net::DISK_CACHE, disk_cache::kNone,
352 cache_thread.message_loop_proxy(), NULL, &backend, &cb); 351 cache_thread.message_loop_proxy(), &backend, &cb);
353 ASSERT_NE(net::OK, cb.GetResult(rv)); 352 ASSERT_NE(net::OK, cb.GetResult(rv));
354 353
355 ASSERT_TRUE(backend == NULL); 354 ASSERT_TRUE(backend == NULL);
356 delete backend; 355 delete backend;
357 } 356 }
358 357
359 void DiskCacheBackendTest::BackendSetSize() { 358 void DiskCacheBackendTest::BackendSetSize() {
360 SetDirectMode(); 359 SetDirectMode();
361 const int cache_size = 0x10000; // 64 kB 360 const int cache_size = 0x10000; // 64 kB
362 SetMaxSize(cache_size); 361 SetMaxSize(cache_size);
(...skipping 909 matching lines...) Expand 10 before | Expand all | Expand 10 after
1272 ASSERT_TRUE(CopyTestCache("wrong_version")); 1271 ASSERT_TRUE(CopyTestCache("wrong_version"));
1273 FilePath path = GetCacheFilePath(); 1272 FilePath path = GetCacheFilePath();
1274 base::Thread cache_thread("CacheThread"); 1273 base::Thread cache_thread("CacheThread");
1275 ASSERT_TRUE(cache_thread.StartWithOptions( 1274 ASSERT_TRUE(cache_thread.StartWithOptions(
1276 base::Thread::Options(MessageLoop::TYPE_IO, 0))); 1275 base::Thread::Options(MessageLoop::TYPE_IO, 0)));
1277 TestCompletionCallback cb; 1276 TestCompletionCallback cb;
1278 1277
1279 disk_cache::Backend* cache; 1278 disk_cache::Backend* cache;
1280 int rv = disk_cache::BackendImpl::CreateBackend( 1279 int rv = disk_cache::BackendImpl::CreateBackend(
1281 path, true, 0, net::DISK_CACHE, disk_cache::kNoRandom, 1280 path, true, 0, net::DISK_CACHE, disk_cache::kNoRandom,
1282 cache_thread.message_loop_proxy(), NULL, &cache, &cb); 1281 cache_thread.message_loop_proxy(), &cache, &cb);
1283 ASSERT_EQ(net::OK, cb.GetResult(rv)); 1282 ASSERT_EQ(net::OK, cb.GetResult(rv));
1284 1283
1285 MessageLoopHelper helper; 1284 MessageLoopHelper helper;
1286 1285
1287 ASSERT_TRUE(NULL != cache); 1286 ASSERT_TRUE(NULL != cache);
1288 ASSERT_EQ(0, cache->GetEntryCount()); 1287 ASSERT_EQ(0, cache->GetEntryCount());
1289 1288
1290 delete cache; 1289 delete cache;
1291 } 1290 }
1292 1291
(...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after
1645 BackendDisable4(); 1644 BackendDisable4();
1646 } 1645 }
1647 1646
1648 TEST_F(DiskCacheTest, Backend_UsageStats) { 1647 TEST_F(DiskCacheTest, Backend_UsageStats) {
1649 MessageLoopHelper helper; 1648 MessageLoopHelper helper;
1650 1649
1651 FilePath path = GetCacheFilePath(); 1650 FilePath path = GetCacheFilePath();
1652 ASSERT_TRUE(DeleteCache(path)); 1651 ASSERT_TRUE(DeleteCache(path));
1653 scoped_ptr<disk_cache::BackendImpl> cache; 1652 scoped_ptr<disk_cache::BackendImpl> cache;
1654 cache.reset(new disk_cache::BackendImpl( 1653 cache.reset(new disk_cache::BackendImpl(
1655 path, base::MessageLoopProxy::CreateForCurrentThread(), 1654 path, base::MessageLoopProxy::CreateForCurrentThread()));
1656 NULL));
1657 ASSERT_TRUE(NULL != cache.get()); 1655 ASSERT_TRUE(NULL != cache.get());
1658 cache->SetUnitTestMode(); 1656 cache->SetUnitTestMode();
1659 ASSERT_EQ(net::OK, cache->SyncInit()); 1657 ASSERT_EQ(net::OK, cache->SyncInit());
1660 1658
1661 // Wait for a callback that never comes... about 2 secs :). The message loop 1659 // Wait for a callback that never comes... about 2 secs :). The message loop
1662 // has to run to allow invocation of the usage timer. 1660 // has to run to allow invocation of the usage timer.
1663 helper.WaitUntilCacheIoFinished(1); 1661 helper.WaitUntilCacheIoFinished(1);
1664 } 1662 }
1665 1663
1666 void DiskCacheBackendTest::BackendDoomAll() { 1664 void DiskCacheBackendTest::BackendDoomAll() {
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
1764 base::Thread cache_thread("CacheThread"); 1762 base::Thread cache_thread("CacheThread");
1765 ASSERT_TRUE(cache_thread.StartWithOptions( 1763 ASSERT_TRUE(cache_thread.StartWithOptions(
1766 base::Thread::Options(MessageLoop::TYPE_IO, 0))); 1764 base::Thread::Options(MessageLoop::TYPE_IO, 0)));
1767 TestCompletionCallback cb; 1765 TestCompletionCallback cb;
1768 1766
1769 const int kNumberOfCaches = 2; 1767 const int kNumberOfCaches = 2;
1770 disk_cache::Backend* cache[kNumberOfCaches]; 1768 disk_cache::Backend* cache[kNumberOfCaches];
1771 1769
1772 int rv = disk_cache::BackendImpl::CreateBackend( 1770 int rv = disk_cache::BackendImpl::CreateBackend(
1773 store1.path(), false, 0, net::DISK_CACHE, disk_cache::kNone, 1771 store1.path(), false, 0, net::DISK_CACHE, disk_cache::kNone,
1774 cache_thread.message_loop_proxy(), NULL, &cache[0], &cb); 1772 cache_thread.message_loop_proxy(), &cache[0], &cb);
1775 ASSERT_EQ(net::OK, cb.GetResult(rv)); 1773 ASSERT_EQ(net::OK, cb.GetResult(rv));
1776 rv = disk_cache::BackendImpl::CreateBackend( 1774 rv = disk_cache::BackendImpl::CreateBackend(
1777 store2.path(), false, 0, net::MEDIA_CACHE, disk_cache::kNone, 1775 store2.path(), false, 0, net::MEDIA_CACHE, disk_cache::kNone,
1778 cache_thread.message_loop_proxy(), NULL, &cache[1], &cb); 1776 cache_thread.message_loop_proxy(), &cache[1], &cb);
1779 ASSERT_EQ(net::OK, cb.GetResult(rv)); 1777 ASSERT_EQ(net::OK, cb.GetResult(rv));
1780 1778
1781 ASSERT_TRUE(cache[0] != NULL && cache[1] != NULL); 1779 ASSERT_TRUE(cache[0] != NULL && cache[1] != NULL);
1782 1780
1783 std::string key("the first key"); 1781 std::string key("the first key");
1784 disk_cache::Entry* entry; 1782 disk_cache::Entry* entry;
1785 for (int i = 0; i < kNumberOfCaches; i++) { 1783 for (int i = 0; i < kNumberOfCaches; i++) {
1786 rv = cache[i]->CreateEntry(key, &entry, &cb); 1784 rv = cache[i]->CreateEntry(key, &entry, &cb);
1787 ASSERT_EQ(net::OK, cb.GetResult(rv)); 1785 ASSERT_EQ(net::OK, cb.GetResult(rv));
1788 entry->Close(); 1786 entry->Close();
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
1946 char buffer1[kSize]; 1944 char buffer1[kSize];
1947 char buffer2[kSize]; 1945 char buffer2[kSize];
1948 memset(buffer1, 't', kSize); 1946 memset(buffer1, 't', kSize);
1949 memset(buffer2, 0, kSize); 1947 memset(buffer2, 0, kSize);
1950 EXPECT_TRUE(file->Write(buffer1, kSize, 0)); 1948 EXPECT_TRUE(file->Write(buffer1, kSize, 0));
1951 EXPECT_TRUE(file->Read(buffer2, kSize, 0)); 1949 EXPECT_TRUE(file->Read(buffer2, kSize, 0));
1952 EXPECT_EQ(0, memcmp(buffer1, buffer2, kSize)); 1950 EXPECT_EQ(0, memcmp(buffer1, buffer2, kSize));
1953 1951
1954 EXPECT_TRUE(disk_cache::DeleteCacheFile(name)); 1952 EXPECT_TRUE(disk_cache::DeleteCacheFile(name));
1955 } 1953 }
OLDNEW
« no previous file with comments | « net/disk_cache/backend_impl.cc ('k') | net/disk_cache/disk_cache.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698