[email protected] | 301116c6 | 2013-11-26 10:37:45 | [diff] [blame] | 1 | // Copyright 2013 The Chromium Authors. All rights reserved. |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | 301116c6 | 2013-11-26 10:37:45 | [diff] [blame] | 5 | #ifndef EXTENSIONS_BROWSER_TEST_MANAGEMENT_POLICY_H_ |
| 6 | #define EXTENSIONS_BROWSER_TEST_MANAGEMENT_POLICY_H_ |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 7 | |
| 8 | #include <string> |
| 9 | |
[email protected] | 46acbf1 | 2013-06-10 18:43:42 | [diff] [blame] | 10 | #include "base/strings/string16.h" |
[email protected] | 301116c6 | 2013-11-26 10:37:45 | [diff] [blame] | 11 | #include "extensions/browser/management_policy.h" |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 12 | |
| 13 | namespace extensions { |
[email protected] | 0d54b68 | 2013-11-05 14:15:36 | [diff] [blame] | 14 | |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 15 | // This class provides a simple way to create providers with specific |
| 16 | // restrictions and a known error message, for use in testing. |
| 17 | class TestManagementPolicyProvider : public ManagementPolicy::Provider { |
| 18 | public: |
| 19 | enum AllowedActionFlag { |
| 20 | ALLOW_ALL = 0, |
| 21 | PROHIBIT_LOAD = 1 << 0, |
| 22 | PROHIBIT_MODIFY_STATUS = 1 << 1, |
[email protected] | 0d54b68 | 2013-11-05 14:15:36 | [diff] [blame] | 23 | MUST_REMAIN_ENABLED = 1 << 2, |
binjin | cccacef | 2014-10-13 19:00:20 | [diff] [blame] | 24 | MUST_REMAIN_DISABLED = 1 << 3, |
| 25 | MUST_REMAIN_INSTALLED = 1 << 4, |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 26 | }; |
| 27 | |
| 28 | static std::string expected_error() { |
| 29 | return "Action prohibited by test provider."; |
| 30 | } |
| 31 | |
| 32 | TestManagementPolicyProvider(); |
| 33 | explicit TestManagementPolicyProvider(int prohibited_actions); |
| 34 | |
| 35 | void SetProhibitedActions(int prohibited_actions); |
[email protected] | 0d54b68 | 2013-11-05 14:15:36 | [diff] [blame] | 36 | void SetDisableReason(Extension::DisableReason reason); |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 37 | |
dcheng | 9168b2f | 2014-10-21 12:38:24 | [diff] [blame] | 38 | std::string GetDebugPolicyProviderName() const override; |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 39 | |
dcheng | 9168b2f | 2014-10-21 12:38:24 | [diff] [blame] | 40 | bool UserMayLoad(const Extension* extension, |
| 41 | base::string16* error) const override; |
| 42 | |
| 43 | bool UserMayModifySettings(const Extension* extension, |
| 44 | base::string16* error) const override; |
| 45 | |
| 46 | bool MustRemainEnabled(const Extension* extension, |
| 47 | base::string16* error) const override; |
| 48 | |
| 49 | bool MustRemainDisabled(const Extension* extension, |
| 50 | Extension::DisableReason* reason, |
| 51 | base::string16* error) const override; |
| 52 | |
| 53 | bool MustRemainInstalled(const Extension* extension, |
mostynb | 0eac4e1b | 2014-10-03 16:32:19 | [diff] [blame] | 54 | base::string16* error) const override; |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 55 | |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 56 | private: |
| 57 | bool may_load_; |
| 58 | bool may_modify_status_; |
| 59 | bool must_remain_enabled_; |
[email protected] | 0d54b68 | 2013-11-05 14:15:36 | [diff] [blame] | 60 | bool must_remain_disabled_; |
binjin | cccacef | 2014-10-13 19:00:20 | [diff] [blame] | 61 | bool must_remain_installed_; |
[email protected] | 0d54b68 | 2013-11-05 14:15:36 | [diff] [blame] | 62 | Extension::DisableReason disable_reason_; |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 63 | |
[email protected] | 0d163dc | 2013-12-20 23:48:36 | [diff] [blame] | 64 | base::string16 error_message_; |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 65 | }; |
[email protected] | 0d54b68 | 2013-11-05 14:15:36 | [diff] [blame] | 66 | |
| 67 | } // namespace extensions |
| 68 | |
[email protected] | 301116c6 | 2013-11-26 10:37:45 | [diff] [blame] | 69 | #endif // EXTENSIONS_BROWSER_TEST_MANAGEMENT_POLICY_H_ |