| 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 48fb40ecd4ab86d55fd8b23c1433ca73ef2c80f5..771bd4213061ffb10d0fe9d9bea59dbfcfee71ae 100644
|
| --- a/chrome/browser/extensions/api/management/management_api_unittest.cc
|
| +++ b/chrome/browser/extensions/api/management/management_api_unittest.cc
|
| @@ -105,7 +105,7 @@ TEST_F(ManagementApiUnitTest, ManagementSetEnabled) {
|
|
|
| // Test disabling an (enabled) extension.
|
| EXPECT_TRUE(registry()->enabled_extensions().Contains(extension_id));
|
| - EXPECT_TRUE(RunFunction(function, disable_args));
|
| + EXPECT_TRUE(RunFunction(function, disable_args)) << function->GetError();
|
| EXPECT_TRUE(registry()->disabled_extensions().Contains(extension_id));
|
|
|
| base::ListValue enable_args;
|
| @@ -114,7 +114,7 @@ TEST_F(ManagementApiUnitTest, ManagementSetEnabled) {
|
|
|
| // Test re-enabling it.
|
| function = new ManagementSetEnabledFunction();
|
| - EXPECT_TRUE(RunFunction(function, enable_args));
|
| + EXPECT_TRUE(RunFunction(function, enable_args)) << function->GetError();
|
| EXPECT_TRUE(registry()->enabled_extensions().Contains(extension_id));
|
|
|
| // Test that the enable function checks management policy, so that we can't
|
| @@ -137,4 +137,72 @@ TEST_F(ManagementApiUnitTest, ManagementSetEnabled) {
|
| // unit test).
|
| }
|
|
|
| +// Tests management.uninstall.
|
| +TEST_F(ManagementApiUnitTest, ManagementUninstall) {
|
| + // We need to be on the UI thread for this.
|
| + ResetThreadBundle(content::TestBrowserThreadBundle::DEFAULT);
|
| + scoped_refptr<const Extension> extension = test_util::CreateEmptyExtension();
|
| + service()->AddExtension(extension.get());
|
| + std::string extension_id = extension->id();
|
| +
|
| + base::ListValue uninstall_args;
|
| + 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));
|
| +
|
| + // 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));
|
| +}
|
| +
|
| } // namespace extensions
|
|
|