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_SPECIAL_STORAGE_POLICY_H_
6 #define STORAGE_BROWSER_TEST_MOCK_SPECIAL_STORAGE_POLICY_H_
7 
8 #include <set>
9 #include <string>
10 
11 #include "services/network/public/cpp/session_cookie_delete_predicate.h"
12 #include "storage/browser/quota/special_storage_policy.h"
13 #include "url/gurl.h"
14 
15 namespace storage {
16 
17 class MockSpecialStoragePolicy : public SpecialStoragePolicy {
18  public:
19   MockSpecialStoragePolicy();
20 
21   bool IsStorageProtected(const GURL& origin) override;
22   bool IsStorageUnlimited(const GURL& origin) override;
23   bool IsStorageSessionOnly(const GURL& origin) override;
24   bool HasIsolatedStorage(const GURL& origin) override;
25   bool HasSessionOnlyOrigins() override;
26   bool IsStorageDurable(const GURL& origin) override;
27   network::DeleteCookiePredicate CreateDeleteCookieOnExitPredicate() override;
28 
AddProtected(const GURL & origin)29   void AddProtected(const GURL& origin) { protected_.insert(origin); }
30 
AddUnlimited(const GURL & origin)31   void AddUnlimited(const GURL& origin) { unlimited_.insert(origin); }
32 
RemoveUnlimited(const GURL & origin)33   void RemoveUnlimited(const GURL& origin) { unlimited_.erase(origin); }
34 
AddSessionOnly(const GURL & origin)35   void AddSessionOnly(const GURL& origin) { session_only_.insert(origin); }
36 
AddIsolated(const GURL & origin)37   void AddIsolated(const GURL& origin) { isolated_.insert(origin); }
38 
RemoveIsolated(const GURL & origin)39   void RemoveIsolated(const GURL& origin) { isolated_.erase(origin); }
40 
SetAllUnlimited(bool all_unlimited)41   void SetAllUnlimited(bool all_unlimited) { all_unlimited_ = all_unlimited; }
42 
AddDurable(const GURL & origin)43   void AddDurable(const GURL& origin) { durable_.insert(origin); }
44 
Reset()45   void Reset() {
46     protected_.clear();
47     unlimited_.clear();
48     session_only_.clear();
49     file_handlers_.clear();
50     isolated_.clear();
51     all_unlimited_ = false;
52   }
53 
NotifyGranted(const url::Origin & origin,int change_flags)54   void NotifyGranted(const url::Origin& origin, int change_flags) {
55     SpecialStoragePolicy::NotifyGranted(origin, change_flags);
56   }
57 
NotifyRevoked(const url::Origin & origin,int change_flags)58   void NotifyRevoked(const url::Origin& origin, int change_flags) {
59     SpecialStoragePolicy::NotifyRevoked(origin, change_flags);
60   }
61 
NotifyCleared()62   void NotifyCleared() { SpecialStoragePolicy::NotifyCleared(); }
63 
NotifyPolicyChanged()64   void NotifyPolicyChanged() { SpecialStoragePolicy::NotifyPolicyChanged(); }
65 
66  protected:
67   ~MockSpecialStoragePolicy() override;
68 
69  private:
70   bool ShouldDeleteCookieOnExit(const std::string& domain, bool is_https);
71 
72   std::set<GURL> protected_;
73   std::set<GURL> unlimited_;
74   std::set<GURL> session_only_;
75   std::set<GURL> isolated_;
76   std::set<GURL> durable_;
77   std::set<std::string> file_handlers_;
78 
79   bool all_unlimited_;
80 };
81 
82 }  // namespace storage
83 
84 #endif  // STORAGE_BROWSER_TEST_MOCK_SPECIAL_STORAGE_POLICY_H_
85