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

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

Issue 2083583002: Extensions: Add test for granting nuisance and implied permissions on update (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2743
Patch Set: Created 4 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
« no previous file with comments | « no previous file | chrome/test/data/extensions/permissions/update.pem » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 695a39769bda59edd873808396c7e6c352f761fe..b6032872bfd8db505391cc0c17f33e43d03e6dc9 100644
--- a/chrome/browser/extensions/extension_service_unittest.cc
+++ b/chrome/browser/extensions/extension_service_unittest.cc
@@ -1410,13 +1410,100 @@ TEST_F(ExtensionServiceTest, GrantedPermissions) {
std::unique_ptr<const PermissionSet> known_perms =
prefs->GetGrantedPermissions(extension->id());
- EXPECT_TRUE(known_perms.get());
+ ASSERT_TRUE(known_perms.get());
EXPECT_FALSE(known_perms->IsEmpty());
EXPECT_EQ(expected_api_perms, known_perms->apis());
EXPECT_FALSE(known_perms->HasEffectiveFullAccess());
EXPECT_EQ(expected_host_perms, known_perms->effective_hosts());
}
+// This tests that the granted permissions preferences are correctly set when
+// updating an extension, and the extension is disabled in case of a permission
+// escalation.
+TEST_F(ExtensionServiceTest, GrantedPermissionsOnUpdate) {
+ InitializeEmptyExtensionService();
+ const base::FilePath base_path = data_dir().AppendASCII("permissions");
+
+ const base::FilePath pem_path = base_path.AppendASCII("update.pem");
+ const base::FilePath path1 = base_path.AppendASCII("update_1");
+ const base::FilePath path2 = base_path.AppendASCII("update_2");
+ const base::FilePath path3 = base_path.AppendASCII("update_3");
+ const base::FilePath path4 = base_path.AppendASCII("update_4");
+
+ ASSERT_TRUE(base::PathExists(pem_path));
+ ASSERT_TRUE(base::PathExists(path1));
+ ASSERT_TRUE(base::PathExists(path2));
+ ASSERT_TRUE(base::PathExists(path3));
+ ASSERT_TRUE(base::PathExists(path4));
+
+ ExtensionPrefs* prefs = ExtensionPrefs::Get(profile());
+
+ // Install version 1, which has the kHistory permission.
+ const Extension* extension = PackAndInstallCRX(path1, pem_path, INSTALL_NEW);
+ const std::string id = extension->id();
+
+ EXPECT_EQ(0u, GetErrors().size());
+ ASSERT_TRUE(registry()->enabled_extensions().Contains(id));
+
+ // Verify that the history permission has been recognized.
+ APIPermissionSet expected_api_perms;
+ expected_api_perms.insert(APIPermission::kHistory);
+ {
+ std::unique_ptr<const PermissionSet> known_perms =
+ prefs->GetGrantedPermissions(id);
+ ASSERT_TRUE(known_perms.get());
+ EXPECT_EQ(expected_api_perms, known_perms->apis());
+ }
+
+ // Update to version 2 that adds the kTopSites permission, which has a
+ // separate message, but is implied by kHistory. The extension should remain
+ // enabled.
+ PackCRXAndUpdateExtension(id, path2, pem_path, ENABLED);
+ extension = service()->GetInstalledExtension(id);
+ ASSERT_TRUE(extension);
+ EXPECT_TRUE(registry()->enabled_extensions().Contains(id));
+
+ // The extra permission should have been granted automatically.
+ expected_api_perms.insert(APIPermission::kTopSites);
+ {
+ std::unique_ptr<const PermissionSet> known_perms =
+ prefs->GetGrantedPermissions(id);
+ ASSERT_TRUE(known_perms.get());
+ EXPECT_EQ(expected_api_perms, known_perms->apis());
+ }
+
+ // Update to version 3 that adds the kStorage permission, which does not have
+ // a message. The extension should remain enabled.
+ PackCRXAndUpdateExtension(id, path3, pem_path, ENABLED);
+ extension = service()->GetInstalledExtension(id);
+ ASSERT_TRUE(extension);
+ EXPECT_TRUE(registry()->enabled_extensions().Contains(id));
+
+ // The extra permission should have been granted automatically.
+ expected_api_perms.insert(APIPermission::kStorage);
+ {
+ std::unique_ptr<const PermissionSet> known_perms =
+ prefs->GetGrantedPermissions(id);
+ ASSERT_TRUE(known_perms.get());
+ EXPECT_EQ(expected_api_perms, known_perms->apis());
+ }
+
+ // Update to version 4 that adds the kNotifications permission, which has a
+ // message and hence is considered a permission increase. Now the extension
+ // should get disabled.
+ PackCRXAndUpdateExtension(id, path4, pem_path, DISABLED);
+ extension = service()->GetInstalledExtension(id);
+ ASSERT_TRUE(extension);
+ EXPECT_TRUE(registry()->disabled_extensions().Contains(id));
+
+ // No new permissions should have been granted.
+ {
+ std::unique_ptr<const PermissionSet> known_perms =
+ prefs->GetGrantedPermissions(id);
+ ASSERT_TRUE(known_perms.get());
+ EXPECT_EQ(expected_api_perms, known_perms->apis());
+ }
+}
#if !defined(OS_CHROMEOS)
// This tests that the granted permissions preferences are correctly set for
« no previous file with comments | « no previous file | chrome/test/data/extensions/permissions/update.pem » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698