| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #ifndef CONTENT_BROWSER_APPCACHE_MOCK_APPCACHE_STORAGE_H_ | 5 #ifndef CONTENT_BROWSER_APPCACHE_MOCK_APPCACHE_STORAGE_H_ |
| 6 #define CONTENT_BROWSER_APPCACHE_MOCK_APPCACHE_STORAGE_H_ | 6 #define CONTENT_BROWSER_APPCACHE_MOCK_APPCACHE_STORAGE_H_ |
| 7 | 7 |
| 8 #include <stdint.h> |
| 9 |
| 8 #include <deque> | 10 #include <deque> |
| 9 #include <map> | 11 #include <map> |
| 10 #include <vector> | 12 #include <vector> |
| 11 | 13 |
| 12 #include "base/callback.h" | 14 #include "base/callback.h" |
| 13 #include "base/containers/hash_tables.h" | 15 #include "base/containers/hash_tables.h" |
| 14 #include "base/gtest_prod_util.h" | 16 #include "base/gtest_prod_util.h" |
| 17 #include "base/macros.h" |
| 15 #include "base/memory/scoped_ptr.h" | 18 #include "base/memory/scoped_ptr.h" |
| 16 #include "base/memory/weak_ptr.h" | 19 #include "base/memory/weak_ptr.h" |
| 17 #include "content/browser/appcache/appcache.h" | 20 #include "content/browser/appcache/appcache.h" |
| 18 #include "content/browser/appcache/appcache_disk_cache.h" | 21 #include "content/browser/appcache/appcache_disk_cache.h" |
| 19 #include "content/browser/appcache/appcache_group.h" | 22 #include "content/browser/appcache/appcache_group.h" |
| 20 #include "content/browser/appcache/appcache_response.h" | 23 #include "content/browser/appcache/appcache_response.h" |
| 21 #include "content/browser/appcache/appcache_storage.h" | 24 #include "content/browser/appcache/appcache_storage.h" |
| 22 | 25 |
| 23 namespace content { | 26 namespace content { |
| 24 FORWARD_DECLARE_TEST(AppCacheServiceImplTest, DeleteAppCachesForOrigin); | 27 FORWARD_DECLARE_TEST(AppCacheServiceImplTest, DeleteAppCachesForOrigin); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 43 // For use in unit tests. | 46 // For use in unit tests. |
| 44 // Note: This class is also being used to bootstrap our development efforts. | 47 // Note: This class is also being used to bootstrap our development efforts. |
| 45 // We can get layout tests up and running, and back fill with real storage | 48 // We can get layout tests up and running, and back fill with real storage |
| 46 // somewhat in parallel. | 49 // somewhat in parallel. |
| 47 class MockAppCacheStorage : public AppCacheStorage { | 50 class MockAppCacheStorage : public AppCacheStorage { |
| 48 public: | 51 public: |
| 49 explicit MockAppCacheStorage(AppCacheServiceImpl* service); | 52 explicit MockAppCacheStorage(AppCacheServiceImpl* service); |
| 50 ~MockAppCacheStorage() override; | 53 ~MockAppCacheStorage() override; |
| 51 | 54 |
| 52 void GetAllInfo(Delegate* delegate) override; | 55 void GetAllInfo(Delegate* delegate) override; |
| 53 void LoadCache(int64 id, Delegate* delegate) override; | 56 void LoadCache(int64_t id, Delegate* delegate) override; |
| 54 void LoadOrCreateGroup(const GURL& manifest_url, Delegate* delegate) override; | 57 void LoadOrCreateGroup(const GURL& manifest_url, Delegate* delegate) override; |
| 55 void StoreGroupAndNewestCache(AppCacheGroup* group, | 58 void StoreGroupAndNewestCache(AppCacheGroup* group, |
| 56 AppCache* newest_cache, | 59 AppCache* newest_cache, |
| 57 Delegate* delegate) override; | 60 Delegate* delegate) override; |
| 58 void FindResponseForMainRequest(const GURL& url, | 61 void FindResponseForMainRequest(const GURL& url, |
| 59 const GURL& preferred_manifest_url, | 62 const GURL& preferred_manifest_url, |
| 60 Delegate* delegate) override; | 63 Delegate* delegate) override; |
| 61 void FindResponseForSubRequest(AppCache* cache, | 64 void FindResponseForSubRequest(AppCache* cache, |
| 62 const GURL& url, | 65 const GURL& url, |
| 63 AppCacheEntry* found_entry, | 66 AppCacheEntry* found_entry, |
| 64 AppCacheEntry* found_fallback_entry, | 67 AppCacheEntry* found_fallback_entry, |
| 65 bool* found_network_namespace) override; | 68 bool* found_network_namespace) override; |
| 66 void MarkEntryAsForeign(const GURL& entry_url, int64 cache_id) override; | 69 void MarkEntryAsForeign(const GURL& entry_url, int64_t cache_id) override; |
| 67 void MakeGroupObsolete(AppCacheGroup* group, | 70 void MakeGroupObsolete(AppCacheGroup* group, |
| 68 Delegate* delegate, | 71 Delegate* delegate, |
| 69 int response_code) override; | 72 int response_code) override; |
| 70 void StoreEvictionTimes(AppCacheGroup* group) override; | 73 void StoreEvictionTimes(AppCacheGroup* group) override; |
| 71 AppCacheResponseReader* CreateResponseReader(const GURL& manifest_url, | 74 AppCacheResponseReader* CreateResponseReader(const GURL& manifest_url, |
| 72 int64 group_id, | 75 int64_t group_id, |
| 73 int64 response_id) override; | 76 int64_t response_id) override; |
| 74 AppCacheResponseWriter* CreateResponseWriter(const GURL& manifest_url, | 77 AppCacheResponseWriter* CreateResponseWriter(const GURL& manifest_url, |
| 75 int64 group_id) override; | 78 int64_t group_id) override; |
| 76 AppCacheResponseMetadataWriter* CreateResponseMetadataWriter( | 79 AppCacheResponseMetadataWriter* CreateResponseMetadataWriter( |
| 77 int64 group_id, | 80 int64_t group_id, |
| 78 int64 response_id) override; | 81 int64_t response_id) override; |
| 79 void DoomResponses(const GURL& manifest_url, | 82 void DoomResponses(const GURL& manifest_url, |
| 80 const std::vector<int64>& response_ids) override; | 83 const std::vector<int64_t>& response_ids) override; |
| 81 void DeleteResponses(const GURL& manifest_url, | 84 void DeleteResponses(const GURL& manifest_url, |
| 82 const std::vector<int64>& response_ids) override; | 85 const std::vector<int64_t>& response_ids) override; |
| 83 | 86 |
| 84 private: | 87 private: |
| 85 friend class AppCacheRequestHandlerTest; | 88 friend class AppCacheRequestHandlerTest; |
| 86 friend class AppCacheServiceImplTest; | 89 friend class AppCacheServiceImplTest; |
| 87 friend class AppCacheUpdateJobTest; | 90 friend class AppCacheUpdateJobTest; |
| 88 friend class MockAppCacheStorageTest; | 91 friend class MockAppCacheStorageTest; |
| 89 | 92 |
| 90 typedef base::hash_map<int64, scoped_refptr<AppCache> > StoredCacheMap; | 93 typedef base::hash_map<int64_t, scoped_refptr<AppCache>> StoredCacheMap; |
| 91 typedef std::map<GURL, scoped_refptr<AppCacheGroup> > StoredGroupMap; | 94 typedef std::map<GURL, scoped_refptr<AppCacheGroup> > StoredGroupMap; |
| 92 typedef std::set<int64> DoomedResponseIds; | 95 typedef std::set<int64_t> DoomedResponseIds; |
| 93 typedef std::map<int64, std::pair<base::Time, base::Time>> | 96 typedef std::map<int64_t, std::pair<base::Time, base::Time>> |
| 94 StoredEvictionTimesMap; | 97 StoredEvictionTimesMap; |
| 95 | 98 |
| 96 void ProcessGetAllInfo(scoped_refptr<DelegateReference> delegate_ref); | 99 void ProcessGetAllInfo(scoped_refptr<DelegateReference> delegate_ref); |
| 97 void ProcessLoadCache( | 100 void ProcessLoadCache(int64_t id, |
| 98 int64 id, scoped_refptr<DelegateReference> delegate_ref); | 101 scoped_refptr<DelegateReference> delegate_ref); |
| 99 void ProcessLoadOrCreateGroup( | 102 void ProcessLoadOrCreateGroup( |
| 100 const GURL& manifest_url, scoped_refptr<DelegateReference> delegate_ref); | 103 const GURL& manifest_url, scoped_refptr<DelegateReference> delegate_ref); |
| 101 void ProcessStoreGroupAndNewestCache( | 104 void ProcessStoreGroupAndNewestCache( |
| 102 scoped_refptr<AppCacheGroup> group, scoped_refptr<AppCache> newest_cache, | 105 scoped_refptr<AppCacheGroup> group, scoped_refptr<AppCache> newest_cache, |
| 103 scoped_refptr<DelegateReference> delegate_ref); | 106 scoped_refptr<DelegateReference> delegate_ref); |
| 104 void ProcessMakeGroupObsolete(scoped_refptr<AppCacheGroup> group, | 107 void ProcessMakeGroupObsolete(scoped_refptr<AppCacheGroup> group, |
| 105 scoped_refptr<DelegateReference> delegate_ref, | 108 scoped_refptr<DelegateReference> delegate_ref, |
| 106 int response_code); | 109 int response_code); |
| 107 void ProcessFindResponseForMainRequest( | 110 void ProcessFindResponseForMainRequest( |
| 108 const GURL& url, scoped_refptr<DelegateReference> delegate_ref); | 111 const GURL& url, scoped_refptr<DelegateReference> delegate_ref); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 simulate_make_group_obsolete_failure_ = true; | 152 simulate_make_group_obsolete_failure_ = true; |
| 150 } | 153 } |
| 151 void SimulateStoreGroupAndNewestCacheFailure() { | 154 void SimulateStoreGroupAndNewestCacheFailure() { |
| 152 simulate_store_group_and_newest_cache_failure_ = true; | 155 simulate_store_group_and_newest_cache_failure_ = true; |
| 153 } | 156 } |
| 154 | 157 |
| 155 // Simulate FindResponseFor results for testing. These | 158 // Simulate FindResponseFor results for testing. These |
| 156 // provided values will be return on the next call to | 159 // provided values will be return on the next call to |
| 157 // the corresponding Find method, subsequent calls are | 160 // the corresponding Find method, subsequent calls are |
| 158 // unaffected. | 161 // unaffected. |
| 159 void SimulateFindMainResource( | 162 void SimulateFindMainResource(const AppCacheEntry& entry, |
| 160 const AppCacheEntry& entry, | 163 const GURL& fallback_url, |
| 161 const GURL& fallback_url, | 164 const AppCacheEntry& fallback_entry, |
| 162 const AppCacheEntry& fallback_entry, | 165 int64_t cache_id, |
| 163 int64 cache_id, | 166 int64_t group_id, |
| 164 int64 group_id, | 167 const GURL& manifest_url) { |
| 165 const GURL& manifest_url) { | |
| 166 simulate_find_main_resource_ = true; | 168 simulate_find_main_resource_ = true; |
| 167 simulate_find_sub_resource_ = false; | 169 simulate_find_sub_resource_ = false; |
| 168 simulated_found_entry_ = entry; | 170 simulated_found_entry_ = entry; |
| 169 simulated_found_fallback_url_ = fallback_url; | 171 simulated_found_fallback_url_ = fallback_url; |
| 170 simulated_found_fallback_entry_ = fallback_entry; | 172 simulated_found_fallback_entry_ = fallback_entry; |
| 171 simulated_found_cache_id_ = cache_id; | 173 simulated_found_cache_id_ = cache_id; |
| 172 simulated_found_group_id_ = group_id; | 174 simulated_found_group_id_ = group_id; |
| 173 simulated_found_manifest_url_ = manifest_url, | 175 simulated_found_manifest_url_ = manifest_url, |
| 174 simulated_found_network_namespace_ = false; // N/A to main resource loads | 176 simulated_found_network_namespace_ = false; // N/A to main resource loads |
| 175 } | 177 } |
| (...skipping 26 matching lines...) Expand all Loading... |
| 202 scoped_ptr<AppCacheDiskCache> disk_cache_; | 204 scoped_ptr<AppCacheDiskCache> disk_cache_; |
| 203 std::deque<base::Closure> pending_tasks_; | 205 std::deque<base::Closure> pending_tasks_; |
| 204 | 206 |
| 205 bool simulate_make_group_obsolete_failure_; | 207 bool simulate_make_group_obsolete_failure_; |
| 206 bool simulate_store_group_and_newest_cache_failure_; | 208 bool simulate_store_group_and_newest_cache_failure_; |
| 207 | 209 |
| 208 bool simulate_find_main_resource_; | 210 bool simulate_find_main_resource_; |
| 209 bool simulate_find_sub_resource_; | 211 bool simulate_find_sub_resource_; |
| 210 AppCacheEntry simulated_found_entry_; | 212 AppCacheEntry simulated_found_entry_; |
| 211 AppCacheEntry simulated_found_fallback_entry_; | 213 AppCacheEntry simulated_found_fallback_entry_; |
| 212 int64 simulated_found_cache_id_; | 214 int64_t simulated_found_cache_id_; |
| 213 int64 simulated_found_group_id_; | 215 int64_t simulated_found_group_id_; |
| 214 GURL simulated_found_fallback_url_; | 216 GURL simulated_found_fallback_url_; |
| 215 GURL simulated_found_manifest_url_; | 217 GURL simulated_found_manifest_url_; |
| 216 bool simulated_found_network_namespace_; | 218 bool simulated_found_network_namespace_; |
| 217 scoped_refptr<AppCacheInfoCollection> simulated_appcache_info_; | 219 scoped_refptr<AppCacheInfoCollection> simulated_appcache_info_; |
| 218 scoped_ptr<AppCacheResponseReader> simulated_reader_; | 220 scoped_ptr<AppCacheResponseReader> simulated_reader_; |
| 219 | 221 |
| 220 base::WeakPtrFactory<MockAppCacheStorage> weak_factory_; | 222 base::WeakPtrFactory<MockAppCacheStorage> weak_factory_; |
| 221 | 223 |
| 222 FRIEND_TEST_ALL_PREFIXES(MockAppCacheStorageTest, | 224 FRIEND_TEST_ALL_PREFIXES(MockAppCacheStorageTest, |
| 223 BasicFindMainResponse); | 225 BasicFindMainResponse); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 239 StoreExistingGroupExistingCache); | 241 StoreExistingGroupExistingCache); |
| 240 FRIEND_TEST_ALL_PREFIXES(AppCacheServiceImplTest, | 242 FRIEND_TEST_ALL_PREFIXES(AppCacheServiceImplTest, |
| 241 DeleteAppCachesForOrigin); | 243 DeleteAppCachesForOrigin); |
| 242 | 244 |
| 243 DISALLOW_COPY_AND_ASSIGN(MockAppCacheStorage); | 245 DISALLOW_COPY_AND_ASSIGN(MockAppCacheStorage); |
| 244 }; | 246 }; |
| 245 | 247 |
| 246 } // namespace content | 248 } // namespace content |
| 247 | 249 |
| 248 #endif // CONTENT_BROWSER_APPCACHE_MOCK_APPCACHE_STORAGE_H_ | 250 #endif // CONTENT_BROWSER_APPCACHE_MOCK_APPCACHE_STORAGE_H_ |
| OLD | NEW |