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_
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"
20 class QuotaManagerProxy
;
23 using storage::QuotaClient
;
24 using storage::QuotaManagerProxy
;
25 using storage::StorageType
;
29 struct MockOriginData
{
35 // Mock storage class for testing.
36 class MockStorageClient
: public QuotaClient
{
38 MockStorageClient(QuotaManagerProxy
* quota_manager_proxy
,
39 const MockOriginData
* mock_data
,
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
,
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
,
68 const DeletionCallback
& callback
) override
;
69 bool DoesSupport(storage::StorageType type
) const override
;
72 void RunGetOriginUsage(const GURL
& origin_url
,
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
,
82 const DeletionCallback
& callback
);
84 void Populate(const MockOriginData
* mock_data
, size_t mock_data_size
);
86 scoped_refptr
<QuotaManagerProxy
> quota_manager_proxy_
;
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_