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

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"
18 13
19 class RenderProcessHostTest : public InProcessBrowserTest { 14 namespace {
20 public: 15
21 RenderProcessHostTest() { 16 const char kTempTestWebUI[] = "chrome://history/";
22 EnableDOMAutomation(); 17 const char kTempTestExtension[] = "chrome://bookmarks/";
18
19 }
20
21 RenderProcessHostTest::RenderProcessHostTest() {
22 EnableDOMAutomation();
23 }
24
25 int RenderProcessHostTest::RenderProcessHostCount() {
26 RenderProcessHost::iterator hosts = RenderProcessHost::AllHostsIterator();
27 int count = 0;
28 while (!hosts.IsAtEnd()) {
29 if (hosts.GetCurrentValue()->HasConnection())
30 count++;
31 hosts.Advance();
23 } 32 }
24 33 return count;
25 int RenderProcessHostCount() { 34 }
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 35
63 IN_PROC_BROWSER_TEST_F(RenderProcessHostTest, ProcessPerTab) { 36 IN_PROC_BROWSER_TEST_F(RenderProcessHostTest, ProcessPerTab) {
64 // Set max renderers to 1 to force running out of processes. 37 // Set max renderers to 1 to force running out of processes.
65 RenderProcessHost::SetMaxRendererProcessCount(1); 38 RenderProcessHost::SetMaxRendererProcessCount(1);
66 39
67 CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess(); 40 CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess();
68 parsed_command_line.AppendSwitch(switches::kProcessPerTab); 41 parsed_command_line.AppendSwitch(switches::kProcessPerTab);
69 42
70 int tab_count = 1; 43 int tab_count = 1;
71 int host_count = 1; 44 int host_count = 1;
72 45
73 #if defined(TOUCH_UI) 46 #if defined(TOUCH_UI)
74 ++host_count; // For the touch keyboard. 47 ++host_count; // For the touch keyboard.
75 #endif 48 #endif
76 49
77 // Change the first tab to be the new tab page (TYPE_WEBUI). 50 // Change the first tab to be the new tab page (TYPE_WEBUI).
78 GURL newtab(chrome::kChromeUINewTabURL); 51 GURL newtab("chrome://newtab");
79 ui_test_utils::NavigateToURL(browser(), newtab); 52 ui_test_utils::NavigateToURL(browser(), newtab);
80 EXPECT_EQ(tab_count, browser()->tab_count()); 53 EXPECT_EQ(tab_count, browser()->tab_count());
81 EXPECT_EQ(host_count, RenderProcessHostCount()); 54 EXPECT_EQ(host_count, RenderProcessHostCount());
82 55
83 // Create a new TYPE_TABBED tab. It should be in its own process. 56 // Create a new TYPE_TABBED tab. It should be in its own process.
84 GURL page1("data:text/html,hello world1"); 57 GURL page1("data:text/html,hello world1");
85 browser()->ShowSingletonTab(page1); 58 browser()->ShowSingletonTab(page1);
86 if (browser()->tab_count() == tab_count) 59 if (browser()->tab_count() == tab_count)
87 ui_test_utils::WaitForNewTab(browser()); 60 ui_test_utils::WaitForNewTab(browser());
88 tab_count++; 61 tab_count++;
(...skipping 20 matching lines...) Expand all
109 82
110 // Create another new tab. It should share the process with the other WebUI. 83 // Create another new tab. It should share the process with the other WebUI.
111 browser()->NewTab(); 84 browser()->NewTab();
112 if (browser()->tab_count() == tab_count) 85 if (browser()->tab_count() == tab_count)
113 ui_test_utils::WaitForNewTab(browser()); 86 ui_test_utils::WaitForNewTab(browser());
114 tab_count++; 87 tab_count++;
115 EXPECT_EQ(tab_count, browser()->tab_count()); 88 EXPECT_EQ(tab_count, browser()->tab_count());
116 EXPECT_EQ(host_count, RenderProcessHostCount()); 89 EXPECT_EQ(host_count, RenderProcessHostCount());
117 } 90 }
118 91
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 92 // 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 93 // 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 94 // 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. 95 // in a process of that type, even if that means creating a new process.
198 IN_PROC_BROWSER_TEST_F(RenderProcessHostTest, ProcessOverflow) { 96 IN_PROC_BROWSER_TEST_F(RenderProcessHostTest, ProcessOverflow) {
199 // Set max renderers to 1 to force running out of processes. 97 // Set max renderers to 1 to force running out of processes.
200 RenderProcessHost::SetMaxRendererProcessCount(1); 98 RenderProcessHost::SetMaxRendererProcessCount(1);
201 99
202 int tab_count = 1; 100 int tab_count = 1;
203 int host_count = 1; 101 int host_count = 1;
204 TabContents* tab1 = NULL; 102 TabContents* tab1 = NULL;
205 TabContents* tab2 = NULL; 103 TabContents* tab2 = NULL;
206 RenderProcessHost* rph1 = NULL; 104 RenderProcessHost* rph1 = NULL;
207 RenderProcessHost* rph2 = NULL; 105 RenderProcessHost* rph2 = NULL;
208 RenderProcessHost* rph3 = NULL; 106 RenderProcessHost* rph3 = NULL;
209 107
210 #if defined(TOUCH_UI) 108 #if defined(TOUCH_UI)
211 ++host_count; // For the touch keyboard. 109 ++host_count; // For the touch keyboard.
212 #endif 110 #endif
213 111
214 // Change the first tab to be the new tab page (TYPE_WEBUI). 112 // Change the first tab to be the new tab page (TYPE_WEBUI).
215 GURL newtab(chrome::kChromeUINewTabURL); 113 GURL newtab("chrome://newtab");
216 ui_test_utils::NavigateToURL(browser(), newtab); 114 ui_test_utils::NavigateToURL(browser(), newtab);
217 EXPECT_EQ(tab_count, browser()->tab_count()); 115 EXPECT_EQ(tab_count, browser()->tab_count());
218 tab1 = browser()->GetTabContentsAt(tab_count - 1); 116 tab1 = browser()->GetTabContentsAt(tab_count - 1);
219 rph1 = tab1->GetRenderProcessHost(); 117 rph1 = tab1->GetRenderProcessHost();
220 EXPECT_EQ(tab1->GetURL(), newtab); 118 EXPECT_EQ(tab1->GetURL(), newtab);
221 EXPECT_EQ(host_count, RenderProcessHostCount()); 119 EXPECT_EQ(host_count, RenderProcessHostCount());
222 120
223 // Create a new TYPE_TABBED tab. It should be in its own process. 121 // Create a new TYPE_TABBED tab. It should be in its own process.
224 GURL page1("data:text/html,hello world1"); 122 GURL page1("data:text/html,hello world1");
225 browser()->ShowSingletonTab(page1); 123 browser()->ShowSingletonTab(page1);
(...skipping 17 matching lines...) Expand all
243 EXPECT_EQ(tab_count, browser()->tab_count()); 141 EXPECT_EQ(tab_count, browser()->tab_count());
244 tab2 = browser()->GetTabContentsAt(tab_count - 1); 142 tab2 = browser()->GetTabContentsAt(tab_count - 1);
245 EXPECT_EQ(tab2->GetURL(), page2); 143 EXPECT_EQ(tab2->GetURL(), page2);
246 EXPECT_EQ(host_count, RenderProcessHostCount()); 144 EXPECT_EQ(host_count, RenderProcessHostCount());
247 EXPECT_EQ(tab2->GetRenderProcessHost(), rph2); 145 EXPECT_EQ(tab2->GetRenderProcessHost(), rph2);
248 146
249 // Create another TYPE_WEBUI tab. It should share the process with newtab. 147 // 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 148 // 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 149 // bug 43448 where extension and WebUI tabs could get combined into normal
252 // renderers. 150 // renderers.
253 GURL history(chrome::kChromeUIHistoryURL); 151 GURL history(kTempTestWebUI);
254 browser()->ShowSingletonTab(history); 152 browser()->ShowSingletonTab(history);
255 if (browser()->tab_count() == tab_count) 153 if (browser()->tab_count() == tab_count)
256 ui_test_utils::WaitForNewTab(browser()); 154 ui_test_utils::WaitForNewTab(browser());
257 tab_count++; 155 tab_count++;
258 EXPECT_EQ(tab_count, browser()->tab_count()); 156 EXPECT_EQ(tab_count, browser()->tab_count());
259 tab2 = browser()->GetTabContentsAt(tab_count - 1); 157 tab2 = browser()->GetTabContentsAt(tab_count - 1);
260 EXPECT_EQ(tab2->GetURL(), history); 158 EXPECT_EQ(tab2->GetURL(), history);
261 EXPECT_EQ(host_count, RenderProcessHostCount()); 159 EXPECT_EQ(host_count, RenderProcessHostCount());
262 EXPECT_EQ(tab2->GetRenderProcessHost(), rph1); 160 EXPECT_EQ(tab2->GetRenderProcessHost(), rph1);
263 161
264 // Create a TYPE_EXTENSION tab. It should be in its own process. 162 // Create a TYPE_EXTENSION tab. It should be in its own process.
265 // (the bookmark manager is implemented as an extension) 163 // (the bookmark manager is implemented as an extension)
266 GURL bookmarks(chrome::kChromeUIBookmarksURL); 164 GURL bookmarks(kTempTestExtension);
267 browser()->ShowSingletonTab(bookmarks); 165 browser()->ShowSingletonTab(bookmarks);
268 if (browser()->tab_count() == tab_count) 166 if (browser()->tab_count() == tab_count)
269 ui_test_utils::WaitForNewTab(browser()); 167 ui_test_utils::WaitForNewTab(browser());
270 tab_count++; 168 tab_count++;
271 #if !defined(TOUCH_UI) 169 #if !defined(TOUCH_UI)
272 // The keyboard in touchui already creates an extension process. So this 170 // The keyboard in touchui already creates an extension process. So this
273 // should not increase the process count. 171 // should not increase the process count.
274 host_count++; 172 host_count++;
275 #endif 173 #endif
276 EXPECT_EQ(tab_count, browser()->tab_count()); 174 EXPECT_EQ(tab_count, browser()->tab_count());
277 tab1 = browser()->GetTabContentsAt(tab_count - 1); 175 tab1 = browser()->GetTabContentsAt(tab_count - 1);
278 rph3 = tab1->GetRenderProcessHost(); 176 rph3 = tab1->GetRenderProcessHost();
279 EXPECT_EQ(tab1->GetURL(), bookmarks); 177 EXPECT_EQ(tab1->GetURL(), bookmarks);
280 EXPECT_EQ(host_count, RenderProcessHostCount()); 178 EXPECT_EQ(host_count, RenderProcessHostCount());
281 EXPECT_NE(rph1, rph3); 179 EXPECT_NE(rph1, rph3);
282 EXPECT_NE(rph2, rph3); 180 EXPECT_NE(rph2, rph3);
283 } 181 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698