| 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/file_path.h" | 6 #include "base/file_path.h" |
| 7 #include "base/files/scoped_temp_dir.h" | 7 #include "base/files/scoped_temp_dir.h" |
| 8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
| 9 #include "base/stringprintf.h" | 9 #include "base/stringprintf.h" |
| 10 #include "chrome/browser/extensions/api/management/management_api.h" | 10 #include "chrome/browser/extensions/api/management/management_api.h" |
| 11 #include "chrome/browser/extensions/api/management/management_api_constants.h" | 11 #include "chrome/browser/extensions/api/management/management_api_constants.h" |
| 12 #include "chrome/browser/extensions/extension_browsertest.h" | 12 #include "chrome/browser/extensions/extension_browsertest.h" |
| 13 #include "chrome/browser/extensions/extension_function_test_utils.h" | 13 #include "chrome/browser/extensions/extension_function_test_utils.h" |
| 14 #include "chrome/browser/extensions/extension_host.h" | 14 #include "chrome/browser/extensions/extension_host.h" |
| 15 #include "chrome/browser/extensions/extension_service.h" | 15 #include "chrome/browser/extensions/extension_service.h" |
| 16 #include "chrome/browser/extensions/extension_system.h" | 16 #include "chrome/browser/extensions/extension_system.h" |
| 17 #include "chrome/browser/extensions/extension_test_message_listener.h" | 17 #include "chrome/browser/extensions/extension_test_message_listener.h" |
| 18 #include "chrome/browser/profiles/profile.h" | 18 #include "chrome/browser/profiles/profile.h" |
| 19 #include "chrome/browser/ui/browser.h" | 19 #include "chrome/browser/ui/browser.h" |
| 20 #include "chrome/common/chrome_notification_types.h" | 20 #include "chrome/common/chrome_notification_types.h" |
| 21 #include "chrome/common/chrome_switches.h" | 21 #include "chrome/common/chrome_switches.h" |
| 22 #include "content/public/common/url_constants.h" | 22 #include "content/public/common/url_constants.h" |
| 23 #include "content/public/test/browser_test_utils.h" |
| 23 #include "content/public/test/test_utils.h" | 24 #include "content/public/test/test_utils.h" |
| 24 | 25 |
| 25 namespace keys = extension_management_api_constants; | 26 namespace keys = extension_management_api_constants; |
| 26 namespace util = extension_function_test_utils; | 27 namespace util = extension_function_test_utils; |
| 27 | 28 |
| 28 class ExtensionManagementApiBrowserTest : public ExtensionBrowserTest { | 29 class ExtensionManagementApiBrowserTest : public ExtensionBrowserTest { |
| 29 protected: | 30 protected: |
| 30 bool CrashEnabledExtension(const std::string& extension_id) { | 31 bool CrashEnabledExtension(const std::string& extension_id) { |
| 31 content::WindowedNotificationObserver extension_crash_observer( | |
| 32 chrome::NOTIFICATION_EXTENSION_PROCESS_TERMINATED, | |
| 33 content::NotificationService::AllSources()); | |
| 34 extensions::ExtensionHost* background_host = | 32 extensions::ExtensionHost* background_host = |
| 35 extensions::ExtensionSystem::Get(browser()->profile())-> | 33 extensions::ExtensionSystem::Get(browser()->profile())-> |
| 36 process_manager()->GetBackgroundHostForExtension(extension_id); | 34 process_manager()->GetBackgroundHostForExtension(extension_id); |
| 37 if (!background_host) | 35 if (!background_host) |
| 38 return false; | 36 return false; |
| 39 background_host->host_contents()->GetController().LoadURL( | 37 content::CrashTab(background_host->host_contents()); |
| 40 GURL(chrome::kChromeUICrashURL), content::Referrer(), | |
| 41 content::PAGE_TRANSITION_LINK, std::string()); | |
| 42 extension_crash_observer.Wait(); | |
| 43 return true; | 38 return true; |
| 44 } | 39 } |
| 45 }; | 40 }; |
| 46 | 41 |
| 47 // We test this here instead of in an ExtensionApiTest because normal extensions | 42 // We test this here instead of in an ExtensionApiTest because normal extensions |
| 48 // are not allowed to call the install function. | 43 // are not allowed to call the install function. |
| 49 IN_PROC_BROWSER_TEST_F(ExtensionManagementApiBrowserTest, InstallEvent) { | 44 IN_PROC_BROWSER_TEST_F(ExtensionManagementApiBrowserTest, InstallEvent) { |
| 50 ExtensionTestMessageListener listener1("ready", false); | 45 ExtensionTestMessageListener listener1("ready", false); |
| 51 ASSERT_TRUE(LoadExtension( | 46 ASSERT_TRUE(LoadExtension( |
| 52 test_data_dir_.AppendASCII("management/install_event"))); | 47 test_data_dir_.AppendASCII("management/install_event"))); |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 255 | 250 |
| 256 // Crash the extension. Mock a reload by disabling and then enabling. The | 251 // Crash the extension. Mock a reload by disabling and then enabling. The |
| 257 // extension should be reloaded and enabled. | 252 // extension should be reloaded and enabled. |
| 258 ASSERT_TRUE(CrashEnabledExtension(kId)); | 253 ASSERT_TRUE(CrashEnabledExtension(kId)); |
| 259 SetEnabled(false, true, ""); | 254 SetEnabled(false, true, ""); |
| 260 SetEnabled(true, true, ""); | 255 SetEnabled(true, true, ""); |
| 261 const extensions::Extension* extension = browser()->profile()-> | 256 const extensions::Extension* extension = browser()->profile()-> |
| 262 GetExtensionService()->GetExtensionById(kId, false); | 257 GetExtensionService()->GetExtensionById(kId, false); |
| 263 EXPECT_TRUE(extension); | 258 EXPECT_TRUE(extension); |
| 264 } | 259 } |
| OLD | NEW |