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

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

Issue 57433010: Prevent creating a swapped out RVH in the same SiteInstance as the current one. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: More diagnosis. Created 7 years, 1 month 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 | Annotate | Revision Log
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/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 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 ASSERT_TRUE(result->IsType(base::Value::TYPE_DICTIONARY)); 245 ASSERT_TRUE(result->IsType(base::Value::TYPE_DICTIONARY));
251 base::DictionaryValue* dict = 246 base::DictionaryValue* dict =
252 static_cast<base::DictionaryValue*>(result.get()); 247 static_cast<base::DictionaryValue*>(result.get());
253 std::string reason; 248 std::string reason;
254 EXPECT_TRUE(dict->GetStringASCII(keys::kDisabledReasonKey, &reason)); 249 EXPECT_TRUE(dict->GetStringASCII(keys::kDisabledReasonKey, &reason));
255 EXPECT_EQ(reason, std::string(keys::kDisabledReasonPermissionsIncrease)); 250 EXPECT_EQ(reason, std::string(keys::kDisabledReasonPermissionsIncrease));
256 } 251 }
257 252
258 IN_PROC_BROWSER_TEST_F(ExtensionManagementApiEscalationTest, 253 IN_PROC_BROWSER_TEST_F(ExtensionManagementApiEscalationTest,
259 SetEnabled) { 254 SetEnabled) {
255 LOG(INFO) << "SetEnabled: start of test.";
260 // Expect an error about no gesture. 256 // Expect an error about no gesture.
261 SetEnabled(true, false, keys::kGestureNeededForEscalationError); 257 SetEnabled(true, false, keys::kGestureNeededForEscalationError);
258 LOG(INFO) << "SetEnabled: setenabled with gesture error.";
ncarter (slow) 2013/11/12 03:38:26 Don't forget to remove these LOG(INFO)s
Charlie Reis 2013/11/12 16:09:35 Done.
262 259
263 // Expect an error that user cancelled the dialog. 260 // Expect an error that user cancelled the dialog.
264 CommandLine::ForCurrentProcess()->AppendSwitchASCII( 261 CommandLine::ForCurrentProcess()->AppendSwitchASCII(
265 switches::kAppsGalleryInstallAutoConfirmForTests, "cancel"); 262 switches::kAppsGalleryInstallAutoConfirmForTests, "cancel");
266 SetEnabled(true, true, keys::kUserDidNotReEnableError); 263 SetEnabled(true, true, keys::kUserDidNotReEnableError);
264 LOG(INFO) << "SetEnabled: setenabled with user cancel error.";
267 265
268 // This should succeed when user accepts dialog. 266 // This should succeed when user accepts dialog. We must wait for the process
267 // to connect before trying to crash it.
268 content::WindowedNotificationObserver observer(
269 content::NOTIFICATION_RENDERER_PROCESS_CREATED,
ncarter (slow) 2013/11/12 03:38:26 Change this to chrome::NOTIFICATION_EXTENSION_HOST
Charlie Reis 2013/11/12 16:09:35 Done.
270 content::NotificationService::AllSources());
269 CommandLine::ForCurrentProcess()->AppendSwitchASCII( 271 CommandLine::ForCurrentProcess()->AppendSwitchASCII(
270 switches::kAppsGalleryInstallAutoConfirmForTests, "accept"); 272 switches::kAppsGalleryInstallAutoConfirmForTests, "accept");
271 SetEnabled(true, true, std::string()); 273 SetEnabled(true, true, std::string());
274 LOG(INFO) << "SetEnabled: setenabled success.";
275 observer.Wait();
276 LOG(INFO) << "SetEnabled: process created.";
272 277
273 // Crash the extension. Mock a reload by disabling and then enabling. The 278 // Crash the extension. Mock a reload by disabling and then enabling. The
274 // extension should be reloaded and enabled. 279 // extension should be reloaded and enabled.
275 ASSERT_TRUE(CrashEnabledExtension(kId)); 280 ASSERT_TRUE(CrashEnabledExtension(kId));
281 LOG(INFO) << "SetEnabled: extension process crashed.";
276 SetEnabled(false, true, std::string()); 282 SetEnabled(false, true, std::string());
283 LOG(INFO) << "SetEnabled: disabled.";
277 SetEnabled(true, true, std::string()); 284 SetEnabled(true, true, std::string());
285 LOG(INFO) << "SetEnabled: enabled.";
278 const Extension* extension = ExtensionSystem::Get(browser()->profile()) 286 const Extension* extension = ExtensionSystem::Get(browser()->profile())
279 ->extension_service()->GetExtensionById(kId, false); 287 ->extension_service()->GetExtensionById(kId, false);
280 EXPECT_TRUE(extension); 288 EXPECT_TRUE(extension);
289 LOG(INFO) << "SetEnabled: done.";
281 } 290 }
282 291
283 } // namespace extensions 292 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698