Home | History | Annotate | Download | only in quota
      1 // Copyright 2013 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 WEBKIT_BROWSER_QUOTA_MOCK_SPECIAL_STORAGE_POLICY_H_
      6 #define WEBKIT_BROWSER_QUOTA_MOCK_SPECIAL_STORAGE_POLICY_H_
      7 
      8 #include <set>
      9 #include <string>
     10 
     11 #include "url/gurl.h"
     12 #include "webkit/browser/quota/special_storage_policy.h"
     13 
     14 namespace quota {
     15 
     16 class MockSpecialStoragePolicy : public quota::SpecialStoragePolicy {
     17  public:
     18   MockSpecialStoragePolicy();
     19 
     20   virtual bool IsStorageProtected(const GURL& origin) OVERRIDE;
     21   virtual bool IsStorageUnlimited(const GURL& origin) OVERRIDE;
     22   virtual bool IsStorageSessionOnly(const GURL& origin) OVERRIDE;
     23   virtual bool CanQueryDiskSize(const GURL& origin) OVERRIDE;
     24   virtual bool IsFileHandler(const std::string& extension_id) OVERRIDE;
     25   virtual bool HasIsolatedStorage(const GURL& origin) OVERRIDE;
     26   virtual bool HasSessionOnlyOrigins() OVERRIDE;
     27 
     28   void AddProtected(const GURL& origin) {
     29     protected_.insert(origin);
     30   }
     31 
     32   void AddUnlimited(const GURL& origin) {
     33     unlimited_.insert(origin);
     34   }
     35 
     36   void RemoveUnlimited(const GURL& origin) {
     37     unlimited_.erase(origin);
     38   }
     39 
     40   void AddSessionOnly(const GURL& origin) {
     41     session_only_.insert(origin);
     42   }
     43 
     44   void GrantQueryDiskSize(const GURL& origin) {
     45     can_query_disk_size_.insert(origin);
     46   }
     47 
     48   void AddFileHandler(const std::string& id) {
     49     file_handlers_.insert(id);
     50   }
     51 
     52   void AddIsolated(const GURL& origin) {
     53     isolated_.insert(origin);
     54   }
     55 
     56   void RemoveIsolated(const GURL& origin) {
     57     isolated_.erase(origin);
     58   }
     59 
     60   void SetAllUnlimited(bool all_unlimited) {
     61     all_unlimited_ = all_unlimited;
     62   }
     63 
     64   void Reset() {
     65     protected_.clear();
     66     unlimited_.clear();
     67     session_only_.clear();
     68     can_query_disk_size_.clear();
     69     file_handlers_.clear();
     70     isolated_.clear();
     71     all_unlimited_ = false;
     72   }
     73 
     74   void NotifyGranted(const GURL& origin, int change_flags) {
     75     SpecialStoragePolicy::NotifyGranted(origin, change_flags);
     76   }
     77 
     78   void NotifyRevoked(const GURL& origin, int change_flags) {
     79     SpecialStoragePolicy::NotifyRevoked(origin, change_flags);
     80   }
     81 
     82   void NotifyCleared() {
     83     SpecialStoragePolicy::NotifyCleared();
     84   }
     85 
     86  protected:
     87   virtual ~MockSpecialStoragePolicy();
     88 
     89  private:
     90   std::set<GURL> protected_;
     91   std::set<GURL> unlimited_;
     92   std::set<GURL> session_only_;
     93   std::set<GURL> can_query_disk_size_;
     94   std::set<GURL> isolated_;
     95   std::set<std::string> file_handlers_;
     96 
     97   bool all_unlimited_;
     98 };
     99 }  // namespace quota
    100 
    101 #endif  // WEBKIT_BROWSER_QUOTA_MOCK_SPECIAL_STORAGE_POLICY_H_
    102