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/common/extensions/permissions/chrome_permission_message_provide
r.h" | 5 #include "chrome/common/extensions/permissions/chrome_permission_message_provide
r.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/strings/string16.h" | 10 #include "base/strings/string16.h" |
(...skipping 17 matching lines...) Expand all Loading... |
28 // chrome/browser/extensions/permission_messages_unittest.cc. | 28 // chrome/browser/extensions/permission_messages_unittest.cc. |
29 class ChromePermissionMessageProviderUnittest : public testing::Test { | 29 class ChromePermissionMessageProviderUnittest : public testing::Test { |
30 public: | 30 public: |
31 ChromePermissionMessageProviderUnittest() | 31 ChromePermissionMessageProviderUnittest() |
32 : message_provider_(new ChromePermissionMessageProvider()) {} | 32 : message_provider_(new ChromePermissionMessageProvider()) {} |
33 ~ChromePermissionMessageProviderUnittest() override {} | 33 ~ChromePermissionMessageProviderUnittest() override {} |
34 | 34 |
35 protected: | 35 protected: |
36 PermissionMessages GetMessages(const APIPermissionSet& permissions, | 36 PermissionMessages GetMessages(const APIPermissionSet& permissions, |
37 Manifest::Type type) { | 37 Manifest::Type type) { |
38 scoped_refptr<const PermissionSet> permission_set = new PermissionSet( | 38 PermissionSet permission_set(permissions, ManifestPermissionSet(), |
39 permissions, ManifestPermissionSet(), URLPatternSet(), URLPatternSet()); | 39 URLPatternSet(), URLPatternSet()); |
40 return message_provider_->GetPermissionMessages( | 40 return message_provider_->GetPermissionMessages( |
41 message_provider_->GetAllPermissionIDs(permission_set.get(), type)); | 41 message_provider_->GetAllPermissionIDs(&permission_set, type)); |
42 } | 42 } |
43 | 43 |
44 bool IsPrivilegeIncrease(const APIPermissionSet& old_permissions, | 44 bool IsPrivilegeIncrease(const APIPermissionSet& old_permissions, |
45 const APIPermissionSet& new_permissions) { | 45 const APIPermissionSet& new_permissions) { |
46 scoped_refptr<PermissionSet> old_set( | 46 PermissionSet old_set(old_permissions, ManifestPermissionSet(), |
47 new PermissionSet(old_permissions, ManifestPermissionSet(), | 47 URLPatternSet(), URLPatternSet()); |
48 URLPatternSet(), URLPatternSet())); | 48 PermissionSet new_set(new_permissions, ManifestPermissionSet(), |
49 scoped_refptr<PermissionSet> new_set( | 49 URLPatternSet(), URLPatternSet()); |
50 new PermissionSet(new_permissions, ManifestPermissionSet(), | 50 return message_provider_->IsPrivilegeIncrease(&old_set, &new_set, |
51 URLPatternSet(), URLPatternSet())); | |
52 return message_provider_->IsPrivilegeIncrease(old_set.get(), new_set.get(), | |
53 Manifest::TYPE_EXTENSION); | 51 Manifest::TYPE_EXTENSION); |
54 } | 52 } |
55 | 53 |
56 private: | 54 private: |
57 scoped_ptr<ChromePermissionMessageProvider> message_provider_; | 55 scoped_ptr<ChromePermissionMessageProvider> message_provider_; |
58 | 56 |
59 DISALLOW_COPY_AND_ASSIGN(ChromePermissionMessageProviderUnittest); | 57 DISALLOW_COPY_AND_ASSIGN(ChromePermissionMessageProviderUnittest); |
60 }; | 58 }; |
61 | 59 |
62 // Checks that if an app has a superset and a subset permission, only the | 60 // Checks that if an app has a superset and a subset permission, only the |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 | 149 |
152 EXPECT_FALSE(IsPrivilegeIncrease(granted_permissions, actual_permissions)); | 150 EXPECT_FALSE(IsPrivilegeIncrease(granted_permissions, actual_permissions)); |
153 | 151 |
154 // Just to be safe: Adding the permission (with or without parameter) should | 152 // Just to be safe: Adding the permission (with or without parameter) should |
155 // still be considered a privilege escalation. | 153 // still be considered a privilege escalation. |
156 EXPECT_TRUE(IsPrivilegeIncrease(APIPermissionSet(), granted_permissions)); | 154 EXPECT_TRUE(IsPrivilegeIncrease(APIPermissionSet(), granted_permissions)); |
157 EXPECT_TRUE(IsPrivilegeIncrease(APIPermissionSet(), actual_permissions)); | 155 EXPECT_TRUE(IsPrivilegeIncrease(APIPermissionSet(), actual_permissions)); |
158 } | 156 } |
159 | 157 |
160 } // namespace extensions | 158 } // namespace extensions |
OLD | NEW |