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" | 5 #include "base/command_line.h" |
6 #include "base/files/file_path.h" | 6 #include "base/files/file_path.h" |
7 #include "base/files/scoped_temp_dir.h" | 7 #include "base/files/scoped_temp_dir.h" |
8 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
9 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
10 #include "chrome/browser/chrome_notification_types.h" | 10 #include "chrome/browser/chrome_notification_types.h" |
11 #include "chrome/browser/extensions/api/management/management_api.h" | 11 #include "chrome/browser/extensions/api/management/management_api.h" |
12 #include "chrome/browser/extensions/api/management/management_api_constants.h" | 12 #include "chrome/browser/extensions/api/management/management_api_constants.h" |
13 #include "chrome/browser/extensions/extension_browsertest.h" | 13 #include "chrome/browser/extensions/extension_browsertest.h" |
14 #include "chrome/browser/extensions/extension_function_test_utils.h" | 14 #include "chrome/browser/extensions/extension_function_test_utils.h" |
15 #include "chrome/browser/extensions/extension_host.h" | 15 #include "chrome/browser/extensions/extension_host.h" |
16 #include "chrome/browser/extensions/extension_service.h" | 16 #include "chrome/browser/extensions/extension_service.h" |
17 #include "chrome/browser/extensions/extension_system.h" | 17 #include "chrome/browser/extensions/extension_system.h" |
18 #include "chrome/browser/extensions/extension_test_message_listener.h" | 18 #include "chrome/browser/extensions/extension_test_message_listener.h" |
19 #include "chrome/browser/profiles/profile.h" | 19 #include "chrome/browser/profiles/profile.h" |
20 #include "chrome/browser/ui/browser.h" | 20 #include "chrome/browser/ui/browser.h" |
21 #include "chrome/common/chrome_switches.h" | 21 #include "chrome/common/chrome_switches.h" |
22 #include "content/public/browser/notification_service.h" | 22 #include "content/public/browser/notification_service.h" |
23 #include "content/public/common/url_constants.h" | 23 #include "content/public/common/url_constants.h" |
| 24 #include "content/public/test/browser_test_utils.h" |
24 #include "content/public/test/test_utils.h" | 25 #include "content/public/test/test_utils.h" |
25 | 26 |
26 namespace keys = extension_management_api_constants; | 27 namespace keys = extension_management_api_constants; |
27 namespace util = extension_function_test_utils; | 28 namespace util = extension_function_test_utils; |
28 | 29 |
29 namespace extensions { | 30 namespace extensions { |
30 | 31 |
31 class ExtensionManagementApiBrowserTest : public ExtensionBrowserTest { | 32 class ExtensionManagementApiBrowserTest : public ExtensionBrowserTest { |
32 protected: | 33 protected: |
33 bool CrashEnabledExtension(const std::string& extension_id) { | 34 bool CrashEnabledExtension(const std::string& extension_id) { |
34 content::WindowedNotificationObserver extension_crash_observer( | |
35 chrome::NOTIFICATION_EXTENSION_PROCESS_TERMINATED, | |
36 content::NotificationService::AllSources()); | |
37 ExtensionHost* background_host = | 35 ExtensionHost* background_host = |
38 ExtensionSystem::Get(browser()->profile())-> | 36 ExtensionSystem::Get(browser()->profile())-> |
39 process_manager()->GetBackgroundHostForExtension(extension_id); | 37 process_manager()->GetBackgroundHostForExtension(extension_id); |
40 if (!background_host) | 38 if (!background_host) |
41 return false; | 39 return false; |
42 background_host->host_contents()->GetController().LoadURL( | 40 content::CrashTab(background_host->host_contents()); |
43 GURL(content::kChromeUICrashURL), content::Referrer(), | |
44 content::PAGE_TRANSITION_LINK, std::string()); | |
45 extension_crash_observer.Wait(); | |
46 return true; | 41 return true; |
47 } | 42 } |
48 }; | 43 }; |
49 | 44 |
50 // We test this here instead of in an ExtensionApiTest because normal extensions | 45 // We test this here instead of in an ExtensionApiTest because normal extensions |
51 // are not allowed to call the install function. | 46 // are not allowed to call the install function. |
52 IN_PROC_BROWSER_TEST_F(ExtensionManagementApiBrowserTest, InstallEvent) { | 47 IN_PROC_BROWSER_TEST_F(ExtensionManagementApiBrowserTest, InstallEvent) { |
53 ExtensionTestMessageListener listener1("ready", false); | 48 ExtensionTestMessageListener listener1("ready", false); |
54 ASSERT_TRUE(LoadExtension( | 49 ASSERT_TRUE(LoadExtension( |
55 test_data_dir_.AppendASCII("management/install_event"))); | 50 test_data_dir_.AppendASCII("management/install_event"))); |
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
258 IN_PROC_BROWSER_TEST_F(ExtensionManagementApiEscalationTest, | 253 IN_PROC_BROWSER_TEST_F(ExtensionManagementApiEscalationTest, |
259 SetEnabled) { | 254 SetEnabled) { |
260 // Expect an error about no gesture. | 255 // Expect an error about no gesture. |
261 SetEnabled(true, false, keys::kGestureNeededForEscalationError); | 256 SetEnabled(true, false, keys::kGestureNeededForEscalationError); |
262 | 257 |
263 // Expect an error that user cancelled the dialog. | 258 // Expect an error that user cancelled the dialog. |
264 CommandLine::ForCurrentProcess()->AppendSwitchASCII( | 259 CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
265 switches::kAppsGalleryInstallAutoConfirmForTests, "cancel"); | 260 switches::kAppsGalleryInstallAutoConfirmForTests, "cancel"); |
266 SetEnabled(true, true, keys::kUserDidNotReEnableError); | 261 SetEnabled(true, true, keys::kUserDidNotReEnableError); |
267 | 262 |
268 // This should succeed when user accepts dialog. | 263 // This should succeed when user accepts dialog. We must wait for the process |
| 264 // to connect *and* for the channel to finish initializing before trying to |
| 265 // crash it. (NOTIFICATION_RENDERER_PROCESS_CREATED does not wait for the |
| 266 // latter and can cause KillProcess to fail on Windows.) |
| 267 content::WindowedNotificationObserver observer( |
| 268 chrome::NOTIFICATION_EXTENSION_HOST_CREATED, |
| 269 content::NotificationService::AllSources()); |
269 CommandLine::ForCurrentProcess()->AppendSwitchASCII( | 270 CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
270 switches::kAppsGalleryInstallAutoConfirmForTests, "accept"); | 271 switches::kAppsGalleryInstallAutoConfirmForTests, "accept"); |
271 SetEnabled(true, true, std::string()); | 272 SetEnabled(true, true, std::string()); |
| 273 observer.Wait(); |
272 | 274 |
273 // Crash the extension. Mock a reload by disabling and then enabling. The | 275 // Crash the extension. Mock a reload by disabling and then enabling. The |
274 // extension should be reloaded and enabled. | 276 // extension should be reloaded and enabled. |
275 ASSERT_TRUE(CrashEnabledExtension(kId)); | 277 ASSERT_TRUE(CrashEnabledExtension(kId)); |
276 SetEnabled(false, true, std::string()); | 278 SetEnabled(false, true, std::string()); |
277 SetEnabled(true, true, std::string()); | 279 SetEnabled(true, true, std::string()); |
278 const Extension* extension = ExtensionSystem::Get(browser()->profile()) | 280 const Extension* extension = ExtensionSystem::Get(browser()->profile()) |
279 ->extension_service()->GetExtensionById(kId, false); | 281 ->extension_service()->GetExtensionById(kId, false); |
280 EXPECT_TRUE(extension); | 282 EXPECT_TRUE(extension); |
281 } | 283 } |
282 | 284 |
283 } // namespace extensions | 285 } // namespace extensions |
OLD | NEW |