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.
4 
5 #ifndef STORAGE_BROWSER_TEST_MOCK_QUOTA_MANAGER_PROXY_H_
6 #define STORAGE_BROWSER_TEST_MOCK_QUOTA_MANAGER_PROXY_H_
7 
8 #include <stdint.h>
9 
10 #include "base/macros.h"
11 #include "storage/browser/quota/quota_client.h"
12 #include "storage/browser/quota/quota_client_type.h"
13 #include "storage/browser/quota/quota_manager_proxy.h"
14 #include "storage/browser/test/mock_quota_manager.h"
15 #include "third_party/blink/public/mojom/quota/quota_types.mojom.h"
16 #include "url/gurl.h"
17 
18 namespace storage {
19 
20 class MockQuotaManager;
21 enum class QuotaClientType;
22 
23 class MockQuotaManagerProxy : public QuotaManagerProxy {
24  public:
25   // It is ok to give nullptr to |quota_manager|.
26   MockQuotaManagerProxy(MockQuotaManager* quota_manager,
27                         base::SingleThreadTaskRunner* task_runner);
28 
29   void RegisterClient(
30       scoped_refptr<QuotaClient> client,
31       QuotaClientType client_type,
32       const std::vector<blink::mojom::StorageType>& storage_types) override;
33 
34   virtual void SimulateQuotaManagerDestroyed();
35 
36   // We don't mock them.
NotifyOriginInUse(const url::Origin & origin)37   void NotifyOriginInUse(const url::Origin& origin) override {}
NotifyOriginNoLongerInUse(const url::Origin & origin)38   void NotifyOriginNoLongerInUse(const url::Origin& origin) override {}
SetUsageCacheEnabled(storage::QuotaClientType client_id,const url::Origin & origin,blink::mojom::StorageType type,bool enabled)39   void SetUsageCacheEnabled(storage::QuotaClientType client_id,
40                             const url::Origin& origin,
41                             blink::mojom::StorageType type,
42                             bool enabled) override {}
43   void GetUsageAndQuota(base::SequencedTaskRunner* original_task_runner,
44                         const url::Origin& origin,
45                         blink::mojom::StorageType type,
46                         QuotaManager::UsageAndQuotaCallback callback) override;
47 
48   // Validates the |client_id| and updates the internal access count
49   // which can be accessed via notify_storage_accessed_count().
50   // The also records the |origin| and |type| in last_notified_origin_ and
51   // last_notified_type_.
52   void NotifyStorageAccessed(const url::Origin& origin,
53                              blink::mojom::StorageType type) override;
54 
55   // Records the |origin|, |type| and |delta| as last_notified_origin_,
56   // last_notified_type_ and last_notified_delta_ respecitvely.
57   // If non-null MockQuotaManager is given to the constructor this also
58   // updates the manager's internal usage information.
59   void NotifyStorageModified(storage::QuotaClientType client_id,
60                              const url::Origin& origin,
61                              blink::mojom::StorageType type,
62                              int64_t delta) override;
63 
notify_storage_accessed_count()64   int notify_storage_accessed_count() const { return storage_accessed_count_; }
notify_storage_modified_count()65   int notify_storage_modified_count() const { return storage_modified_count_; }
last_notified_origin()66   url::Origin last_notified_origin() const { return last_notified_origin_; }
last_notified_type()67   blink::mojom::StorageType last_notified_type() const {
68     return last_notified_type_;
69   }
last_notified_delta()70   int64_t last_notified_delta() const { return last_notified_delta_; }
71 
72  protected:
73   ~MockQuotaManagerProxy() override;
74 
75  private:
mock_manager()76   MockQuotaManager* mock_manager() const {
77     return static_cast<MockQuotaManager*>(quota_manager());
78   }
79 
80   int storage_accessed_count_;
81   int storage_modified_count_;
82   url::Origin last_notified_origin_;
83   blink::mojom::StorageType last_notified_type_;
84   int64_t last_notified_delta_;
85 
86   scoped_refptr<QuotaClient> registered_client_;
87 
88   DISALLOW_COPY_AND_ASSIGN(MockQuotaManagerProxy);
89 };
90 
91 }  // namespace storage
92 
93 #endif  // STORAGE_BROWSER_TEST_MOCK_QUOTA_MANAGER_PROXY_H_
94