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