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

Side by Side Diff: extensions/common/permissions/permissions_data_unittest.cc

Issue 348313003: Create withheld permissions (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 5 months 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
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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 <vector> 5 #include <vector>
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/memory/ref_counted.h" 8 #include "base/memory/ref_counted.h"
9 #include "base/strings/string16.h" 9 #include "base/strings/string16.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 .Set("description", "an extension") 67 .Set("description", "an extension")
68 .Set("manifest_version", 2) 68 .Set("manifest_version", 2)
69 .Set("version", "1.0.0") 69 .Set("version", "1.0.0")
70 .Set("permissions", permissions.Pass()) 70 .Set("permissions", permissions.Pass())
71 .Build()) 71 .Build())
72 .SetLocation(location) 72 .SetLocation(location)
73 .SetID(id) 73 .SetID(id)
74 .Build(); 74 .Build();
75 } 75 }
76 76
77 bool RequiresActionForScriptExecution(const std::string& extension_id,
78 const std::string& host_permissions,
79 Manifest::Location location) {
80 scoped_refptr<const Extension> extension =
81 GetExtensionWithHostPermission(extension_id,
82 host_permissions,
83 location);
84 return extension->permissions_data()->RequiresActionForScriptExecution(
85 extension,
86 -1, // Ignore tab id for these.
87 GURL::EmptyGURL());
88 }
89
90 // Checks that urls are properly restricted for the given extension. 77 // Checks that urls are properly restricted for the given extension.
91 void CheckRestrictedUrls(const Extension* extension, 78 void CheckRestrictedUrls(const Extension* extension,
92 bool block_chrome_urls) { 79 bool block_chrome_urls) {
93 // We log the name so we know _which_ extension failed here. 80 // We log the name so we know _which_ extension failed here.
94 const std::string& name = extension->name(); 81 const std::string& name = extension->name();
95 const GURL chrome_settings_url("chrome://settings/"); 82 const GURL chrome_settings_url("chrome://settings/");
96 const GURL chrome_extension_url("chrome-extension://foo/bar.html"); 83 const GURL chrome_extension_url("chrome-extension://foo/bar.html");
97 const GURL google_url("https://www.google.com/"); 84 const GURL google_url("https://www.google.com/");
98 const GURL self_url("chrome-extension://" + extension->id() + "/foo.html"); 85 const GURL self_url("chrome-extension://" + extension->id() + "/foo.html");
99 const GURL invalid_url("chrome-debugger://foo/bar.html"); 86 const GURL invalid_url("chrome-debugger://foo/bar.html");
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 extension, SocketPermissionRequest::UDP_BIND, "", 8888)); 246 extension, SocketPermissionRequest::UDP_BIND, "", 8888));
260 247
261 EXPECT_FALSE(CheckSocketPermission( 248 EXPECT_FALSE(CheckSocketPermission(
262 extension, SocketPermissionRequest::UDP_SEND_TO, "example.com", 1900)); 249 extension, SocketPermissionRequest::UDP_SEND_TO, "example.com", 1900));
263 EXPECT_TRUE(CheckSocketPermission( 250 EXPECT_TRUE(CheckSocketPermission(
264 extension, 251 extension,
265 SocketPermissionRequest::UDP_SEND_TO, 252 SocketPermissionRequest::UDP_SEND_TO,
266 "239.255.255.250", 1900)); 253 "239.255.255.250", 1900));
267 } 254 }
268 255
269 TEST(ExtensionPermissionsTest, RequiresActionForScriptExecution) {
270 // Extensions with all_hosts should require action.
271 EXPECT_TRUE(RequiresActionForScriptExecution(
272 "all_hosts_permissions", kAllHostsPermission, Manifest::INTERNAL));
273 // Extensions with nearly all hosts are treated the same way.
274 EXPECT_TRUE(RequiresActionForScriptExecution(
275 "pseudo_all_hosts_permissions", "*://*.com/*", Manifest::INTERNAL));
276 // Extensions with explicit permissions shouldn't require action.
277 EXPECT_FALSE(RequiresActionForScriptExecution(
278 "explicit_permissions", "https://www.google.com/*", Manifest::INTERNAL));
279 // Policy extensions are exempt...
280 EXPECT_FALSE(RequiresActionForScriptExecution(
281 "policy", kAllHostsPermission, Manifest::EXTERNAL_POLICY));
282 // ... as are component extensions.
283 EXPECT_FALSE(RequiresActionForScriptExecution(
284 "component", kAllHostsPermission, Manifest::COMPONENT));
285 // Throw in an external pref extension to make sure that it's not just working
286 // for everything non-internal.
287 EXPECT_TRUE(RequiresActionForScriptExecution(
288 "external_pref", kAllHostsPermission, Manifest::EXTERNAL_PREF));
289
290 // If we grant an extension tab permissions, then it should no longer require
291 // action.
292 scoped_refptr<const Extension> extension =
293 GetExtensionWithHostPermission("all_hosts_permissions",
294 kAllHostsPermission,
295 Manifest::INTERNAL);
296 URLPatternSet allowed_hosts;
297 allowed_hosts.AddPattern(
298 URLPattern(URLPattern::SCHEME_HTTPS, "https://www.google.com/*"));
299 scoped_refptr<PermissionSet> tab_permissions(
300 new PermissionSet(APIPermissionSet(),
301 ManifestPermissionSet(),
302 allowed_hosts,
303 URLPatternSet()));
304 extension->permissions_data()->UpdateTabSpecificPermissions(0,
305 tab_permissions);
306 EXPECT_FALSE(extension->permissions_data()->RequiresActionForScriptExecution(
307 extension, 0, GURL("https://www.google.com/")));
308 }
309
310 TEST(ExtensionPermissionsTest, IsRestrictedUrl) { 256 TEST(ExtensionPermissionsTest, IsRestrictedUrl) {
311 scoped_refptr<const Extension> extension = 257 scoped_refptr<const Extension> extension =
312 GetExtensionWithHostPermission("normal_extension", 258 GetExtensionWithHostPermission("normal_extension",
313 kAllHostsPermission, 259 kAllHostsPermission,
314 Manifest::INTERNAL); 260 Manifest::INTERNAL);
315 // Chrome urls should be blocked for normal extensions. 261 // Chrome urls should be blocked for normal extensions.
316 CheckRestrictedUrls(extension, true); 262 CheckRestrictedUrls(extension, true);
317 263
318 scoped_refptr<const Extension> component = 264 scoped_refptr<const Extension> component =
319 GetExtensionWithHostPermission("component", 265 GetExtensionWithHostPermission("component",
(...skipping 480 matching lines...) Expand 10 before | Expand all | Expand 10 after
800 746
801 permissions_data->ClearTabSpecificPermissions(1); 747 permissions_data->ClearTabSpecificPermissions(1);
802 EXPECT_FALSE(permissions_data->GetTabSpecificPermissionsForTesting(1)); 748 EXPECT_FALSE(permissions_data->GetTabSpecificPermissionsForTesting(1));
803 749
804 EXPECT_TRUE(ScriptAllowedExclusivelyOnTab(extension.get(), no_urls, 0)); 750 EXPECT_TRUE(ScriptAllowedExclusivelyOnTab(extension.get(), no_urls, 0));
805 EXPECT_TRUE(ScriptAllowedExclusivelyOnTab(extension.get(), no_urls, 1)); 751 EXPECT_TRUE(ScriptAllowedExclusivelyOnTab(extension.get(), no_urls, 1));
806 EXPECT_TRUE(ScriptAllowedExclusivelyOnTab(extension.get(), no_urls, 2)); 752 EXPECT_TRUE(ScriptAllowedExclusivelyOnTab(extension.get(), no_urls, 2));
807 } 753 }
808 754
809 } // namespace extensions 755 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698