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/tab_contents/tab_contents.h" | 12 #include "content/browser/tab_contents/tab_contents.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 | |
283 // This should fail, because the navigation to the new URL results in | |
284 // the process getting killed. This is an indirect way to check for the | |
285 // process having been terminated. | |
286 EXPECT_FALSE(base::KillProcess(process, 1, false)); | |
287 | |
288 ui_test_utils::NavigateToURL(browser(), same_process_url); | |
289 tab = browser()->GetWebContentsAt(0); | |
290 rph = tab->GetRenderProcessHost(); | |
291 ASSERT_TRUE(tab != NULL); | |
292 EXPECT_EQ(tab->GetURL(), same_process_url); | |
293 | |
294 // Now, let's open another tab with the unresponsive page, which will cause | |
295 // the previous page and the unresponsive one to use the same process. | |
296 ui_test_utils::NavigateToURLWithDisposition(browser(), | |
297 infinite_unload_url, NEW_FOREGROUND_TAB, | |
298 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | |
299 EXPECT_EQ(browser()->tab_count(), 2); | |
300 tab2 = browser()->GetWebContentsAt(1); | |
301 ASSERT_TRUE(tab2 != NULL); | |
302 EXPECT_EQ(tab2->GetURL(), infinite_unload_url); | |
303 EXPECT_EQ(rph, tab2->GetRenderProcessHost()); | |
304 | |
305 process = rph->GetHandle(); | |
306 ASSERT_TRUE(process); | |
307 | |
308 // Navigating to the cross site URL will not kill the process, since it will | |
309 // have more than one tab using it. Kill it to confirm that it is still there, | |
310 // as well as finish the test faster. | |
311 { | |
312 ui_test_utils::WindowedNotificationObserver process_exit_observer( | |
313 content::NOTIFICATION_RENDERER_PROCESS_HANG, | |
314 content::NotificationService::AllSources()); | |
315 ui_test_utils::NavigateToURL(browser(), new_process_url); | |
316 process_exit_observer.Wait(); | |
317 } | |
318 | |
319 EXPECT_TRUE(base::KillProcess(process, 2, false)); | |
320 } | |
321 | |
322 // Test that a hung renderer is killed when we are closing the page. | |
323 IN_PROC_BROWSER_TEST_F(RenderViewHostTest, UnresponsiveClosePage) { | |
324 WebContents* tab = NULL; | |
325 FilePath doc_root; | |
326 | |
327 doc_root = doc_root.Append(FILE_PATH_LITERAL("content")); | |
328 doc_root = doc_root.Append(FILE_PATH_LITERAL("test")); | |
329 doc_root = doc_root.Append(FILE_PATH_LITERAL("data")); | |
330 | |
331 net::TestServer server(net::TestServer::TYPE_HTTP, | |
332 net::TestServer::kLocalhost, doc_root); | |
333 ASSERT_TRUE(server.Start()); | |
334 net::TestServer https_server(net::TestServer::TYPE_HTTPS, | |
335 net::TestServer::kLocalhost, doc_root); | |
336 ASSERT_TRUE(https_server.Start()); | |
337 | |
338 GURL infinite_beforeunload_url( | |
339 server.GetURL("files/infinite_beforeunload.html")); | |
340 GURL infinite_unload_url(server.GetURL("files/infinite_unload.html")); | |
341 GURL new_process_url(https_server.GetURL("files/english_page.html")); | |
342 GURL prompt_infinite_url(server.GetURL( | |
343 "files/prompt_beforeunload_infinite_unload.html")); | |
Charlie Reis
2012/04/10 17:22:05
This apparently isn't used anymore, so we don't ne
| |
344 | |
345 ui_test_utils::NavigateToURL(browser(), new_process_url); | |
346 | |
347 // Navigate a tab to a page which will spin into an infinite loop in the | |
348 // beforeunload handler, tying up the process when we close the tab. | |
349 ui_test_utils::NavigateToURLWithDisposition(browser(), | |
350 infinite_beforeunload_url, NEW_FOREGROUND_TAB, | |
351 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | |
352 tab = browser()->GetWebContentsAt(1); | |
353 { | |
354 ui_test_utils::WindowedNotificationObserver process_exit_observer( | |
355 content::NOTIFICATION_RENDERER_PROCESS_TERMINATED, | |
356 content::NotificationService::AllSources()); | |
357 browser()->CloseTabContents(tab); | |
358 process_exit_observer.Wait(); | |
359 } | |
360 | |
361 // Navigate a tab to a page which will spin into an infinite loop in the | |
362 // unload handler, tying up the process when we close the tab. | |
363 ui_test_utils::NavigateToURLWithDisposition(browser(), | |
364 infinite_unload_url, NEW_FOREGROUND_TAB, | |
365 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | |
366 tab = browser()->GetWebContentsAt(1); | |
367 { | |
368 ui_test_utils::WindowedNotificationObserver process_exit_observer( | |
369 content::NOTIFICATION_RENDERER_PROCESS_TERMINATED, | |
370 content::NotificationService::AllSources()); | |
371 browser()->CloseTabContents(tab); | |
372 process_exit_observer.Wait(); | |
373 } | |
374 | |
375 // Navigate the last remaining tab to a page that will hang and then | |
376 // close the tab. | |
377 ui_test_utils::NavigateToURL(browser(), infinite_unload_url); | |
378 tab = browser()->GetWebContentsAt(0); | |
379 { | |
380 ui_test_utils::WindowedNotificationObserver process_exit_observer( | |
381 content::NOTIFICATION_RENDERER_PROCESS_CLOSED, | |
382 content::NotificationService::AllSources()); | |
383 browser()->CloseTabContents(tab); | |
384 process_exit_observer.Wait(); | |
385 } | |
386 } | |
OLD | NEW |