OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/command_line.h" | |
6 #include "base/files/file_path.h" | 5 #include "base/files/file_path.h" |
7 #include "base/files/scoped_temp_dir.h" | 6 #include "base/files/scoped_temp_dir.h" |
8 #include "base/strings/string_util.h" | 7 #include "base/strings/string_util.h" |
9 #include "base/strings/stringprintf.h" | 8 #include "base/strings/stringprintf.h" |
10 #include "chrome/browser/chrome_notification_types.h" | 9 #include "chrome/browser/chrome_notification_types.h" |
11 #include "chrome/browser/extensions/api/management/management_api.h" | 10 #include "chrome/browser/extensions/api/management/management_api.h" |
12 #include "chrome/browser/extensions/api/management/management_api_constants.h" | 11 #include "chrome/browser/extensions/api/management/management_api_constants.h" |
13 #include "chrome/browser/extensions/extension_browsertest.h" | 12 #include "chrome/browser/extensions/extension_browsertest.h" |
14 #include "chrome/browser/extensions/extension_function_test_utils.h" | 13 #include "chrome/browser/extensions/extension_function_test_utils.h" |
15 #include "chrome/browser/extensions/extension_service.h" | 14 #include "chrome/browser/extensions/extension_service.h" |
16 #include "chrome/browser/extensions/extension_test_message_listener.h" | 15 #include "chrome/browser/extensions/extension_test_message_listener.h" |
17 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
18 #include "chrome/browser/ui/browser.h" | 17 #include "chrome/browser/ui/browser.h" |
19 #include "chrome/common/chrome_switches.h" | |
20 #include "content/public/browser/notification_service.h" | 18 #include "content/public/browser/notification_service.h" |
21 #include "content/public/common/url_constants.h" | 19 #include "content/public/common/url_constants.h" |
22 #include "content/public/test/browser_test_utils.h" | 20 #include "content/public/test/browser_test_utils.h" |
23 #include "content/public/test/test_utils.h" | 21 #include "content/public/test/test_utils.h" |
24 #include "extensions/browser/extension_host.h" | 22 #include "extensions/browser/extension_host.h" |
25 #include "extensions/browser/extension_prefs.h" | 23 #include "extensions/browser/extension_prefs.h" |
26 #include "extensions/browser/extension_system.h" | 24 #include "extensions/browser/extension_system.h" |
27 | 25 |
28 namespace keys = extension_management_api_constants; | 26 namespace keys = extension_management_api_constants; |
29 namespace util = extension_function_test_utils; | 27 namespace util = extension_function_test_utils; |
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
283 EXPECT_TRUE(dict->GetStringASCII(keys::kDisabledReasonKey, &reason)); | 281 EXPECT_TRUE(dict->GetStringASCII(keys::kDisabledReasonKey, &reason)); |
284 EXPECT_EQ(reason, std::string(keys::kDisabledReasonPermissionsIncrease)); | 282 EXPECT_EQ(reason, std::string(keys::kDisabledReasonPermissionsIncrease)); |
285 } | 283 } |
286 | 284 |
287 IN_PROC_BROWSER_TEST_F(ExtensionManagementApiEscalationTest, | 285 IN_PROC_BROWSER_TEST_F(ExtensionManagementApiEscalationTest, |
288 SetEnabled) { | 286 SetEnabled) { |
289 // Expect an error about no gesture. | 287 // Expect an error about no gesture. |
290 SetEnabled(true, false, keys::kGestureNeededForEscalationError); | 288 SetEnabled(true, false, keys::kGestureNeededForEscalationError); |
291 | 289 |
292 // Expect an error that user cancelled the dialog. | 290 // Expect an error that user cancelled the dialog. |
293 CommandLine::ForCurrentProcess()->AppendSwitchASCII( | 291 ExtensionInstallPrompt::g_auto_confirm_for_tests = |
294 switches::kAppsGalleryInstallAutoConfirmForTests, "cancel"); | 292 ExtensionInstallPrompt::CANCEL; |
295 SetEnabled(true, true, keys::kUserDidNotReEnableError); | 293 SetEnabled(true, true, keys::kUserDidNotReEnableError); |
296 | 294 |
297 // This should succeed when user accepts dialog. We must wait for the process | 295 // This should succeed when user accepts dialog. We must wait for the process |
298 // to connect *and* for the channel to finish initializing before trying to | 296 // to connect *and* for the channel to finish initializing before trying to |
299 // crash it. (NOTIFICATION_RENDERER_PROCESS_CREATED does not wait for the | 297 // crash it. (NOTIFICATION_RENDERER_PROCESS_CREATED does not wait for the |
300 // latter and can cause KillProcess to fail on Windows.) | 298 // latter and can cause KillProcess to fail on Windows.) |
301 content::WindowedNotificationObserver observer( | 299 content::WindowedNotificationObserver observer( |
302 chrome::NOTIFICATION_EXTENSION_HOST_CREATED, | 300 chrome::NOTIFICATION_EXTENSION_HOST_CREATED, |
303 content::NotificationService::AllSources()); | 301 content::NotificationService::AllSources()); |
304 CommandLine::ForCurrentProcess()->AppendSwitchASCII( | 302 ExtensionInstallPrompt::g_auto_confirm_for_tests = |
305 switches::kAppsGalleryInstallAutoConfirmForTests, "accept"); | 303 ExtensionInstallPrompt::ACCEPT; |
306 SetEnabled(true, true, std::string()); | 304 SetEnabled(true, true, std::string()); |
307 observer.Wait(); | 305 observer.Wait(); |
308 | 306 |
309 // Crash the extension. Mock a reload by disabling and then enabling. The | 307 // Crash the extension. Mock a reload by disabling and then enabling. The |
310 // extension should be reloaded and enabled. | 308 // extension should be reloaded and enabled. |
311 ASSERT_TRUE(CrashEnabledExtension(kId)); | 309 ASSERT_TRUE(CrashEnabledExtension(kId)); |
312 SetEnabled(false, true, std::string()); | 310 SetEnabled(false, true, std::string()); |
313 SetEnabled(true, true, std::string()); | 311 SetEnabled(true, true, std::string()); |
314 const Extension* extension = ExtensionSystem::Get(browser()->profile()) | 312 const Extension* extension = ExtensionSystem::Get(browser()->profile()) |
315 ->extension_service()->GetExtensionById(kId, false); | 313 ->extension_service()->GetExtensionById(kId, false); |
316 EXPECT_TRUE(extension); | 314 EXPECT_TRUE(extension); |
317 } | 315 } |
318 | 316 |
319 } // namespace extensions | 317 } // namespace extensions |
OLD | NEW |