OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "base/run_loop.h" | 5 #include "base/run_loop.h" |
6 #include "chrome/browser/extensions/extension_install_prompt.h" | 6 #include "chrome/browser/extensions/extension_install_prompt.h" |
7 #include "chrome/browser/extensions/extension_reenabler.h" | 7 #include "chrome/browser/extensions/extension_reenabler.h" |
8 #include "chrome/browser/extensions/extension_service.h" | 8 #include "chrome/browser/extensions/extension_service.h" |
9 #include "chrome/browser/extensions/extension_service_test_base.h" | 9 #include "chrome/browser/extensions/extension_service_test_base.h" |
10 #include "chrome/browser/extensions/extension_system_factory.h" | 10 #include "chrome/browser/extensions/extension_system_factory.h" |
11 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
12 #include "chrome/test/base/testing_profile.h" | 12 #include "chrome/test/base/testing_profile.h" |
13 #include "components/crx_file/id_util.h" | 13 #include "components/crx_file/id_util.h" |
| 14 #include "extensions/browser/extension_dialog_auto_confirm.h" |
14 #include "extensions/browser/extension_registry.h" | 15 #include "extensions/browser/extension_registry.h" |
15 #include "extensions/browser/management_policy.h" | 16 #include "extensions/browser/management_policy.h" |
16 #include "extensions/browser/test_extensions_browser_client.h" | 17 #include "extensions/browser/test_extensions_browser_client.h" |
17 #include "extensions/common/extension.h" | 18 #include "extensions/common/extension.h" |
18 #include "extensions/common/extension_builder.h" | 19 #include "extensions/common/extension_builder.h" |
19 #include "extensions/common/value_builder.h" | 20 #include "extensions/common/value_builder.h" |
20 | 21 |
21 namespace extensions { | 22 namespace extensions { |
22 | 23 |
23 namespace { | 24 namespace { |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 // Check that the ExtensionReenabler can re-enable disabled extensions. | 154 // Check that the ExtensionReenabler can re-enable disabled extensions. |
154 { | 155 { |
155 // Disable the extension due to a permissions increase (the only type of | 156 // Disable the extension due to a permissions increase (the only type of |
156 // disablement we handle with the ExtensionReenabler so far). | 157 // disablement we handle with the ExtensionReenabler so far). |
157 service()->DisableExtension(extension->id(), | 158 service()->DisableExtension(extension->id(), |
158 Extension::DISABLE_PERMISSIONS_INCREASE); | 159 Extension::DISABLE_PERMISSIONS_INCREASE); |
159 // Sanity check that it's disabled. | 160 // Sanity check that it's disabled. |
160 EXPECT_TRUE(registry()->disabled_extensions().Contains(extension->id())); | 161 EXPECT_TRUE(registry()->disabled_extensions().Contains(extension->id())); |
161 | 162 |
162 // Automatically confirm install prompts. | 163 // Automatically confirm install prompts. |
163 ExtensionInstallPrompt::g_auto_confirm_for_tests = | 164 ScopedTestDialogAutoConfirm auto_confirm( |
164 ExtensionInstallPrompt::ACCEPT; | 165 ScopedTestDialogAutoConfirm::ACCEPT); |
165 | 166 |
166 // Run the ExtensionReenabler. | 167 // Run the ExtensionReenabler. |
167 scoped_ptr<ExtensionReenabler> extension_reenabler = | 168 scoped_ptr<ExtensionReenabler> extension_reenabler = |
168 ExtensionReenabler::PromptForReenable(extension, | 169 ExtensionReenabler::PromptForReenable(extension, |
169 profile(), | 170 profile(), |
170 nullptr, // No web contents. | 171 nullptr, // No web contents. |
171 GURL(), // No referrer. | 172 GURL(), // No referrer. |
172 callback_helper.GetCallback()); | 173 callback_helper.GetCallback()); |
173 base::RunLoop().RunUntilIdle(); | 174 base::RunLoop().RunUntilIdle(); |
174 | 175 |
175 // The extension should be enabled. | 176 // The extension should be enabled. |
176 EXPECT_TRUE(registry()->enabled_extensions().Contains(extension->id())); | 177 EXPECT_TRUE(registry()->enabled_extensions().Contains(extension->id())); |
177 EXPECT_TRUE( | 178 EXPECT_TRUE( |
178 callback_helper.result_matches(ExtensionReenabler::REENABLE_SUCCESS)); | 179 callback_helper.result_matches(ExtensionReenabler::REENABLE_SUCCESS)); |
179 } | 180 } |
180 | 181 |
181 // Check that we don't re-enable extensions that must remain disabled, and | 182 // Check that we don't re-enable extensions that must remain disabled, and |
182 // that the re-enabler reports failure correctly. | 183 // that the re-enabler reports failure correctly. |
183 { | 184 { |
| 185 ScopedTestDialogAutoConfirm auto_confirm( |
| 186 ScopedTestDialogAutoConfirm::ACCEPT); |
| 187 |
184 ManagementPolicy* management_policy = | 188 ManagementPolicy* management_policy = |
185 ExtensionSystem::Get(browser_context())->management_policy(); | 189 ExtensionSystem::Get(browser_context())->management_policy(); |
186 ASSERT_TRUE(management_policy); | 190 ASSERT_TRUE(management_policy); |
187 TestManagementProvider test_provider; | 191 TestManagementProvider test_provider; |
188 management_policy->RegisterProvider(&test_provider); | 192 management_policy->RegisterProvider(&test_provider); |
189 service()->DisableExtension(extension->id(), | 193 service()->DisableExtension(extension->id(), |
190 Extension::DISABLE_PERMISSIONS_INCREASE); | 194 Extension::DISABLE_PERMISSIONS_INCREASE); |
191 | 195 |
192 scoped_ptr<ExtensionReenabler> extension_reenabler = | 196 scoped_ptr<ExtensionReenabler> extension_reenabler = |
193 ExtensionReenabler::PromptForReenable(extension, | 197 ExtensionReenabler::PromptForReenable(extension, |
194 profile(), | 198 profile(), |
195 nullptr, // No web contents. | 199 nullptr, // No web contents. |
196 GURL(), // No referrer. | 200 GURL(), // No referrer. |
197 callback_helper.GetCallback()); | 201 callback_helper.GetCallback()); |
198 base::RunLoop().RunUntilIdle(); | 202 base::RunLoop().RunUntilIdle(); |
199 | 203 |
200 // The extension should be enabled. | 204 // The extension should be enabled. |
201 EXPECT_TRUE(registry()->disabled_extensions().Contains(extension->id())); | 205 EXPECT_TRUE(registry()->disabled_extensions().Contains(extension->id())); |
202 EXPECT_TRUE( | 206 EXPECT_TRUE( |
203 callback_helper.result_matches(ExtensionReenabler::NOT_ALLOWED)); | 207 callback_helper.result_matches(ExtensionReenabler::NOT_ALLOWED)); |
204 | 208 |
205 management_policy->UnregisterProvider(&test_provider); | 209 management_policy->UnregisterProvider(&test_provider); |
206 } | 210 } |
207 | 211 |
208 // Check that canceling the re-enable prompt doesn't re-enable the extension. | 212 // Check that canceling the re-enable prompt doesn't re-enable the extension. |
209 { | 213 { |
210 // Disable it again, and try canceling the prompt. | 214 // Disable it again, and try canceling the prompt. |
211 service()->DisableExtension(extension->id(), | 215 service()->DisableExtension(extension->id(), |
212 Extension::DISABLE_PERMISSIONS_INCREASE); | 216 Extension::DISABLE_PERMISSIONS_INCREASE); |
213 ExtensionInstallPrompt::g_auto_confirm_for_tests = | 217 ScopedTestDialogAutoConfirm auto_confirm( |
214 ExtensionInstallPrompt::CANCEL; | 218 ScopedTestDialogAutoConfirm::CANCEL); |
215 scoped_ptr<ExtensionReenabler> extension_reenabler = | 219 scoped_ptr<ExtensionReenabler> extension_reenabler = |
216 ExtensionReenabler::PromptForReenable(extension, | 220 ExtensionReenabler::PromptForReenable(extension, |
217 profile(), | 221 profile(), |
218 nullptr, // No web contents. | 222 nullptr, // No web contents. |
219 GURL(), // No referrer. | 223 GURL(), // No referrer. |
220 callback_helper.GetCallback()); | 224 callback_helper.GetCallback()); |
221 base::RunLoop().RunUntilIdle(); | 225 base::RunLoop().RunUntilIdle(); |
222 | 226 |
223 // The extension should remain disabled. | 227 // The extension should remain disabled. |
224 EXPECT_TRUE(registry()->disabled_extensions().Contains(extension->id())); | 228 EXPECT_TRUE(registry()->disabled_extensions().Contains(extension->id())); |
225 EXPECT_TRUE( | 229 EXPECT_TRUE( |
226 callback_helper.result_matches(ExtensionReenabler::USER_CANCELED)); | 230 callback_helper.result_matches(ExtensionReenabler::USER_CANCELED)); |
227 } | 231 } |
228 | 232 |
229 // Test that if the extension is re-enabled while the prompt is active, the | 233 // Test that if the extension is re-enabled while the prompt is active, the |
230 // prompt exits and reports success. | 234 // prompt exits and reports success. |
231 { | 235 { |
232 // Don't auto-confirm, so that the prompt "stays around". | |
233 ExtensionInstallPrompt::g_auto_confirm_for_tests = | |
234 ExtensionInstallPrompt::NONE; | |
235 base::RunLoop run_loop; | 236 base::RunLoop run_loop; |
236 scoped_ptr<ExtensionReenabler> extension_reenabler = | 237 scoped_ptr<ExtensionReenabler> extension_reenabler = |
237 ExtensionReenabler::PromptForReenableWithPromptForTest( | 238 ExtensionReenabler::PromptForReenableWithPromptForTest( |
238 extension, | 239 extension, |
239 profile(), | 240 profile(), |
240 callback_helper.GetCallback(), | 241 callback_helper.GetCallback(), |
241 callback_helper.CreateTestPrompt(nullptr, run_loop.QuitClosure())); | 242 callback_helper.CreateTestPrompt(nullptr, run_loop.QuitClosure())); |
242 run_loop.Run(); | 243 run_loop.Run(); |
243 | 244 |
244 // We shouldn't have any result yet (the user hasn't confirmed or canceled). | 245 // We shouldn't have any result yet (the user hasn't confirmed or canceled). |
(...skipping 22 matching lines...) Expand all Loading... |
267 EXPECT_FALSE(callback_helper.has_result()); | 268 EXPECT_FALSE(callback_helper.has_result()); |
268 // Destroy the reenabler to simulate the owning context being shut down | 269 // Destroy the reenabler to simulate the owning context being shut down |
269 // (e.g., the tab closing). | 270 // (e.g., the tab closing). |
270 extension_reenabler.reset(); | 271 extension_reenabler.reset(); |
271 EXPECT_TRUE( | 272 EXPECT_TRUE( |
272 callback_helper.result_matches(ExtensionReenabler::ABORTED)); | 273 callback_helper.result_matches(ExtensionReenabler::ABORTED)); |
273 } | 274 } |
274 } | 275 } |
275 | 276 |
276 } // namespace extensions | 277 } // namespace extensions |
OLD | NEW |