OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_MANAGEMENT_TEST_UTIL_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_MANAGEMENT_TEST_UTIL_H_ |
6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_MANAGEMENT_TEST_UTIL_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_MANAGEMENT_TEST_UTIL_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
12 #include "base/values.h" | 12 #include "base/values.h" |
13 #include "chrome/browser/extensions/extension_management_constants.h" | 13 #include "chrome/browser/extensions/extension_management_constants.h" |
14 #include "extensions/browser/pref_names.h" | 14 #include "extensions/browser/pref_names.h" |
15 #include "extensions/common/extension.h" | 15 #include "extensions/common/extension.h" |
16 | 16 |
17 namespace policy { | |
18 class MockConfigurationPolicyProvider; | |
19 class PolicyBundle; | |
20 } // namespace policy | |
21 | |
17 namespace extensions { | 22 namespace extensions { |
18 | 23 |
19 // Base class for essential routines on preference manipulation. | 24 // Base class for essential routines on preference manipulation. |
20 class ExtensionManagementPrefUpdaterBase { | 25 class ExtensionManagementPrefUpdaterBase { |
21 public: | 26 public: |
22 ExtensionManagementPrefUpdaterBase(); | 27 ExtensionManagementPrefUpdaterBase(); |
23 virtual ~ExtensionManagementPrefUpdaterBase(); | 28 virtual ~ExtensionManagementPrefUpdaterBase(); |
24 | 29 |
25 // Helper functions for per extension settings. | 30 // Helper functions for per extension settings. |
26 void UnsetPerExtensionSettings(const ExtensionId& id); | 31 void UnsetPerExtensionSettings(const ExtensionId& id); |
(...skipping 11 matching lines...) Expand all Loading... | |
38 // Helper functions for 'install_sources' manipulation. | 43 // Helper functions for 'install_sources' manipulation. |
39 void UnsetInstallSources(); | 44 void UnsetInstallSources(); |
40 void ClearInstallSources(); | 45 void ClearInstallSources(); |
41 void AddInstallSource(const std::string& install_source); | 46 void AddInstallSource(const std::string& install_source); |
42 void RemoveInstallSource(const std::string& install_source); | 47 void RemoveInstallSource(const std::string& install_source); |
43 | 48 |
44 // Helper functions for 'allowed_types' manipulation. | 49 // Helper functions for 'allowed_types' manipulation. |
45 void UnsetAllowedTypes(); | 50 void UnsetAllowedTypes(); |
46 void ClearAllowedTypes(); | 51 void ClearAllowedTypes(); |
47 void AddAllowedType(const std::string& allowed_type); | 52 void AddAllowedType(const std::string& allowed_type); |
48 void RemoveAllowedType(const std::string& allowd_type); | 53 void RemoveAllowedType(const std::string& allowed_type); |
54 | |
55 // Helper functions for 'blocked_permissions' manipulation. |prefix| can be | |
56 // kWildCard or a valid extension ID. | |
57 void UnsetBlockedPermissions(const std::string& prefix); | |
58 void ClearBlockedPermissions(const std::string& prefix); | |
59 void AddBlockedPermission(const std::string& prefix, | |
60 const std::string& permission); | |
61 void RemoveBlockedPermission(const std::string& prefix, | |
62 const std::string& permission); | |
63 | |
64 // Helper functions for 'allowed_permissions' manipulation. |id| must be a | |
65 // valid extension id. | |
66 void UnsetAllowedPermissions(const std::string& id); | |
67 void ClearAllowedPermissions(const std::string& id); | |
68 void AddAllowedPermission(const std::string& id, | |
69 const std::string& permission); | |
70 void RemoveAllowedPermission(const std::string& id, | |
71 const std::string& permission); | |
49 | 72 |
50 // Expose a read-only preference to user. | 73 // Expose a read-only preference to user. |
51 const base::DictionaryValue* GetPref(); | 74 const base::DictionaryValue* GetPref(); |
52 | 75 |
53 protected: | 76 protected: |
54 // Set the preference with |pref|, pass the ownership of it as well. | 77 // Set the preference with |pref|, pass the ownership of it as well. |
55 // This function must be called before accessing publicly exposed functions, | 78 // This function must be called before accessing publicly exposed functions, |
56 // for example in constructor of subclass. | 79 // for example in constructor of subclass. |
57 void SetPref(base::DictionaryValue* pref); | 80 void SetPref(base::DictionaryValue* pref); |
58 | 81 |
(...skipping 16 matching lines...) Expand all Loading... | |
75 // A helper class to manipulate the extension management preference in unit | 98 // A helper class to manipulate the extension management preference in unit |
76 // tests. | 99 // tests. |
77 template <class TestingPrefService> | 100 template <class TestingPrefService> |
78 class ExtensionManagementPrefUpdater | 101 class ExtensionManagementPrefUpdater |
79 : public ExtensionManagementPrefUpdaterBase { | 102 : public ExtensionManagementPrefUpdaterBase { |
80 public: | 103 public: |
81 explicit ExtensionManagementPrefUpdater(TestingPrefService* service) | 104 explicit ExtensionManagementPrefUpdater(TestingPrefService* service) |
82 : service_(service) { | 105 : service_(service) { |
83 const base::Value* pref_value = | 106 const base::Value* pref_value = |
84 service_->GetManagedPref(pref_names::kExtensionManagement); | 107 service_->GetManagedPref(pref_names::kExtensionManagement); |
85 if (pref_value) { | 108 const base::DictionaryValue* dict_value = nullptr; |
86 const base::DictionaryValue* dict_value = NULL; | 109 if (pref_value && pref_value->GetAsDictionary(&dict_value)) |
87 pref_value->GetAsDictionary(&dict_value); | |
88 SetPref(dict_value->DeepCopy()); | 110 SetPref(dict_value->DeepCopy()); |
89 } else { | 111 else |
90 SetPref(new base::DictionaryValue); | 112 SetPref(new base::DictionaryValue); |
91 } | |
92 } | 113 } |
93 | 114 |
94 virtual ~ExtensionManagementPrefUpdater() { | 115 virtual ~ExtensionManagementPrefUpdater() { |
95 service_->SetManagedPref(pref_names::kExtensionManagement, | 116 service_->SetManagedPref(pref_names::kExtensionManagement, |
96 TakePref().release()); | 117 TakePref().release()); |
97 } | 118 } |
98 | 119 |
99 private: | 120 private: |
100 TestingPrefService* service_; | 121 TestingPrefService* service_; |
101 | 122 |
102 DISALLOW_COPY_AND_ASSIGN(ExtensionManagementPrefUpdater); | 123 DISALLOW_COPY_AND_ASSIGN(ExtensionManagementPrefUpdater); |
103 }; | 124 }; |
104 | 125 |
126 // A helper class to manipulate the extension management policy in browser | |
127 // tests. | |
128 class ExtensionManagementPolicyUpdater | |
129 : public ExtensionManagementPrefUpdaterBase { | |
130 public: | |
131 explicit ExtensionManagementPolicyUpdater( | |
132 policy::MockConfigurationPolicyProvider* provider); | |
133 virtual ~ExtensionManagementPolicyUpdater(); | |
Finnur
2014/10/30 14:16:59
virtual -> override
binjin
2014/10/30 16:41:11
Done.
| |
134 | |
135 private: | |
136 policy::MockConfigurationPolicyProvider* provider_; | |
137 scoped_ptr<policy::PolicyBundle> policies_; | |
138 | |
139 DISALLOW_COPY_AND_ASSIGN(ExtensionManagementPolicyUpdater); | |
140 }; | |
141 | |
105 } // namespace extensions | 142 } // namespace extensions |
106 | 143 |
107 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_MANAGEMENT_TEST_UTIL_H_ | 144 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_MANAGEMENT_TEST_UTIL_H_ |
OLD | NEW |