1 // Copyright (c) 2012 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 WEBKIT_QUOTA_MOCK_STORAGE_CLIENT_H_
6 #define WEBKIT_QUOTA_MOCK_STORAGE_CLIENT_H_
13 #include "base/compiler_specific.h"
14 #include "base/memory/weak_ptr.h"
15 #include "base/time.h"
16 #include "googleurl/src/gurl.h"
17 #include "webkit/quota/quota_client.h"
21 class QuotaManagerProxy
;
23 struct MockOriginData
{
29 // Mock storage class for testing.
30 class MockStorageClient
: public QuotaClient
{
32 MockStorageClient(QuotaManagerProxy
* quota_manager_proxy
,
33 const MockOriginData
* mock_data
,
35 size_t mock_data_size
);
36 virtual ~MockStorageClient();
38 // To add or modify mock data in this client.
39 void AddOriginAndNotify(
40 const GURL
& origin_url
, StorageType type
, int64 size
);
41 void ModifyOriginAndNotify(
42 const GURL
& origin_url
, StorageType type
, int64 delta
);
43 void TouchAllOriginsAndNotify();
45 void AddOriginToErrorSet(const GURL
& origin_url
, StorageType type
);
47 base::Time
IncrementMockTime();
49 // QuotaClient methods.
50 virtual QuotaClient::ID
id() const OVERRIDE
;
51 virtual void OnQuotaManagerDestroyed() OVERRIDE
;
52 virtual void GetOriginUsage(const GURL
& origin_url
,
54 const GetUsageCallback
& callback
) OVERRIDE
;
55 virtual void GetOriginsForType(StorageType type
,
56 const GetOriginsCallback
& callback
) OVERRIDE
;
57 virtual void GetOriginsForHost(StorageType type
, const std::string
& host
,
58 const GetOriginsCallback
& callback
) OVERRIDE
;
59 virtual void DeleteOriginData(const GURL
& origin
,
61 const DeletionCallback
& callback
) OVERRIDE
;
64 void RunGetOriginUsage(const GURL
& origin_url
,
66 const GetUsageCallback
& callback
);
67 void RunGetOriginsForType(StorageType type
,
68 const GetOriginsCallback
& callback
);
69 void RunGetOriginsForHost(StorageType type
,
70 const std::string
& host
,
71 const GetOriginsCallback
& callback
);
72 void RunDeleteOriginData(const GURL
& origin_url
,
74 const DeletionCallback
& callback
);
76 void Populate(const MockOriginData
* mock_data
, size_t mock_data_size
);
78 scoped_refptr
<QuotaManagerProxy
> quota_manager_proxy_
;
81 typedef std::map
<std::pair
<GURL
, StorageType
>, int64
> OriginDataMap
;
82 OriginDataMap origin_data_
;
83 typedef std::set
<std::pair
<GURL
, StorageType
> > ErrorOriginSet
;
84 ErrorOriginSet error_origins_
;
86 int mock_time_counter_
;
88 base::WeakPtrFactory
<MockStorageClient
> weak_factory_
;
90 DISALLOW_COPY_AND_ASSIGN(MockStorageClient
);
95 #endif // WEBKIT_QUOTA_MOCK_STORAGE_CLIENT_H_