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

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

Issue 9514016: Fixing a problem, where a hung renderer process is not killed when navigating away (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Incorporating Charlie's feedback. Created 8 years, 9 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) 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
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 process = NULL;
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")));
jam 2012/03/02 00:21:10 please don't hard code paths in tests. can you p
nasko 2012/03/02 18:40:36 I've moved the files to the content/test/data, but
269 ASSERT_TRUE(https_server.Start());
270
271 GURL infinite_beforeunload_url(
272 test_server()->GetURL("files/infinite_beforeunload.html"));
273 GURL infinite_unload_url(test_server()->GetURL("files/infinite_unload.html"));
274 GURL same_process_url(test_server()->GetURL("files/english_page.html"));
275 GURL new_process_url(https_server.GetURL("files/english_page.html"));
276
277 // Navigate the tab to the page which will lock up the process when we
278 // navigate away from it.
279 ui_test_utils::NavigateToURL(browser(), infinite_unload_url);
280 tab = browser()->GetWebContentsAt(0);
281 rph = tab->GetRenderProcessHost();
282 EXPECT_EQ(tab->GetURL(), infinite_unload_url);
283
284 // Remember the process prior to navigation, as we expect it to get killed.
285 process = rph->GetHandle();
286 ASSERT_TRUE(process);
287
288 ui_test_utils::NavigateToURL(browser(), new_process_url);
289 // This should fail, because the navigation to the new URL would result in
290 // the process getting killed. This is an indirect way to check for the
291 // process having been terminated.
292 EXPECT_FALSE(base::KillProcess(process, 1, false));
293
294 // Now, let's load the unresponsive page in one tab, then open another tab
295 // which will use the same process.
296 ui_test_utils::NavigateToURL(browser(), infinite_beforeunload_url);
297 tab = browser()->GetWebContentsAt(0);
298 rph = tab->GetRenderProcessHost();
299 EXPECT_EQ(tab->GetURL(), infinite_beforeunload_url);
300
301 ui_test_utils::NavigateToURLWithDisposition(browser(), same_process_url,
302 NEW_BACKGROUND_TAB, ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
303 EXPECT_EQ(browser()->tab_count(), 2);
304 tab2 = browser()->GetWebContentsAt(1);
305 ASSERT_TRUE(tab2 != NULL);
306 EXPECT_EQ(tab2->GetURL(), same_process_url);
307 EXPECT_EQ(rph, tab2->GetRenderProcessHost());
308
309 process = rph->GetHandle();
310 ASSERT_TRUE(process);
311
312 // Navigating to the cross site URL will not kill the process, since it will
313 // have more than one tab using it. Kill it to confirm that it is still there,
314 // as well as finish the test faster.
315 ui_test_utils::NavigateToURL(browser(), new_process_url);
316 EXPECT_TRUE(base::KillProcess(process, 1, false));
317 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698