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 <stddef.h> | 5 #include <stddef.h> |
6 | 6 |
7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
8 #include "build/build_config.h" | 8 #include "build/build_config.h" |
9 #include "chrome/browser/chrome_notification_types.h" | 9 #include "chrome/browser/chrome_notification_types.h" |
10 #include "chrome/browser/extensions/extension_apitest.h" | 10 #include "chrome/browser/extensions/extension_apitest.h" |
(...skipping 28 matching lines...) Expand all Loading... |
39 namespace { | 39 namespace { |
40 | 40 |
41 class ProcessManagementTest : public ExtensionBrowserTest { | 41 class ProcessManagementTest : public ExtensionBrowserTest { |
42 private: | 42 private: |
43 // This is needed for testing isolated apps, which are still experimental. | 43 // This is needed for testing isolated apps, which are still experimental. |
44 void SetUpCommandLine(base::CommandLine* command_line) override { | 44 void SetUpCommandLine(base::CommandLine* command_line) override { |
45 ExtensionBrowserTest::SetUpCommandLine(command_line); | 45 ExtensionBrowserTest::SetUpCommandLine(command_line); |
46 command_line->AppendSwitch( | 46 command_line->AppendSwitch( |
47 extensions::switches::kEnableExperimentalExtensionApis); | 47 extensions::switches::kEnableExperimentalExtensionApis); |
48 } | 48 } |
| 49 |
| 50 void SetUpOnMainThread() override { |
| 51 ExtensionBrowserTest::SetUpOnMainThread(); |
| 52 host_resolver()->AddRule("*", "127.0.0.1"); |
| 53 } |
49 }; | 54 }; |
50 | 55 |
51 class ChromeWebStoreProcessTest : public ExtensionBrowserTest { | 56 class ChromeWebStoreProcessTest : public ExtensionBrowserTest { |
52 public: | 57 public: |
53 const GURL& gallery_url() { return gallery_url_; } | 58 const GURL& gallery_url() { return gallery_url_; } |
54 | 59 |
55 private: | 60 private: |
56 // Overrides location of Chrome Web Store gallery to a test controlled URL. | 61 // Overrides location of Chrome Web Store gallery to a test controlled URL. |
57 void SetUpCommandLine(base::CommandLine* command_line) override { | 62 void SetUpCommandLine(base::CommandLine* command_line) override { |
58 ExtensionBrowserTest::SetUpCommandLine(command_line); | 63 ExtensionBrowserTest::SetUpCommandLine(command_line); |
(...skipping 22 matching lines...) Expand all Loading... |
81 #define MAYBE_ProcessOverflow ProcessOverflow | 86 #define MAYBE_ProcessOverflow ProcessOverflow |
82 #endif | 87 #endif |
83 | 88 |
84 // Ensure that an isolated app never shares a process with WebUIs, non-isolated | 89 // Ensure that an isolated app never shares a process with WebUIs, non-isolated |
85 // extensions, and normal webpages. None of these should ever comingle | 90 // extensions, and normal webpages. None of these should ever comingle |
86 // RenderProcessHosts even if we hit the process limit. | 91 // RenderProcessHosts even if we hit the process limit. |
87 IN_PROC_BROWSER_TEST_F(ProcessManagementTest, MAYBE_ProcessOverflow) { | 92 IN_PROC_BROWSER_TEST_F(ProcessManagementTest, MAYBE_ProcessOverflow) { |
88 // Set max renderers to 1 to force running out of processes. | 93 // Set max renderers to 1 to force running out of processes. |
89 content::RenderProcessHost::SetMaxRendererProcessCount(1); | 94 content::RenderProcessHost::SetMaxRendererProcessCount(1); |
90 | 95 |
91 host_resolver()->AddRule("*", "127.0.0.1"); | |
92 ASSERT_TRUE(embedded_test_server()->Start()); | 96 ASSERT_TRUE(embedded_test_server()->Start()); |
93 | 97 |
94 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("isolated_apps/app1"))); | 98 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("isolated_apps/app1"))); |
95 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("isolated_apps/app2"))); | 99 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("isolated_apps/app2"))); |
96 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("hosted_app"))); | 100 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("hosted_app"))); |
97 ASSERT_TRUE( | 101 ASSERT_TRUE( |
98 LoadExtension(test_data_dir_.AppendASCII("api_test/app_process"))); | 102 LoadExtension(test_data_dir_.AppendASCII("api_test/app_process"))); |
99 | 103 |
100 // The app under test acts on URLs whose host is "localhost", | 104 // The app under test acts on URLs whose host is "localhost", |
101 // so the URLs we navigate to must have host "localhost". | 105 // so the URLs we navigate to must have host "localhost". |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
227 #else | 231 #else |
228 #define MAYBE_ExtensionProcessBalancing ExtensionProcessBalancing | 232 #define MAYBE_ExtensionProcessBalancing ExtensionProcessBalancing |
229 #endif | 233 #endif |
230 // Test to verify that the policy of maximum share of extension processes is | 234 // Test to verify that the policy of maximum share of extension processes is |
231 // properly enforced. | 235 // properly enforced. |
232 IN_PROC_BROWSER_TEST_F(ProcessManagementTest, MAYBE_ExtensionProcessBalancing) { | 236 IN_PROC_BROWSER_TEST_F(ProcessManagementTest, MAYBE_ExtensionProcessBalancing) { |
233 // Set max renderers to 6 so we can expect 2 extension processes to be | 237 // Set max renderers to 6 so we can expect 2 extension processes to be |
234 // allocated. | 238 // allocated. |
235 content::RenderProcessHost::SetMaxRendererProcessCount(6); | 239 content::RenderProcessHost::SetMaxRendererProcessCount(6); |
236 | 240 |
237 host_resolver()->AddRule("*", "127.0.0.1"); | |
238 ASSERT_TRUE(embedded_test_server()->Start()); | 241 ASSERT_TRUE(embedded_test_server()->Start()); |
239 | 242 |
240 // The app under test acts on URLs whose host is "localhost", | 243 // The app under test acts on URLs whose host is "localhost", |
241 // so the URLs we navigate to must have host "localhost". | 244 // so the URLs we navigate to must have host "localhost". |
242 GURL base_url = embedded_test_server()->GetURL( | 245 GURL base_url = embedded_test_server()->GetURL( |
243 "/extensions/"); | 246 "/extensions/"); |
244 GURL::Replacements replace_host; | 247 GURL::Replacements replace_host; |
245 replace_host.SetHostStr("localhost"); | 248 replace_host.SetHostStr("localhost"); |
246 base_url = base_url.ReplaceComponents(replace_host); | 249 base_url = base_url.ReplaceComponents(replace_host); |
247 | 250 |
(...skipping 28 matching lines...) Expand all Loading... |
276 // background page, and one isolated app. We expect only 2 unique processes | 279 // background page, and one isolated app. We expect only 2 unique processes |
277 // hosting those extensions. | 280 // hosting those extensions. |
278 extensions::ProcessMap* process_map = extensions::ProcessMap::Get(profile); | 281 extensions::ProcessMap* process_map = extensions::ProcessMap::Get(profile); |
279 | 282 |
280 EXPECT_GE((size_t) 6, process_map->size()); | 283 EXPECT_GE((size_t) 6, process_map->size()); |
281 EXPECT_EQ((size_t) 2, process_ids.size()); | 284 EXPECT_EQ((size_t) 2, process_ids.size()); |
282 } | 285 } |
283 | 286 |
284 IN_PROC_BROWSER_TEST_F(ProcessManagementTest, | 287 IN_PROC_BROWSER_TEST_F(ProcessManagementTest, |
285 NavigateExtensionTabToWebViaPost) { | 288 NavigateExtensionTabToWebViaPost) { |
286 host_resolver()->AddRule("*", "127.0.0.1"); | |
287 ASSERT_TRUE(embedded_test_server()->Start()); | 289 ASSERT_TRUE(embedded_test_server()->Start()); |
288 | 290 |
289 // Load an extension. | 291 // Load an extension. |
290 const extensions::Extension* extension = LoadExtension( | 292 const extensions::Extension* extension = LoadExtension( |
291 test_data_dir_.AppendASCII("api_test/browser_action/popup_with_form")); | 293 test_data_dir_.AppendASCII("api_test/browser_action/popup_with_form")); |
292 ASSERT_TRUE(extension); | 294 ASSERT_TRUE(extension); |
293 | 295 |
294 // Navigate a tab to an extension page. | 296 // Navigate a tab to an extension page. |
295 GURL extension_url = extension->GetResourceURL("popup.html"); | 297 GURL extension_url = extension->GetResourceURL("popup.html"); |
296 ui_test_utils::NavigateToURL(browser(), extension_url); | 298 ui_test_utils::NavigateToURL(browser(), extension_url); |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
389 web_contents->GetMainFrame()->GetProcess(); | 391 web_contents->GetMainFrame()->GetProcess(); |
390 EXPECT_TRUE(extensions::ProcessMap::Get(profile())->Contains( | 392 EXPECT_TRUE(extensions::ProcessMap::Get(profile())->Contains( |
391 extensions::kWebStoreAppId, new_process_host->GetID())); | 393 extensions::kWebStoreAppId, new_process_host->GetID())); |
392 | 394 |
393 // Verify that Chrome Web Store is isolated in a separate renderer process. | 395 // Verify that Chrome Web Store is isolated in a separate renderer process. |
394 EXPECT_NE(old_process_host, new_process_host); | 396 EXPECT_NE(old_process_host, new_process_host); |
395 } | 397 } |
396 | 398 |
397 // This test verifies that blocked navigations to extensions pages do not | 399 // This test verifies that blocked navigations to extensions pages do not |
398 // overwrite process-per-site map inside content/. | 400 // overwrite process-per-site map inside content/. |
399 IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, | 401 IN_PROC_BROWSER_TEST_F(ProcessManagementTest, |
400 NavigateToBlockedExtensionPageInNewTab) { | 402 NavigateToBlockedExtensionPageInNewTab) { |
401 host_resolver()->AddRule("*", "127.0.0.1"); | |
402 ASSERT_TRUE(embedded_test_server()->Start()); | 403 ASSERT_TRUE(embedded_test_server()->Start()); |
403 | 404 |
404 // Load an extension, which will block a request for a specific page in it. | 405 // Load an extension, which will block a request for a specific page in it. |
405 const extensions::Extension* extension = LoadExtension( | 406 const extensions::Extension* extension = LoadExtension( |
406 test_data_dir_.AppendASCII("web_request_site_process_registration")); | 407 test_data_dir_.AppendASCII("web_request_site_process_registration")); |
407 ASSERT_TRUE(extension); | 408 ASSERT_TRUE(extension); |
408 | 409 |
409 WebContents* web_contents = | 410 WebContents* web_contents = |
410 browser()->tab_strip_model()->GetActiveWebContents(); | 411 browser()->tab_strip_model()->GetActiveWebContents(); |
411 GURL blocked_url(extension->GetResourceURL("/blocked.html")); | 412 GURL blocked_url(extension->GetResourceURL("/blocked.html")); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
451 // the process is the same for all SiteInstances. This allows us to verify | 452 // the process is the same for all SiteInstances. This allows us to verify |
452 // that the site-to-process map for the extension hasn't been overwritten by | 453 // that the site-to-process map for the extension hasn't been overwritten by |
453 // the process of the |blocked_url|. | 454 // the process of the |blocked_url|. |
454 scoped_refptr<content::SiteInstance> new_site_instance = | 455 scoped_refptr<content::SiteInstance> new_site_instance = |
455 content::SiteInstance::CreateForURL(web_contents->GetBrowserContext(), | 456 content::SiteInstance::CreateForURL(web_contents->GetBrowserContext(), |
456 extension->GetResourceURL("")); | 457 extension->GetResourceURL("")); |
457 EXPECT_TRUE(new_site_instance->HasProcess()); | 458 EXPECT_TRUE(new_site_instance->HasProcess()); |
458 EXPECT_EQ(new_site_instance->GetProcess(), | 459 EXPECT_EQ(new_site_instance->GetProcess(), |
459 web_contents->GetSiteInstance()->GetProcess()); | 460 web_contents->GetSiteInstance()->GetProcess()); |
460 } | 461 } |
OLD | NEW |