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"
17 #include "webkit/browser/quota/quota_client.h"
20 class QuotaManagerProxy
;
23 using quota::QuotaClient
;
24 using quota::QuotaManagerProxy
;
25 using quota::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 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
,
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
,
67 const DeletionCallback
& callback
) OVERRIDE
;
68 virtual bool DoesSupport(quota::StorageType type
) const OVERRIDE
;
71 void RunGetOriginUsage(const GURL
& origin_url
,
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
,
81 const DeletionCallback
& callback
);
83 void Populate(const MockOriginData
* mock_data
, size_t mock_data_size
);
85 scoped_refptr
<QuotaManagerProxy
> quota_manager_proxy_
;
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_