OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include <string> |
| 6 |
| 7 #include "net/base/io_buffer.h" |
| 8 #include "net/base/net_errors.h" |
| 9 #include "net/disk_cache/disk_cache.h" |
| 10 #include "net/disk_cache/disk_cache_test_util.h" |
| 11 #include "net/disk_cache/backend_tests.h" |
| 12 #include "net/disk_cache/entry_sync_tests.h" |
| 13 #include "net/disk_cache/entry_tests.h" |
| 14 #include "net/disk_cache/memory/mem_entry_impl.h" |
| 15 #include "net/disk_cache/memory/mem_backend_impl.h" |
| 16 |
| 17 namespace disk_cache { |
| 18 |
| 19 namespace { |
| 20 |
| 21 class MemoryCacheBackendTraits : public BackendTestTraits { |
| 22 public: |
| 23 MemoryCacheBackendTraits() {} |
| 24 |
| 25 virtual ~MemoryCacheBackendTraits() {} |
| 26 |
| 27 virtual Backend* CreateBackend( |
| 28 const CreateBackendExtraData* extra_data, |
| 29 const base::FilePath& cache_path, |
| 30 int max_size, |
| 31 base::MessageLoopProxy* task_runner) const OVERRIDE { |
| 32 scoped_ptr<MemBackendImpl> mem_backend(new MemBackendImpl(NULL)); |
| 33 if (max_size) |
| 34 mem_backend->SetMaxSize(max_size); |
| 35 if (!mem_backend->Init()) |
| 36 return NULL; |
| 37 return mem_backend.release(); |
| 38 } |
| 39 |
| 40 virtual bool EnumerationsAreLexicographicByKey() const OVERRIDE { |
| 41 return true; |
| 42 } |
| 43 |
| 44 virtual bool UsesCacheThread() const OVERRIDE { return false; } |
| 45 |
| 46 virtual bool SetMaxSize(Backend* backend, int size) const OVERRIDE { |
| 47 return static_cast<MemBackendImpl*>(backend)->SetMaxSize(size); |
| 48 } |
| 49 |
| 50 static const BackendTestTraits* Get() { |
| 51 static MemoryCacheBackendTraits traits; |
| 52 return &traits; |
| 53 } |
| 54 }; |
| 55 |
| 56 INSTANTIATE_TEST_CASE_P(MemoryOnlyCache, DiskCacheEntryTest, |
| 57 ::testing::Values(MemoryCacheBackendTraits::Get())); |
| 58 |
| 59 INSTANTIATE_TEST_CASE_P(MemoryOnlyCache, DiskCacheEntrySyncTest, |
| 60 ::testing::Values(MemoryCacheBackendTraits::Get())); |
| 61 |
| 62 INSTANTIATE_TEST_CASE_P(MemoryOnlyCache, DiskCacheBackendTest, |
| 63 ::testing::Values(MemoryCacheBackendTraits::Get())); |
| 64 |
| 65 class DiskCacheMemoryBackendTest : public DiskCacheBackendTest {}; |
| 66 |
| 67 INSTANTIATE_TEST_CASE_P(MemoryOnlyCache, DiskCacheMemoryBackendTest, |
| 68 ::testing::Values(MemoryCacheBackendTraits::Get())); |
| 69 |
| 70 TEST_P(DiskCacheMemoryBackendTest, CreateBackend) { |
| 71 // Test the private factory method(s). |
| 72 scoped_ptr<disk_cache::Backend> cache; |
| 73 cache = disk_cache::MemBackendImpl::CreateBackend(0, NULL); |
| 74 ASSERT_TRUE(cache.get()); |
| 75 cache.reset(); |
| 76 } |
| 77 |
| 78 } // namespace |
| 79 |
| 80 } // namespace disk_cache |
OLD | NEW |