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

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

Issue 7049010: Finish removing url_constants from content/. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: constants Created 9 years, 7 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"
6
5 #include "base/command_line.h" 7 #include "base/command_line.h"
6 #include "chrome/browser/debugger/devtools_manager.h"
7 #include "chrome/browser/ui/browser.h" 8 #include "chrome/browser/ui/browser.h"
8 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
9 #include "chrome/common/chrome_switches.h" 9 #include "chrome/common/chrome_switches.h"
10 #include "chrome/common/url_constants.h"
11 #include "chrome/test/in_process_browser_test.h"
12 #include "chrome/test/ui_test_utils.h" 10 #include "chrome/test/ui_test_utils.h"
13 #include "content/browser/renderer_host/render_process_host.h" 11 #include "content/browser/renderer_host/render_process_host.h"
14 #include "content/browser/renderer_host/render_view_host.h"
15 #include "content/browser/renderer_host/render_widget_host.h"
16 #include "content/browser/site_instance.h"
17 #include "content/browser/tab_contents/tab_contents.h" 12 #include "content/browser/tab_contents/tab_contents.h"
13 #include "content/common/test_url_constants.h"
18 14
19 class RenderProcessHostTest : public InProcessBrowserTest { 15 RenderProcessHostTest::RenderProcessHostTest() {
20 public: 16 EnableDOMAutomation();
21 RenderProcessHostTest() { 17 }
22 EnableDOMAutomation(); 18
19 int RenderProcessHostTest::RenderProcessHostCount() {
20 RenderProcessHost::iterator hosts = RenderProcessHost::AllHostsIterator();
21 int count = 0;
22 while (!hosts.IsAtEnd()) {
23 if (hosts.GetCurrentValue()->HasConnection())
24 count++;
25 hosts.Advance();
23 } 26 }
24 27 return count;
25 int RenderProcessHostCount() { 28 }
26 RenderProcessHost::iterator hosts = RenderProcessHost::AllHostsIterator();
27 int count = 0;
28 while (!hosts.IsAtEnd()) {
29 if (hosts.GetCurrentValue()->HasConnection())
30 count++;
31 hosts.Advance();
32 }
33 return count;
34 }
35
36 RenderViewHost* FindFirstDevToolsHost() {
37 RenderProcessHost::iterator hosts = RenderProcessHost::AllHostsIterator();
38 for (; !hosts.IsAtEnd(); hosts.Advance()) {
39 RenderProcessHost* render_process_host = hosts.GetCurrentValue();
40 DCHECK(render_process_host);
41 if (!render_process_host->HasConnection())
42 continue;
43 RenderProcessHost::listeners_iterator iter(
44 render_process_host->ListenersIterator());
45 for (; !iter.IsAtEnd(); iter.Advance()) {
46 const RenderWidgetHost* widget =
47 static_cast<const RenderWidgetHost*>(iter.GetCurrentValue());
48 DCHECK(widget);
49 if (!widget || !widget->IsRenderView())
50 continue;
51 RenderViewHost* host = const_cast<RenderViewHost*>(
52 static_cast<const RenderViewHost*>(widget));
53 RenderViewHostDelegate* host_delegate = host->delegate();
54 GURL url = host_delegate->GetURL();
55 if (url.SchemeIs(chrome::kChromeDevToolsScheme))
56 return host;
57 }
58 }
59 return NULL;
60 }
61 };
62 29
63 IN_PROC_BROWSER_TEST_F(RenderProcessHostTest, ProcessPerTab) { 30 IN_PROC_BROWSER_TEST_F(RenderProcessHostTest, ProcessPerTab) {
64 // Set max renderers to 1 to force running out of processes. 31 // Set max renderers to 1 to force running out of processes.
65 RenderProcessHost::SetMaxRendererProcessCount(1); 32 RenderProcessHost::SetMaxRendererProcessCount(1);
66 33
67 CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess(); 34 CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess();
68 parsed_command_line.AppendSwitch(switches::kProcessPerTab); 35 parsed_command_line.AppendSwitch(switches::kProcessPerTab);
69 36
70 int tab_count = 1; 37 int tab_count = 1;
71 int host_count = 1; 38 int host_count = 1;
72 39
73 #if defined(TOUCH_UI) 40 #if defined(TOUCH_UI)
74 ++host_count; // For the touch keyboard. 41 ++host_count; // For the touch keyboard.
75 #endif 42 #endif
76 43
77 // Change the first tab to be the new tab page (TYPE_WEBUI). 44 // Change the first tab to be the new tab page (TYPE_WEBUI).
78 GURL newtab(chrome::kChromeUINewTabURL); 45 GURL newtab(chrome::kTestNewTabURL);
79 ui_test_utils::NavigateToURL(browser(), newtab); 46 ui_test_utils::NavigateToURL(browser(), newtab);
80 EXPECT_EQ(tab_count, browser()->tab_count()); 47 EXPECT_EQ(tab_count, browser()->tab_count());
81 EXPECT_EQ(host_count, RenderProcessHostCount()); 48 EXPECT_EQ(host_count, RenderProcessHostCount());
82 49
83 // Create a new TYPE_TABBED tab. It should be in its own process. 50 // Create a new TYPE_TABBED tab. It should be in its own process.
84 GURL page1("data:text/html,hello world1"); 51 GURL page1("data:text/html,hello world1");
85 browser()->ShowSingletonTab(page1); 52 browser()->ShowSingletonTab(page1);
86 if (browser()->tab_count() == tab_count) 53 if (browser()->tab_count() == tab_count)
87 ui_test_utils::WaitForNewTab(browser()); 54 ui_test_utils::WaitForNewTab(browser());
88 tab_count++; 55 tab_count++;
(...skipping 20 matching lines...) Expand all
109 76
110 // Create another new tab. It should share the process with the other WebUI. 77 // Create another new tab. It should share the process with the other WebUI.
111 browser()->NewTab(); 78 browser()->NewTab();
112 if (browser()->tab_count() == tab_count) 79 if (browser()->tab_count() == tab_count)
113 ui_test_utils::WaitForNewTab(browser()); 80 ui_test_utils::WaitForNewTab(browser());
114 tab_count++; 81 tab_count++;
115 EXPECT_EQ(tab_count, browser()->tab_count()); 82 EXPECT_EQ(tab_count, browser()->tab_count());
116 EXPECT_EQ(host_count, RenderProcessHostCount()); 83 EXPECT_EQ(host_count, RenderProcessHostCount());
117 } 84 }
118 85
119 // Ensure that DevTools opened to debug DevTools is launched in a separate
120 // process when --process-per-tab is set. See crbug.com/69873.
121 IN_PROC_BROWSER_TEST_F(RenderProcessHostTest, DevToolsOnSelfInOwnProcessPPT) {
122 CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess();
123 parsed_command_line.AppendSwitch(switches::kProcessPerTab);
124
125 int tab_count = 1;
126 int host_count = 1;
127
128 #if defined(TOUCH_UI)
129 ++host_count; // For the touch keyboard.
130 #endif
131
132 GURL page1("data:text/html,hello world1");
133 browser()->ShowSingletonTab(page1);
134 if (browser()->tab_count() == tab_count)
135 ui_test_utils::WaitForNewTab(browser());
136 tab_count++;
137 host_count++;
138 EXPECT_EQ(tab_count, browser()->tab_count());
139 EXPECT_EQ(host_count, RenderProcessHostCount());
140
141 // DevTools start in docked mode (no new tab), in a separate process.
142 browser()->ToggleDevToolsWindow(DEVTOOLS_TOGGLE_ACTION_INSPECT);
143 host_count++;
144 EXPECT_EQ(tab_count, browser()->tab_count());
145 EXPECT_EQ(host_count, RenderProcessHostCount());
146
147 RenderViewHost* devtools = FindFirstDevToolsHost();
148 DCHECK(devtools);
149
150 // DevTools start in a separate process.
151 DevToolsManager::GetInstance()->ToggleDevToolsWindow(
152 devtools, DEVTOOLS_TOGGLE_ACTION_INSPECT);
153 host_count++;
154 EXPECT_EQ(tab_count, browser()->tab_count());
155 EXPECT_EQ(host_count, RenderProcessHostCount());
156 }
157
158 // Ensure that DevTools opened to debug DevTools is launched in a separate
159 // process. See crbug.com/69873.
160 IN_PROC_BROWSER_TEST_F(RenderProcessHostTest, DevToolsOnSelfInOwnProcess) {
161 int tab_count = 1;
162 int host_count = 1;
163
164 #if defined(TOUCH_UI)
165 ++host_count; // For the touch keyboard.
166 #endif
167
168 GURL page1("data:text/html,hello world1");
169 browser()->ShowSingletonTab(page1);
170 if (browser()->tab_count() == tab_count)
171 ui_test_utils::WaitForNewTab(browser());
172 tab_count++;
173 host_count++;
174 EXPECT_EQ(tab_count, browser()->tab_count());
175 EXPECT_EQ(host_count, RenderProcessHostCount());
176
177 // DevTools start in docked mode (no new tab), in a separate process.
178 browser()->ToggleDevToolsWindow(DEVTOOLS_TOGGLE_ACTION_INSPECT);
179 host_count++;
180 EXPECT_EQ(tab_count, browser()->tab_count());
181 EXPECT_EQ(host_count, RenderProcessHostCount());
182
183 RenderViewHost* devtools = FindFirstDevToolsHost();
184 DCHECK(devtools);
185
186 // DevTools start in a separate process.
187 DevToolsManager::GetInstance()->ToggleDevToolsWindow(
188 devtools, DEVTOOLS_TOGGLE_ACTION_INSPECT);
189 host_count++;
190 EXPECT_EQ(tab_count, browser()->tab_count());
191 EXPECT_EQ(host_count, RenderProcessHostCount());
192 }
193
194 // When we hit the max number of renderers, verify that the way we do process 86 // When we hit the max number of renderers, verify that the way we do process
195 // sharing behaves correctly. In particular, this test is verifying that even 87 // sharing behaves correctly. In particular, this test is verifying that even
196 // when we hit the max process limit, that renderers of each type will wind up 88 // when we hit the max process limit, that renderers of each type will wind up
197 // in a process of that type, even if that means creating a new process. 89 // in a process of that type, even if that means creating a new process.
198 IN_PROC_BROWSER_TEST_F(RenderProcessHostTest, ProcessOverflow) { 90 IN_PROC_BROWSER_TEST_F(RenderProcessHostTest, ProcessOverflow) {
199 // Set max renderers to 1 to force running out of processes. 91 // Set max renderers to 1 to force running out of processes.
200 RenderProcessHost::SetMaxRendererProcessCount(1); 92 RenderProcessHost::SetMaxRendererProcessCount(1);
201 93
202 int tab_count = 1; 94 int tab_count = 1;
203 int host_count = 1; 95 int host_count = 1;
204 TabContents* tab1 = NULL; 96 TabContents* tab1 = NULL;
205 TabContents* tab2 = NULL; 97 TabContents* tab2 = NULL;
206 RenderProcessHost* rph1 = NULL; 98 RenderProcessHost* rph1 = NULL;
207 RenderProcessHost* rph2 = NULL; 99 RenderProcessHost* rph2 = NULL;
208 RenderProcessHost* rph3 = NULL; 100 RenderProcessHost* rph3 = NULL;
209 101
210 #if defined(TOUCH_UI) 102 #if defined(TOUCH_UI)
211 ++host_count; // For the touch keyboard. 103 ++host_count; // For the touch keyboard.
212 #endif 104 #endif
213 105
214 // Change the first tab to be the new tab page (TYPE_WEBUI). 106 // Change the first tab to be the new tab page (TYPE_WEBUI).
215 GURL newtab(chrome::kChromeUINewTabURL); 107 GURL newtab(chrome::kTestNewTabURL);
216 ui_test_utils::NavigateToURL(browser(), newtab); 108 ui_test_utils::NavigateToURL(browser(), newtab);
217 EXPECT_EQ(tab_count, browser()->tab_count()); 109 EXPECT_EQ(tab_count, browser()->tab_count());
218 tab1 = browser()->GetTabContentsAt(tab_count - 1); 110 tab1 = browser()->GetTabContentsAt(tab_count - 1);
219 rph1 = tab1->GetRenderProcessHost(); 111 rph1 = tab1->GetRenderProcessHost();
220 EXPECT_EQ(tab1->GetURL(), newtab); 112 EXPECT_EQ(tab1->GetURL(), newtab);
221 EXPECT_EQ(host_count, RenderProcessHostCount()); 113 EXPECT_EQ(host_count, RenderProcessHostCount());
222 114
223 // Create a new TYPE_TABBED tab. It should be in its own process. 115 // Create a new TYPE_TABBED tab. It should be in its own process.
224 GURL page1("data:text/html,hello world1"); 116 GURL page1("data:text/html,hello world1");
225 browser()->ShowSingletonTab(page1); 117 browser()->ShowSingletonTab(page1);
(...skipping 17 matching lines...) Expand all
243 EXPECT_EQ(tab_count, browser()->tab_count()); 135 EXPECT_EQ(tab_count, browser()->tab_count());
244 tab2 = browser()->GetTabContentsAt(tab_count - 1); 136 tab2 = browser()->GetTabContentsAt(tab_count - 1);
245 EXPECT_EQ(tab2->GetURL(), page2); 137 EXPECT_EQ(tab2->GetURL(), page2);
246 EXPECT_EQ(host_count, RenderProcessHostCount()); 138 EXPECT_EQ(host_count, RenderProcessHostCount());
247 EXPECT_EQ(tab2->GetRenderProcessHost(), rph2); 139 EXPECT_EQ(tab2->GetRenderProcessHost(), rph2);
248 140
249 // Create another TYPE_WEBUI tab. It should share the process with newtab. 141 // Create another TYPE_WEBUI tab. It should share the process with newtab.
250 // Note: intentionally create this tab after the TYPE_TABBED tabs to exercise 142 // Note: intentionally create this tab after the TYPE_TABBED tabs to exercise
251 // bug 43448 where extension and WebUI tabs could get combined into normal 143 // bug 43448 where extension and WebUI tabs could get combined into normal
252 // renderers. 144 // renderers.
253 GURL history(chrome::kChromeUIHistoryURL); 145 GURL history(chrome::kTestHistoryURL);
254 browser()->ShowSingletonTab(history); 146 browser()->ShowSingletonTab(history);
255 if (browser()->tab_count() == tab_count) 147 if (browser()->tab_count() == tab_count)
256 ui_test_utils::WaitForNewTab(browser()); 148 ui_test_utils::WaitForNewTab(browser());
257 tab_count++; 149 tab_count++;
258 EXPECT_EQ(tab_count, browser()->tab_count()); 150 EXPECT_EQ(tab_count, browser()->tab_count());
259 tab2 = browser()->GetTabContentsAt(tab_count - 1); 151 tab2 = browser()->GetTabContentsAt(tab_count - 1);
260 EXPECT_EQ(tab2->GetURL(), history); 152 EXPECT_EQ(tab2->GetURL(), history);
261 EXPECT_EQ(host_count, RenderProcessHostCount()); 153 EXPECT_EQ(host_count, RenderProcessHostCount());
262 EXPECT_EQ(tab2->GetRenderProcessHost(), rph1); 154 EXPECT_EQ(tab2->GetRenderProcessHost(), rph1);
263 155
264 // Create a TYPE_EXTENSION tab. It should be in its own process. 156 // Create a TYPE_EXTENSION tab. It should be in its own process.
265 // (the bookmark manager is implemented as an extension) 157 // (the bookmark manager is implemented as an extension)
266 GURL bookmarks(chrome::kChromeUIBookmarksURL); 158 GURL bookmarks(chrome::kTestBookmarksURL);
267 browser()->ShowSingletonTab(bookmarks); 159 browser()->ShowSingletonTab(bookmarks);
268 if (browser()->tab_count() == tab_count) 160 if (browser()->tab_count() == tab_count)
269 ui_test_utils::WaitForNewTab(browser()); 161 ui_test_utils::WaitForNewTab(browser());
270 tab_count++; 162 tab_count++;
271 #if !defined(TOUCH_UI) 163 #if !defined(TOUCH_UI)
272 // The keyboard in touchui already creates an extension process. So this 164 // The keyboard in touchui already creates an extension process. So this
273 // should not increase the process count. 165 // should not increase the process count.
274 host_count++; 166 host_count++;
275 #endif 167 #endif
276 EXPECT_EQ(tab_count, browser()->tab_count()); 168 EXPECT_EQ(tab_count, browser()->tab_count());
277 tab1 = browser()->GetTabContentsAt(tab_count - 1); 169 tab1 = browser()->GetTabContentsAt(tab_count - 1);
278 rph3 = tab1->GetRenderProcessHost(); 170 rph3 = tab1->GetRenderProcessHost();
279 EXPECT_EQ(tab1->GetURL(), bookmarks); 171 EXPECT_EQ(tab1->GetURL(), bookmarks);
280 EXPECT_EQ(host_count, RenderProcessHostCount()); 172 EXPECT_EQ(host_count, RenderProcessHostCount());
281 EXPECT_NE(rph1, rph3); 173 EXPECT_NE(rph1, rph3);
282 EXPECT_NE(rph2, rph3); 174 EXPECT_NE(rph2, rph3);
283 } 175 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698