Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(502)

Unified Diff: webkit/quota/mock_quota_manager.h

Issue 10915202: Cleanup: merge MockQuotaManager in multiple places (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: webkit/quota/mock_quota_manager.h
diff --git a/webkit/quota/mock_quota_manager.h b/webkit/quota/mock_quota_manager.h
index ead5c35407cda00d04d9b5e327db554782bac6d7..b52ac2fe80b4b11574568971e3270535bcb848fe 100644
--- a/webkit/quota/mock_quota_manager.h
+++ b/webkit/quota/mock_quota_manager.h
@@ -17,50 +17,33 @@
namespace quota {
-// Mocks the pieces of QuotaManager's interface that are used for time-based
-// deletion of a profile's browsing data. Origins can be added to the mock by
-// calling AddOrigin, and that list of origins is then searched through in
-// GetOriginsModifiedSince. Neither GetOriginsModifiedSince nor DeleteOriginData
-// touches the actual origin data stored in the profile.
+// Mocks the pieces of QuotaManager's interface.
+//
+// For usage/quota tracking test:
+// Usage and quota information can be updated by following private helper
+// methods: SetQuota() and UpdateUsage().
+//
+// For time-based deletion test:
+// Origins can be added to the mock by calling AddOrigin, and that list of
+// origins is then searched through in GetOriginsModifiedSince.
+// Neither GetOriginsModifiedSince nor DeleteOriginData touches the actual
+// origin data stored in the profile.
class MockQuotaManager : public QuotaManager {
public:
- // Contains the essential bits of information about an origin that the
- // MockQuotaManager needs to understand: the origin itself, the StorageType,
- // and its modification time.
- struct OriginInfo {
- OriginInfo(const GURL& origin,
- StorageType type,
- int quota_client_mask,
- base::Time modified);
- ~OriginInfo();
-
- GURL origin;
- StorageType type;
- int quota_client_mask;
- base::Time modified;
- };
-
MockQuotaManager(bool is_incognito,
const FilePath& profile_path,
base::SingleThreadTaskRunner* io_thread,
base::SequencedTaskRunner* db_thread,
SpecialStoragePolicy* special_storage_policy);
- // Adds an origin to the canned list that will be searched through via
- // GetOriginsModifiedSince. The caller must provide |quota_client_mask|
- // which specifies the types of QuotaClients this canned origin contains
- // as a bitmask built from QuotaClient::IDs.
- bool AddOrigin(const GURL& origin,
- StorageType type,
- int quota_client_mask,
- base::Time modified);
-
- // Checks an origin and type against the origins that have been added via
- // AddOrigin and removed via DeleteOriginData. If the origin exists in the
- // canned list with the proper StorageType and client, returns true.
- bool OriginHasData(const GURL& origin,
- StorageType type,
- QuotaClient::ID quota_client) const;
+ // Overrides QuotaManager's implementation. The internal usage data is
+ // updated when MockQuotaManagerProxy::NotifyStorageModified() is
+ // called. The internal quota value can be updated by calling
+ // a helper method MockQuotaManagerProxy::SetQuota().
+ virtual void GetUsageAndQuota(
+ const GURL& origin,
+ quota::StorageType type,
+ const GetUsageAndQuotaCallback& callback) OVERRIDE;
// Overrides QuotaManager's implementation with a canned implementation that
// allows clients to set up the origin database that should be queried. This
@@ -81,19 +64,132 @@ class MockQuotaManager : public QuotaManager {
int quota_client_mask,
const StatusCallback& callback) OVERRIDE;
+ // Helper method for updating internal quota info.
+ void SetQuota(const GURL& origin, StorageType type, int64 quota);
+
+ // Helper methods for timed-deletion testing:
+ // Adds an origin to the canned list that will be searched through via
+ // GetOriginsModifiedSince. The caller must provide |quota_client_mask|
+ // which specifies the types of QuotaClients this canned origin contains
+ // as a bitmask built from QuotaClient::IDs.
+ bool AddOrigin(const GURL& origin,
+ StorageType type,
+ int quota_client_mask,
+ base::Time modified);
+
+ // Helper methods for timed-deletion testing:
+ // Checks an origin and type against the origins that have been added via
+ // AddOrigin and removed via DeleteOriginData. If the origin exists in the
+ // canned list with the proper StorageType and client, returns true.
+ bool OriginHasData(const GURL& origin,
+ StorageType type,
+ QuotaClient::ID quota_client) const;
+
protected:
virtual ~MockQuotaManager();
private:
+ friend class MockQuotaManagerProxy;
+
+ // Contains the essential bits of information about an origin that the
+ // MockQuotaManager needs to understand for time-based deletion:
+ // the origin itself, the StorageType and its modification time.
+ struct OriginInfo {
+ OriginInfo(const GURL& origin,
+ StorageType type,
+ int quota_client_mask,
+ base::Time modified);
+ ~OriginInfo();
+
+ GURL origin;
+ StorageType type;
+ int quota_client_mask;
+ base::Time modified;
+ };
+
+ // Contains the essential information for each origin for usage/quota testing.
+ // (Ideally this should probably merged into the above struct, but for
+ // regular usage/quota testing we hardly need modified time but only
+ // want to keep usage and quota information, so this struct exists.
+ struct StorageInfo {
+ StorageInfo();
+ ~StorageInfo();
+ int64 usage;
+ int64 quota;
+ };
+
+ typedef std::pair<GURL, StorageType> OriginAndType;
+ typedef std::map<OriginAndType, StorageInfo> UsageAndQuotaMap;
+
class GetModifiedSinceTask;
class DeleteOriginDataTask;
+ // This must be called via MockQuotaManagerProxy.
+ void UpdateUsage(const GURL& origin, StorageType type, int64 delta);
+
// The list of stored origins that have been added via AddOrigin.
std::vector<OriginInfo> origins_;
+ UsageAndQuotaMap usage_and_quota_map_;
+
DISALLOW_COPY_AND_ASSIGN(MockQuotaManager);
};
+// MockQuotaManagerProxy.
+class MockQuotaManagerProxy : public QuotaManagerProxy {
+ public:
+ // It is ok to give NULL to |quota_manager|.
+ MockQuotaManagerProxy(MockQuotaManager* quota_manager,
+ base::SingleThreadTaskRunner* task_runner);
+
+ virtual void RegisterClient(QuotaClient* client) OVERRIDE;
+
+ void SimulateQuotaManagerDestroyed();
+
+ // We don't mock them.
+ virtual void NotifyOriginInUse(const GURL& origin) OVERRIDE {}
+ virtual void NotifyOriginNoLongerInUse(const GURL& origin) OVERRIDE {}
+
+ // Validates the |client_id| and updates the internal access count
+ // which can be accessed via notify_storage_accessed_count().
+ // The also records the |origin| and |type| in last_notified_origin_ and
+ // last_notified_type_.
+ virtual void NotifyStorageAccessed(QuotaClient::ID client_id,
+ const GURL& origin,
+ StorageType type) OVERRIDE;
+
+ // Records the |origin|, |type| and |delta| as last_notified_origin_,
+ // last_notified_type_ and last_notified_delta_ respecitvely.
+ // If non-null MockQuotaManager is given to the constructor this also
+ // updates the manager's internal usage information.
+ virtual void NotifyStorageModified(QuotaClient::ID client_id,
+ const GURL& origin,
+ StorageType type,
+ int64 delta) OVERRIDE;
+
+ int notify_storage_accessed_count() const { return storage_accessed_count_; }
+ int notify_storage_modified_count() const { return storage_modified_count_; }
+ GURL last_notified_origin() const { return last_notified_origin_; }
+ StorageType last_notified_type() const { return last_notified_type_; }
+ int64 last_notified_delta() const { return last_notified_delta_; }
+
+ protected:
+ virtual ~MockQuotaManagerProxy();
+
+ private:
+ MockQuotaManager* mock_manager() const {
+ return static_cast<MockQuotaManager*>(quota_manager());
+ }
+
+ int storage_accessed_count_;
+ int storage_modified_count_;
+ GURL last_notified_origin_;
+ StorageType last_notified_type_;
+ int64 last_notified_delta_;
+
+ QuotaClient* registered_client_;
+};
+
} // namespace quota
#endif // WEBKIT_QUOTA_MOCK_QUOTA_MANAGER_H_

Powered by Google App Engine
This is Rietveld 408576698