Chromium Code Reviews| 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..de1d92cb78c41f716012f22d64487d21cdaeaa60 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) { |
|
not at google - send to devlin
2015/02/25 21:37:57
Looks like this test can be split up into several
Devlin
2015/02/25 23:12:47
Given the amount of set-up/tear-down needed for ea
|
| + // We need to be on the UI thread for this. |
| + ResetThreadBundle(content::TestBrowserThreadBundle::DEFAULT); |
|
not at google - send to devlin
2015/02/25 21:37:57
See comment in ExtensionServiceTestBase.
Devlin
2015/02/25 23:12:47
Acknowledged.
|
| + 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 install should have failed. |
|
not at google - send to devlin
2015/02/25 21:37:57
uninstall?
Devlin
2015/02/25 23:12:47
Done.
|
| + 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 |