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/app_modal_dialogs/app_modal_dialog.h" | |
9 #include "chrome/browser/ui/app_modal_dialogs/native_app_modal_dialog.h" | |
8 #include "chrome/browser/ui/browser.h" | 10 #include "chrome/browser/ui/browser.h" |
9 #include "chrome/test/base/in_process_browser_test.h" | 11 #include "chrome/test/base/in_process_browser_test.h" |
10 #include "chrome/test/base/ui_test_utils.h" | 12 #include "chrome/test/base/ui_test_utils.h" |
11 #include "content/browser/renderer_host/render_view_host_impl.h" | 13 #include "content/browser/renderer_host/render_view_host_impl.h" |
12 #include "content/browser/tab_contents/tab_contents.h" | 14 #include "content/browser/tab_contents/tab_contents.h" |
13 #include "content/common/view_messages.h" | 15 #include "content/common/view_messages.h" |
16 #include "content/public/browser/notification_service.h" | |
14 #include "content/public/browser/notification_types.h" | 17 #include "content/public/browser/notification_types.h" |
15 #include "content/public/browser/web_contents_observer.h" | 18 #include "content/public/browser/web_contents_observer.h" |
16 #include "net/base/host_port_pair.h" | 19 #include "net/base/host_port_pair.h" |
17 #include "net/base/net_util.h" | 20 #include "net/base/net_util.h" |
18 #include "net/test/test_server.h" | 21 #include "net/test/test_server.h" |
19 | 22 |
20 using content::RenderViewHostImpl; | 23 using content::RenderViewHostImpl; |
21 using content::WebContents; | 24 using content::WebContents; |
22 | 25 |
23 class RenderViewHostTest : public InProcessBrowserTest { | 26 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); | 224 ui_test_utils::NavigateToURL(browser(), test_url); |
222 EXPECT_TRUE(observer.base_url().is_empty()); | 225 EXPECT_TRUE(observer.base_url().is_empty()); |
223 EXPECT_EQ(1, observer.navigation_count()); | 226 EXPECT_EQ(1, observer.navigation_count()); |
224 | 227 |
225 // But should be set to the original page when reading MHTML. | 228 // But should be set to the original page when reading MHTML. |
226 test_url = net::FilePathToFileURL(test_server()->document_root().Append( | 229 test_url = net::FilePathToFileURL(test_server()->document_root().Append( |
227 FILE_PATH_LITERAL("google.mht"))); | 230 FILE_PATH_LITERAL("google.mht"))); |
228 ui_test_utils::NavigateToURL(browser(), test_url); | 231 ui_test_utils::NavigateToURL(browser(), test_url); |
229 EXPECT_EQ("http://www.google.com/", observer.base_url().spec()); | 232 EXPECT_EQ("http://www.google.com/", observer.base_url().spec()); |
230 } | 233 } |
234 | |
235 // Test that a hung renderer is killed after navigating away during cross-site | |
236 // navigation. | |
237 IN_PROC_BROWSER_TEST_F(RenderViewHostTest, UnresponsiveCrossSiteNavigation) { | |
238 WebContents* tab = NULL; | |
239 WebContents* tab2 = NULL; | |
240 content::RenderProcessHost* rph = NULL; | |
241 base::ProcessHandle process; | |
242 FilePath doc_root; | |
243 | |
244 doc_root = doc_root.Append(FILE_PATH_LITERAL("content")); | |
245 doc_root = doc_root.Append(FILE_PATH_LITERAL("test")); | |
246 doc_root = doc_root.Append(FILE_PATH_LITERAL("data")); | |
247 | |
248 // Start two servers to enable cross-site navigations. | |
249 net::TestServer server(net::TestServer::TYPE_HTTP, | |
250 net::TestServer::kLocalhost, doc_root); | |
251 ASSERT_TRUE(server.Start()); | |
252 net::TestServer https_server(net::TestServer::TYPE_HTTPS, | |
253 net::TestServer::kLocalhost, doc_root); | |
254 ASSERT_TRUE(https_server.Start()); | |
255 | |
256 GURL infinite_beforeunload_url( | |
257 server.GetURL("files/infinite_beforeunload.html")); | |
258 GURL infinite_unload_url(server.GetURL("files/infinite_unload.html")); | |
259 GURL same_process_url(server.GetURL("files/english_page.html")); | |
260 GURL new_process_url(https_server.GetURL("files/english_page.html")); | |
261 | |
262 // Navigate the tab to the page which will lock up the process when we | |
263 // navigate away from it. | |
264 ui_test_utils::NavigateToURL(browser(), infinite_beforeunload_url); | |
265 tab = browser()->GetWebContentsAt(0); | |
266 rph = tab->GetRenderProcessHost(); | |
267 EXPECT_EQ(tab->GetURL(), infinite_beforeunload_url); | |
268 | |
269 // Remember the process prior to navigation, as we expect it to get killed. | |
270 process = rph->GetHandle(); | |
271 ASSERT_TRUE(process); | |
272 | |
273 { | |
274 ui_test_utils::WindowedNotificationObserver process_exit_observer( | |
275 content::NOTIFICATION_RENDERER_PROCESS_CLOSED, | |
276 content::NotificationService::AllSources()); | |
277 ui_test_utils::NavigateToURL(browser(), new_process_url); | |
278 process_exit_observer.Wait(); | |
279 } | |
280 | |
281 // This should fail, because the navigation to the new URL results in | |
282 // the process getting killed. This is an indirect way to check for the | |
283 // process having been terminated. | |
284 EXPECT_FALSE(base::KillProcess(process, 1, false)); | |
285 | |
286 ui_test_utils::NavigateToURL(browser(), same_process_url); | |
287 tab = browser()->GetWebContentsAt(0); | |
288 rph = tab->GetRenderProcessHost(); | |
289 ASSERT_TRUE(tab != NULL); | |
290 EXPECT_EQ(tab->GetURL(), same_process_url); | |
291 | |
292 // Now, let's open another tab with the unresponsive page, which will cause | |
293 // the previous page and the unresponsive one to use the same process. | |
294 ui_test_utils::NavigateToURLWithDisposition(browser(), | |
295 infinite_unload_url, NEW_FOREGROUND_TAB, | |
296 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(), infinite_unload_url); | |
301 EXPECT_EQ(rph, tab2->GetRenderProcessHost()); | |
302 | |
303 process = rph->GetHandle(); | |
304 ASSERT_TRUE(process); | |
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 { | |
310 ui_test_utils::WindowedNotificationObserver process_exit_observer( | |
311 content::NOTIFICATION_RENDERER_PROCESS_HANG, | |
312 content::NotificationService::AllSources()); | |
313 ui_test_utils::NavigateToURL(browser(), new_process_url); | |
314 process_exit_observer.Wait(); | |
315 } | |
316 | |
317 EXPECT_TRUE(base::KillProcess(process, 2, false)); | |
318 } | |
319 | |
320 // Test that a hung renderer is killed when we are closing the page. | |
321 IN_PROC_BROWSER_TEST_F(RenderViewHostTest, UnresponsiveClosePage) { | |
322 WebContents* tab = NULL; | |
323 FilePath doc_root; | |
324 | |
325 doc_root = doc_root.Append(FILE_PATH_LITERAL("content")); | |
326 doc_root = doc_root.Append(FILE_PATH_LITERAL("test")); | |
327 doc_root = doc_root.Append(FILE_PATH_LITERAL("data")); | |
328 | |
329 net::TestServer server(net::TestServer::TYPE_HTTP, | |
330 net::TestServer::kLocalhost, doc_root); | |
331 ASSERT_TRUE(server.Start()); | |
332 net::TestServer https_server(net::TestServer::TYPE_HTTPS, | |
333 net::TestServer::kLocalhost, doc_root); | |
334 ASSERT_TRUE(https_server.Start()); | |
335 | |
336 GURL infinite_beforeunload_url( | |
337 server.GetURL("files/infinite_beforeunload.html")); | |
338 GURL infinite_unload_url(server.GetURL("files/infinite_unload.html")); | |
339 GURL new_process_url(https_server.GetURL("files/english_page.html")); | |
340 GURL prompt_infinite_url(server.GetURL( | |
341 "files/prompt_beforeunload_infinite_unload.html")); | |
342 | |
343 ui_test_utils::NavigateToURL(browser(), new_process_url); | |
344 | |
345 // Navigate a tab to a page which will spin into an infinite loop in the | |
346 // unload handler after prompting in the beforeunload handler, tying up the | |
347 // process when we navigate away from it. | |
Charlie Reis
2012/04/10 01:19:35
nit: when we try to close it.
nasko
2012/04/10 14:31:26
Done.
| |
348 ui_test_utils::NavigateToURLWithDisposition(browser(), | |
349 prompt_infinite_url, NEW_FOREGROUND_TAB, | |
350 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | |
351 tab = browser()->GetWebContentsAt(1); | |
352 { | |
353 ui_test_utils::WindowedNotificationObserver process_exit_observer( | |
354 content::NOTIFICATION_RENDERER_PROCESS_TERMINATED, | |
355 content::NotificationService::AllSources()); | |
356 browser()->CloseTabContents(tab); | |
357 AppModalDialog* alert = ui_test_utils::WaitForAppModalDialog(); | |
358 alert->native_dialog()->AcceptAppModalDialog(); | |
359 process_exit_observer.Wait(); | |
360 } | |
361 | |
362 // Navigate a tab to a page which will spin into an infinite loop in the | |
363 // beforeunload handler, tying up the process when we navigate away from it. | |
364 ui_test_utils::NavigateToURLWithDisposition(browser(), | |
365 infinite_beforeunload_url, NEW_FOREGROUND_TAB, | |
366 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | |
367 tab = browser()->GetWebContentsAt(1); | |
368 { | |
369 ui_test_utils::WindowedNotificationObserver process_exit_observer( | |
370 content::NOTIFICATION_RENDERER_PROCESS_TERMINATED, | |
371 content::NotificationService::AllSources()); | |
372 browser()->CloseTabContents(tab); | |
373 process_exit_observer.Wait(); | |
374 } | |
375 | |
376 // Navigate a tab to a page which will spin into an infinite loop in the | |
377 // unload handler, tying up the process when we navigate away from it. | |
378 ui_test_utils::NavigateToURLWithDisposition(browser(), | |
379 infinite_unload_url, NEW_FOREGROUND_TAB, | |
380 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | |
381 tab = browser()->GetWebContentsAt(1); | |
382 { | |
383 ui_test_utils::WindowedNotificationObserver process_exit_observer( | |
384 content::NOTIFICATION_RENDERER_PROCESS_TERMINATED, | |
385 content::NotificationService::AllSources()); | |
386 browser()->CloseTabContents(tab); | |
387 process_exit_observer.Wait(); | |
388 } | |
389 | |
390 ui_test_utils::NavigateToURL(browser(), infinite_unload_url); | |
Charlie Reis
2012/04/10 01:19:35
Comment for this last one?
nasko
2012/04/10 14:31:26
Done.
| |
391 tab = browser()->GetWebContentsAt(0); | |
392 { | |
393 ui_test_utils::WindowedNotificationObserver process_exit_observer( | |
394 content::NOTIFICATION_RENDERER_PROCESS_CLOSED, | |
395 content::NotificationService::AllSources()); | |
396 browser()->CloseTabContents(tab); | |
397 process_exit_observer.Wait(); | |
398 } | |
399 } | |
OLD | NEW |