| 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 771bd4213061ffb10d0fe9d9bea59dbfcfee71ae..1cb5b02c3dd9c74b21c01de308e64eba3ea464c5 100644
|
| --- a/chrome/browser/extensions/api/management/management_api_unittest.cc
|
| +++ b/chrome/browser/extensions/api/management/management_api_unittest.cc
|
| @@ -11,6 +11,7 @@
|
| #include "chrome/test/base/test_browser_window.h"
|
| #include "extensions/browser/api/management/management_api.h"
|
| #include "extensions/browser/api/management/management_api_constants.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"
|
| @@ -149,60 +150,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
|
|
|