| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CONTENT_PUBLIC_TEST_MOCK_STORAGE_CLIENT_H_ | |
| 6 #define CONTENT_PUBLIC_TEST_MOCK_STORAGE_CLIENT_H_ | |
| 7 | |
| 8 #include <stddef.h> | |
| 9 #include <stdint.h> | |
| 10 | |
| 11 #include <map> | |
| 12 #include <set> | |
| 13 #include <string> | |
| 14 #include <utility> | |
| 15 | |
| 16 #include "base/compiler_specific.h" | |
| 17 #include "base/macros.h" | |
| 18 #include "base/memory/weak_ptr.h" | |
| 19 #include "base/time/time.h" | |
| 20 #include "storage/browser/quota/quota_client.h" | |
| 21 #include "url/gurl.h" | |
| 22 | |
| 23 namespace storage { | |
| 24 class QuotaManagerProxy; | |
| 25 } | |
| 26 | |
| 27 using storage::QuotaClient; | |
| 28 using storage::QuotaManagerProxy; | |
| 29 using storage::StorageType; | |
| 30 | |
| 31 namespace content { | |
| 32 | |
| 33 struct MockOriginData { | |
| 34 const char* origin; | |
| 35 StorageType type; | |
| 36 int64_t usage; | |
| 37 }; | |
| 38 | |
| 39 // Mock storage class for testing. | |
| 40 class MockStorageClient : public QuotaClient { | |
| 41 public: | |
| 42 MockStorageClient(QuotaManagerProxy* quota_manager_proxy, | |
| 43 const MockOriginData* mock_data, | |
| 44 QuotaClient::ID id, | |
| 45 size_t mock_data_size); | |
| 46 ~MockStorageClient() override; | |
| 47 | |
| 48 // To add or modify mock data in this client. | |
| 49 void AddOriginAndNotify(const GURL& origin_url, | |
| 50 StorageType type, | |
| 51 int64_t size); | |
| 52 void ModifyOriginAndNotify(const GURL& origin_url, | |
| 53 StorageType type, | |
| 54 int64_t delta); | |
| 55 void TouchAllOriginsAndNotify(); | |
| 56 | |
| 57 void AddOriginToErrorSet(const GURL& origin_url, StorageType type); | |
| 58 | |
| 59 base::Time IncrementMockTime(); | |
| 60 | |
| 61 // QuotaClient methods. | |
| 62 QuotaClient::ID id() const override; | |
| 63 void OnQuotaManagerDestroyed() override; | |
| 64 void GetOriginUsage(const GURL& origin_url, | |
| 65 StorageType type, | |
| 66 const GetUsageCallback& callback) override; | |
| 67 void GetOriginsForType(StorageType type, | |
| 68 const GetOriginsCallback& callback) override; | |
| 69 void GetOriginsForHost(StorageType type, | |
| 70 const std::string& host, | |
| 71 const GetOriginsCallback& callback) override; | |
| 72 void DeleteOriginData(const GURL& origin, | |
| 73 StorageType type, | |
| 74 const DeletionCallback& callback) override; | |
| 75 bool DoesSupport(storage::StorageType type) const override; | |
| 76 | |
| 77 private: | |
| 78 void RunGetOriginUsage(const GURL& origin_url, | |
| 79 StorageType type, | |
| 80 const GetUsageCallback& callback); | |
| 81 void RunGetOriginsForType(StorageType type, | |
| 82 const GetOriginsCallback& callback); | |
| 83 void RunGetOriginsForHost(StorageType type, | |
| 84 const std::string& host, | |
| 85 const GetOriginsCallback& callback); | |
| 86 void RunDeleteOriginData(const GURL& origin_url, | |
| 87 StorageType type, | |
| 88 const DeletionCallback& callback); | |
| 89 | |
| 90 void Populate(const MockOriginData* mock_data, size_t mock_data_size); | |
| 91 | |
| 92 scoped_refptr<QuotaManagerProxy> quota_manager_proxy_; | |
| 93 const ID id_; | |
| 94 | |
| 95 typedef std::map<std::pair<GURL, StorageType>, int64_t> OriginDataMap; | |
| 96 OriginDataMap origin_data_; | |
| 97 typedef std::set<std::pair<GURL, StorageType> > ErrorOriginSet; | |
| 98 ErrorOriginSet error_origins_; | |
| 99 | |
| 100 int mock_time_counter_; | |
| 101 | |
| 102 base::WeakPtrFactory<MockStorageClient> weak_factory_; | |
| 103 | |
| 104 DISALLOW_COPY_AND_ASSIGN(MockStorageClient); | |
| 105 }; | |
| 106 | |
| 107 } // namespace content | |
| 108 | |
| 109 #endif // CONTENT_PUBLIC_TEST_MOCK_STORAGE_CLIENT_H_ | |
| OLD | NEW |