OLD | NEW |
---|---|
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" |
11 #include "chrome/test/base/test_browser_window.h" | 11 #include "chrome/test/base/test_browser_window.h" |
12 #include "extensions/browser/api/management/management_api.h" | 12 #include "extensions/browser/api/management/management_api.h" |
13 #include "extensions/browser/api/management/management_api_constants.h" | 13 #include "extensions/browser/api/management/management_api_constants.h" |
14 #include "extensions/browser/extension_dialog_auto_confirm.h" | |
14 #include "extensions/browser/extension_prefs.h" | 15 #include "extensions/browser/extension_prefs.h" |
15 #include "extensions/browser/extension_registry.h" | 16 #include "extensions/browser/extension_registry.h" |
16 #include "extensions/browser/extension_system.h" | 17 #include "extensions/browser/extension_system.h" |
17 #include "extensions/browser/management_policy.h" | 18 #include "extensions/browser/management_policy.h" |
18 #include "extensions/browser/test_management_policy.h" | 19 #include "extensions/browser/test_management_policy.h" |
19 #include "extensions/common/error_utils.h" | 20 #include "extensions/common/error_utils.h" |
20 #include "extensions/common/extension.h" | 21 #include "extensions/common/extension.h" |
21 #include "extensions/common/extension_set.h" | 22 #include "extensions/common/extension_set.h" |
22 #include "extensions/common/test_util.h" | 23 #include "extensions/common/test_util.h" |
23 | 24 |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
142 // We need to be on the UI thread for this. | 143 // We need to be on the UI thread for this. |
143 ResetThreadBundle(content::TestBrowserThreadBundle::DEFAULT); | 144 ResetThreadBundle(content::TestBrowserThreadBundle::DEFAULT); |
144 scoped_refptr<const Extension> extension = test_util::CreateEmptyExtension(); | 145 scoped_refptr<const Extension> extension = test_util::CreateEmptyExtension(); |
145 service()->AddExtension(extension.get()); | 146 service()->AddExtension(extension.get()); |
146 std::string extension_id = extension->id(); | 147 std::string extension_id = extension->id(); |
147 | 148 |
148 base::ListValue uninstall_args; | 149 base::ListValue uninstall_args; |
149 uninstall_args.AppendString(extension->id()); | 150 uninstall_args.AppendString(extension->id()); |
150 | 151 |
151 // Auto-accept any uninstalls. | 152 // Auto-accept any uninstalls. |
152 ManagementUninstallFunctionBase::SetAutoConfirmForTest(true); | 153 { |
154 ScopedExtensionDialogAutoConfirm auto_confirm( | |
155 &g_auto_confirm_uninstall_for_testing, AUTO_CONFIRM_ACCEPT); | |
153 | 156 |
154 // Uninstall requires a user gesture, so this should fail. | 157 // Uninstall requires a user gesture, so this should fail. |
155 scoped_refptr<UIThreadExtensionFunction> function( | 158 scoped_refptr<UIThreadExtensionFunction> function( |
156 new ManagementUninstallFunction()); | 159 new ManagementUninstallFunction()); |
157 EXPECT_FALSE(RunFunction(function, uninstall_args)); | 160 EXPECT_FALSE(RunFunction(function, uninstall_args)); |
158 EXPECT_EQ(std::string(constants::kGestureNeededForUninstallError), | 161 EXPECT_EQ(std::string(constants::kGestureNeededForUninstallError), |
159 function->GetError()); | 162 function->GetError()); |
160 | 163 |
161 ExtensionFunction::ScopedUserGestureForTests scoped_user_gesture; | 164 ExtensionFunction::ScopedUserGestureForTests scoped_user_gesture; |
162 | 165 |
163 function = new ManagementUninstallFunction(); | 166 function = new ManagementUninstallFunction(); |
164 EXPECT_TRUE(registry()->enabled_extensions().Contains(extension_id)); | 167 EXPECT_TRUE(registry()->enabled_extensions().Contains(extension_id)); |
165 EXPECT_TRUE(RunFunction(function, uninstall_args)) << function->GetError(); | 168 EXPECT_TRUE(RunFunction(function, uninstall_args)) << function->GetError(); |
166 // The extension should be uninstalled. | 169 // The extension should be uninstalled. |
167 EXPECT_FALSE(registry()->GetExtensionById( | 170 EXPECT_FALSE(registry()->GetExtensionById(extension_id, |
168 extension_id, ExtensionRegistry::EVERYTHING)); | 171 ExtensionRegistry::EVERYTHING)); |
172 } | |
169 | 173 |
170 // Install the extension again, and try uninstalling, auto-canceling the | 174 // Install the extension again, and try uninstalling, auto-canceling the |
171 // dialog. | 175 // dialog. |
172 service()->AddExtension(extension.get()); | 176 { |
Devlin
2015/05/29 15:29:20
This is a combination of Rietveld being silly and
| |
173 function = new ManagementUninstallFunction(); | 177 ScopedExtensionDialogAutoConfirm auto_confirm( |
174 ManagementUninstallFunctionBase::SetAutoConfirmForTest(false); | 178 &g_auto_confirm_uninstall_for_testing, AUTO_CONFIRM_CANCEL); |
175 EXPECT_TRUE(registry()->enabled_extensions().Contains(extension_id)); | 179 ExtensionFunction::ScopedUserGestureForTests scoped_user_gesture; |
176 EXPECT_FALSE(RunFunction(function, uninstall_args)); | |
177 // The uninstall should have failed. | |
178 EXPECT_TRUE(registry()->enabled_extensions().Contains(extension_id)); | |
179 EXPECT_EQ(ErrorUtils::FormatErrorMessage(constants::kUninstallCanceledError, | |
180 extension_id), | |
181 function->GetError()); | |
182 | 180 |
183 // Try again, using showConfirmDialog: false. | 181 service()->AddExtension(extension.get()); |
184 scoped_ptr<base::DictionaryValue> options(new base::DictionaryValue()); | 182 scoped_refptr<UIThreadExtensionFunction> function = |
185 options->SetBoolean("showConfirmDialog", false); | 183 new ManagementUninstallFunction(); |
186 uninstall_args.Append(options.release()); | 184 EXPECT_TRUE(registry()->enabled_extensions().Contains(extension_id)); |
187 function = new ManagementUninstallFunction(); | 185 EXPECT_FALSE(RunFunction(function, uninstall_args)); |
188 EXPECT_TRUE(registry()->enabled_extensions().Contains(extension_id)); | 186 // The uninstall should have failed. |
189 EXPECT_FALSE(RunFunction(function, uninstall_args)); | 187 EXPECT_TRUE(registry()->enabled_extensions().Contains(extension_id)); |
190 // This should still fail, since extensions can only suppress the dialog for | 188 EXPECT_EQ(ErrorUtils::FormatErrorMessage(constants::kUninstallCanceledError, |
191 // uninstalling themselves. | 189 extension_id), |
192 EXPECT_TRUE(registry()->enabled_extensions().Contains(extension_id)); | 190 function->GetError()); |
193 EXPECT_EQ(ErrorUtils::FormatErrorMessage(constants::kUninstallCanceledError, | |
194 extension_id), | |
195 function->GetError()); | |
196 | 191 |
197 // If we try uninstall the extension itself, the uninstall should succeed | 192 // Try again, using showConfirmDialog: false. |
198 // (even though we auto-cancel any dialog), because the dialog is never shown. | 193 scoped_ptr<base::DictionaryValue> options(new base::DictionaryValue()); |
199 uninstall_args.Remove(0u, nullptr); | 194 options->SetBoolean("showConfirmDialog", false); |
200 function = new ManagementUninstallSelfFunction(); | 195 uninstall_args.Append(options.release()); |
201 function->set_extension(extension); | 196 function = new ManagementUninstallFunction(); |
202 EXPECT_TRUE(registry()->enabled_extensions().Contains(extension_id)); | 197 EXPECT_TRUE(registry()->enabled_extensions().Contains(extension_id)); |
203 EXPECT_TRUE(RunFunction(function, uninstall_args)) << function->GetError(); | 198 EXPECT_FALSE(RunFunction(function, uninstall_args)); |
204 EXPECT_FALSE(registry()->GetExtensionById( | 199 // This should still fail, since extensions can only suppress the dialog for |
205 extension_id, ExtensionRegistry::EVERYTHING)); | 200 // uninstalling themselves. |
201 EXPECT_TRUE(registry()->enabled_extensions().Contains(extension_id)); | |
202 EXPECT_EQ(ErrorUtils::FormatErrorMessage(constants::kUninstallCanceledError, | |
203 extension_id), | |
204 function->GetError()); | |
205 | |
206 // If we try uninstall the extension itself, the uninstall should succeed | |
207 // (even though we auto-cancel any dialog), because the dialog is never | |
208 // shown. | |
209 uninstall_args.Remove(0u, nullptr); | |
210 function = new ManagementUninstallSelfFunction(); | |
211 function->set_extension(extension); | |
212 EXPECT_TRUE(registry()->enabled_extensions().Contains(extension_id)); | |
213 EXPECT_TRUE(RunFunction(function, uninstall_args)) << function->GetError(); | |
214 EXPECT_FALSE(registry()->GetExtensionById(extension_id, | |
215 ExtensionRegistry::EVERYTHING)); | |
216 } | |
206 } | 217 } |
207 | 218 |
208 } // namespace extensions | 219 } // namespace extensions |
OLD | NEW |