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

Unified Diff: chrome/browser/extensions/extension_service_unittest.cc

Issue 7003098: Start refractoring extension permissions into ExtensionPermissionSet. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix a bad merge Created 9 years, 6 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/extensions/extension_service_unittest.cc
diff --git a/chrome/browser/extensions/extension_service_unittest.cc b/chrome/browser/extensions/extension_service_unittest.cc
index 6a28563acdb2189130d39238629bd7f196765034..59187172512c1ec2349ec1e6c4330ae20ad7f3e4 100644
--- a/chrome/browser/extensions/extension_service_unittest.cc
+++ b/chrome/browser/extensions/extension_service_unittest.cc
@@ -114,10 +114,10 @@ static void AddPattern(URLPatternSet* extent, const std::string& pattern) {
extent->AddPattern(URLPattern(schemes, pattern));
}
-static void AssertEqualExtents(URLPatternSet* extent1,
- URLPatternSet* extent2) {
- URLPatternList patterns1 = extent1->patterns();
- URLPatternList patterns2 = extent2->patterns();
+static void AssertEqualExtents(const URLPatternSet& extent1,
+ const URLPatternSet& extent2) {
+ URLPatternList patterns1 = extent1.patterns();
+ URLPatternList patterns2 = extent2.patterns();
std::set<std::string> strings1;
EXPECT_EQ(patterns1.size(), patterns2.size());
@@ -1372,17 +1372,15 @@ TEST_F(ExtensionServiceTest, GrantedPermissions) {
ExtensionPrefs* prefs = service_->extension_prefs();
std::set<std::string> expected_api_perms;
- std::set<std::string> known_api_perms;
- bool full_access;
URLPatternSet expected_host_perms;
- URLPatternSet known_host_perms;
+ bool initialized = false;
// Make sure there aren't any granted permissions before the
// extension is installed.
- EXPECT_FALSE(prefs->GetGrantedPermissions(
- permissions_crx, &full_access, &known_api_perms, &known_host_perms));
- EXPECT_TRUE(known_api_perms.empty());
- EXPECT_TRUE(known_host_perms.is_empty());
+ scoped_ptr<ExtensionPermissionSet> known_perms(
+ prefs->GetGrantedPermissions(permissions_crx, &initialized));
+ EXPECT_FALSE(initialized);
+ EXPECT_TRUE(known_perms->IsEmpty());
PackAndInstallCrx(path, pem_path, true);
@@ -1391,7 +1389,6 @@ TEST_F(ExtensionServiceTest, GrantedPermissions) {
std::string extension_id = service_->extensions()->at(0)->id();
EXPECT_EQ(permissions_crx, extension_id);
-
// Verify that the valid API permissions have been recognized.
expected_api_perms.insert("tabs");
@@ -1400,14 +1397,13 @@ TEST_F(ExtensionServiceTest, GrantedPermissions) {
AddPattern(&expected_host_perms, "http://*.google.com.hk/*");
AddPattern(&expected_host_perms, "http://www.example.com/*");
- EXPECT_TRUE(prefs->GetGrantedPermissions(extension_id,
- &full_access,
- &known_api_perms,
- &known_host_perms));
-
- EXPECT_EQ(expected_api_perms, known_api_perms);
- EXPECT_FALSE(full_access);
- AssertEqualExtents(&expected_host_perms, &known_host_perms);
+ known_perms.reset(prefs->GetGrantedPermissions(extension_id, &initialized));
+ EXPECT_TRUE(initialized);
+ EXPECT_FALSE(known_perms->IsEmpty());
+ EXPECT_EQ(ExtensionAPIPermission::GetAllByName(expected_api_perms),
+ known_perms->apis());
+ EXPECT_FALSE(known_perms->native_code());
+ AssertEqualExtents(expected_host_perms, known_perms->effective_hosts());
}
#if !defined(OS_CHROMEOS)
@@ -1433,15 +1429,12 @@ TEST_F(ExtensionServiceTest, GrantedFullAccessPermissions) {
std::string extension_id = extension->id();
ExtensionPrefs* prefs = service_->extension_prefs();
- bool full_access;
- std::set<std::string> api_permissions;
- URLPatternSet host_permissions;
- EXPECT_TRUE(prefs->GetGrantedPermissions(
- extension_id, &full_access, &api_permissions, &host_permissions));
-
- EXPECT_TRUE(full_access);
- EXPECT_TRUE(api_permissions.empty());
- EXPECT_TRUE(host_permissions.is_empty());
+ scoped_ptr<ExtensionPermissionSet> permissions(
+ prefs->GetGrantedPermissions(extension_id, NULL));
+ EXPECT_FALSE(permissions->IsEmpty());
+ EXPECT_TRUE(permissions->native_code());
+ EXPECT_TRUE(permissions->apis().empty());
+ EXPECT_TRUE(permissions->effective_hosts().is_empty());
}
#endif
@@ -1468,6 +1461,7 @@ TEST_F(ExtensionServiceTest, GrantedAPIAndHostPermissions) {
std::set<std::string> expected_api_permissions;
URLPatternSet expected_host_permissions;
+ bool initialized = false;
expected_api_permissions.insert("tabs");
AddPattern(&expected_host_permissions, "http://*.google.com/*");
@@ -1497,18 +1491,15 @@ TEST_F(ExtensionServiceTest, GrantedAPIAndHostPermissions) {
ASSERT_TRUE(prefs->GetExtensionState(extension_id) == Extension::ENABLED);
ASSERT_FALSE(prefs->DidExtensionEscalatePermissions(extension_id));
- std::set<std::string> current_api_permissions;
- URLPatternSet current_host_permissions;
- bool current_full_access;
-
- ASSERT_TRUE(prefs->GetGrantedPermissions(extension_id,
- &current_full_access,
- &current_api_permissions,
- &current_host_permissions));
-
- ASSERT_FALSE(current_full_access);
- ASSERT_EQ(expected_api_permissions, current_api_permissions);
- AssertEqualExtents(&expected_host_permissions, &current_host_permissions);
+ scoped_ptr<ExtensionPermissionSet> current_perms(
+ prefs->GetGrantedPermissions(extension_id, &initialized));
+ ASSERT_FALSE(current_perms->IsEmpty());
+ ASSERT_TRUE(initialized);
+ ASSERT_FALSE(current_perms->native_code());
+ ASSERT_EQ(ExtensionAPIPermission::GetAllByName(expected_api_permissions),
+ current_perms->apis());
+ AssertEqualExtents(expected_host_permissions,
+ current_perms->effective_hosts());
// Tests that the extension is disabled when a host permission is missing from
// the extension's granted host permissions preference. (This simulates
@@ -1516,8 +1507,7 @@ TEST_F(ExtensionServiceTest, GrantedAPIAndHostPermissions) {
// permissions).
api_permissions.clear();
host_permissions.clear();
- current_api_permissions.clear();
- current_host_permissions.ClearPatterns();
+ current_perms.reset();
api_permissions.insert("tabs");
host_permissions.insert("http://*.google.com/*");
@@ -1541,19 +1531,19 @@ TEST_F(ExtensionServiceTest, GrantedAPIAndHostPermissions) {
ASSERT_TRUE(prefs->GetExtensionState(extension_id) == Extension::ENABLED);
ASSERT_FALSE(prefs->DidExtensionEscalatePermissions(extension_id));
- ASSERT_TRUE(prefs->GetGrantedPermissions(extension_id,
- &current_full_access,
- &current_api_permissions,
- &current_host_permissions));
-
- ASSERT_FALSE(current_full_access);
- ASSERT_EQ(expected_api_permissions, current_api_permissions);
- AssertEqualExtents(&expected_host_permissions, &current_host_permissions);
+ current_perms.reset(
+ prefs->GetGrantedPermissions(extension_id, &initialized));
+ ASSERT_TRUE(initialized);
+ ASSERT_FALSE(current_perms->IsEmpty());
+ ASSERT_FALSE(current_perms->native_code());
+ ASSERT_EQ(ExtensionAPIPermission::GetAllByName(expected_api_permissions),
+ current_perms->apis());
+ AssertEqualExtents(expected_host_permissions,
+ current_perms->effective_hosts());
// Tests that the granted permissions preferences are initialized when
// migrating from the old pref schema.
- current_api_permissions.clear();
- current_host_permissions.ClearPatterns();
+ current_perms.reset();
ClearPref(extension_id, "granted_permissions");
@@ -1565,14 +1555,13 @@ TEST_F(ExtensionServiceTest, GrantedAPIAndHostPermissions) {
ASSERT_TRUE(prefs->GetExtensionState(extension_id) == Extension::ENABLED);
ASSERT_FALSE(prefs->DidExtensionEscalatePermissions(extension_id));
- ASSERT_TRUE(prefs->GetGrantedPermissions(extension_id,
- &current_full_access,
- &current_api_permissions,
- &current_host_permissions));
-
- ASSERT_FALSE(current_full_access);
- ASSERT_EQ(expected_api_permissions, current_api_permissions);
- AssertEqualExtents(&expected_host_permissions, &current_host_permissions);
+ current_perms.reset(prefs->GetGrantedPermissions(extension_id, NULL));
+ ASSERT_FALSE(current_perms->IsEmpty());
+ ASSERT_FALSE(current_perms->native_code());
+ ASSERT_EQ(ExtensionAPIPermission::GetAllByName(expected_api_permissions),
+ current_perms->apis());
+ AssertEqualExtents(expected_host_permissions,
+ current_perms->effective_hosts());
}
// Test Packaging and installing an extension.
@@ -1835,7 +1824,7 @@ TEST_F(ExtensionServiceTest, InstallAppsWithUnlimtedStorage) {
const Extension* extension = service_->extensions()->at(0);
const std::string id1 = extension->id();
EXPECT_TRUE(extension->HasApiPermission(
- Extension::kUnlimitedStoragePermission));
+ ExtensionAPIPermission::UnlimitedStorage()));
EXPECT_TRUE(extension->web_extent().MatchesURL(
extension->GetFullLaunchURL()));
const GURL origin1(extension->GetFullLaunchURL().GetOrigin());
@@ -1849,7 +1838,7 @@ TEST_F(ExtensionServiceTest, InstallAppsWithUnlimtedStorage) {
extension = service_->extensions()->at(1);
const std::string id2 = extension->id();
EXPECT_TRUE(extension->HasApiPermission(
- Extension::kUnlimitedStoragePermission));
+ ExtensionAPIPermission::UnlimitedStorage()));
EXPECT_TRUE(extension->web_extent().MatchesURL(
extension->GetFullLaunchURL()));
const GURL origin2(extension->GetFullLaunchURL().GetOrigin());

Powered by Google App Engine
This is Rietveld 408576698