| Index: net/disk_cache/disk_cache_test.h
|
| diff --git a/net/disk_cache/disk_cache_test.h b/net/disk_cache/disk_cache_test.h
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..4b0185feeee1f550ead87a0aa1284c00ff30f2c6
|
| --- /dev/null
|
| +++ b/net/disk_cache/disk_cache_test.h
|
| @@ -0,0 +1,156 @@
|
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#ifndef NET_DISK_CACHE_DISK_CACHE_TEST_H_
|
| +#define NET_DISK_CACHE_DISK_CACHE_TEST_H_
|
| +
|
| +#include "base/basictypes.h"
|
| +#include "base/files/file_path.h"
|
| +#include "base/files/scoped_temp_dir.h"
|
| +#include "base/memory/scoped_ptr.h"
|
| +#include "base/threading/thread.h"
|
| +#include "net/base/cache_type.h"
|
| +#include "testing/gtest/include/gtest/gtest.h"
|
| +#include "testing/platform_test.h"
|
| +
|
| +namespace base {
|
| +class MessageLoopProxy;
|
| +} // namespace base
|
| +
|
| +namespace net {
|
| +class IOBuffer;
|
| +} // namespace net
|
| +
|
| +namespace disk_cache {
|
| +
|
| +class Backend;
|
| +class BackendImpl;
|
| +class Entry;
|
| +class MemBackendImpl;
|
| +class SimpleBackendImpl;
|
| +
|
| +class BackendTestTraits {
|
| + public:
|
| + class CreateBackendExtraData {
|
| + protected:
|
| + ~CreateBackendExtraData();
|
| + };
|
| +
|
| + BackendTestTraits() {}
|
| + virtual ~BackendTestTraits() {}
|
| +
|
| + virtual Backend* CreateBackend(const CreateBackendExtraData* extra_data,
|
| + const base::FilePath& cache_path,
|
| + int max_size,
|
| + base::MessageLoopProxy* task_runner) const = 0;
|
| +
|
| + virtual bool UsesCacheThread() const = 0;
|
| +
|
| + // Backend specific quirks that tests might want to respect:
|
| + virtual bool WritesUpdateLastUsed() const;
|
| + virtual bool ReadsUpdateLastUsed() const;
|
| + virtual int SparseRoundingInterval() const;
|
| + virtual bool EntryCountIncludesSparseRanges() const;
|
| + virtual bool ImplementsCouldBeSparse() const;
|
| + virtual bool DoomedSparseEntriesIOWorks() const;
|
| + virtual bool EnumerationsAreLexicographicByKey() const;
|
| +
|
| + // Events
|
| + virtual void PreTearDown() const {}
|
| + virtual void PostTearDown() const {}
|
| +
|
| +
|
| + // Helpers
|
| + virtual bool SetMaxSize(Backend* backend, int size) const = 0;
|
| + virtual void FlushQueueForTest(Backend* backend) const {}
|
| + virtual void AddDelay() const;
|
| +};
|
| +
|
| +// Provides basic support for cache related tests.
|
| +class DiskCacheTest : public PlatformTest,
|
| + public ::testing::WithParamInterface<const BackendTestTraits*>
|
| +{
|
| + public:
|
| + void InitCache() { InitCacheWithExtraData(NULL); }
|
| +
|
| + // Utility methods to access the cache and wait for each operation to finish.
|
| + int OpenEntry(const std::string& key, disk_cache::Entry** entry);
|
| + int CreateEntry(const std::string& key, disk_cache::Entry** entry);
|
| + int DoomEntry(const std::string& key);
|
| + int DoomAllEntries();
|
| + int DoomEntriesBetween(const base::Time initial_time,
|
| + const base::Time end_time);
|
| + int DoomEntriesSince(const base::Time initial_time);
|
| + int OpenNextEntry(void** iter, disk_cache::Entry** next_entry);
|
| + int ReadData(disk_cache::Entry* entry, int index, int offset,
|
| + net::IOBuffer* buf, int len);
|
| + int WriteData(disk_cache::Entry* entry, int index, int offset,
|
| + net::IOBuffer* buf, int len, bool truncate);
|
| + int ReadSparseData(disk_cache::Entry* entry, int64 offset, net::IOBuffer* buf,
|
| + int len);
|
| + int WriteSparseData(disk_cache::Entry* entry, int64 offset,
|
| + net::IOBuffer* buf, int len);
|
| +
|
| + const base::FilePath& cache_path() const { return temp_dir_.path(); }
|
| + disk_cache::Backend* cache() { return cache_.get(); }
|
| +
|
| + // Makes sure that some time passes before continuing the test. Time::Now()
|
| + // before and after this method will not be the same.
|
| + void AddDelay();
|
| +
|
| + void FlushQueueForTest();
|
| +
|
| + void SetMaxSize(int max_size);
|
| +
|
| + // Copies a set of cache files from the data folder to the test folder.
|
| + bool CopyTestCache(const std::string& name);
|
| +
|
| + protected:
|
| + DiskCacheTest();
|
| + virtual ~DiskCacheTest();
|
| +
|
| + // Do not call this in a test that may run on multiple backends.
|
| + void InitCacheWithExtraData(const BackendTestTraits::CreateBackendExtraData* extra_data);
|
| +
|
| + void DeleteCache() { cache_.reset(); }
|
| +
|
| + void CreateBackend(uint32 flags, base::Thread* thread);
|
| +
|
| + // Deletes the contents of |cache_path_|.
|
| + bool CleanupCacheDir();
|
| +
|
| + void UseCurrentThread() { use_current_thread_ = true; }
|
| +
|
| + // TODO(implement)
|
| + void DisableIntegrityCheck() {}
|
| +
|
| +
|
| + base::MessageLoopProxy* GetCacheThread();
|
| +
|
| +
|
| + // From PlatformTest:
|
| + virtual void TearDown() OVERRIDE;
|
| +
|
| + const BackendTestTraits* traits() const { return traits_; }
|
| +
|
| + protected:
|
| +
|
| + private:
|
| + bool use_current_thread_;
|
| + int max_size_;
|
| +
|
| + scoped_ptr<disk_cache::Backend> cache_;
|
| +
|
| + base::ScopedTempDir temp_dir_;
|
| + scoped_ptr<base::MessageLoop> message_loop_;
|
| +
|
| + const BackendTestTraits* traits_;
|
| +
|
| + base::Thread cache_thread_;
|
| + DISALLOW_COPY_AND_ASSIGN(DiskCacheTest);
|
| +};
|
| +
|
| +} // namespace disk_cache
|
| +
|
| +#endif // NET_DISK_CACHE_DISK_CACHE_TEST_H_
|
|
|