[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 1 | // Copyright (c) 2012 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 CHROME_BROWSER_EXTENSIONS_TEST_MANAGEMENT_POLICY_H_ |
| 6 | #define CHROME_BROWSER_EXTENSIONS_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] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 11 | #include "chrome/browser/extensions/extension_service.h" |
[email protected] | fdd679b | 2012-11-15 20:49:39 | [diff] [blame] | 12 | #include "chrome/browser/extensions/management_policy.h" |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 13 | |
| 14 | namespace extensions { |
[email protected] | 0d54b68 | 2013-11-05 14:15:36 | [diff] [blame^] | 15 | |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 16 | // This class provides a simple way to create providers with specific |
| 17 | // restrictions and a known error message, for use in testing. |
| 18 | class TestManagementPolicyProvider : public ManagementPolicy::Provider { |
| 19 | public: |
| 20 | enum AllowedActionFlag { |
| 21 | ALLOW_ALL = 0, |
| 22 | PROHIBIT_LOAD = 1 << 0, |
| 23 | PROHIBIT_MODIFY_STATUS = 1 << 1, |
[email protected] | 0d54b68 | 2013-11-05 14:15:36 | [diff] [blame^] | 24 | MUST_REMAIN_ENABLED = 1 << 2, |
| 25 | MUST_REMAIN_DISABLED = 1 << 3 |
[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 | |
[email protected] | a6c7a825 | 2012-06-25 18:28:24 | [diff] [blame] | 38 | virtual std::string GetDebugPolicyProviderName() const OVERRIDE; |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 39 | |
| 40 | virtual bool UserMayLoad(const Extension* extension, |
| 41 | string16* error) const OVERRIDE; |
| 42 | |
| 43 | virtual bool UserMayModifySettings(const Extension* extension, |
| 44 | string16* error) const OVERRIDE; |
| 45 | |
| 46 | virtual bool MustRemainEnabled(const Extension* extension, |
| 47 | string16* error) const OVERRIDE; |
| 48 | |
[email protected] | 0d54b68 | 2013-11-05 14:15:36 | [diff] [blame^] | 49 | virtual bool MustRemainDisabled(const Extension* extension, |
| 50 | Extension::DisableReason* reason, |
| 51 | string16* error) const OVERRIDE; |
| 52 | |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 53 | private: |
| 54 | bool may_load_; |
| 55 | bool may_modify_status_; |
| 56 | bool must_remain_enabled_; |
[email protected] | 0d54b68 | 2013-11-05 14:15:36 | [diff] [blame^] | 57 | bool must_remain_disabled_; |
| 58 | Extension::DisableReason disable_reason_; |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 59 | |
| 60 | string16 error_message_; |
| 61 | }; |
[email protected] | 0d54b68 | 2013-11-05 14:15:36 | [diff] [blame^] | 62 | |
| 63 | } // namespace extensions |
| 64 | |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 65 | #endif // CHROME_BROWSER_EXTENSIONS_TEST_MANAGEMENT_POLICY_H_ |