1 // Copyright (c) 2006-2008 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 #ifndef NET_DISK_CACHE_DISK_CACHE_TEST_BASE_H_ 6 #define NET_DISK_CACHE_DISK_CACHE_TEST_BASE_H_ 7 8 #include "base/basictypes.h" 9 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/platform_test.h" 11 12 class FilePath; 13 14 namespace disk_cache { 15 16 class Backend; 17 class BackendImpl; 18 class MemBackendImpl; 19 20 } // namespace disk_cache 21 22 // These tests can use the path service, which uses autoreleased objects on the 23 // Mac, so this needs to be a PlatformTest. Even tests that do not require a 24 // cache (and that do not need to be a DiskCacheTestWithCache) are susceptible 25 // to this problem; all such tests should use TEST_F(DiskCacheTest, ...). 26 class DiskCacheTest : public PlatformTest { 27 virtual void TearDown(); 28 }; 29 30 // Provides basic support for cache related tests. 31 class DiskCacheTestWithCache : public DiskCacheTest { 32 protected: 33 DiskCacheTestWithCache() 34 : cache_(NULL), cache_impl_(NULL), mem_cache_(NULL), mask_(0), size_(0), 35 memory_only_(false), implementation_(false), force_creation_(false), 36 new_eviction_(false), first_cleanup_(true), integrity_(true) {} 37 38 void InitCache(); 39 virtual void TearDown(); 40 void SimulateCrash(); 41 void SetTestMode(); 42 43 void SetMemoryOnlyMode() { 44 memory_only_ = true; 45 } 46 47 // Use the implementation directly instead of the factory provided object. 48 void SetDirectMode() { 49 implementation_ = true; 50 } 51 52 void SetMask(uint32 mask) { 53 mask_ = mask; 54 } 55 56 void SetMaxSize(int size); 57 58 // Deletes and re-creates the files on initialization errors. 59 void SetForceCreation() { 60 force_creation_ = true; 61 } 62 63 void SetNewEviction() { 64 new_eviction_ = true; 65 } 66 67 void DisableFirstCleanup() { 68 first_cleanup_ = false; 69 } 70 71 void DisableIntegrityCheck() { 72 integrity_ = false; 73 } 74 75 // cache_ will always have a valid object, regardless of how the cache was 76 // initialized. The implementation pointers can be NULL. 77 disk_cache::Backend* cache_; 78 disk_cache::BackendImpl* cache_impl_; 79 disk_cache::MemBackendImpl* mem_cache_; 80 81 uint32 mask_; 82 int size_; 83 bool memory_only_; 84 bool implementation_; 85 bool force_creation_; 86 bool new_eviction_; 87 bool first_cleanup_; 88 bool integrity_; 89 // This is intentionally left uninitialized, to be used by any test. 90 bool success_; 91 92 private: 93 void InitMemoryCache(); 94 void InitDiskCache(); 95 void InitDiskCacheImpl(const FilePath& path); 96 }; 97 98 #endif // NET_DISK_CACHE_DISK_CACHE_TEST_BASE_H_ 99