Index: chrome/browser/extensions/api/management/management_api_unittest.cc |
diff --git a/chrome/browser/extensions/api/management/management_api_unittest.cc b/chrome/browser/extensions/api/management/management_api_unittest.cc |
index e783a7f96ec1d909c11214cd88641b7e237b9e36..4d0a4d9fecbe9d0154b812092cfbe60c9b4647a5 100644 |
--- a/chrome/browser/extensions/api/management/management_api_unittest.cc |
+++ b/chrome/browser/extensions/api/management/management_api_unittest.cc |
@@ -13,6 +13,7 @@ |
#include "extensions/browser/api/management/management_api.h" |
#include "extensions/browser/api/management/management_api_constants.h" |
#include "extensions/browser/event_router_factory.h" |
+#include "extensions/browser/extension_dialog_auto_confirm.h" |
#include "extensions/browser/extension_prefs.h" |
#include "extensions/browser/extension_registry.h" |
#include "extensions/browser/extension_system.h" |
@@ -156,60 +157,70 @@ TEST_F(ManagementApiUnitTest, ManagementUninstall) { |
uninstall_args.AppendString(extension->id()); |
// Auto-accept any uninstalls. |
- ManagementUninstallFunctionBase::SetAutoConfirmForTest(true); |
- |
- // Uninstall requires a user gesture, so this should fail. |
- scoped_refptr<UIThreadExtensionFunction> function( |
- new ManagementUninstallFunction()); |
- EXPECT_FALSE(RunFunction(function, uninstall_args)); |
- EXPECT_EQ(std::string(constants::kGestureNeededForUninstallError), |
- function->GetError()); |
- |
- ExtensionFunction::ScopedUserGestureForTests scoped_user_gesture; |
- |
- function = new ManagementUninstallFunction(); |
- EXPECT_TRUE(registry()->enabled_extensions().Contains(extension_id)); |
- EXPECT_TRUE(RunFunction(function, uninstall_args)) << function->GetError(); |
- // The extension should be uninstalled. |
- EXPECT_FALSE(registry()->GetExtensionById( |
- extension_id, ExtensionRegistry::EVERYTHING)); |
+ { |
+ ScopedTestDialogAutoConfirm auto_confirm( |
+ ScopedTestDialogAutoConfirm::ACCEPT); |
+ |
+ // Uninstall requires a user gesture, so this should fail. |
+ scoped_refptr<UIThreadExtensionFunction> function( |
+ new ManagementUninstallFunction()); |
+ EXPECT_FALSE(RunFunction(function, uninstall_args)); |
+ EXPECT_EQ(std::string(constants::kGestureNeededForUninstallError), |
+ function->GetError()); |
+ |
+ ExtensionFunction::ScopedUserGestureForTests scoped_user_gesture; |
+ |
+ function = new ManagementUninstallFunction(); |
+ EXPECT_TRUE(registry()->enabled_extensions().Contains(extension_id)); |
+ EXPECT_TRUE(RunFunction(function, uninstall_args)) << function->GetError(); |
+ // The extension should be uninstalled. |
+ EXPECT_FALSE(registry()->GetExtensionById(extension_id, |
+ ExtensionRegistry::EVERYTHING)); |
+ } |
// Install the extension again, and try uninstalling, auto-canceling the |
// dialog. |
- service()->AddExtension(extension.get()); |
- function = new ManagementUninstallFunction(); |
- ManagementUninstallFunctionBase::SetAutoConfirmForTest(false); |
- EXPECT_TRUE(registry()->enabled_extensions().Contains(extension_id)); |
- EXPECT_FALSE(RunFunction(function, uninstall_args)); |
- // The uninstall should have failed. |
- EXPECT_TRUE(registry()->enabled_extensions().Contains(extension_id)); |
- EXPECT_EQ(ErrorUtils::FormatErrorMessage(constants::kUninstallCanceledError, |
- extension_id), |
- function->GetError()); |
- |
- // Try again, using showConfirmDialog: false. |
- scoped_ptr<base::DictionaryValue> options(new base::DictionaryValue()); |
- options->SetBoolean("showConfirmDialog", false); |
- uninstall_args.Append(options.release()); |
- function = new ManagementUninstallFunction(); |
- EXPECT_TRUE(registry()->enabled_extensions().Contains(extension_id)); |
- EXPECT_FALSE(RunFunction(function, uninstall_args)); |
- // This should still fail, since extensions can only suppress the dialog for |
- // uninstalling themselves. |
- EXPECT_TRUE(registry()->enabled_extensions().Contains(extension_id)); |
- EXPECT_EQ(ErrorUtils::FormatErrorMessage(constants::kUninstallCanceledError, |
- extension_id), |
- function->GetError()); |
- |
- // If we try uninstall the extension itself, the uninstall should succeed |
- // (even though we auto-cancel any dialog), because the dialog is never shown. |
- uninstall_args.Remove(0u, nullptr); |
- function = new ManagementUninstallSelfFunction(); |
- function->set_extension(extension); |
- EXPECT_TRUE(registry()->enabled_extensions().Contains(extension_id)); |
- EXPECT_TRUE(RunFunction(function, uninstall_args)) << function->GetError(); |
- EXPECT_FALSE(registry()->GetExtensionById( |
- extension_id, ExtensionRegistry::EVERYTHING)); |
+ { |
+ ScopedTestDialogAutoConfirm auto_confirm( |
+ ScopedTestDialogAutoConfirm::CANCEL); |
+ ExtensionFunction::ScopedUserGestureForTests scoped_user_gesture; |
+ |
+ service()->AddExtension(extension.get()); |
+ scoped_refptr<UIThreadExtensionFunction> function = |
+ new ManagementUninstallFunction(); |
+ EXPECT_TRUE(registry()->enabled_extensions().Contains(extension_id)); |
+ EXPECT_FALSE(RunFunction(function, uninstall_args)); |
+ // The uninstall should have failed. |
+ EXPECT_TRUE(registry()->enabled_extensions().Contains(extension_id)); |
+ EXPECT_EQ(ErrorUtils::FormatErrorMessage(constants::kUninstallCanceledError, |
+ extension_id), |
+ function->GetError()); |
+ |
+ // Try again, using showConfirmDialog: false. |
+ scoped_ptr<base::DictionaryValue> options(new base::DictionaryValue()); |
+ options->SetBoolean("showConfirmDialog", false); |
+ uninstall_args.Append(options.release()); |
+ function = new ManagementUninstallFunction(); |
+ EXPECT_TRUE(registry()->enabled_extensions().Contains(extension_id)); |
+ EXPECT_FALSE(RunFunction(function, uninstall_args)); |
+ // This should still fail, since extensions can only suppress the dialog for |
+ // uninstalling themselves. |
+ EXPECT_TRUE(registry()->enabled_extensions().Contains(extension_id)); |
+ EXPECT_EQ(ErrorUtils::FormatErrorMessage(constants::kUninstallCanceledError, |
+ extension_id), |
+ function->GetError()); |
+ |
+ // If we try uninstall the extension itself, the uninstall should succeed |
+ // (even though we auto-cancel any dialog), because the dialog is never |
+ // shown. |
+ uninstall_args.Remove(0u, nullptr); |
+ function = new ManagementUninstallSelfFunction(); |
+ function->set_extension(extension); |
+ EXPECT_TRUE(registry()->enabled_extensions().Contains(extension_id)); |
+ EXPECT_TRUE(RunFunction(function, uninstall_args)) << function->GetError(); |
+ EXPECT_FALSE(registry()->GetExtensionById(extension_id, |
+ ExtensionRegistry::EVERYTHING)); |
+ } |
} |
} // namespace extensions |