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

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

Issue 10014005: Add a preference for why an extension is disabled. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 8 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_disabled_ui_browsertest.cc
diff --git a/chrome/browser/extensions/extension_disabled_ui_browsertest.cc b/chrome/browser/extensions/extension_disabled_ui_browsertest.cc
index d908fa0f60458bfaad4919cbeb132071ce8679ce..f27dbf7654ece58abc630b649ca8c6a9885bf871 100644
--- a/chrome/browser/extensions/extension_disabled_ui_browsertest.cc
+++ b/chrome/browser/extensions/extension_disabled_ui_browsertest.cc
@@ -4,9 +4,11 @@
#include "chrome/app/chrome_command_ids.h"
#include "chrome/browser/extensions/extension_browsertest.h"
+#include "chrome/browser/extensions/extension_prefs.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h"
+#include "chrome/browser/ui/global_error.h"
#include "chrome/browser/ui/global_error_service.h"
#include "chrome/browser/ui/global_error_service_factory.h"
#include "chrome/common/extensions/extension.h"
@@ -24,32 +26,46 @@ class ExtensionDisabledGlobalErrorTest : public ExtensionBrowserTest {
GetGlobalErrorByMenuItemCommandID(IDC_EXTENSION_DISABLED_FIRST);
}
- // Helper function to install an extension and upgrade it to a version
- // requiring additional permissions. Returns the new disabled Extension.
- const Extension* InstallAndUpdateIncreasingPermissionsExtension() {
+ // Install the initial version, which should happen just fine.
+ const Extension* InstallIncreasingPermissionExtensionV1() {
size_t size_before = service_->extensions()->size();
-
- // Install the initial version, which should happen just fine.
const Extension* extension = InstallExtension(
test_data_dir_.AppendASCII("permissions-low-v1.crx"), 1);
if (!extension)
return NULL;
if (service_->extensions()->size() != size_before + 1)
return NULL;
+ return extension;
+ }
- // Upgrade to a version that wants more permissions. We should disable the
- // extension and prompt the user to reenable.
+ // Upgrade to a version that wants more permissions. We should disable the
+ // extension and prompt the user to reenable.
+ const Extension* UpdateIncreasingPermissionExtension(
+ const Extension* extension,
+ const std::string& crx_file,
+ int expected_change) {
+ size_t size_before = service_->extensions()->size();
if (UpdateExtension(
extension->id(),
- test_data_dir_.AppendASCII("permissions-high-v2.crx"), -1))
+ test_data_dir_.AppendASCII(crx_file),
+ expected_change))
return NULL;
- EXPECT_EQ(size_before, service_->extensions()->size());
+ EXPECT_EQ(size_before + expected_change, service_->extensions()->size());
if (service_->disabled_extensions()->size() != 1u)
return NULL;
return *service_->disabled_extensions()->begin();
}
+ // Helper function to install an extension and upgrade it to a version
+ // requiring additional permissions. Returns the new disabled Extension.
+ const Extension* InstallAndUpdateIncreasingPermissionsExtension() {
+ const Extension* extension = InstallIncreasingPermissionExtensionV1();
+ extension = UpdateIncreasingPermissionExtension(
+ extension, "permissions-high-v2.crx", -1);
+ return extension;
+ }
+
ExtensionService* service_;
};
@@ -79,3 +95,53 @@ IN_PROC_BROWSER_TEST_F(ExtensionDisabledGlobalErrorTest, Uninstall) {
EXPECT_EQ(0u, service_->disabled_extensions()->size());
ASSERT_FALSE(GetExtensionDisabledGlobalError());
}
+
+// Tests that no error appears if the user disabled the extension.
+IN_PROC_BROWSER_TEST_F(ExtensionDisabledGlobalErrorTest, UserDisabled) {
+ const Extension* extension = InstallIncreasingPermissionExtensionV1();
+ DisableExtension(extension->id());
+ extension = UpdateIncreasingPermissionExtension(
+ extension, "permissions-high-v2.crx", 0);
+ ASSERT_FALSE(GetExtensionDisabledGlobalError());
+}
+
+// Test that no error appears if the disable reason is unknown
+// (but probably was by the user).
+IN_PROC_BROWSER_TEST_F(ExtensionDisabledGlobalErrorTest,
+ UnknownReasonSamePermissions) {
+ const Extension* extension = InstallIncreasingPermissionExtensionV1();
+ DisableExtension(extension->id());
+ // Override disable reason to UNKNOWN to simulate legacy disables.
+ service_->extension_prefs()->SetDisableReason(
+ extension->id(), ExtensionPrefs::DISABLE_UNKNOWN);
+ // Upgrade to version 2. Infer from version 1 having the same permissions
+ // granted by the user that it was disabled by the user.
+ extension = UpdateIncreasingPermissionExtension(
+ extension, "permissions-high-v2.crx", 0);
+ ASSERT_TRUE(extension);
+ ASSERT_FALSE(GetExtensionDisabledGlobalError());
+}
+
+// Test that an error appears if the disable reason is unknown
+// (but probably was for increased permissions).
+IN_PROC_BROWSER_TEST_F(ExtensionDisabledGlobalErrorTest,
+ UnknownReasonHigherPermissions) {
+ const Extension* extension = InstallAndUpdateIncreasingPermissionsExtension();
+ // Override disable reason to UNKNOWN to simulate legacy disables.
+ // We now have version 2 but only accepted permissions for version 1.
+ service_->extension_prefs()->SetDisableReason(
+ extension->id(), ExtensionPrefs::DISABLE_UNKNOWN);
+ GlobalError* error = GetExtensionDisabledGlobalError();
+ ASSERT_TRUE(error);
+ // Also, remove the upgrade error for version 2.
+ GlobalErrorServiceFactory::GetForProfile(browser()->profile())->
+ RemoveGlobalError(error);
+ delete error;
+ // Upgrade to version 3, with even higher permissions. Infer from
+ // version 2 having higher-than-granted permissions that it was disabled
+ // for permissions increase.
+ extension = UpdateIncreasingPermissionExtension(
+ extension, "permissions-higher-v3.crx", 0);
Aaron Boodman 2012/04/09 20:30:48 These crx files are a maintenance problem. Just ch
Yoyo Zhou 2012/04/10 01:57:36 Done.
+ ASSERT_TRUE(extension);
+ ASSERT_TRUE(GetExtensionDisabledGlobalError());
+}

Powered by Google App Engine
This is Rietveld 408576698