OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "chrome/browser/renderer_host/site_instance.h" | 6 #include "chrome/browser/renderer_host/site_instance.h" |
6 #include "chrome/browser/tab_contents/tab_contents.h" | 7 #include "chrome/browser/tab_contents/tab_contents.h" |
7 #include "chrome/browser/renderer_host/render_process_host.h" | 8 #include "chrome/browser/renderer_host/render_process_host.h" |
8 #include "chrome/browser/ui/browser.h" | 9 #include "chrome/browser/ui/browser.h" |
| 10 #include "chrome/common/chrome_switches.h" |
9 #include "chrome/common/url_constants.h" | 11 #include "chrome/common/url_constants.h" |
10 #include "chrome/test/in_process_browser_test.h" | 12 #include "chrome/test/in_process_browser_test.h" |
11 #include "chrome/test/ui_test_utils.h" | 13 #include "chrome/test/ui_test_utils.h" |
12 | 14 |
13 class RenderProcessHostTest : public InProcessBrowserTest { | 15 class RenderProcessHostTest : public InProcessBrowserTest { |
14 public: | 16 public: |
15 RenderProcessHostTest() { | 17 RenderProcessHostTest() { |
16 EnableDOMAutomation(); | 18 EnableDOMAutomation(); |
17 } | 19 } |
18 | 20 |
19 int RenderProcessHostCount() { | 21 int RenderProcessHostCount() { |
20 RenderProcessHost::iterator hosts = RenderProcessHost::AllHostsIterator(); | 22 RenderProcessHost::iterator hosts = RenderProcessHost::AllHostsIterator(); |
21 int count = 0; | 23 int count = 0; |
22 while (!hosts.IsAtEnd()) { | 24 while (!hosts.IsAtEnd()) { |
23 if (hosts.GetCurrentValue()->HasConnection()) | 25 if (hosts.GetCurrentValue()->HasConnection()) |
24 count++; | 26 count++; |
25 hosts.Advance(); | 27 hosts.Advance(); |
26 } | 28 } |
27 return count; | 29 return count; |
28 } | 30 } |
29 }; | 31 }; |
30 | 32 |
| 33 IN_PROC_BROWSER_TEST_F(RenderProcessHostTest, ProcessPerTab) { |
| 34 // Set max renderers to 1 to force running out of processes. |
| 35 RenderProcessHost::SetMaxRendererProcessCount(1); |
| 36 |
| 37 CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess(); |
| 38 parsed_command_line.AppendSwitch(switches::kProcessPerTab); |
| 39 |
| 40 int tab_count = 1; |
| 41 int host_count = 1; |
| 42 |
| 43 // Change the first tab to be the new tab page (TYPE_DOMUI). |
| 44 GURL newtab(chrome::kChromeUINewTabURL); |
| 45 ui_test_utils::NavigateToURL(browser(), newtab); |
| 46 EXPECT_EQ(tab_count, browser()->tab_count()); |
| 47 EXPECT_EQ(host_count, RenderProcessHostCount()); |
| 48 |
| 49 // Create a new TYPE_NORMAL tab. It should be in its own process. |
| 50 GURL page1("data:text/html,hello world1"); |
| 51 browser()->ShowSingletonTab(page1, false); |
| 52 if (browser()->tab_count() == tab_count) |
| 53 ui_test_utils::WaitForNewTab(browser()); |
| 54 tab_count++; |
| 55 host_count++; |
| 56 EXPECT_EQ(tab_count, browser()->tab_count()); |
| 57 EXPECT_EQ(host_count, RenderProcessHostCount()); |
| 58 |
| 59 // Create another TYPE_NORMAL tab. It should share the previous process. |
| 60 GURL page2("data:text/html,hello world2"); |
| 61 browser()->ShowSingletonTab(page2, false); |
| 62 if (browser()->tab_count() == tab_count) |
| 63 ui_test_utils::WaitForNewTab(browser()); |
| 64 tab_count++; |
| 65 EXPECT_EQ(tab_count, browser()->tab_count()); |
| 66 EXPECT_EQ(host_count, RenderProcessHostCount()); |
| 67 |
| 68 // Create another new tab. It should share the process with the other DOMUI. |
| 69 browser()->NewTab(); |
| 70 if (browser()->tab_count() == tab_count) |
| 71 ui_test_utils::WaitForNewTab(browser()); |
| 72 tab_count++; |
| 73 EXPECT_EQ(tab_count, browser()->tab_count()); |
| 74 EXPECT_EQ(host_count, RenderProcessHostCount()); |
| 75 |
| 76 // Create another new tab. It should share the process with the other DOMUI. |
| 77 browser()->NewTab(); |
| 78 if (browser()->tab_count() == tab_count) |
| 79 ui_test_utils::WaitForNewTab(browser()); |
| 80 tab_count++; |
| 81 EXPECT_EQ(tab_count, browser()->tab_count()); |
| 82 EXPECT_EQ(host_count, RenderProcessHostCount()); |
| 83 } |
| 84 |
31 // When we hit the max number of renderers, verify that the way we do process | 85 // When we hit the max number of renderers, verify that the way we do process |
32 // sharing behaves correctly. In particular, this test is verifying that even | 86 // sharing behaves correctly. In particular, this test is verifying that even |
33 // when we hit the max process limit, that renderers of each type will wind up | 87 // when we hit the max process limit, that renderers of each type will wind up |
34 // in a process of that type, even if that means creating a new process. | 88 // in a process of that type, even if that means creating a new process. |
35 // TODO(erikkay) crbug.com/43448 - disabled for now until we can get a | 89 // TODO(erikkay) crbug.com/43448 - disabled for now until we can get a |
36 // reasonable implementation in place. | 90 // reasonable implementation in place. |
37 IN_PROC_BROWSER_TEST_F(RenderProcessHostTest, DISABLED_ProcessOverflow) { | 91 IN_PROC_BROWSER_TEST_F(RenderProcessHostTest, DISABLED_ProcessOverflow) { |
38 // Set max renderers to 1 to force running out of processes. | 92 // Set max renderers to 1 to force running out of processes. |
39 RenderProcessHost::SetMaxRendererProcessCount(1); | 93 RenderProcessHost::SetMaxRendererProcessCount(1); |
40 | 94 |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 tab_count++; | 159 tab_count++; |
106 host_count++; | 160 host_count++; |
107 EXPECT_EQ(tab_count, browser()->tab_count()); | 161 EXPECT_EQ(tab_count, browser()->tab_count()); |
108 tab1 = browser()->GetTabContentsAt(tab_count - 1); | 162 tab1 = browser()->GetTabContentsAt(tab_count - 1); |
109 rph3 = tab1->GetRenderProcessHost(); | 163 rph3 = tab1->GetRenderProcessHost(); |
110 EXPECT_EQ(tab1->GetURL(), bookmarks); | 164 EXPECT_EQ(tab1->GetURL(), bookmarks); |
111 EXPECT_EQ(host_count, RenderProcessHostCount()); | 165 EXPECT_EQ(host_count, RenderProcessHostCount()); |
112 EXPECT_NE(rph1, rph3); | 166 EXPECT_NE(rph1, rph3); |
113 EXPECT_NE(rph2, rph3); | 167 EXPECT_NE(rph2, rph3); |
114 } | 168 } |
OLD | NEW |