diff options
author | michaeln@google.com <michaeln@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-24 21:42:25 +0000 |
---|---|---|
committer | michaeln@google.com <michaeln@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-24 21:42:25 +0000 |
commit | 550890ec7f1cf968abc4544b170e97a67f919902 (patch) | |
tree | 632dec32bed5266837a2668a9225d303303e3160 /webkit/appcache/mock_appcache_storage.h | |
parent | ed249ab7916d438b0bdb650a796aaf709f6ae1ae (diff) | |
download | chromium_src-550890ec7f1cf968abc4544b170e97a67f919902.zip chromium_src-550890ec7f1cf968abc4544b170e97a67f919902.tar.gz chromium_src-550890ec7f1cf968abc4544b170e97a67f919902.tar.bz2 |
MockAppCacheStorage implemention
This is a quick and easy 'mock' implementation of the storage interface
that doesn't put anything to disk.
We simply add an extra reference to objects when they're put in storage,
and remove the extra reference when they are removed from storage.
Responses are never really removed from the in-memory disk cache.
Delegate callbacks are made asyncly to appropiately mimic what will
happen with a real disk-backed storage impl that involves IO on a
background thread.
This is for use in unit tests and to initially bring up the appcache
related layout tests.
TEST=mock_appcache_storage_unittest.cc
BUG=none
Review URL: http://codereview.chromium.org/300043
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@30017 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/appcache/mock_appcache_storage.h')
-rw-r--r-- | webkit/appcache/mock_appcache_storage.h | 51 |
1 files changed, 43 insertions, 8 deletions
diff --git a/webkit/appcache/mock_appcache_storage.h b/webkit/appcache/mock_appcache_storage.h index 8efb7d9..ca6bd70 100644 --- a/webkit/appcache/mock_appcache_storage.h +++ b/webkit/appcache/mock_appcache_storage.h @@ -5,10 +5,12 @@ #ifndef WEBKIT_APPCACHE_MOCK_APPCACHE_STORAGE_H_ #define WEBKIT_APPCACHE_MOCK_APPCACHE_STORAGE_H_ +#include <deque> #include <map> #include "base/hash_tables.h" #include "base/scoped_ptr.h" +#include "base/task.h" #include "net/disk_cache/disk_cache.h" #include "webkit/appcache/appcache.h" #include "webkit/appcache/appcache_group.h" @@ -23,13 +25,15 @@ namespace appcache { class MockAppCacheStorage : public AppCacheStorage { public: explicit MockAppCacheStorage(AppCacheService* service); + virtual ~MockAppCacheStorage(); + virtual void LoadCache(int64 id, Delegate* delegate); virtual void LoadOrCreateGroup(const GURL& manifest_url, Delegate* delegate); virtual void StoreGroupAndNewestCache( AppCacheGroup* group, Delegate* delegate); virtual void FindResponseForMainRequest(const GURL& url, Delegate* delegate); virtual void MarkEntryAsForeign(const GURL& entry_url, int64 cache_id); - virtual void MarkGroupAsObsolete(AppCacheGroup* group, Delegate* delegate); + virtual void MakeGroupObsolete(AppCacheGroup* group, Delegate* delegate); virtual AppCacheResponseReader* CreateResponseReader( const GURL& manifest_url, int64 response_id); virtual AppCacheResponseWriter* CreateResponseWriter(const GURL& origin); @@ -39,20 +43,40 @@ class MockAppCacheStorage : public AppCacheStorage { private: typedef base::hash_map<int64, scoped_refptr<AppCache> > StoredCacheMap; typedef std::map<GURL, scoped_refptr<AppCacheGroup> > StoredGroupMap; + typedef std::set<int64> DoomedResponseIds; + + void ProcessLoadCache( + int64 id, scoped_refptr<DelegateReference> delegate_ref); + void ProcessLoadOrCreateGroup( + const GURL& manifest_url, scoped_refptr<DelegateReference> delegate_ref); + void ProcessStoreGroupAndNewestCache( + scoped_refptr<AppCacheGroup> group, scoped_refptr<AppCache> newest_cache, + scoped_refptr<DelegateReference> delegate_ref); + void ProcessMakeGroupObsolete( + scoped_refptr<AppCacheGroup> group, + scoped_refptr<DelegateReference> delegate_ref); + void ProcessFindResponseForMainRequest( + const GURL& url, scoped_refptr<DelegateReference> delegate_ref); + + void ScheduleTask(Task* task); + void RunOnePendingTask(); void AddStoredCache(AppCache* cache); void RemoveStoredCache(AppCache* cache); - AppCache* GetStoredCache(int64 id) { - StoredCacheMap::iterator it = stored_caches_.find(id); - return (it != stored_caches_.end()) ? it->second : NULL; + void RemoveStoredCaches(const AppCacheGroup::Caches& caches); + bool IsCacheStored(const AppCache* cache) { + return stored_caches_.find(cache->cache_id()) != stored_caches_.end(); } void AddStoredGroup(AppCacheGroup* group); void RemoveStoredGroup(AppCacheGroup* group); - AppCacheGroup* GetStoredGroup(const GURL& manifest_url) { - StoredGroupMap::iterator it = stored_groups_.find(manifest_url); - return (it != stored_groups_.end()) ? it->second : NULL; - } + + // These helpers determine when certain operations should complete + // asynchronously vs synchronously to faithfully mimic, or mock, + // the behavior of the real implemenation of the AppCacheStorage + // interface. + bool ShouldGroupLoadAppearAsync(const AppCacheGroup* group); + bool ShouldCacheLoadAppearAsync(const AppCache* cache); // Lazily constructed in-memory disk cache. disk_cache::Backend* disk_cache() { @@ -65,7 +89,18 @@ class MockAppCacheStorage : public AppCacheStorage { StoredCacheMap stored_caches_; StoredGroupMap stored_groups_; + DoomedResponseIds doomed_response_ids_; scoped_ptr<disk_cache::Backend> disk_cache_; + std::deque<Task*> pending_tasks_; + ScopedRunnableMethodFactory<MockAppCacheStorage> method_factory_; + + FRIEND_TEST(MockAppCacheStorageTest, CreateGroup); + FRIEND_TEST(MockAppCacheStorageTest, LoadCache_FarHit); + FRIEND_TEST(MockAppCacheStorageTest, LoadGroupAndCache_FarHit); + FRIEND_TEST(MockAppCacheStorageTest, MakeGroupObsolete); + FRIEND_TEST(MockAppCacheStorageTest, StoreNewGroup); + FRIEND_TEST(MockAppCacheStorageTest, StoreExistingGroup); + DISALLOW_COPY_AND_ASSIGN(MockAppCacheStorage); }; } // namespace appcache |