Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(60)

Side by Side Diff: chrome/browser/extensions/api/management/management_api_browsertest.cc

Issue 10832237: Allow chrome.management.setEnabled() to re-enable crashed extensions. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/scoped_temp_dir.h" 7 #include "base/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_install_dialog.h" 15 #include "chrome/browser/extensions/extension_install_dialog.h"
15 #include "chrome/browser/extensions/extension_service.h" 16 #include "chrome/browser/extensions/extension_service.h"
16 #include "chrome/browser/extensions/extension_test_message_listener.h" 17 #include "chrome/browser/extensions/extension_test_message_listener.h"
17 #include "chrome/browser/profiles/profile.h" 18 #include "chrome/browser/profiles/profile.h"
18 #include "chrome/browser/ui/browser.h" 19 #include "chrome/browser/ui/browser.h"
19 #include "chrome/common/chrome_notification_types.h" 20 #include "chrome/common/chrome_notification_types.h"
20 #include "chrome/common/chrome_switches.h" 21 #include "chrome/common/chrome_switches.h"
22 #include "chrome/common/extensions/extension.h"
23 #include "content/public/browser/render_process_host.h"
24 #include "content/public/browser/render_view_host.h"
25 #include "content/public/common/result_codes.h"
21 26
22 namespace keys = extension_management_api_constants; 27 namespace keys = extension_management_api_constants;
23 namespace util = extension_function_test_utils; 28 namespace util = extension_function_test_utils;
24 29
25 class ExtensionManagementApiBrowserTest : public ExtensionBrowserTest {}; 30 class ExtensionManagementApiBrowserTest : public ExtensionBrowserTest {};
26 31
27 // We test this here instead of in an ExtensionApiTest because normal extensions 32 // We test this here instead of in an ExtensionApiTest because normal extensions
28 // are not allowed to call the install function. 33 // are not allowed to call the install function.
29 IN_PROC_BROWSER_TEST_F(ExtensionManagementApiBrowserTest, InstallEvent) { 34 IN_PROC_BROWSER_TEST_F(ExtensionManagementApiBrowserTest, InstallEvent) {
30 ExtensionTestMessageListener listener1("ready", false); 35 ExtensionTestMessageListener listener1("ready", false);
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 browser(), 159 browser(),
155 util::NONE); 160 util::NONE);
156 if (expected_error.empty()) { 161 if (expected_error.empty()) {
157 EXPECT_EQ(true, response); 162 EXPECT_EQ(true, response);
158 } else { 163 } else {
159 EXPECT_TRUE(response == false); 164 EXPECT_TRUE(response == false);
160 EXPECT_EQ(expected_error, function->GetError()); 165 EXPECT_EQ(expected_error, function->GetError());
161 } 166 }
162 } 167 }
163 168
169 bool CrashEnabledExtension(const std::string& extension_id) {
170 const extensions::Extension* extension = browser()->profile()->
171 GetExtensionService()->GetExtensionById(extension_id, false);
172 if (!extension)
173 return false;
174 extensions::ExtensionHost* extension_host = browser()->profile()->
175 GetExtensionProcessManager()->GetBackgroundHostForExtension(
176 extension_id);
177 if (!extension_host)
178 return false;
179 base::KillProcess(
180 extension_host->render_view_host()->GetProcess()->GetHandle(),
181 content::RESULT_CODE_KILLED, false);
182 return WaitForExtensionCrash(extension_id);
183 }
184
164 private: 185 private:
165 ScopedTempDir scoped_temp_dir_; 186 ScopedTempDir scoped_temp_dir_;
166 }; 187 };
167 188
168 const char ExtensionManagementApiEscalationTest::kId[] = 189 const char ExtensionManagementApiEscalationTest::kId[] =
169 "pgdpcfcocojkjfbgpiianjngphoopgmo"; 190 "pgdpcfcocojkjfbgpiianjngphoopgmo";
170 191
171 IN_PROC_BROWSER_TEST_F(ExtensionManagementApiEscalationTest, 192 IN_PROC_BROWSER_TEST_F(ExtensionManagementApiEscalationTest,
172 DisabledReason) { 193 DisabledReason) {
173 scoped_refptr<GetExtensionByIdFunction> function = 194 scoped_refptr<GetExtensionByIdFunction> function =
(...skipping 18 matching lines...) Expand all
192 213
193 // Expect an error that user cancelled the dialog. 214 // Expect an error that user cancelled the dialog.
194 CommandLine::ForCurrentProcess()->AppendSwitchASCII( 215 CommandLine::ForCurrentProcess()->AppendSwitchASCII(
195 switches::kAppsGalleryInstallAutoConfirmForTests, "cancel"); 216 switches::kAppsGalleryInstallAutoConfirmForTests, "cancel");
196 ReEnable(true, keys::kUserDidNotReEnableError); 217 ReEnable(true, keys::kUserDidNotReEnableError);
197 218
198 // This should succeed when user accepts dialog. 219 // This should succeed when user accepts dialog.
199 CommandLine::ForCurrentProcess()->AppendSwitchASCII( 220 CommandLine::ForCurrentProcess()->AppendSwitchASCII(
200 switches::kAppsGalleryInstallAutoConfirmForTests, "accept"); 221 switches::kAppsGalleryInstallAutoConfirmForTests, "accept");
201 ReEnable(true, ""); 222 ReEnable(true, "");
223
224 // Crash the extension and confirm re-enabling works.
225 ASSERT_TRUE(CrashEnabledExtension(kId));
226 ReEnable(true, "");
asargent_no_longer_on_chrome 2012/08/10 20:26:21 can you also add a test here that calls SetEnabled
mitchellwrosen 2012/08/10 23:15:27 Ya. The expected behavior is that the extension is
202 } 227 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698