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/test_utils.h" | 23 #include "content/public/test/test_utils.h" |
24 | 24 |
25 namespace keys = extension_management_api_constants; | 25 namespace keys = extension_management_api_constants; |
26 namespace util = extension_function_test_utils; | 26 namespace util = extension_function_test_utils; |
27 | 27 |
| 28 namespace extensions { |
| 29 |
28 class ExtensionManagementApiBrowserTest : public ExtensionBrowserTest { | 30 class ExtensionManagementApiBrowserTest : public ExtensionBrowserTest { |
29 protected: | 31 protected: |
30 bool CrashEnabledExtension(const std::string& extension_id) { | 32 bool CrashEnabledExtension(const std::string& extension_id) { |
31 content::WindowedNotificationObserver extension_crash_observer( | 33 content::WindowedNotificationObserver extension_crash_observer( |
32 chrome::NOTIFICATION_EXTENSION_PROCESS_TERMINATED, | 34 chrome::NOTIFICATION_EXTENSION_PROCESS_TERMINATED, |
33 content::NotificationService::AllSources()); | 35 content::NotificationService::AllSources()); |
34 extensions::ExtensionHost* background_host = | 36 ExtensionHost* background_host = |
35 extensions::ExtensionSystem::Get(browser()->profile())-> | 37 ExtensionSystem::Get(browser()->profile())-> |
36 process_manager()->GetBackgroundHostForExtension(extension_id); | 38 process_manager()->GetBackgroundHostForExtension(extension_id); |
37 if (!background_host) | 39 if (!background_host) |
38 return false; | 40 return false; |
39 background_host->host_contents()->GetController().LoadURL( | 41 background_host->host_contents()->GetController().LoadURL( |
40 GURL(chrome::kChromeUICrashURL), content::Referrer(), | 42 GURL(chrome::kChromeUICrashURL), content::Referrer(), |
41 content::PAGE_TRANSITION_LINK, std::string()); | 43 content::PAGE_TRANSITION_LINK, std::string()); |
42 extension_crash_observer.Wait(); | 44 extension_crash_observer.Wait(); |
43 return true; | 45 return true; |
44 } | 46 } |
45 }; | 47 }; |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 ExtensionTestMessageListener listener1("success", false); | 88 ExtensionTestMessageListener listener1("success", false); |
87 ASSERT_TRUE(LoadExtension( | 89 ASSERT_TRUE(LoadExtension( |
88 test_data_dir_.AppendASCII("management/self_uninstall_helper"))); | 90 test_data_dir_.AppendASCII("management/self_uninstall_helper"))); |
89 ASSERT_TRUE(LoadExtension( | 91 ASSERT_TRUE(LoadExtension( |
90 test_data_dir_.AppendASCII("management/self_uninstall"))); | 92 test_data_dir_.AppendASCII("management/self_uninstall"))); |
91 ASSERT_TRUE(listener1.WaitUntilSatisfied()); | 93 ASSERT_TRUE(listener1.WaitUntilSatisfied()); |
92 } | 94 } |
93 | 95 |
94 IN_PROC_BROWSER_TEST_F(ExtensionManagementApiBrowserTest, | 96 IN_PROC_BROWSER_TEST_F(ExtensionManagementApiBrowserTest, |
95 UninstallWithConfirmDialog) { | 97 UninstallWithConfirmDialog) { |
96 ExtensionService* service = extensions::ExtensionSystem::Get( | 98 ExtensionService* service = ExtensionSystem::Get(browser()->profile())-> |
97 browser()->profile())->extension_service(); | 99 extension_service(); |
98 | 100 |
99 // Install an extension. | 101 // Install an extension. |
100 const extensions::Extension* extension = InstallExtension( | 102 const Extension* extension = InstallExtension( |
101 test_data_dir_.AppendASCII("api_test/management/enabled_extension"), 1); | 103 test_data_dir_.AppendASCII("api_test/management/enabled_extension"), 1); |
102 ASSERT_TRUE(extension); | 104 ASSERT_TRUE(extension); |
103 | 105 |
104 const std::string id = extension->id(); | 106 const std::string id = extension->id(); |
105 | 107 |
106 // Uninstall, then cancel via the confirm dialog. | 108 // Uninstall, then cancel via the confirm dialog. |
107 scoped_refptr<UninstallFunction> uninstall_function(new UninstallFunction()); | 109 scoped_refptr<UninstallFunction> uninstall_function(new UninstallFunction()); |
108 UninstallFunction::SetAutoConfirmForTest(false); | 110 UninstallFunction::SetAutoConfirmForTest(false); |
109 | 111 |
110 EXPECT_TRUE(MatchPattern( | 112 EXPECT_TRUE(MatchPattern( |
(...skipping 18 matching lines...) Expand all Loading... |
129 | 131 |
130 // Make sure the extension was uninstalled. | 132 // Make sure the extension was uninstalled. |
131 EXPECT_TRUE(service->GetExtensionById(id, false) == NULL); | 133 EXPECT_TRUE(service->GetExtensionById(id, false) == NULL); |
132 } | 134 } |
133 | 135 |
134 IN_PROC_BROWSER_TEST_F(ExtensionManagementApiBrowserTest, | 136 IN_PROC_BROWSER_TEST_F(ExtensionManagementApiBrowserTest, |
135 GetAllIncludesTerminated) { | 137 GetAllIncludesTerminated) { |
136 // Load an extension with a background page, so that we know it has a process | 138 // Load an extension with a background page, so that we know it has a process |
137 // running. | 139 // running. |
138 ExtensionTestMessageListener listener("ready", false); | 140 ExtensionTestMessageListener listener("ready", false); |
139 const extensions::Extension* extension = LoadExtension( | 141 const Extension* extension = LoadExtension( |
140 test_data_dir_.AppendASCII("management/install_event")); | 142 test_data_dir_.AppendASCII("management/install_event")); |
141 ASSERT_TRUE(extension); | 143 ASSERT_TRUE(extension); |
142 ASSERT_TRUE(listener.WaitUntilSatisfied()); | 144 ASSERT_TRUE(listener.WaitUntilSatisfied()); |
143 | 145 |
144 // The management API should list this extension. | 146 // The management API should list this extension. |
145 scoped_refptr<GetAllExtensionsFunction> function = | 147 scoped_refptr<GetAllExtensionsFunction> function = |
146 new GetAllExtensionsFunction(); | 148 new GetAllExtensionsFunction(); |
147 scoped_ptr<base::Value> result(util::RunFunctionAndReturnSingleResult( | 149 scoped_ptr<base::Value> result(util::RunFunctionAndReturnSingleResult( |
148 function.get(), "[]", browser())); | 150 function.get(), "[]", browser())); |
149 base::ListValue* list; | 151 base::ListValue* list; |
(...skipping 24 matching lines...) Expand all Loading... |
174 test_data_dir_.AppendASCII("permissions_increase").AppendASCII("v1"), | 176 test_data_dir_.AppendASCII("permissions_increase").AppendASCII("v1"), |
175 scoped_temp_dir_.path().AppendASCII("permissions1.crx"), | 177 scoped_temp_dir_.path().AppendASCII("permissions1.crx"), |
176 pem_path, | 178 pem_path, |
177 FilePath()); | 179 FilePath()); |
178 FilePath path_v2 = PackExtensionWithOptions( | 180 FilePath path_v2 = PackExtensionWithOptions( |
179 test_data_dir_.AppendASCII("permissions_increase").AppendASCII("v2"), | 181 test_data_dir_.AppendASCII("permissions_increase").AppendASCII("v2"), |
180 scoped_temp_dir_.path().AppendASCII("permissions2.crx"), | 182 scoped_temp_dir_.path().AppendASCII("permissions2.crx"), |
181 pem_path, | 183 pem_path, |
182 FilePath()); | 184 FilePath()); |
183 | 185 |
184 ExtensionService* service = extensions::ExtensionSystem::Get( | 186 ExtensionService* service = ExtensionSystem::Get(browser()->profile())-> |
185 browser()->profile())->extension_service(); | 187 extension_service(); |
186 | 188 |
187 // Install low-permission version of the extension. | 189 // Install low-permission version of the extension. |
188 ASSERT_TRUE(InstallExtension(path_v1, 1)); | 190 ASSERT_TRUE(InstallExtension(path_v1, 1)); |
189 EXPECT_TRUE(service->GetExtensionById(kId, false) != NULL); | 191 EXPECT_TRUE(service->GetExtensionById(kId, false) != NULL); |
190 | 192 |
191 // Update to a high-permission version - it should get disabled. | 193 // Update to a high-permission version - it should get disabled. |
192 EXPECT_FALSE(UpdateExtension(kId, path_v2, -1)); | 194 EXPECT_FALSE(UpdateExtension(kId, path_v2, -1)); |
193 EXPECT_TRUE(service->GetExtensionById(kId, false) == NULL); | 195 EXPECT_TRUE(service->GetExtensionById(kId, false) == NULL); |
194 EXPECT_TRUE(service->GetExtensionById(kId, true) != NULL); | 196 EXPECT_TRUE(service->GetExtensionById(kId, true) != NULL); |
195 EXPECT_TRUE( | 197 EXPECT_TRUE( |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
253 // This should succeed when user accepts dialog. | 255 // This should succeed when user accepts dialog. |
254 CommandLine::ForCurrentProcess()->AppendSwitchASCII( | 256 CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
255 switches::kAppsGalleryInstallAutoConfirmForTests, "accept"); | 257 switches::kAppsGalleryInstallAutoConfirmForTests, "accept"); |
256 SetEnabled(true, true, ""); | 258 SetEnabled(true, true, ""); |
257 | 259 |
258 // Crash the extension. Mock a reload by disabling and then enabling. The | 260 // Crash the extension. Mock a reload by disabling and then enabling. The |
259 // extension should be reloaded and enabled. | 261 // extension should be reloaded and enabled. |
260 ASSERT_TRUE(CrashEnabledExtension(kId)); | 262 ASSERT_TRUE(CrashEnabledExtension(kId)); |
261 SetEnabled(false, true, ""); | 263 SetEnabled(false, true, ""); |
262 SetEnabled(true, true, ""); | 264 SetEnabled(true, true, ""); |
263 const extensions::Extension* extension = browser()->profile()-> | 265 const Extension* extension = ExtensionSystem::Get(browser()->profile())-> |
264 GetExtensionService()->GetExtensionById(kId, false); | 266 extension_service()->GetExtensionById(kId, false); |
265 EXPECT_TRUE(extension); | 267 EXPECT_TRUE(extension); |
266 } | 268 } |
| 269 |
| 270 } // namespace extensions |
OLD | NEW |