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

Side by Side Diff: content/browser/renderer_host/render_process_host_browsertest.cc

Issue 9328011: Adding a command line flag to specify renderer process limit (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Removed the static variable from the interface and moved the test function. Created 8 years, 10 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "content/browser/renderer_host/render_process_host_browsertest.h" 5 #include "content/browser/renderer_host/render_process_host_browsertest.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/process.h" 10 #include "base/process.h"
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 48
49 // Ensure that the backgrounding / foregrounding gets a chance to run. 49 // Ensure that the backgrounding / foregrounding gets a chance to run.
50 content::BrowserThread::PostTaskAndReply( 50 content::BrowserThread::PostTaskAndReply(
51 content::BrowserThread::PROCESS_LAUNCHER, FROM_HERE, 51 content::BrowserThread::PROCESS_LAUNCHER, FROM_HERE,
52 base::Bind(&base::DoNothing), MessageLoop::QuitClosure()); 52 base::Bind(&base::DoNothing), MessageLoop::QuitClosure());
53 MessageLoop::current()->Run(); 53 MessageLoop::current()->Run();
54 54
55 return wc->GetRenderProcessHost()->GetHandle(); 55 return wc->GetRenderProcessHost()->GetHandle();
56 } 56 }
57 57
58 // When we hit the max number of renderers, verify that the way we do process
59 // sharing behaves correctly. In particular, this test is verifying that even
60 // when we hit the max process limit, that renderers of each type will wind up
61 // in a process of that type, even if that means creating a new process.
62 void RenderProcessHostTest::TestProcessOverflow() {
63 int tab_count = 1;
64 int host_count = 1;
65 WebContents* tab1 = NULL;
66 WebContents* tab2 = NULL;
67 content::RenderProcessHost* rph1 = NULL;
68 content::RenderProcessHost* rph2 = NULL;
69 content::RenderProcessHost* rph3 = NULL;
70
71 #if defined(USE_VIRTUAL_KEYBOARD)
72 ++host_count; // For the virtual keyboard.
73 #endif
74
75 // Change the first tab to be the new tab page (TYPE_WEBUI).
76 GURL newtab(chrome::kTestNewTabURL);
77 ui_test_utils::NavigateToURL(browser(), newtab);
78 EXPECT_EQ(tab_count, browser()->tab_count());
79 tab1 = browser()->GetWebContentsAt(tab_count - 1);
80 rph1 = tab1->GetRenderProcessHost();
81 EXPECT_EQ(tab1->GetURL(), newtab);
82 EXPECT_EQ(host_count, RenderProcessHostCount());
83
84 // Create a new TYPE_TABBED tab. It should be in its own process.
85 GURL page1("data:text/html,hello world1");
86 browser()->ShowSingletonTab(page1);
87 if (browser()->tab_count() == tab_count)
88 ui_test_utils::WaitForNewTab(browser());
89 tab_count++;
90 host_count++;
91 EXPECT_EQ(tab_count, browser()->tab_count());
92 tab1 = browser()->GetWebContentsAt(tab_count - 1);
93 rph2 = tab1->GetRenderProcessHost();
94 EXPECT_EQ(tab1->GetURL(), page1);
95 EXPECT_EQ(host_count, RenderProcessHostCount());
96 EXPECT_NE(rph1, rph2);
97
98 // Create another TYPE_TABBED tab. It should share the previous process.
99 GURL page2("data:text/html,hello world2");
100 browser()->ShowSingletonTab(page2);
101 if (browser()->tab_count() == tab_count)
102 ui_test_utils::WaitForNewTab(browser());
103 tab_count++;
104 EXPECT_EQ(tab_count, browser()->tab_count());
105 tab2 = browser()->GetWebContentsAt(tab_count - 1);
106 EXPECT_EQ(tab2->GetURL(), page2);
107 EXPECT_EQ(host_count, RenderProcessHostCount());
108 EXPECT_EQ(tab2->GetRenderProcessHost(), rph2);
109
110 // Create another TYPE_WEBUI tab. It should share the process with newtab.
111 // Note: intentionally create this tab after the TYPE_TABBED tabs to exercise
112 // bug 43448 where extension and WebUI tabs could get combined into normal
113 // renderers.
114 GURL history(chrome::kTestHistoryURL);
115 browser()->ShowSingletonTab(history);
116 if (browser()->tab_count() == tab_count)
117 ui_test_utils::WaitForNewTab(browser());
118 tab_count++;
119 EXPECT_EQ(tab_count, browser()->tab_count());
120 tab2 = browser()->GetWebContentsAt(tab_count - 1);
121 EXPECT_EQ(tab2->GetURL(), history);
122 EXPECT_EQ(host_count, RenderProcessHostCount());
123 EXPECT_EQ(tab2->GetRenderProcessHost(), rph1);
124
125 // Create a TYPE_EXTENSION tab. It should be in its own process.
126 // (the bookmark manager is implemented as an extension)
127 GURL bookmarks(chrome::kTestBookmarksURL);
128 browser()->ShowSingletonTab(bookmarks);
129 if (browser()->tab_count() == tab_count)
130 ui_test_utils::WaitForNewTab(browser());
131 tab_count++;
132 #if !defined(USE_VIRTUAL_KEYBOARD)
133 // The virtual keyboard already creates an extension process. So this
134 // should not increase the process count.
135 host_count++;
136 #endif
137 EXPECT_EQ(tab_count, browser()->tab_count());
138 tab1 = browser()->GetWebContentsAt(tab_count - 1);
139 rph3 = tab1->GetRenderProcessHost();
140 EXPECT_EQ(tab1->GetURL(), bookmarks);
141 EXPECT_EQ(host_count, RenderProcessHostCount());
142 EXPECT_NE(rph1, rph3);
143 EXPECT_NE(rph2, rph3);
144 }
145
58 IN_PROC_BROWSER_TEST_F(RenderProcessHostTest, ProcessPerTab) { 146 IN_PROC_BROWSER_TEST_F(RenderProcessHostTest, ProcessPerTab) {
59 // Set max renderers to 1 to force running out of processes. 147 // Set max renderers to 1 to force running out of processes.
60 content::RenderProcessHost::SetMaxRendererProcessCountForTest(1); 148 content::RenderProcessHost::SetMaxRendererProcessCount(1);
61 149
62 CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess(); 150 CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess();
63 parsed_command_line.AppendSwitch(switches::kProcessPerTab); 151 parsed_command_line.AppendSwitch(switches::kProcessPerTab);
64 152
65 int tab_count = 1; 153 int tab_count = 1;
66 int host_count = 1; 154 int host_count = 1;
67 155
68 #if defined(USE_VIRTUAL_KEYBOARD) 156 #if defined(USE_VIRTUAL_KEYBOARD)
69 ++host_count; // For the virtual keyboard. 157 ++host_count; // For the virtual keyboard.
70 #endif 158 #endif
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 EXPECT_FALSE(base::Process(pid2).IsProcessBackgrounded()); 228 EXPECT_FALSE(base::Process(pid2).IsProcessBackgrounded());
141 229
142 // Navigate back to first page. It should be foreground again, and the second 230 // Navigate back to first page. It should be foreground again, and the second
143 // tab should be background. 231 // tab should be background.
144 EXPECT_EQ(pid1, ShowSingletonTab(page1)); 232 EXPECT_EQ(pid1, ShowSingletonTab(page1));
145 EXPECT_FALSE(base::Process(pid1).IsProcessBackgrounded()); 233 EXPECT_FALSE(base::Process(pid1).IsProcessBackgrounded());
146 EXPECT_TRUE(base::Process(pid2).IsProcessBackgrounded()); 234 EXPECT_TRUE(base::Process(pid2).IsProcessBackgrounded());
147 } 235 }
148 #endif 236 #endif
149 237
150 // When we hit the max number of renderers, verify that the way we do process
151 // sharing behaves correctly. In particular, this test is verifying that even
152 // when we hit the max process limit, that renderers of each type will wind up
153 // in a process of that type, even if that means creating a new process.
154 IN_PROC_BROWSER_TEST_F(RenderProcessHostTest, ProcessOverflow) { 238 IN_PROC_BROWSER_TEST_F(RenderProcessHostTest, ProcessOverflow) {
155 // Set max renderers to 1 to force running out of processes. 239 // Set max renderers to 1 to force running out of processes.
156 content::RenderProcessHost::SetMaxRendererProcessCountForTest(1); 240 content::RenderProcessHost::SetMaxRendererProcessCount(1);
241 TestProcessOverflow();
242 }
157 243
158 int tab_count = 1; 244 // Variation of the ProcessOverflow test, which is driven through command line
159 int host_count = 1; 245 // parameter instead of direct function call into the class.
160 WebContents* tab1 = NULL; 246 IN_PROC_BROWSER_TEST_F(RenderProcessHostTestWithCommandLine, ProcessOverflow) {
161 WebContents* tab2 = NULL; 247 TestProcessOverflow();
162 content::RenderProcessHost* rph1 = NULL;
163 content::RenderProcessHost* rph2 = NULL;
164 content::RenderProcessHost* rph3 = NULL;
165
166 #if defined(USE_VIRTUAL_KEYBOARD)
167 ++host_count; // For the virtual keyboard.
168 #endif
169
170 // Change the first tab to be the new tab page (TYPE_WEBUI).
171 GURL newtab(chrome::kTestNewTabURL);
172 ui_test_utils::NavigateToURL(browser(), newtab);
173 EXPECT_EQ(tab_count, browser()->tab_count());
174 tab1 = browser()->GetWebContentsAt(tab_count - 1);
175 rph1 = tab1->GetRenderProcessHost();
176 EXPECT_EQ(tab1->GetURL(), newtab);
177 EXPECT_EQ(host_count, RenderProcessHostCount());
178
179 // Create a new TYPE_TABBED tab. It should be in its own process.
180 GURL page1("data:text/html,hello world1");
181 browser()->ShowSingletonTab(page1);
182 if (browser()->tab_count() == tab_count)
183 ui_test_utils::WaitForNewTab(browser());
184 tab_count++;
185 host_count++;
186 EXPECT_EQ(tab_count, browser()->tab_count());
187 tab1 = browser()->GetWebContentsAt(tab_count - 1);
188 rph2 = tab1->GetRenderProcessHost();
189 EXPECT_EQ(tab1->GetURL(), page1);
190 EXPECT_EQ(host_count, RenderProcessHostCount());
191 EXPECT_NE(rph1, rph2);
192
193 // Create another TYPE_TABBED tab. It should share the previous process.
194 GURL page2("data:text/html,hello world2");
195 browser()->ShowSingletonTab(page2);
196 if (browser()->tab_count() == tab_count)
197 ui_test_utils::WaitForNewTab(browser());
198 tab_count++;
199 EXPECT_EQ(tab_count, browser()->tab_count());
200 tab2 = browser()->GetWebContentsAt(tab_count - 1);
201 EXPECT_EQ(tab2->GetURL(), page2);
202 EXPECT_EQ(host_count, RenderProcessHostCount());
203 EXPECT_EQ(tab2->GetRenderProcessHost(), rph2);
204
205 // Create another TYPE_WEBUI tab. It should share the process with newtab.
206 // Note: intentionally create this tab after the TYPE_TABBED tabs to exercise
207 // bug 43448 where extension and WebUI tabs could get combined into normal
208 // renderers.
209 GURL history(chrome::kTestHistoryURL);
210 browser()->ShowSingletonTab(history);
211 if (browser()->tab_count() == tab_count)
212 ui_test_utils::WaitForNewTab(browser());
213 tab_count++;
214 EXPECT_EQ(tab_count, browser()->tab_count());
215 tab2 = browser()->GetWebContentsAt(tab_count - 1);
216 EXPECT_EQ(tab2->GetURL(), history);
217 EXPECT_EQ(host_count, RenderProcessHostCount());
218 EXPECT_EQ(tab2->GetRenderProcessHost(), rph1);
219
220 // Create a TYPE_EXTENSION tab. It should be in its own process.
221 // (the bookmark manager is implemented as an extension)
222 GURL bookmarks(chrome::kTestBookmarksURL);
223 browser()->ShowSingletonTab(bookmarks);
224 if (browser()->tab_count() == tab_count)
225 ui_test_utils::WaitForNewTab(browser());
226 tab_count++;
227 #if !defined(USE_VIRTUAL_KEYBOARD)
228 // The virtual keyboard already creates an extension process. So this
229 // should not increase the process count.
230 host_count++;
231 #endif
232 EXPECT_EQ(tab_count, browser()->tab_count());
233 tab1 = browser()->GetWebContentsAt(tab_count - 1);
234 rph3 = tab1->GetRenderProcessHost();
235 EXPECT_EQ(tab1->GetURL(), bookmarks);
236 EXPECT_EQ(host_count, RenderProcessHostCount());
237 EXPECT_NE(rph1, rph3);
238 EXPECT_NE(rph2, rph3);
239 } 248 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698