summaryrefslogtreecommitdiffstats
path: root/content/public/test/mock_special_storage_policy.h
blob: 96003e8c12f8517c457927e9a288645d3e918738 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CONTENT_PUBLIC_TEST_MOCK_SPECIAL_STORAGE_POLICY_H_
#define CONTENT_PUBLIC_TEST_MOCK_SPECIAL_STORAGE_POLICY_H_

#include <set>
#include <string>

#include "storage/browser/quota/special_storage_policy.h"
#include "url/gurl.h"

using storage::SpecialStoragePolicy;

namespace content {

class MockSpecialStoragePolicy : public storage::SpecialStoragePolicy {
 public:
  MockSpecialStoragePolicy();

  bool IsStorageProtected(const GURL& origin) override;
  bool IsStorageUnlimited(const GURL& origin) override;
  bool IsStorageSessionOnly(const GURL& origin) override;
  bool CanQueryDiskSize(const GURL& origin) override;
  bool HasIsolatedStorage(const GURL& origin) override;
  bool HasSessionOnlyOrigins() override;
  bool IsStorageDurable(const GURL& origin) override;

  void AddProtected(const GURL& origin) {
    protected_.insert(origin);
  }

  void AddUnlimited(const GURL& origin) {
    unlimited_.insert(origin);
  }

  void RemoveUnlimited(const GURL& origin) {
    unlimited_.erase(origin);
  }

  void AddSessionOnly(const GURL& origin) {
    session_only_.insert(origin);
  }

  void GrantQueryDiskSize(const GURL& origin) {
    can_query_disk_size_.insert(origin);
  }

  void AddIsolated(const GURL& origin) {
    isolated_.insert(origin);
  }

  void RemoveIsolated(const GURL& origin) {
    isolated_.erase(origin);
  }

  void SetAllUnlimited(bool all_unlimited) {
    all_unlimited_ = all_unlimited;
  }

  void AddDurable(const GURL& origin) {
    durable_.insert(origin);
  }

  void Reset() {
    protected_.clear();
    unlimited_.clear();
    session_only_.clear();
    can_query_disk_size_.clear();
    file_handlers_.clear();
    isolated_.clear();
    all_unlimited_ = false;
  }

  void NotifyGranted(const GURL& origin, int change_flags) {
    SpecialStoragePolicy::NotifyGranted(origin, change_flags);
  }

  void NotifyRevoked(const GURL& origin, int change_flags) {
    SpecialStoragePolicy::NotifyRevoked(origin, change_flags);
  }

  void NotifyCleared() {
    SpecialStoragePolicy::NotifyCleared();
  }

 protected:
  ~MockSpecialStoragePolicy() override;

 private:
  std::set<GURL> protected_;
  std::set<GURL> unlimited_;
  std::set<GURL> session_only_;
  std::set<GURL> can_query_disk_size_;
  std::set<GURL> isolated_;
  std::set<GURL> durable_;
  std::set<std::string> file_handlers_;

  bool all_unlimited_;
};
}  // namespace content

#endif  // CONTENT_PUBLIC_TEST_MOCK_SPECIAL_STORAGE_POLICY_H_