Chromium Code Reviews| 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 "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" |
| 11 #include "chrome/browser/ui/browser.h" | 11 #include "chrome/browser/ui/browser.h" |
| 12 #include "chrome/test/base/ui_test_utils.h" | 12 #include "chrome/test/base/ui_test_utils.h" |
| 13 #include "content/browser/renderer_host/render_process_host_impl.h" | 13 #include "content/browser/renderer_host/render_process_host_impl.h" |
| 14 #include "content/browser/tab_contents/tab_contents.h" | 14 #include "content/browser/tab_contents/tab_contents.h" |
| 15 #include "content/common/test_url_constants.h" | 15 #include "content/common/test_url_constants.h" |
| 16 #include "content/public/browser/browser_thread.h" | 16 #include "content/public/browser/browser_thread.h" |
| 17 #include "content/public/common/content_switches.h" | 17 #include "content/public/common/content_switches.h" |
| 18 #include "net/test/test_server.h" | |
| 18 | 19 |
| 19 using content::WebContents; | 20 using content::WebContents; |
| 20 | 21 |
| 21 RenderProcessHostTest::RenderProcessHostTest() { | 22 RenderProcessHostTest::RenderProcessHostTest() { |
| 22 EnableDOMAutomation(); | 23 EnableDOMAutomation(); |
| 23 } | 24 } |
| 24 | 25 |
| 25 int RenderProcessHostTest::RenderProcessHostCount() { | 26 int RenderProcessHostTest::RenderProcessHostCount() { |
| 26 content::RenderProcessHost::iterator hosts = | 27 content::RenderProcessHost::iterator hosts = |
| 27 content::RenderProcessHost::AllHostsIterator(); | 28 content::RenderProcessHost::AllHostsIterator(); |
| (...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 245 // Set max renderers to 1 to force running out of processes. | 246 // Set max renderers to 1 to force running out of processes. |
| 246 content::RenderProcessHost::SetMaxRendererProcessCount(1); | 247 content::RenderProcessHost::SetMaxRendererProcessCount(1); |
| 247 TestProcessOverflow(); | 248 TestProcessOverflow(); |
| 248 } | 249 } |
| 249 | 250 |
| 250 // Variation of the ProcessOverflow test, which is driven through command line | 251 // Variation of the ProcessOverflow test, which is driven through command line |
| 251 // parameter instead of direct function call into the class. | 252 // parameter instead of direct function call into the class. |
| 252 IN_PROC_BROWSER_TEST_F(RenderProcessHostTestWithCommandLine, ProcessOverflow) { | 253 IN_PROC_BROWSER_TEST_F(RenderProcessHostTestWithCommandLine, ProcessOverflow) { |
| 253 TestProcessOverflow(); | 254 TestProcessOverflow(); |
| 254 } | 255 } |
| 256 | |
| 257 IN_PROC_BROWSER_TEST_F(RenderProcessHostTest, UnresponsiveCrossSiteNavigation) { | |
| 258 WebContents* tab = NULL; | |
| 259 WebContents* tab2 = NULL; | |
| 260 content::RenderProcessHost* rph = NULL; | |
| 261 base::ProcessHandle ph = NULL; | |
|
Charlie Reis
2012/03/01 21:08:17
nit: Rename to process.
nasko
2012/03/01 22:50:15
Done.
| |
| 262 | |
| 263 // Start two servers to enable cross-site navigations. | |
| 264 ASSERT_TRUE(test_server()->Start()); | |
| 265 net::TestServer https_server( | |
| 266 net::TestServer::TYPE_HTTPS, | |
| 267 net::TestServer::kLocalhost, | |
| 268 FilePath(FILE_PATH_LITERAL("chrome/test/data"))); | |
| 269 ASSERT_TRUE(https_server.Start()); | |
| 270 | |
| 271 GURL infinite_url(test_server()->GetURL("files/infinite_beforeunload.html")); | |
|
Charlie Reis
2012/03/01 21:08:17
Why did you choose to hang in beforeunload instead
nasko
2012/03/01 22:50:15
No real reason. After the latest discussions, it m
| |
| 272 GURL same_process_url(test_server()->GetURL("files/english_page.html")); | |
| 273 GURL regular_url(https_server.GetURL("files/english_page.html")); | |
|
Charlie Reis
2012/03/01 21:08:17
What does regular refer to? Maybe new_process_url
nasko
2012/03/01 22:50:15
Done.
| |
| 274 | |
| 275 // Navigate the tab to the page which will lock up the process. | |
|
Charlie Reis
2012/03/01 21:08:17
nit: ...when we navigate away.
nasko
2012/03/01 22:50:15
Done.
| |
| 276 ui_test_utils::NavigateToURL(browser(), infinite_url); | |
| 277 tab = browser()->GetWebContentsAt(0); | |
| 278 rph = tab->GetRenderProcessHost(); | |
| 279 EXPECT_EQ(tab->GetURL(), infinite_url); | |
| 280 | |
| 281 // Remember the process prior to navigation, as we expect it to get killed. | |
| 282 ph = rph->GetHandle(); | |
| 283 ASSERT_TRUE(ph); | |
| 284 | |
| 285 ui_test_utils::NavigateToURL(browser(), regular_url); | |
| 286 EXPECT_FALSE(base::KillProcess(ph, 1, false)); | |
|
Charlie Reis
2012/03/01 21:08:17
Add a comment that this should fail because the pr
nasko
2012/03/01 22:50:15
Done.
| |
| 287 | |
| 288 // Now, let's load the unresponsive page in one tab, then open another tab | |
| 289 // which will use the same process. | |
| 290 ui_test_utils::NavigateToURL(browser(), infinite_url); | |
| 291 tab = browser()->GetWebContentsAt(0); | |
| 292 rph = tab->GetRenderProcessHost(); | |
| 293 EXPECT_EQ(tab->GetURL(), infinite_url); | |
| 294 | |
| 295 ui_test_utils::NavigateToURLWithDisposition(browser(), same_process_url, | |
| 296 NEW_BACKGROUND_TAB, ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | |
| 297 EXPECT_EQ(browser()->tab_count(), 2); | |
| 298 tab2 = browser()->GetWebContentsAt(1); | |
| 299 ASSERT_TRUE(tab2 != NULL); | |
| 300 EXPECT_EQ(tab2->GetURL(), same_process_url); | |
| 301 EXPECT_EQ(rph, tab2->GetRenderProcessHost()); | |
| 302 | |
| 303 ph = rph->GetHandle(); | |
| 304 ASSERT_TRUE(ph); | |
| 305 | |
| 306 // Navigating to the cross site URL will not kill the process, since it will | |
| 307 // have more than one tab using it. Kill it to confirm that it is still there, | |
| 308 // as well as finish the test faster. | |
| 309 ui_test_utils::NavigateToURL(browser(), regular_url); | |
| 310 EXPECT_TRUE(base::KillProcess(ph, 1, false)); | |
| 311 } | |
| OLD | NEW |