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 // Note: if this test becomes flaky and times out during the final navigation, | |
236 // it might be due to an input event that is stopping the hang monitor. Check | |
237 // that StopHangMonitorTimeout doesn't stop while waiting for beforeunload or | |
238 // unload acks. | |
Charlie Reis
2012/04/06 22:34:14
We should update the last sentence now that we han
nasko
2012/04/10 00:16:37
Good point! Removed the note.
| |
239 IN_PROC_BROWSER_TEST_F(RenderViewHostTest, UnresponsiveCrossSiteNavigation) { | |
240 WebContents* tab = NULL; | |
241 WebContents* tab2 = NULL; | |
242 content::RenderProcessHost* rph = NULL; | |
243 base::ProcessHandle process; | |
244 FilePath doc_root; | |
245 | |
246 doc_root = doc_root.Append(FILE_PATH_LITERAL("content")); | |
247 doc_root = doc_root.Append(FILE_PATH_LITERAL("test")); | |
248 doc_root = doc_root.Append(FILE_PATH_LITERAL("data")); | |
249 | |
250 // Start two servers to enable cross-site navigations. | |
251 net::TestServer server(net::TestServer::TYPE_HTTP, | |
252 net::TestServer::kLocalhost, doc_root); | |
253 ASSERT_TRUE(server.Start()); | |
254 net::TestServer https_server(net::TestServer::TYPE_HTTPS, | |
255 net::TestServer::kLocalhost, doc_root); | |
256 ASSERT_TRUE(https_server.Start()); | |
257 | |
258 GURL infinite_beforeunload_url( | |
259 server.GetURL("files/infinite_beforeunload.html")); | |
260 GURL infinite_unload_url(server.GetURL("files/infinite_unload.html")); | |
261 GURL same_process_url(server.GetURL("files/english_page.html")); | |
262 GURL new_process_url(https_server.GetURL("files/english_page.html")); | |
263 | |
264 // Navigate the tab to the page which will lock up the process when we | |
265 // navigate away from it. | |
266 ui_test_utils::NavigateToURL(browser(), infinite_beforeunload_url); | |
267 tab = browser()->GetWebContentsAt(0); | |
268 rph = tab->GetRenderProcessHost(); | |
269 EXPECT_EQ(tab->GetURL(), infinite_beforeunload_url); | |
270 | |
271 // Remember the process prior to navigation, as we expect it to get killed. | |
272 process = rph->GetHandle(); | |
273 ASSERT_TRUE(process); | |
274 | |
275 { | |
276 ui_test_utils::WindowedNotificationObserver process_exit_observer( | |
277 content::NOTIFICATION_RENDERER_PROCESS_CLOSED, | |
Charlie Reis
2012/04/06 22:34:14
Might be nice if we had a more specific killed not
nasko
2012/04/10 00:16:37
As we chatted, there isn't a current notification
Charlie Reis
2012/04/10 01:19:35
No, but we can nest them without adding any flakin
nasko
2012/04/10 14:31:26
What would this add to the test? In your example,
Charlie Reis
2012/04/10 17:22:04
Thanks for adding it in patch set 6, since it ensu
| |
278 content::NotificationService::AllSources()); | |
279 ui_test_utils::NavigateToURL(browser(), new_process_url); | |
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 } | |
OLD | NEW |