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

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

Issue 2019423007: Re-enable extensions disabled due to permission increase if they have all permissions (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@ext_update_test
Patch Set: Created 4 years, 7 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 76212643f7420042f0f4f85eca7bbe195cb2dc0f..cb05dd5c5e29d9f7bab46e557e9d2de0f41070a0 100644
--- a/chrome/browser/extensions/extension_service_unittest.cc
+++ b/chrome/browser/extensions/extension_service_unittest.cc
@@ -1429,12 +1429,14 @@ TEST_F(ExtensionServiceTest, GrantedPermissionsOnUpdate) {
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");
+ const base::FilePath path5 = base_path.AppendASCII("update_5");
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));
+ ASSERT_TRUE(base::PathExists(path5));
ExtensionPrefs* prefs = ExtensionPrefs::Get(profile());
@@ -1503,6 +1505,115 @@ TEST_F(ExtensionServiceTest, GrantedPermissionsOnUpdate) {
ASSERT_TRUE(known_perms.get());
EXPECT_EQ(expected_api_perms, known_perms->apis());
}
+
+ // Update to version 5 that removes the kNotifications permission again.
+ // The extension should get re-enabled.
+ PackCRXAndUpdateExtension(id, path5, pem_path, ENABLED);
+ extension = service()->GetInstalledExtension(id);
+ ASSERT_TRUE(extension);
+ EXPECT_TRUE(registry()->enabled_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());
+ }
+}
+
+TEST_F(ExtensionServiceTest, ReenableWithAllPermissionsGranted) {
Devlin 2016/06/02 16:05:55 How does this differ from the last test?
Marc Treib 2016/06/02 16:36:14 Right - this is essentially the same as the "versi
Marc Treib 2016/06/10 14:12:17 Done. (Removed the added part of the above test ag
+ 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 path4 = base_path.AppendASCII("update_4");
+ const base::FilePath path5 = base_path.AppendASCII("update_5");
+
+ ASSERT_TRUE(base::PathExists(pem_path));
+ ASSERT_TRUE(base::PathExists(path1));
+ ASSERT_TRUE(base::PathExists(path4));
+ ASSERT_TRUE(base::PathExists(path5));
+
+ 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));
+
+ // Update to version 4 that adds the kNotifications permission, which has a
+ // message and hence is considered a permission increase. The extension
+ // should get disabled due to a permissions increase.
+ PackCRXAndUpdateExtension(id, path4, pem_path, DISABLED);
+ extension = service()->GetInstalledExtension(id);
+ ASSERT_TRUE(extension);
+ EXPECT_TRUE(registry()->disabled_extensions().Contains(id));
+ EXPECT_TRUE(
+ prefs->HasDisableReason(id, Extension::DISABLE_PERMISSIONS_INCREASE));
+
+ // Update to version 5 that removes the kNotifications permission again.
+ // The extension should get re-enabled.
+ PackCRXAndUpdateExtension(id, path5, pem_path, ENABLED);
+ extension = service()->GetInstalledExtension(id);
+ ASSERT_TRUE(extension);
+ EXPECT_TRUE(registry()->enabled_extensions().Contains(id));
+}
+
+TEST_F(ExtensionServiceTest,
+ DontReenableWithAllPermissionsGrantedButOtherReason) {
+ 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 path4 = base_path.AppendASCII("update_4");
+ const base::FilePath path5 = base_path.AppendASCII("update_5");
+
+ ASSERT_TRUE(base::PathExists(pem_path));
+ ASSERT_TRUE(base::PathExists(path1));
+ ASSERT_TRUE(base::PathExists(path4));
+ ASSERT_TRUE(base::PathExists(path5));
+
+ 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));
+
+ // Disable the extension.
+ service()->DisableExtension(id, Extension::DISABLE_USER_ACTION);
+ EXPECT_TRUE(registry()->disabled_extensions().Contains(id));
+ EXPECT_TRUE(prefs->HasDisableReason(id, Extension::DISABLE_USER_ACTION));
+
+ // Update to version 4 that adds the kNotifications permission, which has a
+ // message and hence is considered a permission increase. The extension
+ // should get disabled due to a permissions increase.
+ PackCRXAndUpdateExtension(id, path4, pem_path, DISABLED);
+ extension = service()->GetInstalledExtension(id);
+ ASSERT_TRUE(extension);
+ EXPECT_TRUE(registry()->disabled_extensions().Contains(id));
+ EXPECT_TRUE(
+ prefs->HasDisableReason(id, Extension::DISABLE_PERMISSIONS_INCREASE));
+ // The USER_ACTION reason should also still be there.
+ EXPECT_TRUE(prefs->HasDisableReason(id, Extension::DISABLE_USER_ACTION));
+
+ // Update to version 5 that removes the kNotifications permission again.
+ // The PERMISSIONS_INCREASE should be removed, but the extension should stay
+ // disabled since USER_ACTION is still there.
+ PackCRXAndUpdateExtension(id, path5, pem_path, DISABLED);
+ extension = service()->GetInstalledExtension(id);
+ ASSERT_TRUE(extension);
+ EXPECT_TRUE(registry()->disabled_extensions().Contains(id));
+ EXPECT_FALSE(
+ prefs->HasDisableReason(id, Extension::DISABLE_PERMISSIONS_INCREASE));
+ EXPECT_TRUE(prefs->HasDisableReason(id, Extension::DISABLE_USER_ACTION));
Devlin 2016/06/02 16:05:55 Could even just EXPECT_EQ() here, right?
Marc Treib 2016/06/02 16:36:15 Sure, done.
}
Devlin 2016/06/02 16:05:55 How hard would it be to add a test that checks the
Marc Treib 2016/06/02 16:36:14 Shouldn't be too hard - I guess we can simulate a
#if !defined(OS_CHROMEOS)

Powered by Google App Engine
This is Rietveld 408576698