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

Side by Side Diff: chrome/browser/extensions/api/management/management_api_unittest.cc

Issue 948413005: [Extensions] Make chrome://extensions use management.uninstall (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 9 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 unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/extensions/extension_function_test_utils.h" 5 #include "chrome/browser/extensions/extension_function_test_utils.h"
6 #include "chrome/browser/extensions/extension_service.h" 6 #include "chrome/browser/extensions/extension_service.h"
7 #include "chrome/browser/extensions/extension_service_test_base.h" 7 #include "chrome/browser/extensions/extension_service_test_base.h"
8 #include "chrome/browser/extensions/test_extension_system.h" 8 #include "chrome/browser/extensions/test_extension_system.h"
9 #include "chrome/browser/ui/browser.h" 9 #include "chrome/browser/ui/browser.h"
10 #include "chrome/browser/ui/host_desktop.h" 10 #include "chrome/browser/ui/host_desktop.h"
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 std::string extension_id = extension->id(); 98 std::string extension_id = extension->id();
99 scoped_refptr<ManagementSetEnabledFunction> function( 99 scoped_refptr<ManagementSetEnabledFunction> function(
100 new ManagementSetEnabledFunction()); 100 new ManagementSetEnabledFunction());
101 101
102 base::ListValue disable_args; 102 base::ListValue disable_args;
103 disable_args.AppendString(extension_id); 103 disable_args.AppendString(extension_id);
104 disable_args.AppendBoolean(false); 104 disable_args.AppendBoolean(false);
105 105
106 // Test disabling an (enabled) extension. 106 // Test disabling an (enabled) extension.
107 EXPECT_TRUE(registry()->enabled_extensions().Contains(extension_id)); 107 EXPECT_TRUE(registry()->enabled_extensions().Contains(extension_id));
108 EXPECT_TRUE(RunFunction(function, disable_args)); 108 EXPECT_TRUE(RunFunction(function, disable_args)) << function->GetError();
109 EXPECT_TRUE(registry()->disabled_extensions().Contains(extension_id)); 109 EXPECT_TRUE(registry()->disabled_extensions().Contains(extension_id));
110 110
111 base::ListValue enable_args; 111 base::ListValue enable_args;
112 enable_args.AppendString(extension_id); 112 enable_args.AppendString(extension_id);
113 enable_args.AppendBoolean(true); 113 enable_args.AppendBoolean(true);
114 114
115 // Test re-enabling it. 115 // Test re-enabling it.
116 function = new ManagementSetEnabledFunction(); 116 function = new ManagementSetEnabledFunction();
117 EXPECT_TRUE(RunFunction(function, enable_args)); 117 EXPECT_TRUE(RunFunction(function, enable_args)) << function->GetError();
118 EXPECT_TRUE(registry()->enabled_extensions().Contains(extension_id)); 118 EXPECT_TRUE(registry()->enabled_extensions().Contains(extension_id));
119 119
120 // Test that the enable function checks management policy, so that we can't 120 // Test that the enable function checks management policy, so that we can't
121 // disable an extension that is required. 121 // disable an extension that is required.
122 TestManagementPolicyProvider provider( 122 TestManagementPolicyProvider provider(
123 TestManagementPolicyProvider::PROHIBIT_MODIFY_STATUS); 123 TestManagementPolicyProvider::PROHIBIT_MODIFY_STATUS);
124 ManagementPolicy* policy = 124 ManagementPolicy* policy =
125 ExtensionSystem::Get(profile())->management_policy(); 125 ExtensionSystem::Get(profile())->management_policy();
126 policy->RegisterProvider(&provider); 126 policy->RegisterProvider(&provider);
127 127
128 function = new ManagementSetEnabledFunction(); 128 function = new ManagementSetEnabledFunction();
129 EXPECT_FALSE(RunFunction(function, disable_args)); 129 EXPECT_FALSE(RunFunction(function, disable_args));
130 EXPECT_EQ(ErrorUtils::FormatErrorMessage(constants::kUserCantModifyError, 130 EXPECT_EQ(ErrorUtils::FormatErrorMessage(constants::kUserCantModifyError,
131 extension_id), 131 extension_id),
132 function->GetError()); 132 function->GetError());
133 policy->UnregisterProvider(&provider); 133 policy->UnregisterProvider(&provider);
134 134
135 // TODO(devlin): We should also test enabling an extenion that has escalated 135 // TODO(devlin): We should also test enabling an extenion that has escalated
136 // permissions, but that needs a web contents (which is a bit of a pain in a 136 // permissions, but that needs a web contents (which is a bit of a pain in a
137 // unit test). 137 // unit test).
138 } 138 }
139 139
140 // Tests management.uninstall.
141 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
142 // We need to be on the UI thread for this.
143 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.
144 scoped_refptr<const Extension> extension = test_util::CreateEmptyExtension();
145 service()->AddExtension(extension.get());
146 std::string extension_id = extension->id();
147
148 base::ListValue uninstall_args;
149 uninstall_args.AppendString(extension->id());
150
151 // Auto-accept any uninstalls.
152 ManagementUninstallFunctionBase::SetAutoConfirmForTest(true);
153
154 // Uninstall requires a user gesture, so this should fail.
155 scoped_refptr<UIThreadExtensionFunction> function(
156 new ManagementUninstallFunction());
157 EXPECT_FALSE(RunFunction(function, uninstall_args));
158 EXPECT_EQ(std::string(constants::kGestureNeededForUninstallError),
159 function->GetError());
160
161 ExtensionFunction::ScopedUserGestureForTests scoped_user_gesture;
162
163 function = new ManagementUninstallFunction();
164 EXPECT_TRUE(registry()->enabled_extensions().Contains(extension_id));
165 EXPECT_TRUE(RunFunction(function, uninstall_args)) << function->GetError();
166 // The extension should be uninstalled.
167 EXPECT_FALSE(registry()->GetExtensionById(
168 extension_id, ExtensionRegistry::EVERYTHING));
169
170 // Install the extension again, and try uninstalling, auto-canceling the
171 // dialog.
172 service()->AddExtension(extension.get());
173 function = new ManagementUninstallFunction();
174 ManagementUninstallFunctionBase::SetAutoConfirmForTest(false);
175 EXPECT_TRUE(registry()->enabled_extensions().Contains(extension_id));
176 EXPECT_FALSE(RunFunction(function, uninstall_args));
177 // 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.
178 EXPECT_TRUE(registry()->enabled_extensions().Contains(extension_id));
179 EXPECT_EQ(ErrorUtils::FormatErrorMessage(constants::kUninstallCanceledError,
180 extension_id),
181 function->GetError());
182
183 // Try again, using showConfirmDialog: false.
184 scoped_ptr<base::DictionaryValue> options(new base::DictionaryValue());
185 options->SetBoolean("showConfirmDialog", false);
186 uninstall_args.Append(options.release());
187 function = new ManagementUninstallFunction();
188 EXPECT_TRUE(registry()->enabled_extensions().Contains(extension_id));
189 EXPECT_FALSE(RunFunction(function, uninstall_args));
190 // This should still fail, since extensions can only suppress the dialog for
191 // uninstalling themselves.
192 EXPECT_TRUE(registry()->enabled_extensions().Contains(extension_id));
193 EXPECT_EQ(ErrorUtils::FormatErrorMessage(constants::kUninstallCanceledError,
194 extension_id),
195 function->GetError());
196
197 // If we try uninstall the extension itself, the uninstall should succeed
198 // (even though we auto-cancel any dialog), because the dialog is never shown.
199 uninstall_args.Remove(0u, nullptr);
200 function = new ManagementUninstallSelfFunction();
201 function->set_extension(extension);
202 EXPECT_TRUE(registry()->enabled_extensions().Contains(extension_id));
203 EXPECT_TRUE(RunFunction(function, uninstall_args)) << function->GetError();
204 EXPECT_FALSE(registry()->GetExtensionById(
205 extension_id, ExtensionRegistry::EVERYTHING));
206 }
207
140 } // namespace extensions 208 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698