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/strings/utf_string_conversions.h" | 5 #include "base/strings/utf_string_conversions.h" |
6 #include "chrome/browser/extensions/extension_apitest.h" | 6 #include "chrome/browser/extensions/extension_apitest.h" |
7 #include "chrome/browser/extensions/extension_host.h" | 7 #include "chrome/browser/extensions/extension_host.h" |
8 #include "chrome/browser/extensions/extension_process_manager.h" | 8 #include "chrome/browser/extensions/extension_process_manager.h" |
9 #include "chrome/browser/extensions/extension_service.h" | 9 #include "chrome/browser/extensions/extension_service.h" |
10 #include "chrome/browser/extensions/extension_system.h" | 10 #include "chrome/browser/extensions/extension_system.h" |
11 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
12 #include "chrome/browser/profiles/profile_manager.h" | 12 #include "chrome/browser/profiles/profile_manager.h" |
13 #include "chrome/browser/ui/browser.h" | 13 #include "chrome/browser/ui/browser.h" |
14 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 14 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
15 #include "chrome/common/chrome_switches.h" | 15 #include "chrome/common/chrome_switches.h" |
16 #include "chrome/common/url_constants.h" | 16 #include "chrome/common/url_constants.h" |
17 #include "chrome/test/base/ui_test_utils.h" | 17 #include "chrome/test/base/ui_test_utils.h" |
18 #include "content/public/browser/render_process_host.h" | 18 #include "content/public/browser/render_process_host.h" |
19 #include "content/public/browser/render_view_host.h" | 19 #include "content/public/browser/render_view_host.h" |
20 #include "content/public/browser/site_instance.h" | 20 #include "content/public/browser/site_instance.h" |
21 #include "content/public/browser/web_contents.h" | 21 #include "content/public/browser/web_contents.h" |
22 #include "net/dns/mock_host_resolver.h" | 22 #include "net/dns/mock_host_resolver.h" |
| 23 #include "net/test/embedded_test_server/embedded_test_server.h" |
23 | 24 |
24 using content::NavigationController; | 25 using content::NavigationController; |
25 using content::WebContents; | 26 using content::WebContents; |
26 | 27 |
27 namespace { | 28 namespace { |
28 | 29 |
29 class ProcessManagementTest : public ExtensionBrowserTest { | 30 class ProcessManagementTest : public ExtensionBrowserTest { |
30 private: | 31 private: |
31 // This is needed for testing isolated apps, which are still experimental. | 32 // This is needed for testing isolated apps, which are still experimental. |
32 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | 33 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
(...skipping 13 matching lines...) Expand all Loading... |
46 #endif | 47 #endif |
47 | 48 |
48 // Ensure that an isolated app never shares a process with WebUIs, non-isolated | 49 // Ensure that an isolated app never shares a process with WebUIs, non-isolated |
49 // extensions, and normal webpages. None of these should ever comingle | 50 // extensions, and normal webpages. None of these should ever comingle |
50 // RenderProcessHosts even if we hit the process limit. | 51 // RenderProcessHosts even if we hit the process limit. |
51 IN_PROC_BROWSER_TEST_F(ProcessManagementTest, MAYBE_ProcessOverflow) { | 52 IN_PROC_BROWSER_TEST_F(ProcessManagementTest, MAYBE_ProcessOverflow) { |
52 // Set max renderers to 1 to force running out of processes. | 53 // Set max renderers to 1 to force running out of processes. |
53 content::RenderProcessHost::SetMaxRendererProcessCount(1); | 54 content::RenderProcessHost::SetMaxRendererProcessCount(1); |
54 | 55 |
55 host_resolver()->AddRule("*", "127.0.0.1"); | 56 host_resolver()->AddRule("*", "127.0.0.1"); |
56 ASSERT_TRUE(test_server()->Start()); | 57 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
57 | 58 |
58 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("isolated_apps/app1"))); | 59 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("isolated_apps/app1"))); |
59 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("isolated_apps/app2"))); | 60 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("isolated_apps/app2"))); |
60 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("hosted_app"))); | 61 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("hosted_app"))); |
61 ASSERT_TRUE( | 62 ASSERT_TRUE( |
62 LoadExtension(test_data_dir_.AppendASCII("api_test/app_process"))); | 63 LoadExtension(test_data_dir_.AppendASCII("api_test/app_process"))); |
63 | 64 |
64 // The app under test acts on URLs whose host is "localhost", | 65 // The app under test acts on URLs whose host is "localhost", |
65 // so the URLs we navigate to must have host "localhost". | 66 // so the URLs we navigate to must have host "localhost". |
66 GURL base_url = test_server()->GetURL( | 67 GURL base_url = embedded_test_server()->GetURL( |
67 "files/extensions/"); | 68 "/extensions/"); |
68 GURL::Replacements replace_host; | 69 GURL::Replacements replace_host; |
69 std::string host_str("localhost"); // Must stay in scope with replace_host. | 70 std::string host_str("localhost"); // Must stay in scope with replace_host. |
70 replace_host.SetHostStr(host_str); | 71 replace_host.SetHostStr(host_str); |
71 base_url = base_url.ReplaceComponents(replace_host); | 72 base_url = base_url.ReplaceComponents(replace_host); |
72 | 73 |
73 // Load an extension before adding tabs. | 74 // Load an extension before adding tabs. |
74 const extensions::Extension* extension1 = LoadExtension( | 75 const extensions::Extension* extension1 = LoadExtension( |
75 test_data_dir_.AppendASCII("api_test/browser_action/basics")); | 76 test_data_dir_.AppendASCII("api_test/browser_action/basics")); |
76 ASSERT_TRUE(extension1); | 77 ASSERT_TRUE(extension1); |
77 GURL extension1_url = extension1->url(); | 78 GURL extension1_url = extension1->url(); |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 #define MAYBE_ExtensionProcessBalancing ExtensionProcessBalancing | 188 #define MAYBE_ExtensionProcessBalancing ExtensionProcessBalancing |
188 #endif | 189 #endif |
189 // Test to verify that the policy of maximum share of extension processes is | 190 // Test to verify that the policy of maximum share of extension processes is |
190 // properly enforced. | 191 // properly enforced. |
191 IN_PROC_BROWSER_TEST_F(ProcessManagementTest, MAYBE_ExtensionProcessBalancing) { | 192 IN_PROC_BROWSER_TEST_F(ProcessManagementTest, MAYBE_ExtensionProcessBalancing) { |
192 // Set max renderers to 6 so we can expect 2 extension processes to be | 193 // Set max renderers to 6 so we can expect 2 extension processes to be |
193 // allocated. | 194 // allocated. |
194 content::RenderProcessHost::SetMaxRendererProcessCount(6); | 195 content::RenderProcessHost::SetMaxRendererProcessCount(6); |
195 | 196 |
196 host_resolver()->AddRule("*", "127.0.0.1"); | 197 host_resolver()->AddRule("*", "127.0.0.1"); |
197 ASSERT_TRUE(test_server()->Start()); | 198 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
198 | 199 |
199 // The app under test acts on URLs whose host is "localhost", | 200 // The app under test acts on URLs whose host is "localhost", |
200 // so the URLs we navigate to must have host "localhost". | 201 // so the URLs we navigate to must have host "localhost". |
201 GURL base_url = test_server()->GetURL( | 202 GURL base_url = embedded_test_server()->GetURL( |
202 "files/extensions/"); | 203 "/extensions/"); |
203 GURL::Replacements replace_host; | 204 GURL::Replacements replace_host; |
204 std::string host_str("localhost"); // Must stay in scope with replace_host. | 205 std::string host_str("localhost"); // Must stay in scope with replace_host. |
205 replace_host.SetHostStr(host_str); | 206 replace_host.SetHostStr(host_str); |
206 base_url = base_url.ReplaceComponents(replace_host); | 207 base_url = base_url.ReplaceComponents(replace_host); |
207 | 208 |
208 ASSERT_TRUE(LoadExtension( | 209 ASSERT_TRUE(LoadExtension( |
209 test_data_dir_.AppendASCII("api_test/browser_action/none"))); | 210 test_data_dir_.AppendASCII("api_test/browser_action/none"))); |
210 ASSERT_TRUE(LoadExtension( | 211 ASSERT_TRUE(LoadExtension( |
211 test_data_dir_.AppendASCII("api_test/browser_action/basics"))); | 212 test_data_dir_.AppendASCII("api_test/browser_action/basics"))); |
212 ASSERT_TRUE(LoadExtension( | 213 ASSERT_TRUE(LoadExtension( |
(...skipping 27 matching lines...) Expand all Loading... |
240 | 241 |
241 // We've loaded 5 extensions with background pages, 1 extension without | 242 // We've loaded 5 extensions with background pages, 1 extension without |
242 // background page, and one isolated app. We expect only 2 unique processes | 243 // background page, and one isolated app. We expect only 2 unique processes |
243 // hosting those extensions. | 244 // hosting those extensions. |
244 ExtensionService* service = | 245 ExtensionService* service = |
245 extensions::ExtensionSystem::Get(profile)->extension_service(); | 246 extensions::ExtensionSystem::Get(profile)->extension_service(); |
246 | 247 |
247 EXPECT_GE((size_t) 6, service->process_map()->size()); | 248 EXPECT_GE((size_t) 6, service->process_map()->size()); |
248 EXPECT_EQ((size_t) 2, process_ids.size()); | 249 EXPECT_EQ((size_t) 2, process_ids.size()); |
249 } | 250 } |
OLD | NEW |