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 "base/time.h" | 5 #include "base/time.h" |
6 #include "base/utf_string_conversions.h" | 6 #include "base/utf_string_conversions.h" |
7 #include "base/values.h" | 7 #include "base/values.h" |
8 #include "chrome/browser/ui/browser.h" | 8 #include "chrome/browser/ui/browser.h" |
9 #include "chrome/test/base/in_process_browser_test.h" | 9 #include "chrome/test/base/in_process_browser_test.h" |
10 #include "chrome/test/base/ui_test_utils.h" | 10 #include "chrome/test/base/ui_test_utils.h" |
11 #include "content/browser/renderer_host/render_view_host_impl.h" | 11 #include "content/browser/renderer_host/render_view_host_impl.h" |
12 #include "content/browser/web_contents/web_contents_impl.h" | 12 #include "content/browser/web_contents/web_contents_impl.h" |
13 #include "content/common/view_messages.h" | 13 #include "content/common/view_messages.h" |
| 14 #include "content/public/browser/notification_service.h" |
14 #include "content/public/browser/notification_types.h" | 15 #include "content/public/browser/notification_types.h" |
15 #include "content/public/browser/web_contents_observer.h" | 16 #include "content/public/browser/web_contents_observer.h" |
16 #include "net/base/host_port_pair.h" | 17 #include "net/base/host_port_pair.h" |
17 #include "net/base/net_util.h" | 18 #include "net/base/net_util.h" |
18 #include "net/test/test_server.h" | 19 #include "net/test/test_server.h" |
19 | 20 |
20 using content::RenderViewHostImpl; | 21 using content::RenderViewHostImpl; |
21 using content::WebContents; | 22 using content::WebContents; |
22 | 23 |
23 class RenderViewHostTest : public InProcessBrowserTest { | 24 class RenderViewHostTest : public InProcessBrowserTest { |
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
221 ui_test_utils::NavigateToURL(browser(), test_url); | 222 ui_test_utils::NavigateToURL(browser(), test_url); |
222 EXPECT_TRUE(observer.base_url().is_empty()); | 223 EXPECT_TRUE(observer.base_url().is_empty()); |
223 EXPECT_EQ(1, observer.navigation_count()); | 224 EXPECT_EQ(1, observer.navigation_count()); |
224 | 225 |
225 // But should be set to the original page when reading MHTML. | 226 // But should be set to the original page when reading MHTML. |
226 test_url = net::FilePathToFileURL(test_server()->document_root().Append( | 227 test_url = net::FilePathToFileURL(test_server()->document_root().Append( |
227 FILE_PATH_LITERAL("google.mht"))); | 228 FILE_PATH_LITERAL("google.mht"))); |
228 ui_test_utils::NavigateToURL(browser(), test_url); | 229 ui_test_utils::NavigateToURL(browser(), test_url); |
229 EXPECT_EQ("http://www.google.com/", observer.base_url().spec()); | 230 EXPECT_EQ("http://www.google.com/", observer.base_url().spec()); |
230 } | 231 } |
| 232 |
| 233 // Test that a hung renderer is killed after navigating away during cross-site |
| 234 // navigation. |
| 235 IN_PROC_BROWSER_TEST_F(RenderViewHostTest, UnresponsiveCrossSiteNavigation) { |
| 236 WebContents* tab = NULL; |
| 237 WebContents* tab2 = NULL; |
| 238 content::RenderProcessHost* rph = NULL; |
| 239 base::ProcessHandle process; |
| 240 FilePath doc_root; |
| 241 |
| 242 doc_root = doc_root.Append(FILE_PATH_LITERAL("content")); |
| 243 doc_root = doc_root.Append(FILE_PATH_LITERAL("test")); |
| 244 doc_root = doc_root.Append(FILE_PATH_LITERAL("data")); |
| 245 |
| 246 // Start two servers to enable cross-site navigations. |
| 247 net::TestServer server(net::TestServer::TYPE_HTTP, |
| 248 net::TestServer::kLocalhost, doc_root); |
| 249 ASSERT_TRUE(server.Start()); |
| 250 net::TestServer https_server(net::TestServer::TYPE_HTTPS, |
| 251 net::TestServer::kLocalhost, doc_root); |
| 252 ASSERT_TRUE(https_server.Start()); |
| 253 |
| 254 GURL infinite_beforeunload_url( |
| 255 server.GetURL("files/infinite_beforeunload.html")); |
| 256 GURL infinite_unload_url(server.GetURL("files/infinite_unload.html")); |
| 257 GURL same_process_url(server.GetURL("files/english_page.html")); |
| 258 GURL new_process_url(https_server.GetURL("files/english_page.html")); |
| 259 |
| 260 // Navigate the tab to the page which will lock up the process when we |
| 261 // navigate away from it. |
| 262 ui_test_utils::NavigateToURL(browser(), infinite_beforeunload_url); |
| 263 tab = browser()->GetWebContentsAt(0); |
| 264 rph = tab->GetRenderProcessHost(); |
| 265 EXPECT_EQ(tab->GetURL(), infinite_beforeunload_url); |
| 266 |
| 267 // Remember the process prior to navigation, as we expect it to get killed. |
| 268 process = rph->GetHandle(); |
| 269 ASSERT_TRUE(process); |
| 270 |
| 271 { |
| 272 ui_test_utils::WindowedNotificationObserver process_exit_observer( |
| 273 content::NOTIFICATION_RENDERER_PROCESS_CLOSED, |
| 274 content::NotificationService::AllSources()); |
| 275 ui_test_utils::WindowedNotificationObserver process_hang_observer( |
| 276 content::NOTIFICATION_RENDERER_PROCESS_HANG, |
| 277 content::NotificationService::AllSources()); |
| 278 ui_test_utils::NavigateToURL(browser(), new_process_url); |
| 279 process_hang_observer.Wait(); |
| 280 process_exit_observer.Wait(); |
| 281 |
| 282 // Since the process is killed during the navigation, we don't expect the |
| 283 // renderer host to have a connection to it. |
| 284 EXPECT_FALSE(rph->HasConnection()); |
| 285 } |
| 286 |
| 287 ui_test_utils::NavigateToURL(browser(), same_process_url); |
| 288 tab = browser()->GetWebContentsAt(0); |
| 289 rph = tab->GetRenderProcessHost(); |
| 290 ASSERT_TRUE(tab != NULL); |
| 291 EXPECT_EQ(tab->GetURL(), same_process_url); |
| 292 |
| 293 // Now, let's open another tab with the unresponsive page, which will cause |
| 294 // the previous page and the unresponsive one to use the same process. |
| 295 ui_test_utils::NavigateToURLWithDisposition(browser(), |
| 296 infinite_unload_url, NEW_FOREGROUND_TAB, |
| 297 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
| 298 EXPECT_EQ(browser()->tab_count(), 2); |
| 299 tab2 = browser()->GetWebContentsAt(1); |
| 300 ASSERT_TRUE(tab2 != NULL); |
| 301 EXPECT_EQ(tab2->GetURL(), infinite_unload_url); |
| 302 EXPECT_EQ(rph, tab2->GetRenderProcessHost()); |
| 303 |
| 304 process = rph->GetHandle(); |
| 305 ASSERT_TRUE(process); |
| 306 |
| 307 // Navigating to the cross site URL will not kill the process, since it will |
| 308 // have more than one tab using it. Kill it to confirm that it is still there, |
| 309 // as well as finish the test faster. |
| 310 { |
| 311 ui_test_utils::WindowedNotificationObserver process_exit_observer( |
| 312 content::NOTIFICATION_RENDERER_PROCESS_HANG, |
| 313 content::NotificationService::AllSources()); |
| 314 ui_test_utils::NavigateToURL(browser(), new_process_url); |
| 315 process_exit_observer.Wait(); |
| 316 } |
| 317 |
| 318 EXPECT_TRUE(base::KillProcess(process, 2, false)); |
| 319 } |
| 320 |
| 321 // Test that a hung renderer is killed when we are closing the page. |
| 322 IN_PROC_BROWSER_TEST_F(RenderViewHostTest, UnresponsiveClosePage) { |
| 323 WebContents* tab = NULL; |
| 324 FilePath doc_root; |
| 325 |
| 326 doc_root = doc_root.Append(FILE_PATH_LITERAL("content")); |
| 327 doc_root = doc_root.Append(FILE_PATH_LITERAL("test")); |
| 328 doc_root = doc_root.Append(FILE_PATH_LITERAL("data")); |
| 329 |
| 330 net::TestServer server(net::TestServer::TYPE_HTTP, |
| 331 net::TestServer::kLocalhost, doc_root); |
| 332 ASSERT_TRUE(server.Start()); |
| 333 net::TestServer https_server(net::TestServer::TYPE_HTTPS, |
| 334 net::TestServer::kLocalhost, doc_root); |
| 335 ASSERT_TRUE(https_server.Start()); |
| 336 |
| 337 GURL infinite_beforeunload_url( |
| 338 server.GetURL("files/infinite_beforeunload.html")); |
| 339 GURL infinite_unload_url(server.GetURL("files/infinite_unload.html")); |
| 340 GURL new_process_url(https_server.GetURL("files/english_page.html")); |
| 341 |
| 342 ui_test_utils::NavigateToURL(browser(), new_process_url); |
| 343 |
| 344 // Navigate a tab to a page which will spin into an infinite loop in the |
| 345 // beforeunload handler, tying up the process when we close the tab. |
| 346 ui_test_utils::NavigateToURLWithDisposition(browser(), |
| 347 infinite_beforeunload_url, NEW_FOREGROUND_TAB, |
| 348 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
| 349 tab = browser()->GetWebContentsAt(1); |
| 350 { |
| 351 ui_test_utils::WindowedNotificationObserver process_exit_observer( |
| 352 content::NOTIFICATION_RENDERER_PROCESS_TERMINATED, |
| 353 content::NotificationService::AllSources()); |
| 354 browser()->CloseTabContents(tab); |
| 355 process_exit_observer.Wait(); |
| 356 } |
| 357 |
| 358 // Navigate a tab to a page which will spin into an infinite loop in the |
| 359 // unload handler, tying up the process when we close the tab. |
| 360 ui_test_utils::NavigateToURLWithDisposition(browser(), |
| 361 infinite_unload_url, NEW_FOREGROUND_TAB, |
| 362 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
| 363 tab = browser()->GetWebContentsAt(1); |
| 364 { |
| 365 ui_test_utils::WindowedNotificationObserver process_exit_observer( |
| 366 content::NOTIFICATION_RENDERER_PROCESS_TERMINATED, |
| 367 content::NotificationService::AllSources()); |
| 368 browser()->CloseTabContents(tab); |
| 369 process_exit_observer.Wait(); |
| 370 } |
| 371 } |
OLD | NEW |