| 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/permissions_based_management_policy_provider
.h" |
| 6 |
| 7 #include <memory> |
| 5 #include <string> | 8 #include <string> |
| 6 #include <vector> | 9 #include <vector> |
| 7 | 10 |
| 8 #include "base/logging.h" | 11 #include "base/logging.h" |
| 9 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
| 10 #include "base/memory/scoped_ptr.h" | |
| 11 #include "base/stl_util.h" | 13 #include "base/stl_util.h" |
| 12 #include "base/strings/string16.h" | 14 #include "base/strings/string16.h" |
| 13 #include "base/values.h" | 15 #include "base/values.h" |
| 14 #include "chrome/browser/extensions/extension_management.h" | 16 #include "chrome/browser/extensions/extension_management.h" |
| 15 #include "chrome/browser/extensions/extension_management_test_util.h" | 17 #include "chrome/browser/extensions/extension_management_test_util.h" |
| 16 #include "chrome/browser/extensions/permissions_based_management_policy_provider
.h" | |
| 17 #include "chrome/common/extensions/permissions/chrome_api_permissions.h" | 18 #include "chrome/common/extensions/permissions/chrome_api_permissions.h" |
| 18 #include "components/prefs/pref_registry_simple.h" | 19 #include "components/prefs/pref_registry_simple.h" |
| 19 #include "components/prefs/testing_pref_service.h" | 20 #include "components/prefs/testing_pref_service.h" |
| 20 #include "extensions/common/extension.h" | 21 #include "extensions/common/extension.h" |
| 21 #include "extensions/common/manifest.h" | 22 #include "extensions/common/manifest.h" |
| 22 #include "extensions/common/manifest_constants.h" | 23 #include "extensions/common/manifest_constants.h" |
| 23 #include "extensions/common/permissions/api_permission.h" | 24 #include "extensions/common/permissions/api_permission.h" |
| 24 #include "testing/gtest/include/gtest/gtest.h" | 25 #include "testing/gtest/include/gtest/gtest.h" |
| 25 | 26 |
| 26 namespace extensions { | 27 namespace extensions { |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 std::string error; | 77 std::string error; |
| 77 scoped_refptr<const Extension> extension = Extension::Create( | 78 scoped_refptr<const Extension> extension = Extension::Create( |
| 78 base::FilePath(), location, manifest_dict, Extension::NO_FLAGS, &error); | 79 base::FilePath(), location, manifest_dict, Extension::NO_FLAGS, &error); |
| 79 CHECK(extension.get()) << error; | 80 CHECK(extension.get()) << error; |
| 80 return extension; | 81 return extension; |
| 81 } | 82 } |
| 82 | 83 |
| 83 protected: | 84 protected: |
| 84 std::vector<APIPermissionInfo*> perm_list_; | 85 std::vector<APIPermissionInfo*> perm_list_; |
| 85 | 86 |
| 86 scoped_ptr<TestingPrefServiceSimple> pref_service_; | 87 std::unique_ptr<TestingPrefServiceSimple> pref_service_; |
| 87 scoped_ptr<ExtensionManagement> settings_; | 88 std::unique_ptr<ExtensionManagement> settings_; |
| 88 | 89 |
| 89 PermissionsBasedManagementPolicyProvider provider_; | 90 PermissionsBasedManagementPolicyProvider provider_; |
| 90 }; | 91 }; |
| 91 | 92 |
| 92 // Verifies that extensions with conflicting permissions cannot be loaded. | 93 // Verifies that extensions with conflicting permissions cannot be loaded. |
| 93 TEST_F(PermissionsBasedManagementPolicyProviderTest, APIPermissions) { | 94 TEST_F(PermissionsBasedManagementPolicyProviderTest, APIPermissions) { |
| 94 // Prepares the extension manifest. | 95 // Prepares the extension manifest. |
| 95 base::ListValue required_permissions; | 96 base::ListValue required_permissions; |
| 96 required_permissions.AppendString( | 97 required_permissions.AppendString( |
| 97 GetAPIPermissionName(APIPermission::kDownloads)); | 98 GetAPIPermissionName(APIPermission::kDownloads)); |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 pref.ClearBlockedPermissions("*"); | 161 pref.ClearBlockedPermissions("*"); |
| 161 pref.AddBlockedPermission("*", | 162 pref.AddBlockedPermission("*", |
| 162 GetAPIPermissionName(APIPermission::kDownloads)); | 163 GetAPIPermissionName(APIPermission::kDownloads)); |
| 163 } | 164 } |
| 164 error16.clear(); | 165 error16.clear(); |
| 165 EXPECT_FALSE(provider_.UserMayLoad(extension.get(), &error16)); | 166 EXPECT_FALSE(provider_.UserMayLoad(extension.get(), &error16)); |
| 166 EXPECT_FALSE(error16.empty()); | 167 EXPECT_FALSE(error16.empty()); |
| 167 } | 168 } |
| 168 | 169 |
| 169 } // namespace extensions | 170 } // namespace extensions |
| OLD | NEW |