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/file_util.h" | 5 #include "base/file_util.h" |
6 #include "base/memory/ref_counted.h" | 6 #include "base/memory/ref_counted.h" |
7 #include "base/path_service.h" | 7 #include "base/path_service.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 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 &success)); | 77 &success)); |
78 EXPECT_TRUE(success); | 78 EXPECT_TRUE(success); |
79 new_tab_observer.Wait(); | 79 new_tab_observer.Wait(); |
80 | 80 |
81 // Opens in new tab. | 81 // Opens in new tab. |
82 EXPECT_EQ(2, browser()->tab_count()); | 82 EXPECT_EQ(2, browser()->tab_count()); |
83 EXPECT_EQ(1, browser()->active_index()); | 83 EXPECT_EQ(1, browser()->active_index()); |
84 | 84 |
85 // Wait for the navigation in the new tab to finish, if it hasn't. | 85 // Wait for the navigation in the new tab to finish, if it hasn't. |
86 ui_test_utils::WaitForLoadStop(browser()->GetSelectedWebContents()); | 86 ui_test_utils::WaitForLoadStop(browser()->GetSelectedWebContents()); |
87 EXPECT_EQ("/files/title2.html", | 87 EXPECT_EQ("/files/navigate_opener.html", |
88 browser()->GetSelectedWebContents()->GetURL().path()); | 88 browser()->GetSelectedWebContents()->GetURL().path()); |
89 EXPECT_EQ(1, browser()->active_index()); | 89 EXPECT_EQ(1, browser()->active_index()); |
90 | 90 |
91 // Should have the same SiteInstance. | 91 // Should have the same SiteInstance. |
92 scoped_refptr<SiteInstance> blank_site_instance( | 92 scoped_refptr<SiteInstance> blank_site_instance( |
93 browser()->GetSelectedWebContents()->GetSiteInstance()); | 93 browser()->GetSelectedWebContents()->GetSiteInstance()); |
94 EXPECT_EQ(orig_site_instance, blank_site_instance); | 94 EXPECT_EQ(orig_site_instance, blank_site_instance); |
95 | 95 |
96 // We should have access to the opened tab's location. | 96 // We should have access to the opened tab's location. |
97 browser()->ActivateTabAt(0, true); | 97 browser()->ActivateTabAt(0, true); |
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
330 EXPECT_EQ(0, browser()->active_index()); | 330 EXPECT_EQ(0, browser()->active_index()); |
331 EXPECT_EQ("/files/title2.html", | 331 EXPECT_EQ("/files/title2.html", |
332 browser()->GetSelectedWebContents()->GetURL().path()); | 332 browser()->GetSelectedWebContents()->GetURL().path()); |
333 | 333 |
334 // Should have the same SiteInstance. | 334 // Should have the same SiteInstance. |
335 scoped_refptr<SiteInstance> noref_site_instance( | 335 scoped_refptr<SiteInstance> noref_site_instance( |
336 browser()->GetSelectedWebContents()->GetSiteInstance()); | 336 browser()->GetSelectedWebContents()->GetSiteInstance()); |
337 EXPECT_EQ(orig_site_instance, noref_site_instance); | 337 EXPECT_EQ(orig_site_instance, noref_site_instance); |
338 } | 338 } |
339 | 339 |
| 340 // Test for crbug.com/116192. Targeted links should still work after the |
| 341 // named target window has swapped processes. |
| 342 IN_PROC_BROWSER_TEST_F(RenderViewHostManagerTest, |
| 343 AllowTargetedNavigationsAfterSwap) { |
| 344 // Start two servers with different sites. |
| 345 ASSERT_TRUE(test_server()->Start()); |
| 346 net::TestServer https_server( |
| 347 net::TestServer::TYPE_HTTPS, |
| 348 net::TestServer::kLocalhost, |
| 349 FilePath(FILE_PATH_LITERAL("chrome/test/data"))); |
| 350 ASSERT_TRUE(https_server.Start()); |
| 351 |
| 352 // Load a page with links that open in a new window. |
| 353 std::string replacement_path; |
| 354 ASSERT_TRUE(GetFilePathWithHostAndPortReplacement( |
| 355 "files/click-noreferrer-links.html", |
| 356 https_server.host_port_pair(), |
| 357 &replacement_path)); |
| 358 ui_test_utils::NavigateToURL(browser(), |
| 359 test_server()->GetURL(replacement_path)); |
| 360 |
| 361 // Get the original SiteInstance for later comparison. |
| 362 scoped_refptr<SiteInstance> orig_site_instance( |
| 363 browser()->GetSelectedWebContents()->GetSiteInstance()); |
| 364 EXPECT_TRUE(orig_site_instance != NULL); |
| 365 |
| 366 // Test clicking a target=foo link. |
| 367 ui_test_utils::WindowedNotificationObserver new_tab_observer( |
| 368 content::NOTIFICATION_TAB_ADDED, |
| 369 content::Source<content::WebContentsDelegate>(browser())); |
| 370 bool success = false; |
| 371 EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( |
| 372 browser()->GetSelectedWebContents()->GetRenderViewHost(), L"", |
| 373 L"window.domAutomationController.send(clickSameSiteTargetedLink());", |
| 374 &success)); |
| 375 EXPECT_TRUE(success); |
| 376 new_tab_observer.Wait(); |
| 377 |
| 378 // Opens in new tab. |
| 379 EXPECT_EQ(2, browser()->tab_count()); |
| 380 EXPECT_EQ(1, browser()->active_index()); |
| 381 |
| 382 // Wait for the navigation in the new tab to finish, if it hasn't. |
| 383 ui_test_utils::WaitForLoadStop(browser()->GetSelectedWebContents()); |
| 384 EXPECT_EQ("/files/navigate_opener.html", |
| 385 browser()->GetSelectedWebContents()->GetURL().path()); |
| 386 EXPECT_EQ(1, browser()->active_index()); |
| 387 |
| 388 // Should have the same SiteInstance. |
| 389 scoped_refptr<SiteInstance> blank_site_instance( |
| 390 browser()->GetSelectedWebContents()->GetSiteInstance()); |
| 391 EXPECT_EQ(orig_site_instance, blank_site_instance); |
| 392 |
| 393 // Now navigate the new tab to a different site. |
| 394 //browser()->ActivateTabAt(1, true); |
| 395 content::WebContents* new_contents = browser()->GetSelectedWebContents(); |
| 396 ui_test_utils::NavigateToURL(browser(), |
| 397 https_server.GetURL("files/title1.html")); |
| 398 scoped_refptr<SiteInstance> new_site_instance( |
| 399 browser()->GetSelectedWebContents()->GetSiteInstance()); |
| 400 EXPECT_NE(orig_site_instance, new_site_instance); |
| 401 |
| 402 // Clicking the original link in the first tab should cause us to swap back. |
| 403 browser()->ActivateTabAt(0, true); |
| 404 ui_test_utils::WindowedNotificationObserver navigation_observer( |
| 405 content::NOTIFICATION_NAV_ENTRY_COMMITTED, |
| 406 content::Source<content::NavigationController>( |
| 407 &new_contents->GetController())); |
| 408 EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( |
| 409 browser()->GetSelectedWebContents()->GetRenderViewHost(), L"", |
| 410 L"window.domAutomationController.send(clickSameSiteTargetedLink());", |
| 411 &success)); |
| 412 EXPECT_TRUE(success); |
| 413 navigation_observer.Wait(); |
| 414 |
| 415 // Should have swapped back and shown the new tab again. |
| 416 EXPECT_EQ(1, browser()->active_index()); |
| 417 scoped_refptr<SiteInstance> revisit_site_instance( |
| 418 browser()->GetSelectedWebContents()->GetSiteInstance()); |
| 419 EXPECT_EQ(orig_site_instance, revisit_site_instance); |
| 420 } |
| 421 |
| 422 // Test for crbug.com/116192. Navigations to a window's opener should |
| 423 // still work after a process swap. |
| 424 IN_PROC_BROWSER_TEST_F(RenderViewHostManagerTest, |
| 425 AllowTargetedNavigationsInOpenerAfterSwap) { |
| 426 // Start two servers with different sites. |
| 427 ASSERT_TRUE(test_server()->Start()); |
| 428 net::TestServer https_server( |
| 429 net::TestServer::TYPE_HTTPS, |
| 430 net::TestServer::kLocalhost, |
| 431 FilePath(FILE_PATH_LITERAL("chrome/test/data"))); |
| 432 ASSERT_TRUE(https_server.Start()); |
| 433 |
| 434 // Load a page with links that open in a new window. |
| 435 std::string replacement_path; |
| 436 ASSERT_TRUE(GetFilePathWithHostAndPortReplacement( |
| 437 "files/click-noreferrer-links.html", |
| 438 https_server.host_port_pair(), |
| 439 &replacement_path)); |
| 440 ui_test_utils::NavigateToURL(browser(), |
| 441 test_server()->GetURL(replacement_path)); |
| 442 |
| 443 // Get the original tab and SiteInstance for later comparison. |
| 444 content::WebContents* orig_contents = browser()->GetSelectedWebContents(); |
| 445 scoped_refptr<SiteInstance> orig_site_instance( |
| 446 browser()->GetSelectedWebContents()->GetSiteInstance()); |
| 447 EXPECT_TRUE(orig_site_instance != NULL); |
| 448 |
| 449 // Test clicking a target=foo link. |
| 450 ui_test_utils::WindowedNotificationObserver new_tab_observer( |
| 451 content::NOTIFICATION_TAB_ADDED, |
| 452 content::Source<content::WebContentsDelegate>(browser())); |
| 453 bool success = false; |
| 454 EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( |
| 455 browser()->GetSelectedWebContents()->GetRenderViewHost(), L"", |
| 456 L"window.domAutomationController.send(clickSameSiteTargetedLink());", |
| 457 &success)); |
| 458 EXPECT_TRUE(success); |
| 459 new_tab_observer.Wait(); |
| 460 |
| 461 // Opens in new tab. |
| 462 EXPECT_EQ(2, browser()->tab_count()); |
| 463 EXPECT_EQ(1, browser()->active_index()); |
| 464 |
| 465 // Wait for the navigation in the new tab to finish, if it hasn't. |
| 466 ui_test_utils::WaitForLoadStop(browser()->GetSelectedWebContents()); |
| 467 EXPECT_EQ("/files/navigate_opener.html", |
| 468 browser()->GetSelectedWebContents()->GetURL().path()); |
| 469 EXPECT_EQ(1, browser()->active_index()); |
| 470 |
| 471 // Should have the same SiteInstance. |
| 472 scoped_refptr<SiteInstance> blank_site_instance( |
| 473 browser()->GetSelectedWebContents()->GetSiteInstance()); |
| 474 EXPECT_EQ(orig_site_instance, blank_site_instance); |
| 475 |
| 476 // Now navigate the original (opener) tab to a different site. |
| 477 browser()->ActivateTabAt(0, true); |
| 478 ui_test_utils::NavigateToURL(browser(), |
| 479 https_server.GetURL("files/title1.html")); |
| 480 scoped_refptr<SiteInstance> new_site_instance( |
| 481 browser()->GetSelectedWebContents()->GetSiteInstance()); |
| 482 EXPECT_NE(orig_site_instance, new_site_instance); |
| 483 |
| 484 // The opened tab should be able to navigate the opener back to its process. |
| 485 browser()->ActivateTabAt(1, true); |
| 486 ui_test_utils::WindowedNotificationObserver navigation_observer( |
| 487 content::NOTIFICATION_NAV_ENTRY_COMMITTED, |
| 488 content::Source<content::NavigationController>( |
| 489 &orig_contents->GetController())); |
| 490 EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( |
| 491 browser()->GetSelectedWebContents()->GetRenderViewHost(), L"", |
| 492 L"window.domAutomationController.send(navigateOpener());", |
| 493 &success)); |
| 494 EXPECT_TRUE(success); |
| 495 navigation_observer.Wait(); |
| 496 |
| 497 // Active tab should not have changed. |
| 498 EXPECT_EQ(1, browser()->active_index()); |
| 499 |
| 500 // Should have swapped back into this process. |
| 501 browser()->ActivateTabAt(0, true); |
| 502 scoped_refptr<SiteInstance> revisit_site_instance( |
| 503 browser()->GetSelectedWebContents()->GetSiteInstance()); |
| 504 EXPECT_EQ(orig_site_instance, revisit_site_instance); |
| 505 } |
| 506 |
340 // Test for crbug.com/76666. A cross-site navigation that fails with a 204 | 507 // Test for crbug.com/76666. A cross-site navigation that fails with a 204 |
341 // error should not make us ignore future renderer-initiated navigations. | 508 // error should not make us ignore future renderer-initiated navigations. |
342 IN_PROC_BROWSER_TEST_F(RenderViewHostManagerTest, ClickLinkAfter204Error) { | 509 IN_PROC_BROWSER_TEST_F(RenderViewHostManagerTest, ClickLinkAfter204Error) { |
343 // Start two servers with different sites. | 510 // Start two servers with different sites. |
344 ASSERT_TRUE(test_server()->Start()); | 511 ASSERT_TRUE(test_server()->Start()); |
345 net::TestServer https_server( | 512 net::TestServer https_server( |
346 net::TestServer::TYPE_HTTPS, | 513 net::TestServer::TYPE_HTTPS, |
347 net::TestServer::kLocalhost, | 514 net::TestServer::kLocalhost, |
348 FilePath(FILE_PATH_LITERAL("chrome/test/data"))); | 515 FilePath(FILE_PATH_LITERAL("chrome/test/data"))); |
349 ASSERT_TRUE(https_server.Start()); | 516 ASSERT_TRUE(https_server.Start()); |
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
607 // Now navigate to a different instance so that we swap out again. | 774 // Now navigate to a different instance so that we swap out again. |
608 ui_test_utils::NavigateToURL(browser(), | 775 ui_test_utils::NavigateToURL(browser(), |
609 https_server.GetURL("files/title2.html")); | 776 https_server.GetURL("files/title2.html")); |
610 rvh_observers.AddObserverToRVH(browser()->GetSelectedWebContents()-> | 777 rvh_observers.AddObserverToRVH(browser()->GetSelectedWebContents()-> |
611 GetRenderViewHost()); | 778 GetRenderViewHost()); |
612 | 779 |
613 // This used to leak a render view host. | 780 // This used to leak a render view host. |
614 browser()->CloseTabContents(browser()->GetSelectedWebContents()); | 781 browser()->CloseTabContents(browser()->GetSelectedWebContents()); |
615 EXPECT_EQ(0U, rvh_observers.GetNumObservers()); | 782 EXPECT_EQ(0U, rvh_observers.GetNumObservers()); |
616 } | 783 } |
OLD | NEW |