Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(838)

Side by Side Diff: chrome/common/extensions/extension_permission_set_unittest.cc

Issue 8598022: Restrict access to permissions based on extension types. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/common/extensions/extension_permission_set.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/extension_permission_set.h" 5 #include "chrome/common/extensions/extension_permission_set.h"
6 6
7 #include "base/json/json_value_serializer.h" 7 #include "base/json/json_value_serializer.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/path_service.h" 9 #include "base/path_service.h"
10 #include "base/utf_string_conversions.h" 10 #include "base/utf_string_conversions.h"
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 hosted_perms.insert(ExtensionAPIPermission::kGeolocation); 151 hosted_perms.insert(ExtensionAPIPermission::kGeolocation);
152 hosted_perms.insert(ExtensionAPIPermission::kNotification); 152 hosted_perms.insert(ExtensionAPIPermission::kNotification);
153 hosted_perms.insert(ExtensionAPIPermission::kUnlimitedStorage); 153 hosted_perms.insert(ExtensionAPIPermission::kUnlimitedStorage);
154 hosted_perms.insert(ExtensionAPIPermission::kWebstorePrivate); 154 hosted_perms.insert(ExtensionAPIPermission::kWebstorePrivate);
155 155
156 ExtensionAPIPermissionSet perms = info->GetAll(); 156 ExtensionAPIPermissionSet perms = info->GetAll();
157 size_t count = 0; 157 size_t count = 0;
158 for (ExtensionAPIPermissionSet::iterator i = perms.begin(); 158 for (ExtensionAPIPermissionSet::iterator i = perms.begin();
159 i != perms.end(); ++i) { 159 i != perms.end(); ++i) {
160 count += hosted_perms.count(*i); 160 count += hosted_perms.count(*i);
161 EXPECT_EQ(hosted_perms.count(*i) > 0, info->GetByID(*i)->is_hosted_app()); 161 EXPECT_EQ(hosted_perms.count(*i) > 0,
162 info->GetByID(*i)->supports_hosted_apps());
162 } 163 }
163 164
164 EXPECT_EQ(hosted_perms.size(), count); 165 EXPECT_EQ(hosted_perms.size(), count);
165 EXPECT_EQ(hosted_perms.size(), info->get_hosted_app_permission_count()); 166 }
167
168 TEST(ExtensionAPIPermissionTest, PlatformAppPermissions) {
169 ExtensionPermissionsInfo* info = ExtensionPermissionsInfo::GetInstance();
170 ExtensionAPIPermissionSet blacklist;
171 blacklist.insert(ExtensionAPIPermission::kChromeAuthPrivate);
172 blacklist.insert(ExtensionAPIPermission::kChromePrivate);
173 blacklist.insert(ExtensionAPIPermission::kCookie);
174 blacklist.insert(ExtensionAPIPermission::kTab);
175 blacklist.insert(ExtensionAPIPermission::kWebNavigation);
176 blacklist.insert(ExtensionAPIPermission::kWebRequest);
177 blacklist.insert(ExtensionAPIPermission::kWebRequestBlocking);
178 blacklist.insert(ExtensionAPIPermission::kWebSocketProxyPrivate);
179
180 ExtensionAPIPermissionSet perms = info->GetAll();
181 size_t count = 0;
182 for (ExtensionAPIPermissionSet::iterator i = perms.begin();
183 i != perms.end(); ++i) {
184 count += blacklist.count(*i);
185 EXPECT_EQ(blacklist.count(*i) > 0,
186 !info->GetByID(*i)->supports_platform_apps());
187 }
188
189 EXPECT_EQ(blacklist.size(), count);
166 } 190 }
167 191
168 TEST(ExtensionAPIPermissionTest, ComponentOnlyPermissions) { 192 TEST(ExtensionAPIPermissionTest, ComponentOnlyPermissions) {
169 ExtensionPermissionsInfo* info = ExtensionPermissionsInfo::GetInstance(); 193 ExtensionPermissionsInfo* info = ExtensionPermissionsInfo::GetInstance();
170 ExtensionAPIPermissionSet private_perms; 194 ExtensionAPIPermissionSet private_perms;
171 private_perms.insert(ExtensionAPIPermission::kChromeAuthPrivate); 195 private_perms.insert(ExtensionAPIPermission::kChromeAuthPrivate);
172 private_perms.insert(ExtensionAPIPermission::kChromeosInfoPrivate); 196 private_perms.insert(ExtensionAPIPermission::kChromeosInfoPrivate);
173 private_perms.insert(ExtensionAPIPermission::kFileBrowserPrivate); 197 private_perms.insert(ExtensionAPIPermission::kFileBrowserPrivate);
174 private_perms.insert(ExtensionAPIPermission::kMediaPlayerPrivate); 198 private_perms.insert(ExtensionAPIPermission::kMediaPlayerPrivate);
175 private_perms.insert(ExtensionAPIPermission::kMetricsPrivate); 199 private_perms.insert(ExtensionAPIPermission::kMetricsPrivate);
(...skipping 922 matching lines...) Expand 10 before | Expand all | Expand 10 after
1098 AddPattern(&non_empty_extent, "http://www.google.com/*"); 1122 AddPattern(&non_empty_extent, "http://www.google.com/*");
1099 1123
1100 perm_set = new ExtensionPermissionSet( 1124 perm_set = new ExtensionPermissionSet(
1101 empty_apis, non_empty_extent, empty_extent); 1125 empty_apis, non_empty_extent, empty_extent);
1102 EXPECT_FALSE(perm_set->IsEmpty()); 1126 EXPECT_FALSE(perm_set->IsEmpty());
1103 1127
1104 perm_set = new ExtensionPermissionSet( 1128 perm_set = new ExtensionPermissionSet(
1105 empty_apis, empty_extent, non_empty_extent); 1129 empty_apis, empty_extent, non_empty_extent);
1106 EXPECT_FALSE(perm_set->IsEmpty()); 1130 EXPECT_FALSE(perm_set->IsEmpty());
1107 } 1131 }
OLDNEW
« no previous file with comments | « chrome/common/extensions/extension_permission_set.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698