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 #include "chrome/browser/extensions/extension_management.h" |
| 6 |
5 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <memory> |
6 #include <string> | 9 #include <string> |
7 #include <vector> | 10 #include <vector> |
8 | 11 |
9 #include "base/json/json_parser.h" | 12 #include "base/json/json_parser.h" |
10 #include "base/memory/scoped_ptr.h" | |
11 #include "base/values.h" | 13 #include "base/values.h" |
12 #include "chrome/browser/extensions/extension_management.h" | |
13 #include "chrome/browser/extensions/extension_management_internal.h" | 14 #include "chrome/browser/extensions/extension_management_internal.h" |
14 #include "chrome/browser/extensions/extension_management_test_util.h" | 15 #include "chrome/browser/extensions/extension_management_test_util.h" |
15 #include "chrome/browser/extensions/external_policy_loader.h" | 16 #include "chrome/browser/extensions/external_policy_loader.h" |
16 #include "chrome/browser/extensions/standard_management_policy_provider.h" | 17 #include "chrome/browser/extensions/standard_management_policy_provider.h" |
17 #include "components/prefs/pref_registry_simple.h" | 18 #include "components/prefs/pref_registry_simple.h" |
18 #include "components/prefs/testing_pref_service.h" | 19 #include "components/prefs/testing_pref_service.h" |
19 #include "extensions/browser/pref_names.h" | 20 #include "extensions/browser/pref_names.h" |
20 #include "extensions/common/manifest.h" | 21 #include "extensions/common/manifest.h" |
21 #include "extensions/common/manifest_constants.h" | 22 #include "extensions/common/manifest_constants.h" |
22 #include "extensions/common/permissions/api_permission.h" | 23 #include "extensions/common/permissions/api_permission.h" |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 return GetBlockedAPIPermissions(id, kNonExistingUpdateUrl); | 143 return GetBlockedAPIPermissions(id, kNonExistingUpdateUrl); |
143 } | 144 } |
144 | 145 |
145 APIPermissionSet GetBlockedAPIPermissionsByUpdateUrl( | 146 APIPermissionSet GetBlockedAPIPermissionsByUpdateUrl( |
146 const std::string& update_url) { | 147 const std::string& update_url) { |
147 return GetBlockedAPIPermissions(kNonExistingExtension, update_url); | 148 return GetBlockedAPIPermissions(kNonExistingExtension, update_url); |
148 } | 149 } |
149 | 150 |
150 void SetExampleDictPref() { | 151 void SetExampleDictPref() { |
151 std::string error_msg; | 152 std::string error_msg; |
152 scoped_ptr<base::Value> parsed = base::JSONReader::ReadAndReturnError( | 153 std::unique_ptr<base::Value> parsed = base::JSONReader::ReadAndReturnError( |
153 kExampleDictPreference, | 154 kExampleDictPreference, |
154 base::JSONParserOptions::JSON_ALLOW_TRAILING_COMMAS, NULL, &error_msg); | 155 base::JSONParserOptions::JSON_ALLOW_TRAILING_COMMAS, NULL, &error_msg); |
155 ASSERT_TRUE(parsed && parsed->IsType(base::Value::TYPE_DICTIONARY)) | 156 ASSERT_TRUE(parsed && parsed->IsType(base::Value::TYPE_DICTIONARY)) |
156 << error_msg; | 157 << error_msg; |
157 SetPref(true, pref_names::kExtensionManagement, parsed.release()); | 158 SetPref(true, pref_names::kExtensionManagement, parsed.release()); |
158 } | 159 } |
159 | 160 |
160 // Wrapper of ExtensionManagement::GetInstallationMode, |id| and | 161 // Wrapper of ExtensionManagement::GetInstallationMode, |id| and |
161 // |update_url| are used to construct an Extension for testing. | 162 // |update_url| are used to construct an Extension for testing. |
162 ExtensionManagement::InstallationMode GetInstallationMode( | 163 ExtensionManagement::InstallationMode GetInstallationMode( |
(...skipping 21 matching lines...) Expand all Loading... |
184 std::string minimum_version_required; | 185 std::string minimum_version_required; |
185 bool ret = extension_management_->CheckMinimumVersion( | 186 bool ret = extension_management_->CheckMinimumVersion( |
186 extension.get(), &minimum_version_required); | 187 extension.get(), &minimum_version_required); |
187 EXPECT_EQ(ret, minimum_version_required.empty()); | 188 EXPECT_EQ(ret, minimum_version_required.empty()); |
188 EXPECT_EQ(ret, extension_management_->CheckMinimumVersion(extension.get(), | 189 EXPECT_EQ(ret, extension_management_->CheckMinimumVersion(extension.get(), |
189 nullptr)); | 190 nullptr)); |
190 return ret; | 191 return ret; |
191 } | 192 } |
192 | 193 |
193 protected: | 194 protected: |
194 scoped_ptr<TestingPrefServiceSimple> pref_service_; | 195 std::unique_ptr<TestingPrefServiceSimple> pref_service_; |
195 scoped_ptr<ExtensionManagement> extension_management_; | 196 std::unique_ptr<ExtensionManagement> extension_management_; |
196 | 197 |
197 private: | 198 private: |
198 // Create an extension with specified |location|, |version|, |id| and | 199 // Create an extension with specified |location|, |version|, |id| and |
199 // |update_url|. | 200 // |update_url|. |
200 scoped_refptr<const Extension> CreateExtension( | 201 scoped_refptr<const Extension> CreateExtension( |
201 Manifest::Location location, | 202 Manifest::Location location, |
202 const std::string& version, | 203 const std::string& version, |
203 const std::string& id, | 204 const std::string& id, |
204 const std::string& update_url) { | 205 const std::string& update_url) { |
205 base::DictionaryValue manifest_dict; | 206 base::DictionaryValue manifest_dict; |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
253 bool UserMayLoad(const base::ListValue* blacklist, | 254 bool UserMayLoad(const base::ListValue* blacklist, |
254 const base::ListValue* whitelist, | 255 const base::ListValue* whitelist, |
255 const base::DictionaryValue* forcelist, | 256 const base::DictionaryValue* forcelist, |
256 const base::ListValue* allowed_types, | 257 const base::ListValue* allowed_types, |
257 const Extension* extension, | 258 const Extension* extension, |
258 base::string16* error); | 259 base::string16* error); |
259 bool UserMayModifySettings(const Extension* extension, base::string16* error); | 260 bool UserMayModifySettings(const Extension* extension, base::string16* error); |
260 bool MustRemainEnabled(const Extension* extension, base::string16* error); | 261 bool MustRemainEnabled(const Extension* extension, base::string16* error); |
261 | 262 |
262 protected: | 263 protected: |
263 scoped_ptr<StandardManagementPolicyProvider> provider_; | 264 std::unique_ptr<StandardManagementPolicyProvider> provider_; |
264 scoped_refptr<Extension> extension_; | 265 scoped_refptr<Extension> extension_; |
265 }; | 266 }; |
266 | 267 |
267 bool ExtensionAdminPolicyTest::BlacklistedByDefault( | 268 bool ExtensionAdminPolicyTest::BlacklistedByDefault( |
268 const base::ListValue* blacklist) { | 269 const base::ListValue* blacklist) { |
269 SetUpPolicyProvider(); | 270 SetUpPolicyProvider(); |
270 if (blacklist) | 271 if (blacklist) |
271 SetPref(true, pref_names::kInstallDenyList, blacklist->DeepCopy()); | 272 SetPref(true, pref_names::kInstallDenyList, blacklist->DeepCopy()); |
272 return extension_management_->BlacklistedByDefault(); | 273 return extension_management_->BlacklistedByDefault(); |
273 } | 274 } |
(...skipping 599 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
873 EXPECT_FALSE(error.empty()); | 874 EXPECT_FALSE(error.empty()); |
874 | 875 |
875 CreateExtension(Manifest::INTERNAL); | 876 CreateExtension(Manifest::INTERNAL); |
876 error.clear(); | 877 error.clear(); |
877 EXPECT_FALSE(MustRemainEnabled(extension_.get(), NULL)); | 878 EXPECT_FALSE(MustRemainEnabled(extension_.get(), NULL)); |
878 EXPECT_FALSE(MustRemainEnabled(extension_.get(), &error)); | 879 EXPECT_FALSE(MustRemainEnabled(extension_.get(), &error)); |
879 EXPECT_TRUE(error.empty()); | 880 EXPECT_TRUE(error.empty()); |
880 } | 881 } |
881 | 882 |
882 } // namespace extensions | 883 } // namespace extensions |
OLD | NEW |