Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / content / public / test / mock_storage_client.h
blobd54626df0c5b44163b0fad0498d8a8f2354cbe08
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 "url/gurl.h"
17 #include "webkit/browser/quota/quota_client.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 virtual ~MockStorageClient();
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 virtual QuotaClient::ID id() const OVERRIDE;
57 virtual void OnQuotaManagerDestroyed() OVERRIDE;
58 virtual void GetOriginUsage(const GURL& origin_url,
59 StorageType type,
60 const GetUsageCallback& callback) OVERRIDE;
61 virtual void GetOriginsForType(StorageType type,
62 const GetOriginsCallback& callback) OVERRIDE;
63 virtual void GetOriginsForHost(StorageType type, const std::string& host,
64 const GetOriginsCallback& callback) OVERRIDE;
65 virtual void DeleteOriginData(const GURL& origin,
66 StorageType type,
67 const DeletionCallback& callback) OVERRIDE;
68 virtual bool DoesSupport(storage::StorageType type) const OVERRIDE;
70 private:
71 void RunGetOriginUsage(const GURL& origin_url,
72 StorageType type,
73 const GetUsageCallback& callback);
74 void RunGetOriginsForType(StorageType type,
75 const GetOriginsCallback& callback);
76 void RunGetOriginsForHost(StorageType type,
77 const std::string& host,
78 const GetOriginsCallback& callback);
79 void RunDeleteOriginData(const GURL& origin_url,
80 StorageType type,
81 const DeletionCallback& callback);
83 void Populate(const MockOriginData* mock_data, size_t mock_data_size);
85 scoped_refptr<QuotaManagerProxy> quota_manager_proxy_;
86 const ID id_;
88 typedef std::map<std::pair<GURL, StorageType>, int64> OriginDataMap;
89 OriginDataMap origin_data_;
90 typedef std::set<std::pair<GURL, StorageType> > ErrorOriginSet;
91 ErrorOriginSet error_origins_;
93 int mock_time_counter_;
95 base::WeakPtrFactory<MockStorageClient> weak_factory_;
97 DISALLOW_COPY_AND_ASSIGN(MockStorageClient);
100 } // namespace content
102 #endif // CONTENT_PUBLIC_TEST_MOCK_STORAGE_CLIENT_H_