Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / content / public / test / mock_storage_client.h
blob09ac94b68afebc613e0f5e8d0e69c8ad0d1266cb
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.
5 #ifndef CONTENT_PUBLIC_TEST_MOCK_STORAGE_CLIENT_H_
6 #define CONTENT_PUBLIC_TEST_MOCK_STORAGE_CLIENT_H_
8 #include <map>
9 #include <set>
10 #include <string>
11 #include <utility>
13 #include "base/compiler_specific.h"
14 #include "base/memory/weak_ptr.h"
15 #include "base/time/time.h"
16 #include "storage/browser/quota/quota_client.h"
17 #include "url/gurl.h"
19 namespace storage {
20 class QuotaManagerProxy;
23 using storage::QuotaClient;
24 using storage::QuotaManagerProxy;
25 using storage::StorageType;
27 namespace content {
29 struct MockOriginData {
30 const char* origin;
31 StorageType type;
32 int64 usage;
35 // Mock storage class for testing.
36 class MockStorageClient : public QuotaClient {
37 public:
38 MockStorageClient(QuotaManagerProxy* quota_manager_proxy,
39 const MockOriginData* mock_data,
40 QuotaClient::ID id,
41 size_t mock_data_size);
42 ~MockStorageClient() override;
44 // To add or modify mock data in this client.
45 void AddOriginAndNotify(
46 const GURL& origin_url, StorageType type, int64 size);
47 void ModifyOriginAndNotify(
48 const GURL& origin_url, StorageType type, int64 delta);
49 void TouchAllOriginsAndNotify();
51 void AddOriginToErrorSet(const GURL& origin_url, StorageType type);
53 base::Time IncrementMockTime();
55 // QuotaClient methods.
56 QuotaClient::ID id() const override;
57 void OnQuotaManagerDestroyed() override;
58 void GetOriginUsage(const GURL& origin_url,
59 StorageType type,
60 const GetUsageCallback& callback) override;
61 void GetOriginsForType(StorageType type,
62 const GetOriginsCallback& callback) override;
63 void GetOriginsForHost(StorageType type,
64 const std::string& host,
65 const GetOriginsCallback& callback) override;
66 void DeleteOriginData(const GURL& origin,
67 StorageType type,
68 const DeletionCallback& callback) override;
69 bool DoesSupport(storage::StorageType type) const override;
71 private:
72 void RunGetOriginUsage(const GURL& origin_url,
73 StorageType type,
74 const GetUsageCallback& callback);
75 void RunGetOriginsForType(StorageType type,
76 const GetOriginsCallback& callback);
77 void RunGetOriginsForHost(StorageType type,
78 const std::string& host,
79 const GetOriginsCallback& callback);
80 void RunDeleteOriginData(const GURL& origin_url,
81 StorageType type,
82 const DeletionCallback& callback);
84 void Populate(const MockOriginData* mock_data, size_t mock_data_size);
86 scoped_refptr<QuotaManagerProxy> quota_manager_proxy_;
87 const ID id_;
89 typedef std::map<std::pair<GURL, StorageType>, int64> OriginDataMap;
90 OriginDataMap origin_data_;
91 typedef std::set<std::pair<GURL, StorageType> > ErrorOriginSet;
92 ErrorOriginSet error_origins_;
94 int mock_time_counter_;
96 base::WeakPtrFactory<MockStorageClient> weak_factory_;
98 DISALLOW_COPY_AND_ASSIGN(MockStorageClient);
101 } // namespace content
103 #endif // CONTENT_PUBLIC_TEST_MOCK_STORAGE_CLIENT_H_