summaryrefslogtreecommitdiffstats
path: root/extensions/browser/test_management_policy.h
blob: cf91143cdeae993fa5407f3156a09466f65ad4b5 (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
// Copyright 2013 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 EXTENSIONS_BROWSER_TEST_MANAGEMENT_POLICY_H_
#define EXTENSIONS_BROWSER_TEST_MANAGEMENT_POLICY_H_

#include <string>

#include "base/strings/string16.h"
#include "extensions/browser/management_policy.h"

namespace extensions {

// This class provides a simple way to create providers with specific
// restrictions and a known error message, for use in testing.
class TestManagementPolicyProvider : public ManagementPolicy::Provider {
 public:
  enum AllowedActionFlag {
    ALLOW_ALL = 0,
    PROHIBIT_LOAD = 1 << 0,
    PROHIBIT_MODIFY_STATUS = 1 << 1,
    MUST_REMAIN_ENABLED = 1 << 2,
    MUST_REMAIN_DISABLED = 1 << 3,
    MUST_REMAIN_INSTALLED = 1 << 4,
  };

  static std::string expected_error() {
    return "Action prohibited by test provider.";
  }

  TestManagementPolicyProvider();
  explicit TestManagementPolicyProvider(int prohibited_actions);

  void SetProhibitedActions(int prohibited_actions);
  void SetDisableReason(Extension::DisableReason reason);

  std::string GetDebugPolicyProviderName() const override;

  bool UserMayLoad(const Extension* extension,
                   base::string16* error) const override;

  bool UserMayModifySettings(const Extension* extension,
                             base::string16* error) const override;

  bool MustRemainEnabled(const Extension* extension,
                         base::string16* error) const override;

  bool MustRemainDisabled(const Extension* extension,
                          Extension::DisableReason* reason,
                          base::string16* error) const override;

  bool MustRemainInstalled(const Extension* extension,
                           base::string16* error) const override;

 private:
  bool may_load_;
  bool may_modify_status_;
  bool must_remain_enabled_;
  bool must_remain_disabled_;
  bool must_remain_installed_;
  Extension::DisableReason disable_reason_;

  base::string16 error_message_;
};

}  // namespace extensions

#endif  // EXTENSIONS_BROWSER_TEST_MANAGEMENT_POLICY_H_