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